import { BattleStats } from '@datamoc/mw_games/battle';
const stats = new BattleStats();
stats.record('kills', 'orc-grunt');
stats.record('kills', 'orc-grunt');
stats.record('damageDealt', 'elvish-archer', 12);
console.log(stats.total('kills')); // 2
console.log(stats.breakdown('kills')); // [{ unitType: 'orc-grunt', count: 2 }]
A per-run battle statistics breakdown by category and unit type - recruits, recalls, advances, kills, deaths, damage dealt, damage taken - the shape Wesnoth's own statistics dialog shows and a bare
core.PlayerStats<T>cannot give a game for free, sinceTthere is an opaque summary the game must already know how to combine. Here the categories and the per-unit-type breakdown are the primitive: a game records one event at a time as it happens and reads either a category's total or its breakdown by unit type, then foldstoJSON()into acore.RunHistoryentry or acore.PlayerStatstotal the way any other run summary would.