feat(新年活动): 补充弹幕翻译,补充注释

This commit is contained in:
hzj 2026-01-04 18:49:53 +08:00
parent 996e5dbd5f
commit 995b2fba4c
4 changed files with 41 additions and 29 deletions

View File

@ -441,5 +441,8 @@
"Spend 50000 coins in the game ({currentValue}/{targetValue})": "أنفق 50000 عملة في اللعبة ({currentValue}/{targetValue})",
"Gifts: 5 gifts({currentValue}/{targetValue})": "هدايا: 5 هدايا({currentValue}/{targetValue})",
"exchange_success_coins": "تم تبادل {amount} عملة بنجاح",
"exchange_failed_coins": "فشل التبادل لـ {amount} عملة، يرجى المحاولة لاحقاً."
"exchange_failed_coins": "فشل التبادل لـ {amount} عملة، يرجى المحاولة لاحقاً.",
"barrage_won_prize": "فاز {nickname} بـ {prizeName}",
"barrage_won_the_prize": "فاز {nickname} بـ {prizeName}"
}

View File

@ -441,5 +441,8 @@
"Spend 50000 coins in the game ({currentValue}/{targetValue})": "Spend 50000 coins in the game ({currentValue}/{targetValue})",
"Gifts: 5 gifts({currentValue}/{targetValue})": "Gifts: 5 gifts({currentValue}/{targetValue})",
"exchange_success_coins": "Successfully exchanged {amount} coins",
"exchange_failed_coins": "Exchange failed for {amount} coins, please try again later."
"exchange_failed_coins": "Exchange failed for {amount} coins, please try again later.",
"barrage_won_prize": "{nickname} won {prizeName}",
"barrage_won_the_prize": "{nickname} won the {prizeName}"
}

View File

@ -441,5 +441,8 @@
"Spend 50000 coins in the game ({currentValue}/{targetValue})": "在游戏内消费50000金币 ({currentValue}/{targetValue})",
"Gifts: 5 gifts({currentValue}/{targetValue})": "礼物: 5个礼物({currentValue}/{targetValue})",
"exchange_success_coins": "成功兑换 {amount} 金币",
"exchange_failed_coins": "兑换 {amount} 金币失败,请稍后重试。"
"exchange_failed_coins": "兑换 {amount} 金币失败,请稍后重试。",
"barrage_won_prize": "{nickname} 赢得了 {prizeName}",
"barrage_won_the_prize": "{nickname} 赢得了 {prizeName}"
}

View File

@ -64,7 +64,7 @@ import { ref, computed, onMounted, onUnmounted, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { handleAvatarImageError } from '@/utils/imageHandler.js'
const { locale } = useI18n()
const { locale, t } = useI18n()
const props = defineProps({
barrageList: {
@ -91,16 +91,17 @@ const props = defineProps({
const tracks = ref([[], []]) //
const idCounter = ref(0) // ID
const currentIndex = ref(0) //
const currentIndex = ref(0) //
//
const visibleTracks = computed(() => tracks.value.filter((track) => track.length > 0))
//
const barrageText = (item) => {
const params = { nickname: item.nickname, prizeName: item.prizeName }
return item.prizeType == 'GOLD' || item.prizeType == 'MONEY'
? `${item.nickname} won ${item.prizeName}`
: `${item.nickname} won the ${item.prizeName}`
? t('barrage_won_prize', params)
: t('barrage_won_the_prize', params)
}
//
@ -135,14 +136,14 @@ const getBarrageStyle = (item) => {
const generateBarrageProps = (item) => {
const textLength = barrageText(item).length
return {
duration: Math.max(8 - textLength * 0.2, 5) * (100 / props.speed), //
startPos: Math.floor(Math.random() * 21) - 10, //
duration: Math.max(8 - textLength * 0.2, 5) * (100 / props.speed), // 0.25
startPos: Math.floor(Math.random() * 21) - 10, // -1010
}
}
//
const addToTrack = (item) => {
//
//
const trackIndex = tracks.value.reduce(
(minIndex, track, index) => (track.length < tracks.value[minIndex].length ? index : minIndex),
0
@ -151,14 +152,14 @@ const addToTrack = (item) => {
if (tracks.value[trackIndex].length < props.maxItems) {
tracks.value[trackIndex].push({
...item,
id: idCounter.value++,
id: idCounter.value++, //
delay: Math.random() * 4, // 0-4
...generateBarrageProps(item),
})
}
}
//
//
const cleanCompleted = () => {
tracks.value.forEach((track) => {
for (let i = track.length - 1; i >= 0; i--) {
@ -169,7 +170,7 @@ const cleanCompleted = () => {
})
}
//
//
const handleAnimationEnd = (id) => {
tracks.value.forEach((track) => {
const item = track.find((item) => item.id === id)
@ -181,43 +182,45 @@ const handleAnimationEnd = (id) => {
const getNextBarrage = () => {
if (props.barrageList.length === 0) return null
//
const item = props.barrageList[currentIndex.value]
currentIndex.value = (currentIndex.value + 1) % props.barrageList.length
const item = props.barrageList[currentIndex.value] //
currentIndex.value = (currentIndex.value + 1) % props.barrageList.length //0
return { ...item } //
}
//
let barrageInterval = null
//
const startBarrage = () => {
barrageInterval = setInterval(() => {
cleanCompleted()
cleanCompleted() //
const nextBarrage = getNextBarrage()
const nextBarrage = getNextBarrage() //
if (nextBarrage) {
addToTrack(nextBarrage)
addToTrack(nextBarrage) //
}
}, props.loopInterval)
}
onMounted(startBarrage)
onUnmounted(() => clearInterval(barrageInterval))
onMounted(() => {
startBarrage() //
})
onUnmounted(() => {
clearInterval(barrageInterval) //
})
//
watch(
() => props.barrageList,
(newList) => {
//
currentIndex.value = 0
currentIndex.value = 0 //
clearInterval(barrageInterval) //
//
if (newList.length === 0) {
clearInterval(barrageInterval)
} else {
//
clearInterval(barrageInterval)
startBarrage()
if (newList.length !== 0) {
startBarrage() //
}
},
{ deep: true }