game: init
This commit is contained in:
parent
4432214d98
commit
35859db051
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 }
|
33
frontend/static/js/views/GameView.js
Normal file
33
frontend/static/js/views/GameView.js
Normal file
@ -0,0 +1,33 @@
|
||||
import { client } from "../index.js";
|
||||
import { Game } from "../api/Game.js";
|
||||
import AbstractView from "./abstracts/AbstractView.js";
|
||||
|
||||
export default class extends AbstractView
|
||||
{
|
||||
constructor(params)
|
||||
{
|
||||
super(params, "Game");
|
||||
this.game = new Game(client, params.id);
|
||||
}
|
||||
|
||||
async postInit()
|
||||
{
|
||||
let error_code = await this.game.init();
|
||||
|
||||
if (error_code)
|
||||
return error_code;
|
||||
}
|
||||
|
||||
async getHtml()
|
||||
{
|
||||
return `
|
||||
<h1>Welcome back, Dom</h1>
|
||||
<p>
|
||||
Fugiat voluptate et nisi Lorem cillum anim sit do eiusmod occaecat irure do. Reprehenderit anim fugiat sint exercitation consequat. Sit anim laborum sit amet Lorem adipisicing ullamco duis. Anim in do magna ea pariatur et.
|
||||
</p>
|
||||
<p>
|
||||
<a href="/posts" data-link>View recent posts</a>.
|
||||
</p>
|
||||
`;
|
||||
}
|
||||
}
|
@ -28,7 +28,7 @@ class GameWebSocket(AsyncWebsocketConsumer):
|
||||
self.room = game_room_manager.get(self.game_id)
|
||||
|
||||
if (self.room is None):
|
||||
self.member.send("Tournament not found")
|
||||
self.member.send("Game not found.")
|
||||
self.disconnect(1017)
|
||||
|
||||
self.room.append(self.member)
|
||||
|
Loading…
Reference in New Issue
Block a user