import { GameConfig } from "./GameConfig.js" class Game { /** * @param {Client} client */ constructor(client, id) { /** * @type {Client} */ this.client = client; this.id = id; } async init() { let response = await this.client._get(`/api/games/${this.id}`); if (response.status !== 200) return response.status; let response_data = await response.json(); this.players_id = response_data.players_id; this.state = response_data.state; this.started = response_data.started; this.finished = response_data.finished; this.winner_id = this.finished ? response_data.winner_id : undefined; //TODO invert line if (false) //if (this.finished === true || this.started === false) return 0; this.config = new GameConfig(this.client); let ret = await this.config.init(); if (ret) return ret; this.players = response_data.players; this.ball_pos_x = this.config.ball_spawn_x; this.ball_pos_y = this.config.ball_spawn_y; return 0; } } export { Game }