diff --git a/src/game/gameState.ts b/src/game/gameState.ts index 0404585..cdae362 100644 --- a/src/game/gameState.ts +++ b/src/game/gameState.ts @@ -1,4 +1,5 @@ import { DatabaseService } from "../db/services/Database"; +import { Comment } from "../rdrama/models/Comment"; /** * Represents the state of a game session for an Oregon Trail-style game. @@ -6,7 +7,9 @@ import { DatabaseService } from "../db/services/Database"; * to load from and save to a database. */ class GameState { - authorId: number = 0; + comment: Comment; + authorId: number; + authorName: string; amountSpentOnAnimals: number = 0; amountSpentOnAmmunition: number = 0; actualResponseTimeForBang: number = 0; @@ -16,7 +19,7 @@ class GameState { yesNoResponseToQuestions: string = ''; eventCounter: number = 0; turnNumberForSettingDate: number = 0; - currentDate: string = ''; + currentDate: string = 'MONDAY MARCH 29 1847'; shootingExpertiseLevelChoice: number = 0; eatingChoice: number = 0; amountSpentOnFood: number = 0; @@ -43,8 +46,10 @@ class GameState { phase: PHASE_ENUM = PHASE_ENUM.SETUP; subPhase: number = 0; - private constructor(authorId: number, state?: Partial) { - this.authorId = authorId; + private constructor(comment: Comment, state?: Partial) { + this.comment = comment + this.authorId = comment.author_id; + this.authorName = comment.author_name; Object.assign(this, state); // Initialize with loaded state or undefined } @@ -57,20 +62,21 @@ class GameState { /** * Loads an existing game state from the database or creates a new one if it doesn't exist. - * @param {number} authorId - The ID of the author/player. + * @param {Comment} comment - The invoking comment of the author/player. * @returns {Promise} - The loaded or newly created game state. */ - public static async load(authorId: number): Promise { - const loadedState = await DatabaseService.loadGameState(authorId); + public static async load(comment: Comment): Promise { + const loadedState = await DatabaseService.loadGameState(comment.author_id); if (loadedState) { - return new GameState(authorId, loadedState); + return new GameState(comment, loadedState); } else { // Create a new GameState with default values - const newState = new GameState(authorId); + const newState = new GameState(comment); await newState.save(); // Optionally save the new state to the database return newState; } } + } export default GameState