From cdd78585b803cfb4a8c42c30342254c4ea2763cd Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Fri, 27 Nov 2020 02:44:06 -0600 Subject: [PATCH] Start game logic --- imports/api/methods/joinGame.js | 10 ++++----- imports/api/methods/newGame.js | 7 +++---- imports/ui/components/WaitingRoom.vue | 29 +++++++++++++++++++++++---- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/imports/api/methods/joinGame.js b/imports/api/methods/joinGame.js index 0be8ec1..00d9acd 100644 --- a/imports/api/methods/joinGame.js +++ b/imports/api/methods/joinGame.js @@ -24,8 +24,10 @@ Meteor.methods({ throw new Meteor.Error("room-id-undefined"); } + let level = 2; + let playerId; try { - let playerId = Players.insert({ roomId, name }); + playerId = Players.insert({ roomId, name, level }); } catch (e) { if (e.code === 11000) { throw new Meteor.Error("name-collision"); @@ -33,10 +35,6 @@ Meteor.methods({ } let joinCode = room.joinCode; - let players = {}; - Players.find({ roomId }).forEach((doc) => { - players[doc._id] = doc.name; - }); - return { joinCode, players, roomId }; + return { joinCode, playerId, roomId }; } }); diff --git a/imports/api/methods/newGame.js b/imports/api/methods/newGame.js index 104a654..7f2e2ad 100644 --- a/imports/api/methods/newGame.js +++ b/imports/api/methods/newGame.js @@ -37,15 +37,14 @@ Meteor.methods({ } console.log("ROOM ID", roomId); - let playerId = Players.insert({ roomId, name }); + let level = 2; + let playerId = Players.insert({ roomId, name, level }); Rooms.update(roomId, { $set: { owner: playerId } }); if (remainingAttempts == 0 && roomId === undefined) { throw new Meteor.Error("no-more-rooms"); } - let players = {}; - players[playerId] = name; - return { players, roomId, joinCode }; + return { playerId, roomId, joinCode }; }, }); diff --git a/imports/ui/components/WaitingRoom.vue b/imports/ui/components/WaitingRoom.vue index 5cca564..cd2d39c 100644 --- a/imports/ui/components/WaitingRoom.vue +++ b/imports/ui/components/WaitingRoom.vue @@ -2,21 +2,29 @@

Waiting for players...

Join code: {{ currentRoom.joinCode }}

-

State: {{ currentRoom.state }}

Owner: {{ playerNames[currentRoom.owner] }}

-

Rules:

{{ JSON.stringify(currentRoom.ruleset, null, 2) }}

+

Info:

{{ JSON.stringify(roomInfo, null, 2) }}

+

Room:

{{ JSON.stringify(currentRoom, null, 2) }}

Players:

+