mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-25 03:28:33 +00:00
use error update to show error modal
This commit is contained in:
@@ -8,7 +8,7 @@ import { loadTerrainFromFile, loadTerrainMap } from "../core/game/TerrainMapLoad
|
|||||||
import { SendAttackIntentEvent, SendSpawnIntentEvent, Transport } from "./Transport";
|
import { SendAttackIntentEvent, SendSpawnIntentEvent, Transport } from "./Transport";
|
||||||
import { createCanvas } from "./Utils";
|
import { createCanvas } from "./Utils";
|
||||||
import { MessageType } from '../core/game/Game';
|
import { MessageType } from '../core/game/Game';
|
||||||
import { DisplayMessageUpdate } from "../core/game/GameUpdates";
|
import { DisplayMessageUpdate, ErrorUpdate } from "../core/game/GameUpdates";
|
||||||
import { WorkerClient } from "../core/worker/WorkerClient";
|
import { WorkerClient } from "../core/worker/WorkerClient";
|
||||||
import { consolex, initRemoteSender } from "../core/Consolex";
|
import { consolex, initRemoteSender } from "../core/Consolex";
|
||||||
import { getConfig, getServerConfig } from "../core/configuration/Config";
|
import { getConfig, getServerConfig } from "../core/configuration/Config";
|
||||||
@@ -121,9 +121,11 @@ export class ClientGameRunner {
|
|||||||
|
|
||||||
this.renderer.initialize()
|
this.renderer.initialize()
|
||||||
this.input.initialize()
|
this.input.initialize()
|
||||||
this.worker.start((gu: GameUpdateViewData) => {
|
this.worker.start((gu: GameUpdateViewData | ErrorUpdate) => {
|
||||||
const size = gu.packedTileUpdates.length * 4 / 1000
|
if ('errMsg' in gu) {
|
||||||
// console.log(`game update size: ${size}kb`)
|
showErrorModal(gu.errMsg, gu.stack, this.clientID)
|
||||||
|
return
|
||||||
|
}
|
||||||
this.gameView.update(gu)
|
this.gameView.update(gu)
|
||||||
this.renderer.tick()
|
this.renderer.tick()
|
||||||
})
|
})
|
||||||
@@ -209,8 +211,8 @@ export class ClientGameRunner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function showErrorModal(error: Error, clientID: ClientID) {
|
function showErrorModal(errMsg: string, stack: string, clientID: ClientID) {
|
||||||
const errorText = `Error: ${error.message}\nStack: ${error.stack}`;
|
const errorText = `Error: ${errMsg}\nStack: ${stack}`;
|
||||||
consolex.error(errorText);
|
consolex.error(errorText);
|
||||||
|
|
||||||
const modal = document.createElement('div');
|
const modal = document.createElement('div');
|
||||||
|
|||||||
+19
-4
@@ -4,8 +4,8 @@ import { getConfig } from "./configuration/Config";
|
|||||||
import { EventBus } from "./EventBus";
|
import { EventBus } from "./EventBus";
|
||||||
import { Executor } from "./execution/ExecutionManager";
|
import { Executor } from "./execution/ExecutionManager";
|
||||||
import { WinCheckExecution } from "./execution/WinCheckExecution";
|
import { WinCheckExecution } from "./execution/WinCheckExecution";
|
||||||
import { AllPlayers, Cell, Game, MessageType, Player, PlayerActions, PlayerID, PlayerProfile, PlayerType, UnitType } from "./game/Game";
|
import { AllPlayers, Cell, Game, GameUpdates, MessageType, Player, PlayerActions, PlayerID, PlayerProfile, PlayerType, UnitType } from "./game/Game";
|
||||||
import { DisplayMessageUpdate } from "./game/GameUpdates";
|
import { DisplayMessageUpdate, ErrorUpdate } from "./game/GameUpdates";
|
||||||
import { NameViewData } from './game/Game';
|
import { NameViewData } from './game/Game';
|
||||||
import { GameUpdateType } from "./game/GameUpdates";
|
import { GameUpdateType } from "./game/GameUpdates";
|
||||||
import { createGame } from "./game/GameImpl";
|
import { createGame } from "./game/GameImpl";
|
||||||
@@ -35,7 +35,7 @@ export class GameRunner {
|
|||||||
constructor(
|
constructor(
|
||||||
public game: Game,
|
public game: Game,
|
||||||
private execManager: Executor,
|
private execManager: Executor,
|
||||||
private callBack: (gu: GameUpdateViewData) => void
|
private callBack: (gu: GameUpdateViewData | ErrorUpdate) => void
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +64,22 @@ export class GameRunner {
|
|||||||
|
|
||||||
this.game.addExecution(...this.execManager.createExecs(this.turns[this.currTurn]))
|
this.game.addExecution(...this.execManager.createExecs(this.turns[this.currTurn]))
|
||||||
this.currTurn++
|
this.currTurn++
|
||||||
const updates = this.game.executeNextTick()
|
|
||||||
|
let updates: GameUpdates;
|
||||||
|
|
||||||
|
try {
|
||||||
|
updates = this.game.executeNextTick();
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
console.error('Game tick error:', error.message);
|
||||||
|
this.callBack({
|
||||||
|
errMsg: error.message,
|
||||||
|
stack: error.stack
|
||||||
|
} as ErrorUpdate)
|
||||||
|
clearInterval(this.tickInterval)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (this.game.inSpawnPhase() && this.game.ticks() % 2 == 0) {
|
if (this.game.inSpawnPhase() && this.game.ticks() % 2 == 0) {
|
||||||
this.game.players()
|
this.game.players()
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ export interface GameUpdateViewData {
|
|||||||
playerNameViewData: Record<number, NameViewData>;
|
playerNameViewData: Record<number, NameViewData>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ErrorUpdate {
|
||||||
|
errMsg: string
|
||||||
|
stack?: string
|
||||||
|
}
|
||||||
|
|
||||||
export enum GameUpdateType {
|
export enum GameUpdateType {
|
||||||
Tile,
|
Tile,
|
||||||
Unit,
|
Unit,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { PlayerActions, PlayerID, PlayerInfo, PlayerProfile } from "../game/Game";
|
import { PlayerActions, PlayerID, PlayerInfo, PlayerProfile } from "../game/Game";
|
||||||
import { GameUpdateViewData } from '../game/GameUpdates';
|
import { ErrorUpdate, GameUpdateViewData } from '../game/GameUpdates';
|
||||||
import { GameConfig, GameID, Turn } from "../Schemas";
|
import { GameConfig, GameID, Turn } from "../Schemas";
|
||||||
import { generateID } from "../Util";
|
import { generateID } from "../Util";
|
||||||
import { WorkerMessage } from "./WorkerMessages";
|
import { WorkerMessage } from "./WorkerMessages";
|
||||||
@@ -8,7 +8,7 @@ export class WorkerClient {
|
|||||||
private worker: Worker;
|
private worker: Worker;
|
||||||
private isInitialized = false;
|
private isInitialized = false;
|
||||||
private messageHandlers: Map<string, (message: WorkerMessage) => void>;
|
private messageHandlers: Map<string, (message: WorkerMessage) => void>;
|
||||||
private gameUpdateCallback?: (update: GameUpdateViewData) => void;
|
private gameUpdateCallback?: (update: GameUpdateViewData | ErrorUpdate) => void;
|
||||||
|
|
||||||
constructor(private gameID: GameID, private gameConfig: GameConfig) {
|
constructor(private gameID: GameID, private gameConfig: GameConfig) {
|
||||||
this.worker = new Worker(new URL('./Worker.worker.ts', import.meta.url));
|
this.worker = new Worker(new URL('./Worker.worker.ts', import.meta.url));
|
||||||
@@ -67,7 +67,7 @@ export class WorkerClient {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
start(gameUpdate: (gu: GameUpdateViewData) => void) {
|
start(gameUpdate: (gu: GameUpdateViewData | ErrorUpdate) => void) {
|
||||||
if (!this.isInitialized) {
|
if (!this.isInitialized) {
|
||||||
throw new Error('Failed to initialize pathfinder');
|
throw new Error('Failed to initialize pathfinder');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user