summaryrefslogtreecommitdiff
path: root/client/src/app.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app.ts')
-rw-r--r--client/src/app.ts19
1 files changed, 18 insertions, 1 deletions
diff --git a/client/src/app.ts b/client/src/app.ts
index 197fb63..05fccb5 100644
--- a/client/src/app.ts
+++ b/client/src/app.ts
@@ -29,4 +29,21 @@ function destroyGame () {
export let client = new Client('ws://localhost:8080');
let game: Phaser.Game | null | undefined;
-if (!game) newGame();
+
+function delay(ms: number) {
+ return new Promise(resolve => {
+ setTimeout(resolve, ms);
+ });
+}
+
+async function awaitRegistrationReplyAndStart() {
+ if (!game) {
+ while (client.getSessionTrainerId() === undefined) {
+ console.log("can't start game, this trainerId is still undefined");
+ await delay(1000);
+ }
+ newGame();
+ }
+}
+
+awaitRegistrationReplyAndStart();