add: game history
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import { Client } from "./Client.js";
|
||||
import { Game } from "./game/Game.js";
|
||||
|
||||
class Profile
|
||||
{
|
||||
@ -59,6 +60,36 @@ class Profile
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {[Game]}
|
||||
*/
|
||||
async getGameHistory()
|
||||
{
|
||||
let response = await this.client._get(`/api/games/history/${this.id}`);
|
||||
let response_data = await response.json();
|
||||
|
||||
let games = [];
|
||||
|
||||
response_data.forEach(game_data => {
|
||||
games.push(new Game(this.client,
|
||||
game_data.id,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
game_data.winner_id,
|
||||
game_data.state,
|
||||
game_data.started,
|
||||
game_data.finished,
|
||||
game_data.players,
|
||||
game_data.start_timestamp,
|
||||
game_data.stop_timestamp
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
return games;
|
||||
}
|
||||
|
||||
async getBlock() {
|
||||
let block_response = await this.client._get("/api/profiles/block");
|
||||
|
||||
|
@ -42,6 +42,11 @@ class Profiles
|
||||
return profile;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Number} id
|
||||
* @returns {Profile}
|
||||
*/
|
||||
async getProfileId(id)
|
||||
{
|
||||
let profile = new Profile(this.client, undefined, id);
|
||||
|
@ -13,8 +13,16 @@ class Game
|
||||
* @param {CallableFunction} goal_handler
|
||||
* @param {CallableFunction} finish_handler
|
||||
* @param {CallableFunction} disconnect_handler
|
||||
* @param {Boolean} finished
|
||||
* @param {Number} id
|
||||
* @param {[Object]} players_data
|
||||
* @param {Number} start_timestamp
|
||||
* @param {Number} stop_timestamp
|
||||
* @param {Boolean} started
|
||||
* @param {Number} winner_id
|
||||
* @param {String} state
|
||||
*/
|
||||
constructor(client, id, disconnect_handler, goal_handler, finish_handler)
|
||||
constructor(client, id, disconnect_handler, goal_handler, finish_handler, winner_id, state, started, finished, players_data, start_timestamp, stop_timestamp)
|
||||
{
|
||||
/**
|
||||
* @type {Client}
|
||||
@ -40,6 +48,50 @@ class Game
|
||||
* @type {CallableFunction}
|
||||
*/
|
||||
this.disconnect_handler = disconnect_handler;
|
||||
|
||||
/**
|
||||
* @type {String}
|
||||
*/
|
||||
this.state = state;
|
||||
|
||||
/**
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.started = started;
|
||||
|
||||
/**
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.finished = finished;
|
||||
|
||||
/**
|
||||
* @type {Number}
|
||||
*/
|
||||
this.winner_id = this.finished ? winner_id : undefined;
|
||||
|
||||
/**
|
||||
* @type {Number}
|
||||
*/
|
||||
this.start_timestamp = start_timestamp;
|
||||
|
||||
/**
|
||||
* @type {Number}
|
||||
*/
|
||||
this.stop_timestamp = stop_timestamp;
|
||||
|
||||
/**
|
||||
* @type {[Player]}
|
||||
*/
|
||||
this.players = [];
|
||||
|
||||
players_data.forEach(player_data => {
|
||||
this.players.push(new Player(this,
|
||||
player_data.player_id,
|
||||
player_data.username,
|
||||
player_data.score
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -55,9 +107,6 @@ class Game
|
||||
|
||||
let response_data = await response.json();
|
||||
|
||||
/**
|
||||
* @type {[Player]}
|
||||
*/
|
||||
this.players = [];
|
||||
|
||||
response_data.players.forEach(player_data => {
|
||||
@ -69,34 +118,14 @@ class Game
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* @type {String}
|
||||
*/
|
||||
this.state = response_data.state;
|
||||
|
||||
/**
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.started = response_data.started;
|
||||
|
||||
/**
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.finished = response_data.finished;
|
||||
|
||||
/**
|
||||
* @type {Number}
|
||||
*/
|
||||
this.winner_id = this.finished ? response_data.winner_id : undefined;
|
||||
|
||||
/**
|
||||
* @type {Number}
|
||||
*/
|
||||
this.start_timestamp = response_data.start_timestamp;
|
||||
|
||||
/**
|
||||
* @type {Number}
|
||||
*/
|
||||
this.stop_timestamp = response_data.stop_timestamp;
|
||||
|
||||
if (this.finished === true)
|
||||
|
Reference in New Issue
Block a user