Refactor screen layout code, start player progress code
This commit is contained in:
34
src/playerprogress.ts
Normal file
34
src/playerprogress.ts
Normal file
@ -0,0 +1,34 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user