更新成数据覆盖同步
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
=
|
||||
<script setup>
|
||||
import { computed } from "vue";
|
||||
import BowPower from "@/components/BowPower.vue";
|
||||
import { RoundImages } from "@/constants";
|
||||
defineProps({
|
||||
const props = defineProps({
|
||||
roundResults: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
@@ -20,6 +21,10 @@ defineProps({
|
||||
default: 0,
|
||||
},
|
||||
});
|
||||
|
||||
const normalRounds = computed(
|
||||
() => props.roundResults.length - props.goldenRound
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -43,15 +48,9 @@ defineProps({
|
||||
<view class="players">
|
||||
<view>
|
||||
<view v-for="(result, index) in roundResults" :key="index">
|
||||
<block
|
||||
v-if="goldenRound > 0 && index >= roundResults.length - goldenRound"
|
||||
>
|
||||
<block v-if="index + 1 > normalRounds">
|
||||
<image
|
||||
:src="
|
||||
RoundImages[
|
||||
`gold${index + 1 - (roundResults.length - goldenRound)}`
|
||||
]
|
||||
"
|
||||
:src="RoundImages[`gold${index + 1 - normalRounds}`]"
|
||||
mode="widthFix"
|
||||
/>
|
||||
</block>
|
||||
@@ -84,15 +83,9 @@ defineProps({
|
||||
</view>
|
||||
<view>
|
||||
<view v-for="(result, index) in roundResults" :key="index">
|
||||
<block
|
||||
v-if="goldenRound > 0 && index >= roundResults.length - goldenRound"
|
||||
>
|
||||
<block v-if="index + 1 > normalRounds">
|
||||
<image
|
||||
:src="
|
||||
RoundImages[
|
||||
`gold${index + 1 - (roundResults.length - goldenRound)}`
|
||||
]
|
||||
"
|
||||
:src="RoundImages[`gold${index + 1 - normalRounds}`]"
|
||||
mode="widthFix"
|
||||
/>
|
||||
</block>
|
||||
@@ -148,7 +141,7 @@ defineProps({
|
||||
.container > view:nth-child(2) > text {
|
||||
z-index: 1;
|
||||
margin-top: 2px;
|
||||
color: #8A323E;
|
||||
color: #8a323e;
|
||||
font-weight: 500;
|
||||
}
|
||||
.container > view:nth-child(2) > text:nth-child(2) {
|
||||
|
||||
@@ -117,10 +117,10 @@ onBeforeUnmount(() => {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
font-size: 16px;
|
||||
font-size: 32rpx;
|
||||
}
|
||||
.round-end-tip > text:first-child {
|
||||
font-size: 18px;
|
||||
font-size: 36rpx;
|
||||
color: #fff;
|
||||
}
|
||||
.point-view1 {
|
||||
@@ -137,7 +137,7 @@ onBeforeUnmount(() => {
|
||||
}
|
||||
.point-view2 {
|
||||
margin: 12px 0;
|
||||
font-size: 24px;
|
||||
font-size: 48rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
@@ -155,7 +155,7 @@ onBeforeUnmount(() => {
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-top: 10px;
|
||||
font-size: 14px;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
.final-shoot > text:nth-child(1) {
|
||||
width: 20px;
|
||||
@@ -163,7 +163,7 @@ onBeforeUnmount(() => {
|
||||
}
|
||||
.final-shoot > text:nth-child(1),
|
||||
.final-shoot > text:nth-child(3) {
|
||||
font-size: 18px;
|
||||
font-size: 32rpx;
|
||||
color: #fed847;
|
||||
margin-left: 10px;
|
||||
margin-right: 5px;
|
||||
|
||||
@@ -83,7 +83,8 @@ onBeforeUnmount(() => {
|
||||
margin-bottom: 12vw;
|
||||
}
|
||||
.container > image {
|
||||
width: 100%;
|
||||
width: 360rpx;
|
||||
height: 80rpx;
|
||||
transform: translateY(7px);
|
||||
}
|
||||
.container > view:last-child {
|
||||
|
||||
@@ -28,7 +28,6 @@ const currentRound = ref(1);
|
||||
const goldenRound = ref(0);
|
||||
const currentRedPoint = ref(0);
|
||||
const currentBluePoint = ref(0);
|
||||
const totalRounds = ref(0);
|
||||
const scores = ref([]);
|
||||
const blueScores = ref([]);
|
||||
const redTeam = ref([]);
|
||||
@@ -63,8 +62,8 @@ function recoverData(battleInfo) {
|
||||
bluePoints.value = 0;
|
||||
redPoints.value = 0;
|
||||
currentRound.value = battleInfo.currentRound;
|
||||
totalRounds.value = battleInfo.maxRound;
|
||||
roundResults.value = [...battleInfo.roundResults];
|
||||
// 算得分
|
||||
battleInfo.roundResults.forEach((round) => {
|
||||
const blueTotal = round.blueArrows.reduce(
|
||||
(last, next) => last + next.ring,
|
||||
@@ -83,6 +82,36 @@ function recoverData(battleInfo) {
|
||||
redPoints.value += 2;
|
||||
}
|
||||
});
|
||||
if (battleInfo.goldenRoundNumber) {
|
||||
currentRound.value += battleInfo.goldenRoundNumber;
|
||||
goldenRound.value = battleInfo.goldenRoundNumber;
|
||||
isFinalShoot.value = true;
|
||||
for (let i = 1; i <= battleInfo.goldenRoundNumber; i++) {
|
||||
const redArrows = [];
|
||||
battleInfo.redTeam.forEach((item) => {
|
||||
if (item.shotHistory[roundResults.value.length + 1]) {
|
||||
item.shotHistory[roundResults.value.length + 1]
|
||||
.filter((item) => !!item.playerId)
|
||||
.forEach((item) => redArrows.push(item));
|
||||
}
|
||||
});
|
||||
const blueArrows = [];
|
||||
battleInfo.blueTeam.forEach((item) => {
|
||||
if (item.shotHistory[roundResults.value.length + 1]) {
|
||||
item.shotHistory[roundResults.value.length + 1]
|
||||
.filter((item) => !!item.playerId)
|
||||
.forEach((item) => blueArrows.push(item));
|
||||
}
|
||||
});
|
||||
roundResults.value.push({
|
||||
number: roundResults.value.length + 1,
|
||||
blueArrows,
|
||||
redArrows,
|
||||
blueTotal: blueArrows.reduce((last, next) => last + next.ring, 0),
|
||||
redTotal: redArrows.reduce((last, next) => last + next.ring, 0),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
const hasCurrentRoundData =
|
||||
battleInfo.redTeam.some(
|
||||
(item) => !!item.shotHistory[battleInfo.currentRound]
|
||||
@@ -111,22 +140,6 @@ function recoverData(battleInfo) {
|
||||
blueArrows,
|
||||
});
|
||||
}
|
||||
if (battleInfo.goldenRound) {
|
||||
const { ShotCount, RedRecords, BlueRecords } = battleInfo.goldenRound;
|
||||
currentRound.value += ShotCount;
|
||||
goldenRound.value += ShotCount;
|
||||
isFinalShoot.value = true;
|
||||
for (let i = 0; i < ShotCount; i++) {
|
||||
const roundData = {
|
||||
redArrows:
|
||||
RedRecords && RedRecords[i] ? RedRecords[i].Arrows || [] : [],
|
||||
blueArrows:
|
||||
BlueRecords && BlueRecords[i] ? BlueRecords[i].Arrows || [] : [],
|
||||
gold: true,
|
||||
};
|
||||
roundResults.value.push(roundData);
|
||||
}
|
||||
} else {
|
||||
[...battleInfo.redTeam, ...battleInfo.blueTeam].some((p) => {
|
||||
if (p.id === user.value.id) {
|
||||
const roundArrows = Object.values(p.shotHistory);
|
||||
@@ -144,9 +157,13 @@ function recoverData(battleInfo) {
|
||||
const lastIndex = roundResults.value.length - 1;
|
||||
if (roundResults.value[lastIndex]) {
|
||||
const redArrows = roundResults.value[lastIndex].redArrows;
|
||||
scores.value = [...redArrows].filter((item) => !!item.playerId);
|
||||
scores.value = [...redArrows]
|
||||
.filter((item) => !!item.playerId)
|
||||
.sort((a, b) => a.shotTimeUnix - b.shotTimeUnix);
|
||||
const blueArrows = roundResults.value[lastIndex].blueArrows;
|
||||
blueScores.value = [...blueArrows].filter((item) => !!item.playerId);
|
||||
blueScores.value = [...blueArrows]
|
||||
.filter((item) => !!item.playerId)
|
||||
.sort((a, b) => a.shotTimeUnix - b.shotTimeUnix);
|
||||
}
|
||||
// if (battleInfo.status !== 11) return;
|
||||
if (battleInfo.firePlayerIndex) {
|
||||
@@ -174,7 +191,6 @@ async function onReceiveMessage(messages = []) {
|
||||
messages.forEach((msg) => {
|
||||
if (msg.constructor === MESSAGETYPES.AllReady) {
|
||||
start.value = true;
|
||||
totalRounds.value = msg.groupUserStatus.config.maxRounds;
|
||||
}
|
||||
if (msg.constructor === MESSAGETYPES.ToSomeoneShoot) {
|
||||
if (currentShooterId.value !== msg.userId) {
|
||||
@@ -193,7 +209,7 @@ async function onReceiveMessage(messages = []) {
|
||||
}
|
||||
}
|
||||
if (msg.constructor === MESSAGETYPES.ShootResult) {
|
||||
if (currentShooterId.value !== msg.userId) return;
|
||||
// if (currentShooterId.value !== msg.userId) return;
|
||||
// const isRed = redTeam.value.find((item) => item.id === msg.userId);
|
||||
// if (isRed) scores.value.push({ ...msg.target });
|
||||
// else blueScores.value.push({ ...msg.target });
|
||||
@@ -208,7 +224,12 @@ async function onReceiveMessage(messages = []) {
|
||||
// roundResults.value[currentRound.value - 1][
|
||||
// isRed ? "redArrows" : "blueArrows"
|
||||
// ].push({ ...msg.target });
|
||||
if (msg.battleInfo) recoverData(msg.battleInfo);
|
||||
if (msg.battleInfo) {
|
||||
recoverData(msg.battleInfo);
|
||||
// if (isFinalShoot.value) {
|
||||
// uni.setStorageSync(`current-battle-${Date.now()}`, msg.battleInfo);
|
||||
// }
|
||||
}
|
||||
}
|
||||
if (msg.constructor === MESSAGETYPES.CurrentRoundEnded) {
|
||||
const result = msg.preRoundResult;
|
||||
@@ -219,19 +240,12 @@ async function onReceiveMessage(messages = []) {
|
||||
currentRedPoint.value = result.redScore;
|
||||
bluePoints.value += result.blueScore;
|
||||
redPoints.value += result.redScore;
|
||||
currentRound.value = result.currentRound + 1;
|
||||
if (!result.goldenRound) {
|
||||
showRoundTip.value = true;
|
||||
}
|
||||
}
|
||||
if (msg.constructor === MESSAGETYPES.FinalShoot) {
|
||||
currentShooterId.value = 0;
|
||||
currentRound.value = msg.groupUserStatus.currentRound + 1;
|
||||
goldenRound.value += 1;
|
||||
roundResults.value.push({
|
||||
redArrows: [],
|
||||
blueArrows: [],
|
||||
});
|
||||
currentBluePoint.value = bluePoints.value;
|
||||
currentRedPoint.value = redPoints.value;
|
||||
if (!isFinalShoot.value) {
|
||||
@@ -242,7 +256,6 @@ async function onReceiveMessage(messages = []) {
|
||||
}
|
||||
if (msg.constructor === MESSAGETYPES.MatchOver) {
|
||||
if (msg.endStatus.noSaved) {
|
||||
currentRound.value += 1;
|
||||
currentBluePoint.value = 0;
|
||||
currentRedPoint.value = 0;
|
||||
showRoundTip.value = true;
|
||||
@@ -356,7 +369,7 @@ onHide(() => {
|
||||
<RoundEndTip
|
||||
v-if="showRoundTip"
|
||||
:isFinal="isFinalShoot"
|
||||
:round="currentRound - 1"
|
||||
:round="currentRound"
|
||||
:bluePoint="currentBluePoint"
|
||||
:redPoint="currentRedPoint"
|
||||
:roundData="
|
||||
|
||||
Reference in New Issue
Block a user