0
0
Fork 0

Change constructor to work with the fromJSON method

This commit is contained in:
Oliver-Akins 2021-01-07 12:34:17 -07:00
parent d385f8830e
commit 348b0453f7

View file

@ -4,14 +4,14 @@ import { readFile } from "fs";
import neatCSV from "neat-csv"; import neatCSV from "neat-csv";
import { Logger } from "tslog"; import { Logger } from "tslog";
import { Player } from "./Player"; import { Player } from "./Player";
import { games, hibernatedGames } from "../main"; import { games, hibernatedGames, conf } from "../main";
export class Game { export class Game {
readonly id: string; readonly id: string;
readonly host: Player; readonly host: Player;
public log: Logger; public log: Logger;
public ingame: boolean; public ingame: boolean;
public teams: [Team, Team]; public teams: Team[];
public players: Player[]; public players: Player[];
private _questions: Deck<question_deck>; private _questions: Deck<question_deck>;
private _objects: Deck<object_deck>; private _objects: Deck<object_deck>;
@ -19,23 +19,28 @@ export class Game {
public object: string; public object: string;
constructor(conf: config, host: Player) { constructor(host: Player, options:any=null) {
this.id = Game.generateID(conf.game.code_length);
this.host = host; this.host = host;
this.ingame = false; this.ingame = false;
this.players = []; this.players = [host];
this.id = options.id || Game.generateID(conf.game.code_length);
// Get the decks based on what type of data they are. // If the object is being instantiated from JSON we don't want to do
switch (conf.game.cards.type) { // any of the stuff that requires weird per-game stuff
case "csv": if (!options) {
this.parseDeckCSV(conf);
break; // Get the decks based on what type of data they are.
case "sheets": switch (conf.game.cards.type) {
this.parseDeckGoogleSheets(conf); case "csv":
break; this.parseDeckCSV(conf);
break;
case "sheets":
this.parseDeckGoogleSheets(conf);
break;
};
// Instantiate everything for the teams
this.teams = [ new Team(1), new Team(2) ];
}; };
// Instantiate everything for the teams
this.teams = [ new Team(1), new Team(2) ];
}; };
get questions() { return this._questions; }; get questions() { return this._questions; };