From 23d26f72031df8d879d55ec791e0a487564f6c98 Mon Sep 17 00:00:00 2001
From: Paolo Brasolin <paolo.brasolin@eurac.edu>
Date: Tue, 29 Mar 2022 18:48:31 +0200
Subject: [PATCH] feat: #be #fe track game end

---
 frontend/src/js/fight_scene.ts | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/frontend/src/js/fight_scene.ts b/frontend/src/js/fight_scene.ts
index 63f33e3..e26e475 100644
--- a/frontend/src/js/fight_scene.ts
+++ b/frontend/src/js/fight_scene.ts
@@ -224,11 +224,17 @@ export default class FightScene extends Phaser.Scene {
 
   checkAlive() {
     if (this.health > 0) return;
+    this.endGame();
+  }
+
+  async endGame() {
+    this.beGame = (
+      await backend.updateGame(this.beGame.id, {
+        began_at: this.beGame.began_at, // TODO: make this optional in the type
+        ended_at: new Date().toISOString(),
+      })
+    ).data;
     this.foes.forEach((foe) => foe.destroy());
-    // this.scene.transition({
-    //   target: "game_over",
-    // });
-    // // this.scene.stop();
     this.scene.start("game_over");
   }
 
-- 
GitLab