diff --git a/src/core/worker/Worker.worker.ts b/src/core/worker/Worker.worker.ts index 65e33c6de..1a41bfb3c 100644 --- a/src/core/worker/Worker.worker.ts +++ b/src/core/worker/Worker.worker.ts @@ -60,6 +60,9 @@ async function drain(): Promise { const batch: GameUpdateViewData[] = []; const onTickUpdate = (gu: GameUpdateViewData | ErrorUpdate) => { if (!("updates" in gu)) { + if ("errMsg" in gu) { + sendMessage({ type: "game_error", error: gu } as WorkerMessage); + } return; } batch.push(gu); diff --git a/src/core/worker/WorkerClient.ts b/src/core/worker/WorkerClient.ts index 3ceadf32e..459ada824 100644 --- a/src/core/worker/WorkerClient.ts +++ b/src/core/worker/WorkerClient.ts @@ -53,6 +53,11 @@ export class WorkerClient { } } break; + case "game_error": + if (this.gameUpdateCallback && message.error) { + this.gameUpdateCallback(message.error); + } + break; case "initialized": default: diff --git a/src/core/worker/WorkerMessages.ts b/src/core/worker/WorkerMessages.ts index 861e31172..7f4158a46 100644 --- a/src/core/worker/WorkerMessages.ts +++ b/src/core/worker/WorkerMessages.ts @@ -7,7 +7,7 @@ import { PlayerProfile, } from "../game/Game"; import { TileRef } from "../game/GameMap"; -import { GameUpdateViewData } from "../game/GameUpdates"; +import { ErrorUpdate, GameUpdateViewData } from "../game/GameUpdates"; import { ClientID, GameStartInfo, Turn } from "../Schemas"; export type WorkerMessageType = @@ -16,6 +16,7 @@ export type WorkerMessageType = | "turn" | "game_update" | "game_update_batch" + | "game_error" | "player_actions" | "player_actions_result" | "player_buildables" @@ -62,6 +63,11 @@ export interface GameUpdateBatchMessage extends BaseWorkerMessage { gameUpdates: GameUpdateViewData[]; } +export interface GameErrorMessage extends BaseWorkerMessage { + type: "game_error"; + error: ErrorUpdate; +} + export interface PlayerActionsMessage extends BaseWorkerMessage { type: "player_actions"; playerID: PlayerID; @@ -147,6 +153,7 @@ export type WorkerMessage = | InitializedMessage | GameUpdateMessage | GameUpdateBatchMessage + | GameErrorMessage | PlayerActionsResultMessage | PlayerBuildablesResultMessage | PlayerProfileResultMessage