-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmem_db.js
98 lines (98 loc) · 2.37 KB
/
mem_db.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
module.exports = {
races: {},
sockets: {},
addNewRace(code) {
if (!code || this.races[code]) {
return false;
}
this.races[code] = {
players: [],
playing: false,
track: "",
tracksReady: 0,
playersReady: 0,
readySetGo: 0,
finished: []
};
this.sockets[code] = [];
return true;
},
addPlayerToRace(code, id, agent, scrn, socket) {
if (!this.races[code]) {
return false;
}
this.races[code].players.push({
id,
agent,
scrn,
color: this.races[code].players.length,
webaudio: true,
name: "NEW"
});
this.sockets[code].push(socket);
return true;
},
editPlayerName(code, player, name) {
if (!this.races[code]) {
return false;
}
this.races[code].players[player].name = name;
return true;
},
setRaceTrack(code, track) {
if (!this.races[code]) {
return false;
}
this.races[code].track = track;
return true;
},
incrementTrackReady(code) {
if (!this.races[code]) {
return false;
}
this.races[code].tracksReady += 1;
return true;
},
incrementPlayerReady(code) {
if (!this.races[code]) {
return false;
}
this.races[code].playersReady += 1;
return true;
},
incrementReadySetGo(code) {
if (!this.races[code]) {
return false;
}
this.races[code].readySetGo += 1;
return true;
},
markFinished(code, player, lap_time, color) {
if (!this.races[code]) {
return false;
}
this.races[code].finished.push({
player,
lap_time,
color
});
return true;
},
getRace(code) {
return this.races[code];
},
getRaceSockets(code) {
return this.sockets[code];
},
resetRace(code) {
if (!this.races[code]) {
return false;
}
this.races[code].track = "";
this.races[code].tracksReady = 0;
this.races[code].playersReady = 0;
this.races[code].readySetGo = 0;
this.races[code].finished = [];
return true;
}
}