Start game logic
This commit is contained in:
parent
8ed8449b11
commit
cdd78585b8
3 changed files with 32 additions and 14 deletions
|
@ -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 };
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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 };
|
||||
},
|
||||
});
|
||||
|
|
|
@ -2,21 +2,29 @@
|
|||
<div>
|
||||
<h1>Waiting for players...</h1>
|
||||
<p>Join code: {{ currentRoom.joinCode }}</p>
|
||||
<p>State: {{ currentRoom.state }}
|
||||
<p>Owner: {{ playerNames[currentRoom.owner] }}</p>
|
||||
<p>Rules: <br /><pre>{{ JSON.stringify(currentRoom.ruleset, null, 2) }}</pre></p>
|
||||
<p>Info: <br /><pre>{{ JSON.stringify(roomInfo, null, 2) }}</pre></p>
|
||||
<p>Room: <br /><pre>{{ JSON.stringify(currentRoom, null, 2) }}</pre></p>
|
||||
<p>
|
||||
Players:
|
||||
<ul>
|
||||
<li v-for="player in players" v-bind:key="player._id">{{ player.name }}</li>
|
||||
<li v-for="player in players" v-bind:key="player._id">
|
||||
{{ player.name }} (level {{ player.level }})
|
||||
</li>
|
||||
</ul>
|
||||
</p>
|
||||
<p><button v-if="isOwner" :disabled="!canStart">Start Game</button></p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
props: ["currentRoom", "players", "roomInfo"],
|
||||
props: [
|
||||
"currentRoom",
|
||||
"players",
|
||||
"roomInfo",
|
||||
],
|
||||
|
||||
computed: {
|
||||
playerNames: function() {
|
||||
let names = new Map();
|
||||
|
@ -25,6 +33,19 @@ export default {
|
|||
}
|
||||
return names;
|
||||
},
|
||||
|
||||
isOwner: function() {
|
||||
return this.currentRoom.owner === this.roomInfo.playerId;
|
||||
},
|
||||
|
||||
canStart: function() {
|
||||
let val =
|
||||
// only the owner can start the game
|
||||
this.isOwner
|
||||
// TODO: actually calculate number of players based on decks?
|
||||
&& this.players.length === 4;
|
||||
return val;
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Reference in a new issue