50 lines
1.0 KiB
JavaScript
50 lines
1.0 KiB
JavaScript
const service = require("../../services/game-service");
|
|
const { GAME_MODES } = require("../../utils/constants");
|
|
|
|
Page({
|
|
data: {
|
|
currentRoom: null,
|
|
modeName: ""
|
|
},
|
|
|
|
onShow() {
|
|
let currentRoom = service.getCurrentRoom();
|
|
if (currentRoom && currentRoom.status === "cancelled") {
|
|
service.clearCurrentRoom();
|
|
currentRoom = null;
|
|
}
|
|
this.setData({
|
|
currentRoom,
|
|
modeName: currentRoom
|
|
? GAME_MODES[currentRoom.settings.mode].name
|
|
: ""
|
|
});
|
|
},
|
|
|
|
createGame() {
|
|
wx.navigateTo({ url: "/pages/create/create" });
|
|
},
|
|
|
|
joinGame() {
|
|
wx.navigateTo({ url: "/pages/join/join" });
|
|
},
|
|
|
|
openRules() {
|
|
wx.navigateTo({ url: "/pages/rules/rules" });
|
|
},
|
|
|
|
continueGame() {
|
|
const room = this.data.currentRoom;
|
|
if (!room) return;
|
|
const page =
|
|
room.status === "finished"
|
|
? "result"
|
|
: room.status === "waiting"
|
|
? "lobby"
|
|
: "game";
|
|
wx.navigateTo({
|
|
url: `/pages/${page}/${page}?code=${room.code}`
|
|
});
|
|
}
|
|
});
|