修复声音问题

This commit is contained in:
kron
2025-07-14 22:39:53 +08:00
parent 926b8dea69
commit f02062c1ad
3 changed files with 33 additions and 13 deletions

View File

@@ -19,6 +19,14 @@ const props = defineProps({
type: Number,
default: 0,
},
currentRound: {
type: Number,
default: 90,
},
battleId: {
type: String,
default: "",
},
});
const barColor = ref("#fed847");
@@ -26,21 +34,15 @@ const remain = ref(props.total);
const timer = ref(null);
const sound = ref(true);
const currentSound = ref("");
const currentRound = ref(0);
const currentRoundEnded = ref(true);
const currentRound = ref(props.currentRound);
const currentRoundEnded = ref(!props.battleId);
watch(
() => props.tips,
(newVal) => {
let key = "";
if (newVal.includes("红队")) {
barColor.value = "#FF6060";
key = "请红方射击";
}
if (newVal.includes("蓝队")) {
barColor.value = "#5FADFF";
key = "请蓝方射击";
}
if (newVal.includes("红队")) key = "请红方射击";
if (newVal.includes("蓝队")) key = "请蓝方射击";
if (key && sound.value) {
if (currentRoundEnded.value) {
currentRound.value += 1;
@@ -57,6 +59,15 @@ watch(
audioManager.play(key);
}
}
}
);
watch(
() => props.tips,
(newVal) => {
let key = "";
if (newVal.includes("红队")) barColor.value = "#FF6060";
if (newVal.includes("蓝队")) barColor.value = "#5FADFF";
},
{
immediate: true,
@@ -111,8 +122,8 @@ async function onReceiveMessage(messages = []) {
if (!sound.value) return;
messages.forEach((msg) => {
if (
msg.constructor === MESSAGETYPES.ShootSyncMeArrowID ||
msg.constructor === MESSAGETYPES.ShootResult
(props.battleId && msg.constructor === MESSAGETYPES.ShootResult) ||
(!props.battleId && msg.constructor === MESSAGETYPES.ShootSyncMeArrowID)
) {
if (msg.target) {
currentSound.value = msg.target.ring