update:优化语音和训练文案
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
nextTick,
|
||||
} from "vue";
|
||||
import audioManager, {
|
||||
getTrainingEndAudioKey,
|
||||
getTrainingStartAudioKey,
|
||||
RHYTHM_SHOOT_WINDOW_AUDIO_KEY,
|
||||
} from "@/audioManager";
|
||||
@@ -111,6 +112,8 @@ const props = defineProps({
|
||||
},
|
||||
});
|
||||
|
||||
const emit = defineEmits(["rhythm-round-complete"]);
|
||||
|
||||
const trainingTitleIconMap = Object.freeze({
|
||||
base:
|
||||
"https://static.shelingxingqiu.com/shootmini/static/training-difficulty-design/text-icon-jcxl.png",
|
||||
@@ -143,6 +146,7 @@ let rhythmCountdownTimer = null;
|
||||
let rhythmTransitionTimer = null;
|
||||
let rhythmServerClockOffsetMs = 0;
|
||||
let rhythmSyncGeneration = 0;
|
||||
let rhythmRoundCompletionTimer = null;
|
||||
|
||||
const isRhythmTraining = computed(() => props.trainingType === "rhythm");
|
||||
const isStabilityTraining = computed(
|
||||
@@ -306,6 +310,30 @@ const getRhythmRoundRemainingMs = () => {
|
||||
);
|
||||
};
|
||||
|
||||
const clearRhythmRoundCompletionTimer = () => {
|
||||
if (rhythmRoundCompletionTimer !== null) {
|
||||
clearTimeout(rhythmRoundCompletionTimer);
|
||||
rhythmRoundCompletionTimer = null;
|
||||
}
|
||||
};
|
||||
|
||||
// 与当前显示的倒计时一起计时;消息校准不重建此任务,避免同一轮重复计数。
|
||||
const scheduleRhythmRoundCompletion = (remainingMs) => {
|
||||
if (
|
||||
rhythmRoundCompletionTimer !== null ||
|
||||
!props.start ||
|
||||
!isRhythmTraining.value ||
|
||||
remainingMs <= 0
|
||||
) return;
|
||||
|
||||
rhythmRoundCompletionTimer = setTimeout(() => {
|
||||
rhythmRoundCompletionTimer = null;
|
||||
if (!props.start || !isRhythmTraining.value) return;
|
||||
emit("rhythm-round-complete");
|
||||
scheduleRhythmRoundCompletion(rhythmRoundDurationMs.value);
|
||||
}, remainingMs);
|
||||
};
|
||||
|
||||
const updateRhythmShootWindow = (isInWindow) => {
|
||||
const nextIsInWindow = Boolean(isInWindow);
|
||||
const enteredShootWindow =
|
||||
@@ -364,7 +392,8 @@ const syncRhythmCountdown = async () => {
|
||||
const generation = ++rhythmSyncGeneration;
|
||||
clearRhythmTimers();
|
||||
|
||||
if (!isRhythmTraining.value) {
|
||||
if (!isRhythmTraining.value || !props.start) {
|
||||
clearRhythmRoundCompletionTimer();
|
||||
rhythmTransitionStyle.value = "none";
|
||||
rhythmRemainingMs.value = 0;
|
||||
rhythmRemainingSeconds.value = 0;
|
||||
@@ -382,6 +411,7 @@ const syncRhythmCountdown = async () => {
|
||||
!validRhythmShootTime.value ||
|
||||
!normalizeTimestamp(props.shootWindowStart)
|
||||
) {
|
||||
clearRhythmRoundCompletionTimer();
|
||||
rhythmTransitionStyle.value = "none";
|
||||
rhythmRemainingMs.value = 0;
|
||||
rhythmRemainingSeconds.value = 0;
|
||||
@@ -391,6 +421,7 @@ const syncRhythmCountdown = async () => {
|
||||
|
||||
rhythmTransitionStyle.value = "none";
|
||||
rhythmRemainingMs.value = getRhythmRoundRemainingMs();
|
||||
scheduleRhythmRoundCompletion(rhythmRemainingMs.value);
|
||||
rhythmRemainingSeconds.value = Math.ceil(rhythmRemainingMs.value / 1000);
|
||||
updateRhythmShootWindow(
|
||||
rhythmRemainingMs.value > 0 &&
|
||||
@@ -462,6 +493,7 @@ watch(
|
||||
|
||||
watch(
|
||||
() => [
|
||||
props.start,
|
||||
props.trainingType,
|
||||
props.roundTime,
|
||||
props.shootTime,
|
||||
@@ -493,7 +525,7 @@ async function onReceiveMessage(msg) {
|
||||
audioManager.play("比赛开始");
|
||||
}
|
||||
} else if (msg.type === MESSAGETYPESV2.BattleEnd) {
|
||||
audioManager.play("练习结束", false);
|
||||
audioManager.play(getTrainingEndAudioKey(msg.completed), false);
|
||||
} else if (msg.type === MESSAGETYPESV2.ShootResult) {
|
||||
// 精准和节奏训练由页面统一处理专属结果语音,其他训练保持原播放链路。
|
||||
if (props.externalShootResultAudio) return;
|
||||
@@ -550,6 +582,7 @@ onBeforeUnmount(() => {
|
||||
clearTimer();
|
||||
rhythmSyncGeneration += 1;
|
||||
clearRhythmTimers();
|
||||
clearRhythmRoundCompletionTimer();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user