game: init
This commit is contained in:
34
frontend/static/js/api/Game.js
Normal file
34
frontend/static/js/api/Game.js
Normal file
@ -0,0 +1,34 @@
|
||||
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;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
export { Game }
|
Reference in New Issue
Block a user