bug修复

This commit is contained in:
kron
2025-07-16 12:09:27 +08:00
parent d5bc1a6a89
commit c1fa8b9469
5 changed files with 93 additions and 58 deletions

View File

@@ -48,6 +48,8 @@ const props = defineProps({
}); });
const latestOne = ref(null); const latestOne = ref(null);
const prevScores = ref([]);
const prevBlueScores = ref([]);
// const startCount = ref(false); // const startCount = ref(false);
const timer = ref(null); const timer = ref(null);
@@ -63,12 +65,15 @@ const timer = ref(null);
watch( watch(
() => props.scores, () => props.scores,
(newVal, oldVal) => { (newVal) => {
latestOne.value = newVal[newVal.length - 1]; if (newVal.length - prevScores.value.length === 1) {
if (timer.value) clearTimeout(timer.value); latestOne.value = newVal[newVal.length - 1];
timer.value = setTimeout(() => { if (timer.value) clearTimeout(timer.value);
latestOne.value = null; timer.value = setTimeout(() => {
}, 1000); latestOne.value = null;
}, 1000);
}
prevScores.value = [...newVal];
}, },
{ {
deep: true, deep: true,
@@ -78,11 +83,14 @@ watch(
watch( watch(
() => props.blueScores, () => props.blueScores,
(newVal) => { (newVal) => {
latestOne.value = newVal[newVal.length - 1]; if (newVal.length - prevBlueScores.value.length === 1) {
if (timer.value) clearTimeout(timer.value); latestOne.value = newVal[newVal.length - 1];
timer.value = setTimeout(() => { if (timer.value) clearTimeout(timer.value);
latestOne.value = null; timer.value = setTimeout(() => {
}, 1000); latestOne.value = null;
}, 1000);
}
prevBlueScores.value = [...newVal];
}, },
{ {
deep: true, deep: true,
@@ -141,7 +149,7 @@ const simulShoot2 = async () => {
<view <view
v-if="bow.ring > 0" v-if="bow.ring > 0"
:class="`hit ${ :class="`hit ${
index === scores.length - 1 && showLatestArrow ? 'pump-in' : '' index === scores.length - 1 && latestOne ? 'pump-in' : ''
}`" }`"
:style="{ :style="{
left: calcRealX(bow.x), left: calcRealX(bow.x),
@@ -149,7 +157,7 @@ const simulShoot2 = async () => {
backgroundColor: backgroundColor:
index === scores.length - 1 && index === scores.length - 1 &&
!blueScores.length && !blueScores.length &&
showLatestArrow && latestOne &&
mode !== 'team' mode !== 'team'
? 'green' ? 'green'
: 'red', : 'red',
@@ -161,7 +169,7 @@ const simulShoot2 = async () => {
<view <view
v-if="bow.ring > 0" v-if="bow.ring > 0"
:class="`hit ${ :class="`hit ${
index === blueScores.length - 1 && showLatestArrow ? 'pump-in' : '' index === blueScores.length - 1 && latestOne ? 'pump-in' : ''
}`" }`"
:style="{ :style="{
left: calcRealX(bow.x), left: calcRealX(bow.x),
@@ -240,7 +248,6 @@ const simulShoot2 = async () => {
font-size: 8px; font-size: 8px;
text-align: center; text-align: center;
line-height: 10px; line-height: 10px;
transition: all 0.3s ease;
box-sizing: border-box; box-sizing: border-box;
} }
.hit > text { .hit > text {

View File

@@ -98,16 +98,12 @@ watch(
watch( watch(
() => props.start, () => props.start,
(newVal) => { (newVal) => {
if (!newVal && timer.value) { if (timer.value) clearInterval(timer.value);
if (timer.value) clearInterval(timer.value);
}
if (newVal) { if (newVal) {
remain.value = props.total; remain.value = props.total;
timer.value = setInterval(() => { timer.value = setInterval(() => {
if (remain.value > 0) remain.value--; if (remain.value > 0) remain.value--;
}, 1000); }, 1000);
} else {
if (timer.value) clearInterval(timer.value);
} }
}, },
{ {
@@ -118,9 +114,11 @@ watch(
const updateRemain = (value) => { const updateRemain = (value) => {
if (timer.value) clearInterval(timer.value); if (timer.value) clearInterval(timer.value);
remain.value = Math.floor(value); remain.value = Math.floor(value);
timer.value = setInterval(() => { if (remain.value > 0) {
if (remain.value > 0) remain.value--; timer.value = setInterval(() => {
}, 1000); if (remain.value > 0) remain.value--;
}, 1000);
}
}; };
const updateSound = () => { const updateSound = () => {

View File

@@ -42,16 +42,17 @@ onMounted(async () => {
const battleInfo = uni.getStorageSync("last-battle"); const battleInfo = uni.getStorageSync("last-battle");
console.log("----battleInfo", battleInfo); console.log("----battleInfo", battleInfo);
data.value = battleInfo; data.value = battleInfo;
if (battleInfo.mode === 1) { const mine = battleInfo.playerStats.find((p) => p.id === user.value.id);
battleInfo.playerStats.forEach((p) => { if (mine) {
if (p.id === user.value.id) { if (battleInfo.mode === 1) {
totalPoints.value = p.totalScore; totalPoints.value = mine.roundStats.reduce(
if (p.team === battleInfo.winner) ifWin.value = true; (last, next) => last + next.arrows.length,
} 0
}); );
} else if (battleInfo.mode === 2) { if (mine.team === battleInfo.winner) ifWin.value = true;
const mine = battleInfo.playerStats.find((p) => p.id === user.value.id); } else if (battleInfo.mode === 2) {
if (mine) totalPoints.value = mine.totalScore; totalPoints.value = mine.totalScore;
}
} }
// const result = await getHomeData(); // const result = await getHomeData();
// if (result.user) updateUser(result.user); // if (result.user) updateUser(result.user);
@@ -151,7 +152,7 @@ const checkBowData = () => {
:borderColor="topThreeColors[index] || ''" :borderColor="topThreeColors[index] || ''"
/> />
<view class="player-title"> <view class="player-title">
<text>{{ player.name }}</text> <text class="truncate">{{ player.name }}</text>
<text>{{ getLvlName(player.totalScore) }}</text> <text>{{ getLvlName(player.totalScore) }}</text>
</view> </view>
<text <text
@@ -164,12 +165,12 @@ const checkBowData = () => {
<view class="battle-e"> <view class="battle-e">
<image src="../static/row-yellow-bg.png" mode="widthFix" /> <image src="../static/row-yellow-bg.png" mode="widthFix" />
<Avatar v-if="data.mode === 1" :src="user.avatar" :size="40" /> <Avatar v-if="data.mode === 1" :src="user.avatar" :size="40" />
<text v-if="data.battleMode === 1" <text v-if="data.battleMode === 1">
>经验 {{ totalPoints > 0 ? "+" + totalPoints : totalPoints }}</text 经验 {{ totalPoints > 0 ? "+" + totalPoints : totalPoints }}
> </text>
<text v-if="data.battleMode === 2" <text v-if="data.battleMode === 2">
>积分 {{ totalPoints > 0 ? "+" + totalPoints : totalPoints }}</text 积分 {{ totalPoints > 0 ? "+" + totalPoints : totalPoints }}
> </text>
</view> </view>
<text v-if="data.mode === 1" class="description">{{ <text v-if="data.mode === 1" class="description">{{
ifWin ? "你已经奔跑在通向王者的路上了" : "失败是成功之母儿子在等你" ifWin ? "你已经奔跑在通向王者的路上了" : "失败是成功之母儿子在等你"
@@ -350,6 +351,7 @@ const checkBowData = () => {
.player-title > text:first-child { .player-title > text:first-child {
color: #fff; color: #fff;
margin-bottom: 3px; margin-bottom: 3px;
width: 40vw;
} }
.player-title > text:last-child { .player-title > text:last-child {
font-size: 13px; font-size: 13px;

View File

@@ -55,6 +55,7 @@ const showModal = ref(false);
const halfTimeTip = ref(false); const halfTimeTip = ref(false);
const isFinalShoot = ref(false); const isFinalShoot = ref(false);
const total = ref(15); const total = ref(15);
const battleType = ref(0);
watch( watch(
() => [players.value, playersScores.value], () => [players.value, playersScores.value],
@@ -77,6 +78,7 @@ onLoad(async (options) => {
console.log("----battleInfo", battleInfo); console.log("----battleInfo", battleInfo);
if (battleInfo) { if (battleInfo) {
battleId.value = battleInfo.id; battleId.value = battleInfo.id;
battleType.value = battleInfo.config.mode;
start.value = true; start.value = true;
step.value = 3; step.value = 3;
if (battleInfo.config.mode === 1) { if (battleInfo.config.mode === 1) {
@@ -88,6 +90,18 @@ onLoad(async (options) => {
totalRounds.value = battleInfo.maxRound; totalRounds.value = battleInfo.maxRound;
roundResults.value = battleInfo.roundResults; roundResults.value = battleInfo.roundResults;
currentShooterId.value = battleInfo.firePlayerIndex; currentShooterId.value = battleInfo.firePlayerIndex;
setTimeout(() => {
if (battleInfo.roundResults[battleInfo.roundResults.length - 1]) {
scores.value =
battleInfo.roundResults[
battleInfo.roundResults.length - 1
].redArrows;
blueScores.value =
battleInfo.roundResults[
battleInfo.roundResults.length - 1
].blueArrows;
}
}, 300);
if ( if (
battleInfo.redTeam[0].shotHistory[battleInfo.currentRound] || battleInfo.redTeam[0].shotHistory[battleInfo.currentRound] ||
battleInfo.blueTeam[0].shotHistory[battleInfo.currentRound] battleInfo.blueTeam[0].shotHistory[battleInfo.currentRound]
@@ -151,6 +165,7 @@ onLoad(async (options) => {
roomNumber.value = options.roomNumber; roomNumber.value = options.roomNumber;
const result = await getRoomAPI(options.roomNumber); const result = await getRoomAPI(options.roomNumber);
room.value = result; room.value = result;
battleType.value = result.battleType;
result.members.some((m) => { result.members.some((m) => {
if (m.userInfo.id === result.creator) { if (m.userInfo.id === result.creator) {
owner.value = { owner.value = {
@@ -218,10 +233,10 @@ async function onReceiveMessage(messages = []) {
timerSeq.value += 1; timerSeq.value += 1;
battleId.value = msg.id; battleId.value = msg.id;
step.value = 2; step.value = 2;
if (room.value.battleType === 1) { if (battleType.value === 1) {
redTeam.value = msg.groupUserStatus.redTeam; redTeam.value = msg.groupUserStatus.redTeam;
blueTeam.value = msg.groupUserStatus.blueTeam; blueTeam.value = msg.groupUserStatus.blueTeam;
} else if (room.value.battleType === 2) { } else if (battleType.value === 2) {
players.value = [ players.value = [
...msg.groupUserStatus.redTeam, ...msg.groupUserStatus.redTeam,
...msg.groupUserStatus.blueTeam, ...msg.groupUserStatus.blueTeam,
@@ -233,7 +248,7 @@ async function onReceiveMessage(messages = []) {
} }
if (msg.roomNumber === roomNumber.value) { if (msg.roomNumber === roomNumber.value) {
if (msg.constructor === MESSAGETYPES.UserEnterRoom) { if (msg.constructor === MESSAGETYPES.UserEnterRoom) {
if (room.value.battleType === 1) { if (battleType.value === 1) {
if (msg.userId === room.value.creator) { if (msg.userId === room.value.creator) {
owner.value = { owner.value = {
id: msg.userId, id: msg.userId,
@@ -248,7 +263,7 @@ async function onReceiveMessage(messages = []) {
}; };
} }
} }
if (room.value.battleType === 2) { if (battleType.value === 2) {
if (room.value.creator === msg.userId) { if (room.value.creator === msg.userId) {
players.value[0] = { players.value[0] = {
id: msg.userId, id: msg.userId,
@@ -265,7 +280,7 @@ async function onReceiveMessage(messages = []) {
} }
} }
if (!start.value && msg.constructor === MESSAGETYPES.UserExitRoom) { if (!start.value && msg.constructor === MESSAGETYPES.UserExitRoom) {
if (room.value.battleType === 1) { if (battleType.value === 1) {
if (msg.userId === room.value.creator) { if (msg.userId === room.value.creator) {
owner.value = { owner.value = {
id: "", id: "",
@@ -276,7 +291,7 @@ async function onReceiveMessage(messages = []) {
}; };
} }
} }
if (room.value.battleType === 2) { if (battleType.value === 2) {
players.value = players.value.filter((p) => p.id !== msg.userId); players.value = players.value.filter((p) => p.id !== msg.userId);
} }
} }
@@ -298,7 +313,7 @@ async function onReceiveMessage(messages = []) {
scores.value = []; scores.value = [];
totalRounds.value = msg.groupUserStatus.config.maxRounds; totalRounds.value = msg.groupUserStatus.config.maxRounds;
step.value = 3; step.value = 3;
if (room.value.battleType === 2) { if (battleType.value === 2) {
tips.value = "请在90秒内射完12支箭"; tips.value = "请在90秒内射完12支箭";
seq.value += 1; seq.value += 1;
} }
@@ -319,7 +334,7 @@ async function onReceiveMessage(messages = []) {
total.value = 90; total.value = 90;
} }
if (msg.constructor === MESSAGETYPES.ToSomeoneShoot) { if (msg.constructor === MESSAGETYPES.ToSomeoneShoot) {
if (room.value.battleType === 1) { if (battleType.value === 1) {
if (currentShooterId.value !== msg.userId) { if (currentShooterId.value !== msg.userId) {
seq.value += 1; seq.value += 1;
currentShooterId.value = msg.userId; currentShooterId.value = msg.userId;
@@ -337,7 +352,7 @@ async function onReceiveMessage(messages = []) {
} }
} }
if (msg.constructor === MESSAGETYPES.ShootResult) { if (msg.constructor === MESSAGETYPES.ShootResult) {
if (room.value.battleType === 1) { if (battleType.value === 1) {
const isRed = redTeam.value.find((item) => item.id === msg.userId); const isRed = redTeam.value.find((item) => item.id === msg.userId);
if (isRed) scores.value.push(msg.target); if (isRed) scores.value.push(msg.target);
else blueScores.value.push(msg.target); else blueScores.value.push(msg.target);
@@ -362,7 +377,7 @@ async function onReceiveMessage(messages = []) {
}); });
} }
} }
if (room.value.battleType === 2) { if (battleType.value === 2) {
scores.value.push(msg.target); scores.value.push(msg.target);
power.value = msg.target.battery; power.value = msg.target.battery;
} }
@@ -370,7 +385,7 @@ async function onReceiveMessage(messages = []) {
playersScores.value[msg.userId].push(msg.target); playersScores.value[msg.userId].push(msg.target);
} }
if (msg.constructor === MESSAGETYPES.CurrentRoundEnded) { if (msg.constructor === MESSAGETYPES.CurrentRoundEnded) {
if (room.value.battleType === 1) { if (battleType.value === 1) {
const result = msg.preRoundResult; const result = msg.preRoundResult;
scores.value = []; scores.value = [];
blueScores.value = []; blueScores.value = [];
@@ -381,6 +396,7 @@ async function onReceiveMessage(messages = []) {
redPoints.value += result.redScore; redPoints.value += result.redScore;
// roundResults.value = result.roundResults; // roundResults.value = result.roundResults;
currentRound.value = result.currentRound + 1; currentRound.value = result.currentRound + 1;
uni.$emit("update-ramain", 0);
if (result.currentRound < 5) { if (result.currentRound < 5) {
roundResults.value.push({ roundResults.value.push({
redArrows: [], redArrows: [],
@@ -468,13 +484,13 @@ onUnmounted(() => {
<view class="battle-guide"> <view class="battle-guide">
<view :style="{ display: 'flex', flexDirection: 'column' }"> <view :style="{ display: 'flex', flexDirection: 'column' }">
<text :style="{ color: '#fed847' }">弓箭手们人都到齐了吗?</text> <text :style="{ color: '#fed847' }">弓箭手们人都到齐了吗?</text>
<text v-if="room.battleType === 1">1v1比赛即将开始! </text> <text v-if="battleType === 1">1v1比赛即将开始! </text>
<text v-if="room.battleType === 2">大乱斗即将开始! </text> <text v-if="battleType === 2">大乱斗即将开始! </text>
</view> </view>
<view @click="setClipboardData">邀请好友</view> <view @click="setClipboardData">邀请好友</view>
</view> </view>
</Guide> </Guide>
<view v-if="room.battleType === 1" class="team-mode"> <view v-if="battleType === 1" class="team-mode">
<image src="../static/1v1-bg.png" mode="widthFix" /> <image src="../static/1v1-bg.png" mode="widthFix" />
<view> <view>
<view class="player" :style="{ transform: 'translateY(-60px)' }"> <view class="player" :style="{ transform: 'translateY(-60px)' }">
@@ -502,19 +518,19 @@ onUnmounted(() => {
</view> </view>
</view> </view>
<PlayerSeats <PlayerSeats
v-if="room.battleType === 2" v-if="battleType === 2"
:total="room.count || 10" :total="room.count || 10"
:players="players" :players="players"
/> />
<view> <view>
<SButton <SButton
v-if="user.id === owner.id && room.battleType === 1" v-if="user.id === owner.id && battleType === 1"
:disabled="!opponent.id" :disabled="!opponent.id"
:onClick="startGame" :onClick="startGame"
>进入对战</SButton >进入对战</SButton
> >
<SButton <SButton
v-if="user.id === owner.id && room.battleType === 2" v-if="user.id === owner.id && battleType === 2"
:disabled="players.length < 3" :disabled="players.length < 3"
:onClick="startGame" :onClick="startGame"
>进入大乱斗</SButton >进入大乱斗</SButton
@@ -548,7 +564,7 @@ onUnmounted(() => {
:currentShooterId="currentShooterId" :currentShooterId="currentShooterId"
/> />
<BowTarget <BowTarget
:mode="room.battleType ? 'team' : 'solo'" :mode="battleType ? 'team' : 'solo'"
:power="start ? power : 0" :power="start ? power : 0"
:currentRound="currentRound" :currentRound="currentRound"
:totalRound="totalRounds" :totalRound="totalRounds"

View File

@@ -58,6 +58,18 @@ onLoad(async (options) => {
redPoints.value = battleInfo.redScore; redPoints.value = battleInfo.redScore;
totalRounds.value = battleInfo.maxRound; totalRounds.value = battleInfo.maxRound;
roundResults.value = battleInfo.roundResults; roundResults.value = battleInfo.roundResults;
setTimeout(() => {
if (battleInfo.roundResults[battleInfo.roundResults.length - 1]) {
scores.value =
battleInfo.roundResults[
battleInfo.roundResults.length - 1
].redArrows;
blueScores.value =
battleInfo.roundResults[
battleInfo.roundResults.length - 1
].blueArrows;
}
}, 300);
if ( if (
battleInfo.redTeam[0].shotHistory[battleInfo.currentRound] || battleInfo.redTeam[0].shotHistory[battleInfo.currentRound] ||
battleInfo.blueTeam[0].shotHistory[battleInfo.currentRound] battleInfo.blueTeam[0].shotHistory[battleInfo.currentRound]