From 75e0123b9bcb539bda9dd8949cc6a0f6b08f6a2b Mon Sep 17 00:00:00 2001
From: Paolo Brasolin <paolo.brasolin@eurac.edu>
Date: Tue, 29 Mar 2022 18:13:14 +0200
Subject: [PATCH] refactor: #fe fith scene spawning

---
 frontend/src/js/fight_scene.ts | 28 ++++++++++++----------------
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/frontend/src/js/fight_scene.ts b/frontend/src/js/fight_scene.ts
index 7529674..a2a9c3b 100644
--- a/frontend/src/js/fight_scene.ts
+++ b/frontend/src/js/fight_scene.ts
@@ -126,7 +126,7 @@ export default class FightScene extends Phaser.Scene {
       })
     ).data;
 
-    gameStart(this);
+    spawnFoes();
   }
 
   createAnimations() {
@@ -333,21 +333,17 @@ export default class FightScene extends Phaser.Scene {
       this.hud.input.text = inputStatus.final;
     };
   }
-}
-
-function gameStart(scene: any) {
-  spawn(scene);
-}
 
-async function spawn(scene: any) {
-  if (!scene.scene.isActive()) return;
-  await spawnFoe(scene);
-  scene.time.now;
-  const delay =
-    (8 * 1000 * (60 * 1000 - scene.time.now)) / 60 / 1000 + 2 * 1000;
-  setTimeout(() => spawn(scene), Math.max(2000, delay));
-}
+  async spawnFoes() {
+    if (!this.scene.isActive()) return;
+    await this.spawnFoe();
+    const delay =
+      (8 * 1000 * (60 * 1000 - this.time.now)) / 60 / 1000 + 2 * 1000;
+    // TODO: think of a progression which makes sense
+    setTimeout(this.spawnFoes.bind(this), Math.max(2000, delay));
+  }
 
-async function spawnFoe(scene: FightScene) {
-  await new Foe(scene).initialize();
+  async spawnFoe() {
+    await new Foe(this).initialize();
+  }
 }
-- 
GitLab