Merge branch 'new-race-mode' into test
This commit is contained in:
@@ -113,17 +113,39 @@ const recoverData = (battleInfo, {force = false, arrowOnly = false} = {}) => {
|
||||
audioManager.play(audioKey, false);
|
||||
}
|
||||
tips.value = nextTips;
|
||||
uni.$emit("update-tips", nextTips);
|
||||
// 同步写入 Pinia store,供 HeaderProgress 通过 immediate watch 在 onMounted 时立即读取
|
||||
// 规避 WeChat 小程序 onShow 在组件 onMounted 之前触发导致 uni.$emit 事件丢失的时序问题
|
||||
store.updateTips(nextTips);
|
||||
// force 模式下改为在 nextTick 内发送 update-tips,规避 WeChat 小程序
|
||||
// onShow 与 onMounted 时序问题导致 HeaderProgress 监听器尚未注册的边界情况
|
||||
if (!force) {
|
||||
uni.$emit("update-tips", nextTips);
|
||||
}
|
||||
// redPlayer 已在上方 find() 确认:不为 null 则当前射手在红队
|
||||
uni.$emit("update-remain", {reset: true, value: 15, team: redPlayer?'red':'blue'});
|
||||
const targetTeam = redPlayer ? 'red' : 'blue';
|
||||
if (force) {
|
||||
const remain = (Date.now() - battleInfo.current.startTime) / 1000;
|
||||
console.log(`当前轮已进行${remain}秒`);
|
||||
if (remain > 0 && remain < 15) {
|
||||
updateRemainSecond.value = 15 - remain - 0.2
|
||||
// force 模式下 start.value 刚由 null 变 true,Vue 异步调度渲染,
|
||||
// ShootProgress2(v-if="start")尚未挂载,update-remain 事件会被丢弃。
|
||||
// 同时 HeaderProgress 对含"重回"的 tips 拦截音频,倒计时无法依赖
|
||||
// onAudioEnded 驱动,需在 nextTick 后直接启动。
|
||||
const elapsed = (Date.now() - battleInfo.current.startTime) / 1000;
|
||||
console.log(`当前轮已进行${elapsed}秒`);
|
||||
if (elapsed > 0 && elapsed < 15) {
|
||||
updateRemainSecond.value = 15 - elapsed - 0.2;
|
||||
}
|
||||
const actualRemain = updateRemainSecond.value;
|
||||
nextTick(() => {
|
||||
// 在 nextTick 内统一发送,确保 ShootProgress2 和 HeaderProgress 均已挂载
|
||||
uni.$emit("update-tips", nextTips);
|
||||
uni.$emit("update-remain", {reset: true, value: 15, team: targetTeam});
|
||||
// 重置动画完成后,直接启动倒计时(无需依赖音频结束回调)
|
||||
setTimeout(() => {
|
||||
uni.$emit("update-remain", {stop: false, value: actualRemain, team: targetTeam});
|
||||
}, 100);
|
||||
});
|
||||
} else {
|
||||
updateRemainSecond.value = battleInfo.readyTime
|
||||
uni.$emit("update-remain", {reset: true, value: 15, team: targetTeam});
|
||||
updateRemainSecond.value = battleInfo.readyTime;
|
||||
}
|
||||
} else {
|
||||
currentRound.value = battleInfo.current.round || 1;
|
||||
@@ -176,7 +198,7 @@ function onNewRound(msg, prevRound) {
|
||||
isFinalShoot.value = msg.current.goldRound;
|
||||
// 决金箭轮每人只射一箭,重置箭数显示为 (0/1)
|
||||
if (msg.current.goldRound) {
|
||||
uni.$emit("update-shot", { currentShot: 0, totalShot: 1 });
|
||||
store.updateShotInfo(0, 1);
|
||||
}
|
||||
// 用传入的 prevRound(捕获时刻的旧轮次)展示结算 Tip,与进度条 currentRound 解耦
|
||||
roundTipRound.value = prevRound;
|
||||
@@ -228,6 +250,9 @@ async function onReceiveMessage(msg) {
|
||||
|
||||
onLoad(async (options) => {
|
||||
if (options.battleId) battleId.value = options.battleId;
|
||||
// 重置箭数和提示文案,防止因 Pinia 保留上一场比赛的旧值而错误展示
|
||||
store.updateShotInfo(0, 0);
|
||||
store.updateTips("");
|
||||
// uni.enableAlertBeforeUnload({
|
||||
// message: "离开比赛可能导致比赛失败,是否继续?",
|
||||
// success: (res) => {
|
||||
@@ -263,9 +288,16 @@ onShow(async () => {
|
||||
url: `/pages/friend-battle-result?battleId=${result.matchId}`,
|
||||
});
|
||||
} else {
|
||||
// shootNumber 来自后端,恢复状态时同步 totalShot,防止 BattleStart 不重新推送导致显示错误
|
||||
if (result.shootNumber) {
|
||||
uni.$emit("update-shot", { currentShot: 0, totalShot: result.shootNumber });
|
||||
if (result.status !== 0) {
|
||||
// 比赛进行中,从后端恢复箭数(测距阶段不展示)
|
||||
if (result.shootNumber) {
|
||||
// current.index 为 0 基的已射箭数(0=尚未射出),与 ShootResult 累加语义一致
|
||||
// 注意:不再 +1,避免重进时与后续 ShootResult 自增形成双重计数导致超出 totalShot
|
||||
store.updateShotInfo(result.current?.index ?? 0, result.shootNumber);
|
||||
}
|
||||
} else {
|
||||
// 测距阶段重置箭数,防止 ImmediateWatcher 读取 Pinia 保留的旧值
|
||||
store.updateShotInfo(0, 0);
|
||||
}
|
||||
recoverData(result, {force: true});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user