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