新版房间1v1对战数据调试完成
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<script setup>
|
||||
import { ref, watch, onMounted, onBeforeUnmount } from "vue";
|
||||
import { onLoad, onShareAppMessage } from "@dcloudio/uni-app";
|
||||
import { onShow, onLoad, onShareAppMessage } from "@dcloudio/uni-app";
|
||||
import Container from "@/components/Container.vue";
|
||||
import PlayerSeats from "@/components/PlayerSeats.vue";
|
||||
import Guide from "@/components/Guide.vue";
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
getReadyAPI,
|
||||
} from "@/apis";
|
||||
|
||||
import { MESSAGETYPES } from "@/constants";
|
||||
import { MESSAGETYPES, MESSAGETYPESV2 } from "@/constants";
|
||||
import useStore from "@/store";
|
||||
import { storeToRefs } from "pinia";
|
||||
const store = useStore();
|
||||
@@ -38,6 +38,7 @@ const allReady = ref(false);
|
||||
const timer = ref(null);
|
||||
|
||||
async function refreshRoomData() {
|
||||
if (!roomNumber.value) return;
|
||||
const result = await getRoomAPI(roomNumber.value);
|
||||
if (result.started) return;
|
||||
room.value = result;
|
||||
@@ -94,7 +95,7 @@ async function refreshRoomData() {
|
||||
refreshMembers(result.members);
|
||||
}
|
||||
if (timer.value) clearInterval(timer.value);
|
||||
timer.value = setTimeout(refreshRoomData, 1000);
|
||||
// timer.value = setTimeout(refreshRoomData, 2000);
|
||||
}
|
||||
|
||||
const startGame = async () => {
|
||||
@@ -122,9 +123,10 @@ const refreshMembers = (members = []) => {
|
||||
}
|
||||
};
|
||||
|
||||
async function onReceiveMessage(messages = []) {
|
||||
messages.forEach((msg) => {
|
||||
if (msg.roomNumber === roomNumber.value) {
|
||||
async function onReceiveMessage(message) {
|
||||
if (Array.isArray(message)) {
|
||||
message.forEach((msg) => {
|
||||
if (msg.roomNumber !== roomNumber.value) return;
|
||||
if (msg.constructor === MESSAGETYPES.UserEnterRoom) {
|
||||
if (battleType.value === 1) {
|
||||
if (msg.userId === room.value.creator) {
|
||||
@@ -193,29 +195,45 @@ async function onReceiveMessage(messages = []) {
|
||||
} else if (msg.constructor === MESSAGETYPES.SomeoneIsReady) {
|
||||
refreshRoomData();
|
||||
}
|
||||
} else if (msg.constructor === MESSAGETYPES.WaitForAllReady) {
|
||||
if (msg.groupUserStatus) {
|
||||
uni.setStorageSync("red-team", msg.groupUserStatus.redTeam);
|
||||
uni.setStorageSync("blue-team", msg.groupUserStatus.blueTeam);
|
||||
uni.setStorageSync("melee-players", [
|
||||
...msg.groupUserStatus.redTeam,
|
||||
...msg.groupUserStatus.blueTeam,
|
||||
]);
|
||||
uni.removeStorageSync("current-battle");
|
||||
// 避免离开页面,触发退出房间
|
||||
roomNumber.value = "";
|
||||
if (msg.groupUserStatus.config.mode == 1) {
|
||||
uni.redirectTo({
|
||||
url: `/pages/team-battle?battleId=${msg.id}&gameMode=1`,
|
||||
});
|
||||
} else if (msg.groupUserStatus.config.mode == 2) {
|
||||
uni.redirectTo({
|
||||
url: `/pages/melee-match?battleId=${msg.id}&gameMode=1`,
|
||||
});
|
||||
}
|
||||
}
|
||||
// else if (msg.constructor === MESSAGETYPES.WaitForAllReady) {
|
||||
// if (msg.groupUserStatus) {
|
||||
// uni.setStorageSync("red-team", msg.groupUserStatus.redTeam);
|
||||
// uni.setStorageSync("blue-team", msg.groupUserStatus.blueTeam);
|
||||
// uni.setStorageSync("melee-players", [
|
||||
// ...msg.groupUserStatus.redTeam,
|
||||
// ...msg.groupUserStatus.blueTeam,
|
||||
// ]);
|
||||
// uni.removeStorageSync("current-battle");
|
||||
// // 避免离开页面,触发退出房间
|
||||
// roomNumber.value = "";
|
||||
// if (msg.groupUserStatus.config.mode == 1) {
|
||||
// uni.redirectTo({
|
||||
// url: `/pages/team-battle?battleId=${msg.id}&gameMode=1`,
|
||||
// });
|
||||
// } else if (msg.groupUserStatus.config.mode == 2) {
|
||||
// uni.redirectTo({
|
||||
// url: `/pages/melee-match?battleId=${msg.id}&gameMode=1`,
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
});
|
||||
} else if (message.type === MESSAGETYPESV2.AboutToStart) {
|
||||
uni.setStorageSync("blue-team", message.teams[1].players || []);
|
||||
uni.setStorageSync("red-team", message.teams[2].players || []);
|
||||
uni.removeStorageSync("current-battle");
|
||||
roomNumber.value = "";
|
||||
let params = `?gameMode=1&battleId=${message.matchId}`;
|
||||
if (message.way == 1) {
|
||||
uni.redirectTo({
|
||||
url: "/pages/team-battle" + params,
|
||||
});
|
||||
} else if (message.way == 2) {
|
||||
uni.redirectTo({
|
||||
url: "/pages/melee-match" + params,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const chooseTeam = async (team) => {
|
||||
@@ -254,11 +272,12 @@ onShareAppMessage(() => {
|
||||
};
|
||||
});
|
||||
|
||||
onShow(() => {
|
||||
refreshRoomData();
|
||||
});
|
||||
|
||||
onLoad(async (options) => {
|
||||
if (options.roomNumber) {
|
||||
roomNumber.value = options.roomNumber;
|
||||
refreshRoomData();
|
||||
}
|
||||
if (options.roomNumber) roomNumber.value = options.roomNumber;
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
|
||||
Reference in New Issue
Block a user