From: xangelo Date: Wed, 12 Jul 2023 18:40:36 +0000 (-0400) Subject: fix: define stats as an enum for easier iteration X-Git-Tag: v0.1.0~2 X-Git-Url: https://git.xangelo.ca/?a=commitdiff_plain;h=f113d4aab6345a0375bd0ffc6112f104980a790c;p=risinglegends.git fix: define stats as an enum for easier iteration Stats make more sense as a string-based enum for most of our usecases, even accounting for odd typescript enum things. --- diff --git a/src/shared/player.ts b/src/shared/player.ts index e571ae1..7762a41 100644 --- a/src/shared/player.ts +++ b/src/shared/player.ts @@ -1,5 +1,5 @@ import { Profession } from './profession'; - +import { Stat } from './stats'; import { SkillDefinition, Skill } from './skills'; export type Player = { @@ -18,6 +18,7 @@ export type Player = { gold: number; hp: number; city_id: number; + stat_points: number; } export type PlayerWithSkills = Player & { @@ -37,3 +38,35 @@ export function expToLevel(level: number): number { } } + +export type StatDisplay = { + id: Stat, + display: string; + abbrv: string; +} + +export const StatDef: Map = new Map(); + +StatDef.set(Stat.strength, { + id: Stat.strength, + display: 'Strength', + abbrv: 'STR' +}); + +StatDef.set(Stat.constitution, { + id: Stat.constitution, + display: 'Constitution', + abbrv: 'CON' +}); + +StatDef.set(Stat.dexterity, { + id: Stat.dexterity, + display: 'Dexterity', + abbrv: 'DEX' +}); + +StatDef.set(Stat.intelligence, { + id: Stat.intelligence, + display: 'Intelligence', + abbrv: 'INT' +}); diff --git a/src/shared/stats.ts b/src/shared/stats.ts index 48e4bf6..a553bd4 100644 --- a/src/shared/stats.ts +++ b/src/shared/stats.ts @@ -1 +1,6 @@ -export type Stats = 'strength' | 'constitution' | 'intelligence' | 'dexterity'; +export enum Stat { + strength = 'strength', + constitution = 'constitution', + dexterity = 'dexterity', + intelligence = 'intelligence' +};