From 323b360aee810791c14848efd790381bbdf134a8 Mon Sep 17 00:00:00 2001 From: starnakin Date: Tue, 27 Feb 2024 09:38:37 +0100 Subject: [PATCH] game: fix: reload view work --- frontend/static/js/views/GameView.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/frontend/static/js/views/GameView.js b/frontend/static/js/views/GameView.js index e9d81ad..a208904 100644 --- a/frontend/static/js/views/GameView.js +++ b/frontend/static/js/views/GameView.js @@ -12,9 +12,7 @@ export default class extends AbstractView constructor(params) { super(params, "Game"); - this.game = new Game(client, params.id, this.on_goal, this.on_finish); - this.keys_pressed = []; - this.my_player = undefined; + this.game_id = params.id; } keyReleaseHandler(event) @@ -76,7 +74,7 @@ export default class extends AbstractView clearInterval(loop_id); this.my_player?.update_paddle(this.keys_pressed); this.render_game(); - this.game?.time.new_frame(); + this.game?.time?.new_frame(); //clearInterval(loop_id); // 1 sec fps }, 1000 / 60); @@ -170,8 +168,6 @@ export default class extends AbstractView data = [{x: 0, y: 0}, ...data]; - console.log(data); - data.push({x: Math.round((this.game.stop_timestamp - this.game.start_timestamp) / 1000), y: data[data.length - 1].y}); @@ -234,6 +230,10 @@ export default class extends AbstractView async postInit() { + this.game = new Game(client, this.game_id, this.on_goal, this.on_finish); + this.keys_pressed = []; + this.my_player = undefined; + let error_code = await this.game.init(); if (error_code) @@ -249,6 +249,7 @@ export default class extends AbstractView this.game.leave(); this.game = undefined; } + this.game = undefined; this.unregister_key(); }