make terrain map load async

This commit is contained in:
evanpelle
2024-08-30 11:56:29 -07:00
parent 64265b1a75
commit 9cfe983824
2 changed files with 15 additions and 13 deletions
+10 -8
View File
@@ -18,7 +18,7 @@ class Client {
private hasJoined = false
private socket: WebSocket | null = null;
private terrainMap: TerrainMap
private terrainMap: Promise<TerrainMap>
private game: ClientGame
private lobbiesContainer: HTMLElement | null;
@@ -115,13 +115,15 @@ class Client {
if (this.game != null) {
return;
}
this.game = createClientGame(getUsername(), new PseudoRandom(Date.now()).nextID(), lobby.id, getConfig(), this.terrainMap);
this.game.join();
const g = this.game;
window.addEventListener('beforeunload', function (event) {
console.log('Browser is closing');
g.stop();
});
this.terrainMap.then(tm => {
this.game = createClientGame(getUsername(), new PseudoRandom(Date.now()).nextID(), lobby.id, getConfig(), tm);
this.game.join();
const g = this.game;
window.addEventListener('beforeunload', function (event) {
console.log('Browser is closing');
g.stop();
});
})
}