fledgling/src/playerprogress.ts

34 lines
652 B
TypeScript

import {Stat} from "./datatypes.ts";
export class PlayerProgress {
#stats: Record<Stat, number>
constructor() {
this.#stats = {
AGI: 10,
INT: 10,
CHA: 10,
PSI: 10,
}
}
add(stat: Stat, amount: number) {
if (amount != Math.floor(amount)) {
throw `stat increment must be integer: ${amount}`
}
if (amount <= 0) {
throw `stat increment must be >0: ${amount}`
}
this.#stats[stat] += amount;
}
get(stat: Stat): number {
return this.#stats[stat]
}
}
let active: PlayerProgress = new PlayerProgress();
export function getPlayerProgress(): PlayerProgress {
return active
}