-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathschema.js
58 lines (47 loc) · 1.46 KB
/
schema.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import _ from "lodash"
import Game from "./models/Game";
let games = {}
function getOrCreateGame(partyCode, cb) {
if (games[partyCode]) {
return games[partyCode]
}
else {
games[partyCode] = new Game(partyCode, 60, cb)
}
return games[partyCode]
}
export function joinGame(partyCode, sessionID, name) {
let game = getOrCreateGame(partyCode)
game.addNewPlayer(name, sessionID);
}
// returns the players in the game []
export function getLobbyState(partyCode, sessionID, cb) {
let game = getOrCreateGame(partyCode, cb);
let currentPlayer = game.getPlayer(sessionID)
let players = _.map(game.players, (player) => player.name);
let response = {
players,
currentPlayer: currentPlayer || null
}
return response;
}
export function getPlayerRoundState(partyCode, sessionID, cb) {
let game = getOrCreateGame(partyCode);
return game.getPlayerRoundState(sessionID);
}
export function playCard(partyCode, cardID, sessionID, cb) {
let game = getOrCreateGame(partyCode);
game.playCard(sessionID, cardID, cb);
}
export function judgeSelectCard(partyCode, cardID, sessionID, cb) {
let game = getOrCreateGame(partyCode);
game.judgeSelectCard(sessionID, cardID, cb);
}
export function shuffleCards(partyCode, sourceIdx, destIdx, sessionID, cb) {
let game = getOrCreateGame(partyCode);
game.shuffleCard(sessionID, sourceIdx, destIdx, cb);
}
export function endRound(partyCode, cb) {
let game = getOrCreateGame(partyCode);
game.endRound(cb);
}