summaryrefslogtreecommitdiff
path: root/client/src/app.ts
blob: 82fdc8114934ff74cbb2cef07a9e3744248d69d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// // import Phaser from 'phaser';
// import AkkamonStartScene from './scene';
// import { AkkamonUI } from './uiScene';
// import { Client } from './client';
//
// const serviceUrl = 'ws://localhost:8080';
//
// export const akkamonClient = new Client(serviceUrl);
//
//
// const game: Phaser.Game = new Phaser.Game(config);


import Phaser from 'phaser';
import { gameConfig } from './akkamon/GameConfig';
import { Client } from './akkamon/client/Client';

export var client = new Client('ws://localhost:8080');

function newGame () {
  if (game) return;
  game = new Phaser.Game(gameConfig);
}

function destroyGame () {
  if (!game) return;
  game.destroy(true);
  game = null;
}

let game: Phaser.Game | null | undefined;


function delay(ms: number) {
    return new Promise(resolve => {
        setTimeout(resolve, ms);
    });
}

async function awaitRegistrationReplyAndStart() {
    if (!game) {
        while (client.getTrainerID() === undefined) {
            console.log("can't start game, this trainerID is still undefined");
            await delay(1000);
        }
        newGame();
    }
}

awaitRegistrationReplyAndStart();