Skip to content
Binary file added proprietary/images/Statisticsicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 22 additions & 1 deletion src/client/ClientGameRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { createGameRecord } from "../core/Util";
import { ServerConfig } from "../core/configuration/Config";
import { getConfig } from "../core/configuration/ConfigLoader";
import { PlayerActions, UnitType } from "../core/game/Game";
import { PlayerActions, PlayerType, UnitType } from "../core/game/Game";
import { TileRef } from "../core/game/GameMap";
import {
ErrorUpdate,
Expand Down Expand Up @@ -43,6 +43,8 @@ import {
} from "./Transport";
import { createCanvas } from "./Utils";
import { createRenderer, GameRenderer } from "./graphics/GameRenderer";
import { AVAILABLE_STATS, computeStatValue } from "./stats/StatDefinitions";
import statsStore from "./stats/StatsStore";

export interface LobbyConfig {
serverConfig: ServerConfig;
Expand Down Expand Up @@ -238,6 +240,24 @@ export class ClientGameRunner {
public start() {
console.log("starting client game");

// Initialize stats collection
for (const metric of AVAILABLE_STATS) {
statsStore.start(
metric,
() =>
this.gameView
.players()
.filter((p) =>
[PlayerType.Human, PlayerType.FakeHuman].includes(
p.type() as PlayerType,
),
),
(m, p) => computeStatValue(this.gameView, m, p).sortValue,
(p) => p.isAlive(),
() => this.gameView.ticks(),
);
}

this.isActive = true;
this.lastMessageTime = Date.now();
setTimeout(() => {
Expand Down Expand Up @@ -289,6 +309,7 @@ export class ClientGameRunner {
});
this.gameView.update(gu);
this.renderer.tick();
statsStore.onTick(gu.tick);

if (gu.updates[GameUpdateType.Win].length > 0) {
this.saveGame(gu.updates[GameUpdateType.Win][0]);
Expand Down
Loading
Loading