Massive restructuring, most of the progress on reorganising Data Access Layer etc. finished. Gotta get the app back up and running now
This commit is contained in:
33
src/Objects/AccountStats.ts
Normal file
33
src/Objects/AccountStats.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import {Ruleset} from "../rulesets";
|
||||
import {AccountStatsMongoData, OutcomeType, PlayerGameResults} from "./DefaultStatsMongoData";
|
||||
import {UpdateError} from "../errors";
|
||||
import StatsUpdater from "./StatsUpdater";
|
||||
|
||||
class AccountStats {
|
||||
private data?: AccountStatsMongoData;
|
||||
private readonly updater: StatsUpdater;
|
||||
constructor(data?: AccountStatsMongoData) {
|
||||
if (data) {
|
||||
this.data = data;
|
||||
}
|
||||
this.updater = new StatsUpdater();
|
||||
}
|
||||
|
||||
use(data: AccountStatsMongoData) {
|
||||
this.data = data;
|
||||
this.updater.use(data);
|
||||
}
|
||||
|
||||
updateStats(playerGameResults: PlayerGameResults & {outcome: OutcomeType}, ruleset: Ruleset): void {
|
||||
if (this.data) {
|
||||
this.updater.updateStats(playerGameResults, ruleset);
|
||||
this.data.gamesPlayed += 1;
|
||||
}
|
||||
else {
|
||||
throw new UpdateError(`Cannot update without data! Call the use() method to hydrate the updater with data
|
||||
to analyse.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default AccountStats;
|
||||
Reference in New Issue
Block a user