Add a game manager to the server
This commit is contained in:
parent
0ddf5d8a14
commit
6bbd8d68c0
2 changed files with 31 additions and 0 deletions
29
server/src/objects/GameDB.ts
Normal file
29
server/src/objects/GameDB.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import { Game } from "./Game";
|
||||
|
||||
export class GameDB {
|
||||
private games: {[index: string]: Game};
|
||||
|
||||
constructor () {
|
||||
this.games = {};
|
||||
};
|
||||
|
||||
/** Determines if a game exists with the provided ID */
|
||||
public has(id: string): boolean {
|
||||
return this.games[id] != null;
|
||||
};
|
||||
|
||||
/** Get's the Game object associated with the provided ID */
|
||||
public get(id: string): Game {
|
||||
return this.games[id];
|
||||
};
|
||||
|
||||
/** Adds a Game object into the database */
|
||||
public set(game: Game): void {
|
||||
this.games[game.id] = game;
|
||||
};
|
||||
|
||||
/** Returns a count of how many games currently exist in the database */
|
||||
public get count() {
|
||||
return Object.keys(this.games).length;
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue