fix(engine): wait for engine lifecycle after scene change (#55)

This commit is contained in:
lucas authored and GitHub committed 2026-08-31 20:53:42 +02:00
1 parent eae3f376a7
commit ede991de51
1 file changed
+14 -3
+14 -3
View File
@@ -31,10 +31,10 @@ const mocked = urlParams.get("mock");
await game.start(); await game.start();
await loadImages(); await loadImages();
await game.goToScene("lobby"); await goToScene(game, "lobby");
connection.on("lobby-message", () => game.goToScene("lobby")); connection.on("lobby-message", () => goToScene(game, "lobby"));
connection.on("match-message", () => game.goToScene("match")); connection.on("match-message", () => goToScene(game, "match"));
if (mocked != null) { if (mocked != null) {
runMockScenario(mocked, connection, mockSocket!); runMockScenario(mocked, connection, mockSocket!);
@@ -58,3 +58,14 @@ function runMockScenario(
mockSocket.sendToClient(mockGameMessage()); mockSocket.sendToClient(mockGameMessage());
} }
} }
async function waitEngine(engine: ex.Engine): Promise<void> {
await new Promise<void>((resolve) => {
engine.once("postupdate", () => resolve());
});
}
async function goToScene(engine: ex.Engine, scene: string): Promise<void> {
await engine.goToScene(scene);
await waitEngine(engine);
}