Add a game manager to the server

This commit is contained in:
Oliver Akins 2022-03-07 23:36:55 -06:00
parent 0ddf5d8a14
commit 6bbd8d68c0
No known key found for this signature in database
GPG key ID: 3C2014AF9457AF99
2 changed files with 31 additions and 0 deletions

View 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;
};
}