import Intl from 'intl-ts'; import { Game, Location } from '@gecogvidanto/shared'; import { langType } from '../../locale'; /** * The game store is used to manipulate the current game. */ export default class GameStore { private readonly lang; private _game?; private _loading; /** * Create store. * * @param lang - The tools store. * @param game - The current game, if any. */ constructor(lang: Intl, game?: Game); /** * @returns The current game, if any. */ get game(): Game | undefined; /** * @returns The current game, expected to exist. Throws an error if not. */ get neededGame(): Game; /** * Indicate if game is currently being loaded. * * @returns The loading state. */ get loading(): boolean; /** * Create a new game. * * @param location - The location of the game. * @param roundsPerSet - The count of rounds for each set. * @param roundLength - The length of each round in minutes. */ create: (location: Location, roundsPerSet: number, roundLength: number) => Promise; /** * Update location. * * @param location - The location of the game. */ updateLocation: (location: Location) => Promise; /** * Update summary. * * @param summary - The summary of the game. */ updateSummary: (summary: string) => Promise; /** * Load the requested game if it is not the current one. * * @param id - The game identifier, undefined to unload game. */ loadIfNeeded: (id?: string) => Promise; /** * Add a player to the current game. * * @param name - The name to give to the player. */ addPlayer: (name: string) => Promise; /** * Update a player's name. * * @param player - The number associated to the player. * @param name - The name to give to the player. */ updatePlayer: (player: number, name: string) => Promise; /** * Delete the player. * * @param player - The number associated to the player. */ deletePlayer: (player: number) => Promise; /** * Add a new set to the current game. * * @param ecoSysId - The identifier of the economic system. */ addSet: (ecoSysId: string) => Promise; /** * Send the form and terminate round if round end form. * * @param data - The form data. * @param optionId - The form option identifier, if any. */ sendForm: (data: { [key: string]: string | number | boolean; }, optionId?: string) => Promise; /** * Record a technological break in current set. */ recordTechnologicalBreak: () => Promise; /** * Close the game. */ close: () => Promise; /** * Execute the method which should update the current game. * * @param method - The method to execute. * @returns True if action finished successfully. */ private doAndUpdate; }