mwg API
    Preparing search index...

    Class PlayerStats<T, S>

    A lifetime running total, folded in one run at a time - distinct from RunHistory, which keeps individual runs and may drop the oldest ones once its own limit is reached. Deriving a lifetime total by reducing over RunHistory.all() would silently undercount the moment that limit trims anything, so this keeps its own persisted total instead, updated incrementally by record and never recomputed from a list that can shrink. A game wanting both a "last 50 runs" list and a true lifetime total uses both classes side by side, each for the question it actually answers.

    import { PlayerStats } from '@datamoc/mw_games/core';

    const lifetimeKills = new PlayerStats<number, number>({
    namespace: 'my-game',
    initial: 0,
    combine: (total, killsThisRun) => total + killsThisRun,
    });

    lifetimeKills.record(12); // this run's own kill count folds into the total
    console.log(lifetimeKills.get());

    Type Parameters

    • T
    • S = T
    Index
    • the current lifetime total, initial if nothing has been recorded yet

      Returns T

    • folds summary into the running total and persists it, returning the new total

      Parameters

      • summary: S

      Returns T

    • back to initial, as a new save file or a "reset stats" option should

      Returns void