新建项目
This commit is contained in:
49
pages/home/home.js
Normal file
49
pages/home/home.js
Normal file
@@ -0,0 +1,49 @@
|
||||
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}`
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user