bug修复
This commit is contained in:
@@ -48,6 +48,8 @@ const props = defineProps({
|
||||
});
|
||||
|
||||
const latestOne = ref(null);
|
||||
const prevScores = ref([]);
|
||||
const prevBlueScores = ref([]);
|
||||
// const startCount = ref(false);
|
||||
const timer = ref(null);
|
||||
|
||||
@@ -63,12 +65,15 @@ const timer = ref(null);
|
||||
|
||||
watch(
|
||||
() => props.scores,
|
||||
(newVal, oldVal) => {
|
||||
(newVal) => {
|
||||
if (newVal.length - prevScores.value.length === 1) {
|
||||
latestOne.value = newVal[newVal.length - 1];
|
||||
if (timer.value) clearTimeout(timer.value);
|
||||
timer.value = setTimeout(() => {
|
||||
latestOne.value = null;
|
||||
}, 1000);
|
||||
}
|
||||
prevScores.value = [...newVal];
|
||||
},
|
||||
{
|
||||
deep: true,
|
||||
@@ -78,11 +83,14 @@ watch(
|
||||
watch(
|
||||
() => props.blueScores,
|
||||
(newVal) => {
|
||||
if (newVal.length - prevBlueScores.value.length === 1) {
|
||||
latestOne.value = newVal[newVal.length - 1];
|
||||
if (timer.value) clearTimeout(timer.value);
|
||||
timer.value = setTimeout(() => {
|
||||
latestOne.value = null;
|
||||
}, 1000);
|
||||
}
|
||||
prevBlueScores.value = [...newVal];
|
||||
},
|
||||
{
|
||||
deep: true,
|
||||
@@ -141,7 +149,7 @@ const simulShoot2 = async () => {
|
||||
<view
|
||||
v-if="bow.ring > 0"
|
||||
:class="`hit ${
|
||||
index === scores.length - 1 && showLatestArrow ? 'pump-in' : ''
|
||||
index === scores.length - 1 && latestOne ? 'pump-in' : ''
|
||||
}`"
|
||||
:style="{
|
||||
left: calcRealX(bow.x),
|
||||
@@ -149,7 +157,7 @@ const simulShoot2 = async () => {
|
||||
backgroundColor:
|
||||
index === scores.length - 1 &&
|
||||
!blueScores.length &&
|
||||
showLatestArrow &&
|
||||
latestOne &&
|
||||
mode !== 'team'
|
||||
? 'green'
|
||||
: 'red',
|
||||
@@ -161,7 +169,7 @@ const simulShoot2 = async () => {
|
||||
<view
|
||||
v-if="bow.ring > 0"
|
||||
:class="`hit ${
|
||||
index === blueScores.length - 1 && showLatestArrow ? 'pump-in' : ''
|
||||
index === blueScores.length - 1 && latestOne ? 'pump-in' : ''
|
||||
}`"
|
||||
:style="{
|
||||
left: calcRealX(bow.x),
|
||||
@@ -240,7 +248,6 @@ const simulShoot2 = async () => {
|
||||
font-size: 8px;
|
||||
text-align: center;
|
||||
line-height: 10px;
|
||||
transition: all 0.3s ease;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.hit > text {
|
||||
|
||||
@@ -98,16 +98,12 @@ watch(
|
||||
watch(
|
||||
() => props.start,
|
||||
(newVal) => {
|
||||
if (!newVal && timer.value) {
|
||||
if (timer.value) clearInterval(timer.value);
|
||||
}
|
||||
if (newVal) {
|
||||
remain.value = props.total;
|
||||
timer.value = setInterval(() => {
|
||||
if (remain.value > 0) remain.value--;
|
||||
}, 1000);
|
||||
} else {
|
||||
if (timer.value) clearInterval(timer.value);
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -118,9 +114,11 @@ watch(
|
||||
const updateRemain = (value) => {
|
||||
if (timer.value) clearInterval(timer.value);
|
||||
remain.value = Math.floor(value);
|
||||
if (remain.value > 0) {
|
||||
timer.value = setInterval(() => {
|
||||
if (remain.value > 0) remain.value--;
|
||||
}, 1000);
|
||||
}
|
||||
};
|
||||
|
||||
const updateSound = () => {
|
||||
|
||||
@@ -42,16 +42,17 @@ onMounted(async () => {
|
||||
const battleInfo = uni.getStorageSync("last-battle");
|
||||
console.log("----battleInfo", battleInfo);
|
||||
data.value = battleInfo;
|
||||
if (battleInfo.mode === 1) {
|
||||
battleInfo.playerStats.forEach((p) => {
|
||||
if (p.id === user.value.id) {
|
||||
totalPoints.value = p.totalScore;
|
||||
if (p.team === battleInfo.winner) ifWin.value = true;
|
||||
}
|
||||
});
|
||||
} else if (battleInfo.mode === 2) {
|
||||
const mine = battleInfo.playerStats.find((p) => p.id === user.value.id);
|
||||
if (mine) totalPoints.value = mine.totalScore;
|
||||
if (mine) {
|
||||
if (battleInfo.mode === 1) {
|
||||
totalPoints.value = mine.roundStats.reduce(
|
||||
(last, next) => last + next.arrows.length,
|
||||
0
|
||||
);
|
||||
if (mine.team === battleInfo.winner) ifWin.value = true;
|
||||
} else if (battleInfo.mode === 2) {
|
||||
totalPoints.value = mine.totalScore;
|
||||
}
|
||||
}
|
||||
// const result = await getHomeData();
|
||||
// if (result.user) updateUser(result.user);
|
||||
@@ -151,7 +152,7 @@ const checkBowData = () => {
|
||||
:borderColor="topThreeColors[index] || ''"
|
||||
/>
|
||||
<view class="player-title">
|
||||
<text>{{ player.name }}</text>
|
||||
<text class="truncate">{{ player.name }}</text>
|
||||
<text>{{ getLvlName(player.totalScore) }}</text>
|
||||
</view>
|
||||
<text
|
||||
@@ -164,12 +165,12 @@ const checkBowData = () => {
|
||||
<view class="battle-e">
|
||||
<image src="../static/row-yellow-bg.png" mode="widthFix" />
|
||||
<Avatar v-if="data.mode === 1" :src="user.avatar" :size="40" />
|
||||
<text v-if="data.battleMode === 1"
|
||||
>经验 {{ totalPoints > 0 ? "+" + totalPoints : totalPoints }}</text
|
||||
>
|
||||
<text v-if="data.battleMode === 2"
|
||||
>积分 {{ totalPoints > 0 ? "+" + totalPoints : totalPoints }}</text
|
||||
>
|
||||
<text v-if="data.battleMode === 1">
|
||||
经验 {{ totalPoints > 0 ? "+" + totalPoints : totalPoints }}
|
||||
</text>
|
||||
<text v-if="data.battleMode === 2">
|
||||
积分 {{ totalPoints > 0 ? "+" + totalPoints : totalPoints }}
|
||||
</text>
|
||||
</view>
|
||||
<text v-if="data.mode === 1" class="description">{{
|
||||
ifWin ? "你已经奔跑在通向王者的路上了!" : "失败是成功之母,儿子在等你!"
|
||||
@@ -350,6 +351,7 @@ const checkBowData = () => {
|
||||
.player-title > text:first-child {
|
||||
color: #fff;
|
||||
margin-bottom: 3px;
|
||||
width: 40vw;
|
||||
}
|
||||
.player-title > text:last-child {
|
||||
font-size: 13px;
|
||||
|
||||
@@ -55,6 +55,7 @@ const showModal = ref(false);
|
||||
const halfTimeTip = ref(false);
|
||||
const isFinalShoot = ref(false);
|
||||
const total = ref(15);
|
||||
const battleType = ref(0);
|
||||
|
||||
watch(
|
||||
() => [players.value, playersScores.value],
|
||||
@@ -77,6 +78,7 @@ onLoad(async (options) => {
|
||||
console.log("----battleInfo", battleInfo);
|
||||
if (battleInfo) {
|
||||
battleId.value = battleInfo.id;
|
||||
battleType.value = battleInfo.config.mode;
|
||||
start.value = true;
|
||||
step.value = 3;
|
||||
if (battleInfo.config.mode === 1) {
|
||||
@@ -88,6 +90,18 @@ onLoad(async (options) => {
|
||||
totalRounds.value = battleInfo.maxRound;
|
||||
roundResults.value = battleInfo.roundResults;
|
||||
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 (
|
||||
battleInfo.redTeam[0].shotHistory[battleInfo.currentRound] ||
|
||||
battleInfo.blueTeam[0].shotHistory[battleInfo.currentRound]
|
||||
@@ -151,6 +165,7 @@ onLoad(async (options) => {
|
||||
roomNumber.value = options.roomNumber;
|
||||
const result = await getRoomAPI(options.roomNumber);
|
||||
room.value = result;
|
||||
battleType.value = result.battleType;
|
||||
result.members.some((m) => {
|
||||
if (m.userInfo.id === result.creator) {
|
||||
owner.value = {
|
||||
@@ -218,10 +233,10 @@ async function onReceiveMessage(messages = []) {
|
||||
timerSeq.value += 1;
|
||||
battleId.value = msg.id;
|
||||
step.value = 2;
|
||||
if (room.value.battleType === 1) {
|
||||
if (battleType.value === 1) {
|
||||
redTeam.value = msg.groupUserStatus.redTeam;
|
||||
blueTeam.value = msg.groupUserStatus.blueTeam;
|
||||
} else if (room.value.battleType === 2) {
|
||||
} else if (battleType.value === 2) {
|
||||
players.value = [
|
||||
...msg.groupUserStatus.redTeam,
|
||||
...msg.groupUserStatus.blueTeam,
|
||||
@@ -233,7 +248,7 @@ async function onReceiveMessage(messages = []) {
|
||||
}
|
||||
if (msg.roomNumber === roomNumber.value) {
|
||||
if (msg.constructor === MESSAGETYPES.UserEnterRoom) {
|
||||
if (room.value.battleType === 1) {
|
||||
if (battleType.value === 1) {
|
||||
if (msg.userId === room.value.creator) {
|
||||
owner.value = {
|
||||
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) {
|
||||
players.value[0] = {
|
||||
id: msg.userId,
|
||||
@@ -265,7 +280,7 @@ async function onReceiveMessage(messages = []) {
|
||||
}
|
||||
}
|
||||
if (!start.value && msg.constructor === MESSAGETYPES.UserExitRoom) {
|
||||
if (room.value.battleType === 1) {
|
||||
if (battleType.value === 1) {
|
||||
if (msg.userId === room.value.creator) {
|
||||
owner.value = {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -298,7 +313,7 @@ async function onReceiveMessage(messages = []) {
|
||||
scores.value = [];
|
||||
totalRounds.value = msg.groupUserStatus.config.maxRounds;
|
||||
step.value = 3;
|
||||
if (room.value.battleType === 2) {
|
||||
if (battleType.value === 2) {
|
||||
tips.value = "请在90秒内射完12支箭";
|
||||
seq.value += 1;
|
||||
}
|
||||
@@ -319,7 +334,7 @@ async function onReceiveMessage(messages = []) {
|
||||
total.value = 90;
|
||||
}
|
||||
if (msg.constructor === MESSAGETYPES.ToSomeoneShoot) {
|
||||
if (room.value.battleType === 1) {
|
||||
if (battleType.value === 1) {
|
||||
if (currentShooterId.value !== msg.userId) {
|
||||
seq.value += 1;
|
||||
currentShooterId.value = msg.userId;
|
||||
@@ -337,7 +352,7 @@ async function onReceiveMessage(messages = []) {
|
||||
}
|
||||
}
|
||||
if (msg.constructor === MESSAGETYPES.ShootResult) {
|
||||
if (room.value.battleType === 1) {
|
||||
if (battleType.value === 1) {
|
||||
const isRed = redTeam.value.find((item) => item.id === msg.userId);
|
||||
if (isRed) scores.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);
|
||||
power.value = msg.target.battery;
|
||||
}
|
||||
@@ -370,7 +385,7 @@ async function onReceiveMessage(messages = []) {
|
||||
playersScores.value[msg.userId].push(msg.target);
|
||||
}
|
||||
if (msg.constructor === MESSAGETYPES.CurrentRoundEnded) {
|
||||
if (room.value.battleType === 1) {
|
||||
if (battleType.value === 1) {
|
||||
const result = msg.preRoundResult;
|
||||
scores.value = [];
|
||||
blueScores.value = [];
|
||||
@@ -381,6 +396,7 @@ async function onReceiveMessage(messages = []) {
|
||||
redPoints.value += result.redScore;
|
||||
// roundResults.value = result.roundResults;
|
||||
currentRound.value = result.currentRound + 1;
|
||||
uni.$emit("update-ramain", 0);
|
||||
if (result.currentRound < 5) {
|
||||
roundResults.value.push({
|
||||
redArrows: [],
|
||||
@@ -468,13 +484,13 @@ onUnmounted(() => {
|
||||
<view class="battle-guide">
|
||||
<view :style="{ display: 'flex', flexDirection: 'column' }">
|
||||
<text :style="{ color: '#fed847' }">弓箭手们,人都到齐了吗?</text>
|
||||
<text v-if="room.battleType === 1">1v1比赛即将开始! </text>
|
||||
<text v-if="room.battleType === 2">大乱斗即将开始! </text>
|
||||
<text v-if="battleType === 1">1v1比赛即将开始! </text>
|
||||
<text v-if="battleType === 2">大乱斗即将开始! </text>
|
||||
</view>
|
||||
<view @click="setClipboardData">邀请好友</view>
|
||||
</view>
|
||||
</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" />
|
||||
<view>
|
||||
<view class="player" :style="{ transform: 'translateY(-60px)' }">
|
||||
@@ -502,19 +518,19 @@ onUnmounted(() => {
|
||||
</view>
|
||||
</view>
|
||||
<PlayerSeats
|
||||
v-if="room.battleType === 2"
|
||||
v-if="battleType === 2"
|
||||
:total="room.count || 10"
|
||||
:players="players"
|
||||
/>
|
||||
<view>
|
||||
<SButton
|
||||
v-if="user.id === owner.id && room.battleType === 1"
|
||||
v-if="user.id === owner.id && battleType === 1"
|
||||
:disabled="!opponent.id"
|
||||
:onClick="startGame"
|
||||
>进入对战</SButton
|
||||
>
|
||||
<SButton
|
||||
v-if="user.id === owner.id && room.battleType === 2"
|
||||
v-if="user.id === owner.id && battleType === 2"
|
||||
:disabled="players.length < 3"
|
||||
:onClick="startGame"
|
||||
>进入大乱斗</SButton
|
||||
@@ -548,7 +564,7 @@ onUnmounted(() => {
|
||||
:currentShooterId="currentShooterId"
|
||||
/>
|
||||
<BowTarget
|
||||
:mode="room.battleType ? 'team' : 'solo'"
|
||||
:mode="battleType ? 'team' : 'solo'"
|
||||
:power="start ? power : 0"
|
||||
:currentRound="currentRound"
|
||||
:totalRound="totalRounds"
|
||||
|
||||
@@ -58,6 +58,18 @@ onLoad(async (options) => {
|
||||
redPoints.value = battleInfo.redScore;
|
||||
totalRounds.value = battleInfo.maxRound;
|
||||
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 (
|
||||
battleInfo.redTeam[0].shotHistory[battleInfo.currentRound] ||
|
||||
battleInfo.blueTeam[0].shotHistory[battleInfo.currentRound]
|
||||
|
||||
Reference in New Issue
Block a user