Merge branch 'test' into feat-vip
This commit is contained in:
@@ -315,7 +315,7 @@ function goBack() {
|
||||
<Container
|
||||
:bgType="data.mode > 3 ? -1 : 0"
|
||||
bgColor="#000000"
|
||||
:onBack="goBack"
|
||||
:onBack="exit"
|
||||
>
|
||||
|
||||
<!-- ----- Banner 区:game 胜负展示图(仅 NvN 对抗模式)----- -->
|
||||
|
||||
+238
-2
@@ -1,19 +1,23 @@
|
||||
<script setup>
|
||||
import {onMounted, ref} from "vue";
|
||||
import {onMounted, onUnmounted, ref} from "vue";
|
||||
import {onShareAppMessage, onShareTimeline, onShow} from "@dcloudio/uni-app";
|
||||
import Container from "@/components/Container.vue";
|
||||
import AppFooter from "@/components/AppFooter.vue";
|
||||
import UserHeader from "@/components/UserHeader.vue";
|
||||
import Signin from "@/components/Signin.vue";
|
||||
import BubbleTip from "@/components/BubbleTip.vue";
|
||||
import OtaModal from "@/components/OtaModal.vue";
|
||||
|
||||
import {
|
||||
checkUserBindAPI,
|
||||
getAppConfig,
|
||||
getDeviceBatteryAPI,
|
||||
getHardwareBoxTaskStatusAPI,
|
||||
getHardwareBoxVersionAPI,
|
||||
getHomeData,
|
||||
getMyDevicesAPI,
|
||||
getScoreRankList,
|
||||
sendHardwareBoxUpdateAPI,
|
||||
silentLoginAPI,
|
||||
} from "@/apis";
|
||||
import {topThreeColors} from "@/constants";
|
||||
@@ -26,6 +30,7 @@ const {
|
||||
updateConfig,
|
||||
updateUser,
|
||||
updateDevice,
|
||||
clearDevice,
|
||||
getLvlName,
|
||||
getLvlNameByScore,
|
||||
updateOnline,
|
||||
@@ -36,6 +41,208 @@ const showModal = ref(false);
|
||||
const showGuide = ref(false);
|
||||
const scoreRankList = ref([]);
|
||||
|
||||
// OTA 相关
|
||||
const otaVisible = ref(false);
|
||||
const otaState = ref("new_version");
|
||||
const otaProgress = ref(0);
|
||||
const otaInfo = ref({
|
||||
versionNumber: "",
|
||||
versionInfo: "",
|
||||
resourceUrl: "",
|
||||
forceUpdate: false,
|
||||
});
|
||||
const isStartingOta = ref(false);
|
||||
let otaProgressTimer = null;
|
||||
let otaStatusTimer = null;
|
||||
let otaTimeoutTimer = null;
|
||||
|
||||
// 清理首页 OTA 更新定时器,避免弹窗关闭或页面卸载后继续轮询。
|
||||
const clearOtaUpdateTimers = () => {
|
||||
clearInterval(otaProgressTimer);
|
||||
clearTimeout(otaStatusTimer);
|
||||
clearTimeout(otaTimeoutTimer);
|
||||
otaProgressTimer = null;
|
||||
otaStatusTimer = null;
|
||||
otaTimeoutTimer = null;
|
||||
};
|
||||
|
||||
// 启动首页 OTA 本地进度动画,最终成功失败以后端任务状态为准。
|
||||
const startOtaProgressAnimation = () => {
|
||||
clearInterval(otaProgressTimer);
|
||||
otaProgressTimer = setInterval(() => {
|
||||
if (otaProgress.value >= 90) {
|
||||
clearInterval(otaProgressTimer);
|
||||
return;
|
||||
}
|
||||
const increment = Math.max(0.5, 2 - otaProgress.value / 60);
|
||||
otaProgress.value = Math.min(90, otaProgress.value + increment);
|
||||
}, 500);
|
||||
};
|
||||
|
||||
// 获取并保存后端返回的 OTA 版本信息,供弹窗展示和更新接口使用。
|
||||
const applyOtaVersionInfo = (versionInfo) => {
|
||||
otaInfo.value = {
|
||||
versionNumber: versionInfo?.versionNumber || "",
|
||||
versionInfo: versionInfo?.versionInfo || "",
|
||||
resourceUrl: versionInfo?.resourceUrl || "",
|
||||
forceUpdate: Number(versionInfo?.forceUpdate) === 1,
|
||||
};
|
||||
};
|
||||
|
||||
// 检查当前设备盒子是否存在可升级版本。
|
||||
const checkOtaUpdate = async () => {
|
||||
let versionInfo;
|
||||
try {
|
||||
versionInfo = await getHardwareBoxVersionAPI();
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
if (!versionInfo?.needUpdate) return;
|
||||
applyOtaVersionInfo(versionInfo);
|
||||
|
||||
const dismissedAt = uni.getStorageSync("ota_dismissed_at");
|
||||
const now = Date.now();
|
||||
if (!otaInfo.value.forceUpdate && dismissedAt && now - dismissedAt < 24 * 60 * 60 * 1000) return;
|
||||
otaState.value = "new_version";
|
||||
otaVisible.value = true;
|
||||
};
|
||||
|
||||
// 拼接 OTA WiFi 页参数,让未连 WiFi 的设备继续使用同一份版本信息。
|
||||
const getOtaWifiUrl = () => {
|
||||
const { versionNumber, resourceUrl } = otaInfo.value;
|
||||
const query = [
|
||||
`versionNumber=${encodeURIComponent(versionNumber)}`,
|
||||
`resourceUrl=${encodeURIComponent(resourceUrl)}`,
|
||||
].join("&");
|
||||
return `/pages/ota-wifi?${query}`;
|
||||
};
|
||||
|
||||
// 处理 OTA 弹窗暂不更新,强制更新时不允许关闭。
|
||||
const handleOtaDismiss = () => {
|
||||
if (otaInfo.value.forceUpdate) return;
|
||||
uni.setStorageSync("ota_dismissed_at", Date.now());
|
||||
otaVisible.value = false;
|
||||
};
|
||||
|
||||
// 将首页 OTA 直连更新流程标记为失败。
|
||||
const failHomeOtaUpdate = () => {
|
||||
clearOtaUpdateTimers();
|
||||
isStartingOta.value = false;
|
||||
otaState.value = "update_failure";
|
||||
otaVisible.value = true;
|
||||
};
|
||||
|
||||
// 将首页 OTA 直连更新流程标记为成功。
|
||||
const completeHomeOtaUpdate = () => {
|
||||
clearOtaUpdateTimers();
|
||||
isStartingOta.value = false;
|
||||
otaProgress.value = 100;
|
||||
setTimeout(() => {
|
||||
otaState.value = "update_success";
|
||||
otaVisible.value = true;
|
||||
}, 300);
|
||||
};
|
||||
|
||||
// 轮询首页直接发起的 OTA 更新任务状态。
|
||||
const pollHomeOtaTaskStatus = (taskId) => {
|
||||
clearTimeout(otaStatusTimer);
|
||||
otaStatusTimer = setTimeout(async () => {
|
||||
try {
|
||||
const taskStatus = await getHardwareBoxTaskStatusAPI(taskId);
|
||||
const status = Number(taskStatus?.status);
|
||||
if (status === 2) {
|
||||
completeHomeOtaUpdate();
|
||||
return;
|
||||
}
|
||||
if (status === 3) {
|
||||
failHomeOtaUpdate();
|
||||
return;
|
||||
}
|
||||
if (status === 0 || status === 1) {
|
||||
pollHomeOtaTaskStatus(taskId);
|
||||
return;
|
||||
}
|
||||
failHomeOtaUpdate();
|
||||
} catch (err) {
|
||||
failHomeOtaUpdate();
|
||||
}
|
||||
}, 3000);
|
||||
};
|
||||
|
||||
// 设备盒子已连 WiFi 时,从首页直接传空 WiFi 信息发起 OTA 更新。
|
||||
const startHomeOtaUpdate = async () => {
|
||||
otaState.value = "update_progress";
|
||||
otaVisible.value = true;
|
||||
otaProgress.value = 0;
|
||||
startOtaProgressAnimation();
|
||||
otaTimeoutTimer = setTimeout(() => {
|
||||
if (otaState.value === "update_progress") {
|
||||
failHomeOtaUpdate();
|
||||
}
|
||||
}, 5 * 60 * 1000);
|
||||
|
||||
try {
|
||||
const updateResult = await sendHardwareBoxUpdateAPI({
|
||||
versionNumber: otaInfo.value.versionNumber,
|
||||
wifiSsid: "",
|
||||
wifiPassword: "",
|
||||
resourceUrl: otaInfo.value.resourceUrl,
|
||||
});
|
||||
if (!updateResult?.taskId) {
|
||||
failHomeOtaUpdate();
|
||||
return;
|
||||
}
|
||||
pollHomeOtaTaskStatus(updateResult.taskId);
|
||||
} catch (err) {
|
||||
failHomeOtaUpdate();
|
||||
}
|
||||
};
|
||||
|
||||
// 点击立即更新时先判断设备是否在线并已通过 WiFi 联网,已联网则首页直接更新,否则跳转 WiFi 页面。
|
||||
const handleOtaUpdate = async () => {
|
||||
if (isStartingOta.value) return;
|
||||
isStartingOta.value = true;
|
||||
let deviceStatus;
|
||||
try {
|
||||
deviceStatus = await getDeviceBatteryAPI();
|
||||
} catch (err) {
|
||||
isStartingOta.value = false;
|
||||
uni.showToast({
|
||||
title: "获取设备状态失败,请重试",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (deviceStatus?.online !== true) {
|
||||
isStartingOta.value = false;
|
||||
uni.showToast({
|
||||
title: "请先开启智能弓",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (String(deviceStatus?.netType || "").toLowerCase() === "wifi") {
|
||||
startHomeOtaUpdate();
|
||||
return;
|
||||
}
|
||||
|
||||
isStartingOta.value = false;
|
||||
otaVisible.value = false;
|
||||
uni.navigateTo({ url: getOtaWifiUrl() });
|
||||
};
|
||||
|
||||
// 处理 OTA 更新成功后的完成按钮,关闭结果弹窗。
|
||||
const handleOtaDone = () => {
|
||||
otaVisible.value = false;
|
||||
};
|
||||
|
||||
// 处理 OTA 更新失败后的重试按钮,重新走立即更新判断流程。
|
||||
const handleOtaRetry = () => {
|
||||
handleOtaUpdate();
|
||||
};
|
||||
|
||||
// 提取积分榜接口返回的榜单数组,兼容数组和对象两种返回格式。
|
||||
const getScoreRankData = (result) => {
|
||||
if (Array.isArray(result)) return result;
|
||||
@@ -63,10 +270,18 @@ const toRankListPage = () => {
|
||||
});
|
||||
};
|
||||
|
||||
onShow(async () => {
|
||||
onShow(async (options) => {
|
||||
const env = uni.getAccountInfoSync().miniProgram.envVersion;
|
||||
const token = uni.getStorageSync(`${env}_token`);
|
||||
|
||||
// 检查是否从 OTA 更新页面返回
|
||||
if (options && options.updateResult) {
|
||||
otaState.value = options.updateResult;
|
||||
otaVisible.value = true;
|
||||
} else if (token || user.value.id) {
|
||||
await checkOtaUpdate();
|
||||
}
|
||||
|
||||
if (!user.value.id && !token) {
|
||||
// showModal.value = true;
|
||||
// try {
|
||||
@@ -127,6 +342,8 @@ onShow(async () => {
|
||||
);
|
||||
const data = await getDeviceBatteryAPI();
|
||||
updateOnline(data.online);
|
||||
} else {
|
||||
clearDevice();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -138,6 +355,10 @@ onMounted(async () => {
|
||||
console.log("全局配置:", config);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
clearOtaUpdateTimers();
|
||||
});
|
||||
|
||||
onShareAppMessage(() => {
|
||||
return {
|
||||
title: "智能真弓:实时捕捉+毫秒级同步,弓箭选手全球竞技!", // 分享卡片的标题
|
||||
@@ -158,6 +379,21 @@ onShareTimeline(() => {
|
||||
|
||||
<template>
|
||||
<Container :isHome="true" :showBackToGame="true">
|
||||
<!-- OTA 升级弹窗:使用 visible 控制显隐,description 为副标题,changelog 为详细说明 -->
|
||||
<OtaModal
|
||||
:visible="otaVisible"
|
||||
:state="otaState"
|
||||
:version="otaInfo.versionNumber"
|
||||
:progress="otaProgress"
|
||||
:description="''"
|
||||
:changelog="otaInfo.versionInfo"
|
||||
:forceUpdate="otaInfo.forceUpdate"
|
||||
@update="handleOtaUpdate"
|
||||
@skip="handleOtaDismiss"
|
||||
@close="handleOtaDismiss"
|
||||
@done="handleOtaDone"
|
||||
@retry="handleOtaRetry"
|
||||
/>
|
||||
<view class="container">
|
||||
<view class="top-theme">
|
||||
<!-- <image
|
||||
|
||||
+73
-14
@@ -30,11 +30,64 @@ const playersSorted = ref([]);
|
||||
const playersScores = ref([]);
|
||||
const halfTimeTip = ref(false);
|
||||
const halfRest = ref(false);
|
||||
const HALF_REST_SECONDS = 20;
|
||||
const halfRestRemain = ref(HALF_REST_SECONDS);
|
||||
let halfRestTimer = null;
|
||||
/** 控制设备离线提示弹窗的显示状态 */
|
||||
const showOfflineModal = ref(false);
|
||||
/** 记录每位玩家当前半场连续 X 环数,key 为 playerId,用于触发 tententen 音效 */
|
||||
/** 记录每位玩家当前半场连续 10 环及以上次数,key 为 playerId,用于触发 tententen 音效 */
|
||||
const xRingStreaks = ref({});
|
||||
|
||||
function clearHalfRestCountdown() {
|
||||
if (halfRestTimer) {
|
||||
clearInterval(halfRestTimer);
|
||||
halfRestTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
function getHalfRestSeconds(battleInfo) {
|
||||
const remainCandidates = [
|
||||
battleInfo?.halfRestRemain,
|
||||
battleInfo?.halfRestRemainSeconds,
|
||||
battleInfo?.restRemain,
|
||||
battleInfo?.restRemainSeconds,
|
||||
];
|
||||
|
||||
for (const item of remainCandidates) {
|
||||
const remain = Number(item);
|
||||
if (Number.isFinite(remain) && remain > 0 && remain <= HALF_REST_SECONDS) {
|
||||
return Math.ceil(remain);
|
||||
}
|
||||
}
|
||||
|
||||
const endTime = Number(battleInfo?.halfRestEndTime ?? battleInfo?.restEndTime);
|
||||
if (!Number.isFinite(endTime) || endTime <= 0) return HALF_REST_SECONDS;
|
||||
|
||||
const timestamp = endTime < 1e12 ? endTime * 1000 : endTime;
|
||||
const diffSeconds = (timestamp - Date.now()) / 1000;
|
||||
if (diffSeconds > 0 && diffSeconds <= HALF_REST_SECONDS) {
|
||||
return Math.ceil(diffSeconds);
|
||||
}
|
||||
|
||||
return HALF_REST_SECONDS;
|
||||
}
|
||||
|
||||
function startHalfRestCountdown(seconds = HALF_REST_SECONDS) {
|
||||
clearHalfRestCountdown();
|
||||
halfRestRemain.value = Math.max(0, Math.ceil(Number(seconds) || HALF_REST_SECONDS));
|
||||
|
||||
if (halfRestRemain.value <= 0) return;
|
||||
|
||||
halfRestTimer = setInterval(() => {
|
||||
if (halfRestRemain.value <= 1) {
|
||||
halfRestRemain.value = 0;
|
||||
clearHalfRestCountdown();
|
||||
return;
|
||||
}
|
||||
|
||||
halfRestRemain.value -= 1;
|
||||
}, 1000);
|
||||
}
|
||||
const currentPlayer = computed(() =>
|
||||
players.value.find((player) => String(player?.id) === String(user.value.id))
|
||||
);
|
||||
@@ -96,8 +149,7 @@ function recoverData(battleInfo, { force = false } = {}) {
|
||||
halfTimeTip.value = true;
|
||||
halfRest.value = true;
|
||||
tips.value = "准备下半场";
|
||||
// 剩余休息时间
|
||||
// const remain = (Date.now() - battleInfo.timeoutTime) / 1000;
|
||||
startHalfRestCountdown(getHalfRestSeconds(battleInfo));
|
||||
setTimeout(() => {
|
||||
uni.$emit("update-remain", 0);
|
||||
}, 200);
|
||||
@@ -128,23 +180,27 @@ onLoad(async (options) => {
|
||||
});
|
||||
|
||||
/**
|
||||
* 检测指定玩家连续 X 环是否达到 3 箭,达到则在环数播报入队后追加 tententen 音效
|
||||
* 检测指定玩家连续 10 环及以上是否达到 3 箭,达到则在环数播报入队后追加 tententen 音效
|
||||
* @param {number|string} playerId - 本次射手的 ID(大乱斗中 ShootResult 保留 playerId)
|
||||
* @param {boolean} isXRing - 本次射击是否为 X 环
|
||||
* @param {boolean} isTenPlusRingShot - 本次射击是否为 10 环及以上
|
||||
*/
|
||||
function checkAndPlayTententen(playerId, isXRing) {
|
||||
function isTenPlusRing(shot) {
|
||||
return !!(shot?.ringX || Number(shot?.ring) >= 10);
|
||||
}
|
||||
|
||||
function checkAndPlayTententen(playerId, isTenPlusRingShot) {
|
||||
if (!playerId) return;
|
||||
const id = parseInt(playerId);
|
||||
if (isXRing) {
|
||||
if (isTenPlusRingShot) {
|
||||
xRingStreaks.value[id] = (xRingStreaks.value[id] || 0) + 1;
|
||||
// 同一玩家连续 3 箭均为 X 环,追加到环数音效队列尾部播放
|
||||
// 同一玩家连续 3 箭均为 10 环及以上,追加到环数音效队列尾部播放
|
||||
if (xRingStreaks.value[id] >= 3) {
|
||||
xRingStreaks.value[id] = 0;
|
||||
// nextTick 确保 HeaderProgress 的环数播报已入队后再追加 tententen,避免播放顺序颠倒
|
||||
nextTick(() => audioManager.play("tententen", false));
|
||||
}
|
||||
} else {
|
||||
// 非 X 环则重置该玩家的连续计数
|
||||
// 低于 10 环或未上靶则重置该玩家的连续计数
|
||||
xRingStreaks.value[id] = 0;
|
||||
}
|
||||
}
|
||||
@@ -152,6 +208,7 @@ function checkAndPlayTententen(playerId, isXRing) {
|
||||
async function onReceiveMessage(msg) {
|
||||
if (Array.isArray(msg)) return;
|
||||
if (msg.type === MESSAGETYPESV2.BattleStart) {
|
||||
clearHalfRestCountdown();
|
||||
halfTimeTip.value = false;
|
||||
halfRest.value = false;
|
||||
recoverData(msg);
|
||||
@@ -166,22 +223,23 @@ async function onReceiveMessage(msg) {
|
||||
// 对比更新后数据找出箭数增加的玩家(即本次射手),并读取其最新箭的 ring 数据
|
||||
const newRound = playersScores.value[playersScores.value.length - 1] || {};
|
||||
let shooterId = null;
|
||||
let isXRing = false;
|
||||
let isTenPlusRingShot = false;
|
||||
for (const pid of Object.keys(newRound)) {
|
||||
const newLen = (newRound[pid] || []).length;
|
||||
if (newLen > (prevCounts[pid] || 0)) {
|
||||
shooterId = parseInt(pid);
|
||||
const shot = newRound[pid][newLen - 1];
|
||||
isXRing = !!(shot?.ringX && shot?.ring);
|
||||
isTenPlusRingShot = isTenPlusRing(shot);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 检测同一玩家三箭全 X 环,触发 tententen 音效
|
||||
checkAndPlayTententen(shooterId, isXRing);
|
||||
// 检测同一玩家连续三箭 10 环及以上,触发 tententen 音效
|
||||
checkAndPlayTententen(shooterId, isTenPlusRingShot);
|
||||
} else if (msg.type === MESSAGETYPESV2.HalfRest) {
|
||||
halfTimeTip.value = true;
|
||||
halfRest.value = true;
|
||||
tips.value = "准备下半场";
|
||||
startHalfRestCountdown();
|
||||
} else if (msg.type === MESSAGETYPESV2.BattleEnd) {
|
||||
setTimeout(() => {
|
||||
// 全部跳转到新结算页
|
||||
@@ -202,6 +260,7 @@ onBeforeUnmount(() => {
|
||||
uni.setKeepScreenOn({
|
||||
keepScreenOn: false,
|
||||
});
|
||||
clearHalfRestCountdown();
|
||||
uni.$off("socket-inbox", onReceiveMessage);
|
||||
audioManager.stopAll();
|
||||
});
|
||||
@@ -268,7 +327,7 @@ onShow(async () => {
|
||||
>
|
||||
<view class="half-time-tip">
|
||||
<text>上半场结束,休息一下吧:)</text>
|
||||
<text>20秒后开始下半场</text>
|
||||
<text>{{ halfRestRemain }}秒后开始下半场</text>
|
||||
</view>
|
||||
</ScreenHint>
|
||||
<!-- 设备离线提示弹窗 -->
|
||||
|
||||
+37
-4
@@ -16,7 +16,7 @@ const showTip = ref(false);
|
||||
const confirmBindTip = ref(false);
|
||||
const addDevice = ref();
|
||||
const store = useStore();
|
||||
const { updateDevice } = store;
|
||||
const { updateDevice, clearDevice } = store;
|
||||
const { user, device } = storeToRefs(store);
|
||||
const justBind = ref(false);
|
||||
const calibration = ref(false);
|
||||
@@ -86,13 +86,26 @@ const toFristTryPage = () => {
|
||||
};
|
||||
|
||||
const unbindDevice = async () => {
|
||||
await unbindDeviceAPI(device.value.deviceId);
|
||||
try {
|
||||
await unbindDeviceAPI(device.value.deviceId);
|
||||
} catch (error) {
|
||||
if (error?.type === "DEVICE_BIND_INVALID") {
|
||||
uni.setStorageSync("calibration", false);
|
||||
clearDevice();
|
||||
}
|
||||
return;
|
||||
}
|
||||
uni.setStorageSync("calibration", false);
|
||||
uni.showToast({
|
||||
title: "解绑成功",
|
||||
icon: "success",
|
||||
});
|
||||
device.value = {};
|
||||
clearDevice();
|
||||
};
|
||||
|
||||
/** 连接wifi跳转到wifi列表页面 */
|
||||
const joinWifi = () => {
|
||||
uni.navigateTo({ url: "/pages/ota-wifi" });
|
||||
};
|
||||
|
||||
const toDeviceIntroPage = () => {
|
||||
@@ -124,8 +137,23 @@ const goCalibration = async () => {
|
||||
});
|
||||
};
|
||||
|
||||
onShow(() => {
|
||||
const syncDeviceBinding = async () => {
|
||||
if (!user.value.id) return;
|
||||
try {
|
||||
const devices = await getMyDevicesAPI();
|
||||
if (devices.bindings && devices.bindings.length) {
|
||||
updateDevice(devices.bindings[0].deviceId, devices.bindings[0].deviceName);
|
||||
} else {
|
||||
clearDevice();
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("sync device binding error", error);
|
||||
}
|
||||
};
|
||||
|
||||
onShow(async () => {
|
||||
calibration.value = uni.getStorageSync("calibration");
|
||||
await syncDeviceBinding();
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -299,6 +327,11 @@ onShow(() => {
|
||||
>解绑</SButton
|
||||
>
|
||||
</view>
|
||||
<view :style="{ marginTop: '20rpx' }">
|
||||
<SButton :onClick="() => $clickSound(joinWifi)" width="80vw" :rounded="40"
|
||||
>设备连接WIFI</SButton
|
||||
>
|
||||
</view>
|
||||
</view>
|
||||
</Container>
|
||||
</template>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -32,7 +32,7 @@ const start = ref(false);
|
||||
const scores = ref([]);
|
||||
const isSvip = ref(false);
|
||||
const total = 12;
|
||||
/** 当前练习中连续 X 环计数,用于触发 tententen 音效 */
|
||||
/** 当前练习中连续 10 环及以上计数,用于触发 tententen 音效 */
|
||||
const xRingStreak = ref(0);
|
||||
const practiseResult = ref({});
|
||||
const practiseId = ref("");
|
||||
@@ -62,19 +62,23 @@ const onOver = async () => {
|
||||
};
|
||||
|
||||
/**
|
||||
* 检测连续 X 环是否达到 3 箭,达到则播放 tententen 音效
|
||||
* @param {boolean} isXRing - 本次射击是否为 X 环
|
||||
* 检测连续 10 环及以上是否达到 3 箭,达到则播放 tententen 音效
|
||||
* @param {boolean} isTenPlusRingShot - 本次射击是否为 10 环及以上
|
||||
*/
|
||||
function checkAndPlayTententen(isXRing) {
|
||||
if (isXRing) {
|
||||
function isTenPlusRing(shot) {
|
||||
return !!(shot?.ringX || Number(shot?.ring) >= 10);
|
||||
}
|
||||
|
||||
function checkAndPlayTententen(isTenPlusRingShot) {
|
||||
if (isTenPlusRingShot) {
|
||||
xRingStreak.value += 1;
|
||||
// 连续 3 箭均为 X 环,在环数播报入队后追加 tententen,避免播放顺序颠倒
|
||||
// 连续 3 箭均为 10 环及以上,在环数播报入队后追加 tententen,避免播放顺序颠倒
|
||||
if (xRingStreak.value >= 3) {
|
||||
xRingStreak.value = 0;
|
||||
nextTick(() => audioManager.play("tententen", false));
|
||||
}
|
||||
} else {
|
||||
// 非 X 环则重置连续计数
|
||||
// 低于 10 环或未上靶则重置连续计数
|
||||
xRingStreak.value = 0;
|
||||
}
|
||||
}
|
||||
@@ -84,10 +88,10 @@ async function onReceiveMessage(msg) {
|
||||
const prevLen = scores.value.length;
|
||||
isSvip.value = msg.sVip === true;
|
||||
scores.value = msg.details;
|
||||
// 有新箭时取最后一箭判断是否 X 环并检测连续计数
|
||||
// 有新箭时取最后一箭判断是否 10 环及以上并检测连续计数
|
||||
if (scores.value.length > prevLen) {
|
||||
const latestArrow = scores.value[scores.value.length - 1];
|
||||
checkAndPlayTententen(!!(latestArrow?.ringX && latestArrow?.ring));
|
||||
checkAndPlayTententen(isTenPlusRing(latestArrow));
|
||||
}
|
||||
} else if (msg.type === MESSAGETYPESV2.BattleEnd) {
|
||||
// setTimeout(onOver, 1500);
|
||||
|
||||
@@ -32,7 +32,7 @@ const start = ref(false);
|
||||
const scores = ref([]);
|
||||
const isSvip = ref(false);
|
||||
const total = 36;
|
||||
/** 当前练习中连续 X 环计数,用于触发 tententen 音效 */
|
||||
/** 当前练习中连续 10 环及以上计数,用于触发 tententen 音效 */
|
||||
const xRingStreak = ref(0);
|
||||
const practiseResult = ref({});
|
||||
const practiseId = ref("");
|
||||
@@ -61,19 +61,23 @@ const onOver = async () => {
|
||||
};
|
||||
|
||||
/**
|
||||
* 检测连续 X 环是否达到 3 箭,达到则播放 tententen 音效
|
||||
* @param {boolean} isXRing - 本次射击是否为 X 环
|
||||
* 检测连续 10 环及以上是否达到 3 箭,达到则播放 tententen 音效
|
||||
* @param {boolean} isTenPlusRingShot - 本次射击是否为 10 环及以上
|
||||
*/
|
||||
function checkAndPlayTententen(isXRing) {
|
||||
if (isXRing) {
|
||||
function isTenPlusRing(shot) {
|
||||
return !!(shot?.ringX || Number(shot?.ring) >= 10);
|
||||
}
|
||||
|
||||
function checkAndPlayTententen(isTenPlusRingShot) {
|
||||
if (isTenPlusRingShot) {
|
||||
xRingStreak.value += 1;
|
||||
// 连续 3 箭均为 X 环,在环数播报入队后追加 tententen,避免播放顺序颠倒
|
||||
// 连续 3 箭均为 10 环及以上,在环数播报入队后追加 tententen,避免播放顺序颠倒
|
||||
if (xRingStreak.value >= 3) {
|
||||
xRingStreak.value = 0;
|
||||
nextTick(() => audioManager.play("tententen", false));
|
||||
}
|
||||
} else {
|
||||
// 非 X 环则重置连续计数
|
||||
// 低于 10 环或未上靶则重置连续计数
|
||||
xRingStreak.value = 0;
|
||||
}
|
||||
}
|
||||
@@ -83,10 +87,10 @@ async function onReceiveMessage(msg) {
|
||||
const prevLen = scores.value.length;
|
||||
isSvip.value = msg.sVip === true;
|
||||
scores.value = msg.details;
|
||||
// 有新箭时取最后一箭判断是否 X 环并检测连续计数
|
||||
// 有新箭时取最后一箭判断是否 10 环及以上并检测连续计数
|
||||
if (scores.value.length > prevLen) {
|
||||
const latestArrow = scores.value[scores.value.length - 1];
|
||||
checkAndPlayTententen(!!(latestArrow?.ringX && latestArrow?.ring));
|
||||
checkAndPlayTententen(isTenPlusRing(latestArrow));
|
||||
}
|
||||
} else if (msg.type === MESSAGETYPESV2.BattleEnd) {
|
||||
setTimeout(onOver, 1500);
|
||||
|
||||
@@ -49,7 +49,7 @@ const battleWay = ref(0);
|
||||
const lastToSomeoneShootKey = ref("");
|
||||
/** 控制设备离线提示弹窗的显示状态 */
|
||||
const showOfflineModal = ref(false);
|
||||
/** 记录每位玩家当前轮连续 X 环数,key 为 playerId,用于触发 tententen 音效 */
|
||||
/** 记录每位玩家当前轮连续 10 环及以上次数,key 为 playerId,用于触发 tententen 音效 */
|
||||
const xRingStreaks = ref({});
|
||||
|
||||
/**
|
||||
@@ -234,22 +234,26 @@ function onNewRound(msg, prevRound) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测指定射手连续 X 环是否达到 3 箭,达到则在环数播报入队后追加 tententen 音效
|
||||
* 检测指定射手连续 10 环及以上是否达到 3 箭,达到则在环数播报入队后追加 tententen 音效
|
||||
* @param {number} shooterId - 本次射手的 ID(取自 currentShooterId.value)
|
||||
* @param {boolean} isXRing - 本次射击是否为 X 环
|
||||
* @param {boolean} isTenPlusRingShot - 本次射击是否为 10 环及以上
|
||||
*/
|
||||
function checkAndPlayTententen(shooterId, isXRing) {
|
||||
function isTenPlusRing(shot) {
|
||||
return !!(shot?.ringX || Number(shot?.ring) >= 10);
|
||||
}
|
||||
|
||||
function checkAndPlayTententen(shooterId, isTenPlusRingShot) {
|
||||
if (!shooterId) return;
|
||||
if (isXRing) {
|
||||
if (isTenPlusRingShot) {
|
||||
xRingStreaks.value[shooterId] = (xRingStreaks.value[shooterId] || 0) + 1;
|
||||
// 同一玩家连续 3 箭均为 X 环,追加到环数音效队列尾部播放
|
||||
// 同一玩家连续 3 箭均为 10 环及以上,追加到环数音效队列尾部播放
|
||||
if (xRingStreaks.value[shooterId] >= 3) {
|
||||
xRingStreaks.value[shooterId] = 0;
|
||||
// nextTick 确保 HeaderProgress 的环数播报已入队后再追加 tententen,避免播放顺序颠倒
|
||||
nextTick(() => audioManager.play("tententen", false));
|
||||
}
|
||||
} else {
|
||||
// 非 X 环则重置该玩家的连续计数
|
||||
// 低于 10 环或未上靶则重置该玩家的连续计数
|
||||
xRingStreaks.value[shooterId] = 0;
|
||||
}
|
||||
}
|
||||
@@ -268,9 +272,9 @@ async function onReceiveMessage(msg) {
|
||||
} else if (msg.type === MESSAGETYPESV2.ShootResult) {
|
||||
showRoundTip.value = false;
|
||||
recoverData(msg, {arrowOnly: true});
|
||||
// 检测同一玩家三箭全 X 环,触发 tententen 音效
|
||||
// 检测同一玩家连续三箭 10 环及以上,触发 tententen 音效
|
||||
// currentShooterId 在 ToSomeoneShoot 时写入,ShootResult 不会覆盖,可靠识别本次射手
|
||||
checkAndPlayTententen(currentShooterId.value, !!(msg.shootData?.ringX && msg.shootData?.ring));
|
||||
checkAndPlayTententen(currentShooterId.value, isTenPlusRing(msg.shootData));
|
||||
} else if (msg.type === MESSAGETYPESV2.NewRound) {
|
||||
// 在进入延迟前先捕获当前轮次,供 onNewRound 使用,防止 800ms 内 ToSomeoneShoot 提前更新 currentRound 造成 Tip 展示错轮
|
||||
const prevRound = currentRound.value;
|
||||
|
||||
@@ -432,7 +432,10 @@ function playAudioKeys(keys, { interrupt = false, timeout } = {}) {
|
||||
resolve();
|
||||
},
|
||||
};
|
||||
const timer = setTimeout(waiter.done, waitTime);
|
||||
const timer = setTimeout(() => {
|
||||
audioManager.recoverIfStale(expectedKey);
|
||||
waiter.done();
|
||||
}, waitTime);
|
||||
audioWaiters.add(waiter);
|
||||
audioManager.play(audioKeys, interrupt);
|
||||
});
|
||||
@@ -473,17 +476,14 @@ function updateTeams(battleInfo) {
|
||||
}
|
||||
|
||||
function updateGoldenRound(battleInfo) {
|
||||
const rounds = Array.isArray(battleInfo?.rounds) ? battleInfo.rounds : [];
|
||||
const currentRoundNo = Number(battleInfo?.current?.round || 0);
|
||||
const currentRoundInfo = rounds.find((round) => Number(round?.round) === currentRoundNo);
|
||||
const activeGoldRoundInfo = rounds.find(
|
||||
(round) => Number(round?.goldRound || 0) > 0 && round?.status === 1
|
||||
);
|
||||
const roundGoldRound = Number(currentRoundInfo?.goldRound || 0);
|
||||
const activeGoldRound = Number(activeGoldRoundInfo?.goldRound || 0);
|
||||
const currentGoldRound = Number(battleInfo?.current?.goldRound || 0);
|
||||
const nextGoldRound = roundGoldRound || activeGoldRound || currentGoldRound;
|
||||
goldenRound.value = nextGoldRound > 0 ? nextGoldRound : 0;
|
||||
if (!battleInfo?.current?.goldRound) {
|
||||
goldenRound.value = 0;
|
||||
return;
|
||||
}
|
||||
const rounds = Array.isArray(battleInfo.rounds) ? battleInfo.rounds : [];
|
||||
const finishedGoldCount = rounds.filter((round) => !!round?.ifGold).length;
|
||||
// goldenRound.value = Math.max(1, finishedGoldCount + (battleInfo.current?.playerId ? 1 : 0));
|
||||
goldenRound.value = Math.max(1, finishedGoldCount);
|
||||
}
|
||||
|
||||
// Restore an info snapshot whose eventType points at the NewRound phase.
|
||||
@@ -861,10 +861,14 @@ async function runToSomeoneShootTask(task, runId) {
|
||||
});
|
||||
}
|
||||
|
||||
function updateXRingStreak(shooterId, isXRing) {
|
||||
function isTenPlusRing(shot) {
|
||||
return !!(shot?.ringX || Number(shot?.ring) >= 10);
|
||||
}
|
||||
|
||||
function updateXRingStreak(shooterId, isTenPlusRingShot) {
|
||||
if (!shooterId) return false;
|
||||
const id = String(shooterId);
|
||||
if (!isXRing) {
|
||||
if (!isTenPlusRingShot) {
|
||||
xRingStreaks.value[id] = 0;
|
||||
saveXRingStreaks();
|
||||
return false;
|
||||
@@ -909,7 +913,7 @@ async function runShootResultTask(task) {
|
||||
|
||||
const isTententen = updateXRingStreak(
|
||||
currentShooterId.value,
|
||||
!!(battleInfo.shootData?.ringX && battleInfo.shootData?.ring)
|
||||
isTenPlusRing(battleInfo.shootData)
|
||||
);
|
||||
const audioKeys = buildShootResultAudioKeys(battleInfo.shootData);
|
||||
if (isTententen) audioKeys.push("tententen");
|
||||
@@ -1255,7 +1259,7 @@ onShow(() => {
|
||||
<view class="offline-modal">
|
||||
<text class="offline-title">设备已离线</text>
|
||||
<text class="offline-desc">检测到设备已断开连接,请检查设备后继续比赛</text>
|
||||
<SButton @click="showOfflineModal = false">我知道了</SButton>
|
||||
<SButton :onClick="() => (showOfflineModal = false)">我知道了</SButton>
|
||||
</view>
|
||||
</SModal>
|
||||
</view>
|
||||
|
||||
Reference in New Issue
Block a user