feat: save stats to local storage

Victory lose, player stats, lobby config are stored to local storage
(for later use)
This commit is contained in:
ilan schemoul
2025-03-06 00:32:57 +01:00
parent d2208755c4
commit 398d354702
10 changed files with 130 additions and 14 deletions
-1
View File
@@ -168,7 +168,6 @@ export class GameRunner {
canBreakAlliance: player.isAlliedWith(other),
canDonate: player.canDonate(other),
canEmbargo: !player.hasEmbargoAgainst(other),
stats: this.game.stats().getPlayerStats(other.id()),
};
}
-1
View File
@@ -421,7 +421,6 @@ export interface PlayerInteraction {
canTarget: boolean;
canDonate: boolean;
canEmbargo: boolean;
stats: PlayerStats;
}
export interface EmojiMessage {
+2
View File
@@ -12,6 +12,7 @@ import {
UnitType,
} from "./Game";
import { TileRef, TileUpdate } from "./GameMap";
import { PlayerStats } from "./Stats";
export interface GameUpdateViewData {
tick: number;
@@ -105,6 +106,7 @@ export interface PlayerUpdate {
outgoingAttacks: AttackUpdate[];
incomingAttacks: AttackUpdate[];
outgoingAllianceRequests: PlayerID[];
stats: PlayerStats;
}
export interface AllianceRequestUpdate {
+9 -1
View File
@@ -24,12 +24,13 @@ import {
UnitInfo,
UnitType,
} from "./Game";
import { ClientID } from "../Schemas";
import { ClientID, GameID } from "../Schemas";
import { TerraNulliusImpl } from "./TerraNulliusImpl";
import { WorkerClient } from "../worker/WorkerClient";
import { GameMap, GameMapImpl, TileRef, TileUpdate } from "./GameMap";
import { GameUpdateViewData } from "./GameUpdates";
import { DefenseGrid } from "./DefensePostGrid";
import { PlayerStats } from "./Stats";
export class UnitView {
public _wasUpdated = true;
@@ -220,6 +221,9 @@ export class PlayerView {
this.id(),
);
}
stats(): PlayerStats {
return this.data.stats;
}
}
export class GameView implements GameMap {
@@ -240,6 +244,7 @@ export class GameView implements GameMap {
private _config: Config,
private _map: GameMap,
private _myClientID: ClientID,
private _gameID: GameID,
) {
this.lastUpdate = {
tick: 0,
@@ -487,4 +492,7 @@ export class GameView implements GameMap {
numTilesWithFallout(): number {
return this._map.numTilesWithFallout();
}
gameID(): GameID {
return this._gameID;
}
}
+1
View File
@@ -150,6 +150,7 @@ export class PlayerImpl implements Player {
}) as AttackUpdate,
),
outgoingAllianceRequests: outgoingAllianceRequests,
stats: this.mg.stats().getPlayerStats(this.id()),
};
}