mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-22 09:56:55 +00:00
Merge pull request #159 from ilan-schemoul/save-stats
feat: save stats to local storage
This commit is contained in:
@@ -22,6 +22,7 @@ import { getConfig, ServerConfig } from "../core/configuration/Config";
|
||||
import { GameView, PlayerView } from "../core/game/GameView";
|
||||
import { GameUpdateViewData } from "../core/game/GameUpdates";
|
||||
import { UserSettings } from "../core/game/UserSettings";
|
||||
import { LocalPersistantStats } from "./LocalPersistantStats";
|
||||
|
||||
export interface LobbyConfig {
|
||||
serverConfig: ServerConfig;
|
||||
@@ -119,6 +120,7 @@ export async function createClientGame(
|
||||
config,
|
||||
gameMap.gameMap,
|
||||
lobbyConfig.clientID,
|
||||
lobbyConfig.gameID,
|
||||
);
|
||||
|
||||
consolex.log("going to init path finder");
|
||||
@@ -136,7 +138,7 @@ export async function createClientGame(
|
||||
);
|
||||
|
||||
return new ClientGameRunner(
|
||||
lobbyConfig.clientID,
|
||||
lobbyConfig,
|
||||
eventBus,
|
||||
gameRenderer,
|
||||
new InputHandler(canvas, eventBus),
|
||||
@@ -147,6 +149,7 @@ export async function createClientGame(
|
||||
}
|
||||
|
||||
export class ClientGameRunner {
|
||||
private localPersistantsStats = new LocalPersistantStats();
|
||||
private myPlayer: PlayerView;
|
||||
private isActive = false;
|
||||
|
||||
@@ -154,7 +157,7 @@ export class ClientGameRunner {
|
||||
private hasJoined = false;
|
||||
|
||||
constructor(
|
||||
private clientID: ClientID,
|
||||
private lobby: LobbyConfig,
|
||||
private eventBus: EventBus,
|
||||
private renderer: GameRenderer,
|
||||
private input: InputHandler,
|
||||
@@ -164,6 +167,7 @@ export class ClientGameRunner {
|
||||
) {}
|
||||
|
||||
public start() {
|
||||
this.localPersistantsStats.startGame(this.lobby);
|
||||
consolex.log("starting client game");
|
||||
this.isActive = true;
|
||||
this.eventBus.on(MouseUpEvent, (e) => this.inputEvent(e));
|
||||
@@ -172,7 +176,7 @@ export class ClientGameRunner {
|
||||
this.input.initialize();
|
||||
this.worker.start((gu: GameUpdateViewData | ErrorUpdate) => {
|
||||
if ("errMsg" in gu) {
|
||||
showErrorModal(gu.errMsg, gu.stack, this.clientID);
|
||||
showErrorModal(gu.errMsg, gu.stack, this.lobby.clientID);
|
||||
return;
|
||||
}
|
||||
gu.updates[GameUpdateType.Hash].forEach((hu: HashUpdate) => {
|
||||
@@ -216,7 +220,7 @@ export class ClientGameRunner {
|
||||
showErrorModal(
|
||||
`desync from server: ${JSON.stringify(message)}`,
|
||||
"",
|
||||
this.clientID,
|
||||
this.lobby.clientID,
|
||||
);
|
||||
}
|
||||
if (message.type == "turn") {
|
||||
@@ -268,7 +272,7 @@ export class ClientGameRunner {
|
||||
return;
|
||||
}
|
||||
if (this.myPlayer == null) {
|
||||
this.myPlayer = this.gameView.playerByClientID(this.clientID);
|
||||
this.myPlayer = this.gameView.playerByClientID(this.lobby.clientID);
|
||||
if (this.myPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user