38 lines
No EOL
1 KiB
TypeScript
38 lines
No EOL
1 KiB
TypeScript
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|undefined {
|
|
return this.games[id];
|
|
};
|
|
|
|
/** Adds a Game object into the database */
|
|
public set(game: Game): void {
|
|
this.games[game.id] = game;
|
|
};
|
|
|
|
/**
|
|
* This removes all inactive games from the system, this includes any games
|
|
* that do not have any currently connected players and are in the lobby
|
|
* state. This will not remove any games that are currently in-progress so
|
|
* that players can resume the game later if they happened to all get
|
|
* disconnected for some reason.
|
|
*/
|
|
public cleanup(): void {};
|
|
|
|
/** Returns a count of how many games currently exist in the database */
|
|
public get count() {
|
|
return Object.keys(this.games).length;
|
|
};
|
|
} |