update:语音优化
This commit is contained in:
+60
-8
@@ -329,18 +329,70 @@ export const getDirectionText = (angle = 0) => {
|
||||
}
|
||||
};
|
||||
|
||||
// 正式射箭阶段的距离单位为厘米,按距离异常类型选择对应语音。
|
||||
export const getInvalidShotAudioKey = (shootData) => {
|
||||
if (!shootData || typeof shootData !== "object") return "射击无效";
|
||||
// protobuf 会省略值为 0 的标量字段;消息体存在且距离缺失时按 0 处理。
|
||||
// 射箭数据中的距离单位为厘米;旧版本会明确上报 target_ok=true。
|
||||
export const getShootValidation = (shootData) => {
|
||||
if (!shootData || typeof shootData !== "object") {
|
||||
return {
|
||||
rawDistance: 0,
|
||||
distance: 0,
|
||||
distanceOk: false,
|
||||
targetOk: false,
|
||||
targetDetected: false,
|
||||
};
|
||||
}
|
||||
|
||||
const rawDistance = Number(shootData.distance ?? shootData.dst ?? 0);
|
||||
if (!Number.isFinite(rawDistance)) return "射击无效";
|
||||
if (rawDistance < 0) return "射箭无效,靶纸错误";
|
||||
if (rawDistance === 0) return "射箭无效,未识别到靶纸";
|
||||
if (rawDistance / 100 < 5) return "射箭无效,距离不足";
|
||||
const finiteDistance = Number.isFinite(rawDistance) ? rawDistance : 0;
|
||||
const targetFlag = shootData.targetOk ?? shootData.target_ok;
|
||||
const targetDetected = finiteDistance !== 0;
|
||||
const targetOk = finiteDistance > 0 && targetFlag === true;
|
||||
|
||||
return {
|
||||
rawDistance: finiteDistance,
|
||||
distance: Math.max(0, finiteDistance / 100),
|
||||
// 旧固件以负距离表示靶纸错误,此时只提示靶纸问题,不叠加距离不足。
|
||||
distanceOk: finiteDistance < 0 || finiteDistance >= 500,
|
||||
targetOk: targetDetected && targetOk,
|
||||
targetDetected,
|
||||
};
|
||||
};
|
||||
|
||||
// 测距阶段提示音:同时校验站距和靶纸,保留旧版本距离不足音频。
|
||||
export const getDistanceCheckAudioKey = (shootData) => {
|
||||
const result = getShootValidation(shootData);
|
||||
if (!result.targetDetected) return "未发现靶纸,请瞄准靶纸射箭";
|
||||
if (!result.distanceOk && !result.targetOk) {
|
||||
return "射箭无效,距离不足且靶纸错误";
|
||||
}
|
||||
if (!result.targetOk) return "靶纸不符!请更换靶纸";
|
||||
if (result.distanceOk) return "站距与靶纸合格";
|
||||
return "距离不足";
|
||||
};
|
||||
|
||||
export const getDistanceCheckText = (shootData) => {
|
||||
const result = getShootValidation(shootData);
|
||||
if (!result.targetDetected) return "未识别到靶纸,请瞄准靶纸射箭";
|
||||
if (result.rawDistance < 0) return "靶纸错误";
|
||||
return `${result.distanceOk ? "站距合格" : "站距过近"},${
|
||||
result.targetOk ? "靶纸正确" : "靶纸错误"
|
||||
}`;
|
||||
};
|
||||
|
||||
// 正式射箭阶段的距离和靶纸异常类型选择对应语音。
|
||||
export const getInvalidShotAudioKey = (shootData) => {
|
||||
const result = getShootValidation(shootData);
|
||||
if (!result.targetDetected) return "射箭无效,未识别到靶纸";
|
||||
if (!result.distanceOk && !result.targetOk) {
|
||||
return "射箭无效,距离不足且靶纸错误";
|
||||
}
|
||||
if (!result.targetOk) return "射箭无效,靶纸错误";
|
||||
if (!result.distanceOk) return "射箭无效,距离不足";
|
||||
return "射击无效";
|
||||
};
|
||||
|
||||
export const getInvalidShotText = (shootData) =>
|
||||
getInvalidShotAudioKey(shootData);
|
||||
|
||||
export const wxLogin = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.login({
|
||||
|
||||
Reference in New Issue
Block a user