update: state FlatMapper

This commit is contained in:
Vick Scarlet
2026-08-16 20:06:16 +08:00
committed by 神戸小鳥
parent e646492e75
commit 807a84de7f
+34 -34
View File
@@ -90,48 +90,48 @@ interface FlatPropertiesTarget {
profile: ProfileState profile: ProfileState
} }
type FlatMapper<Key extends keyof FlatState> = (
state: FlatPropertiesTarget,
) => FlatState[Key]
const FlatMappers = { const FlatMappers = {
AGE: (state: FlatPropertiesTarget) => state.game.properties.age, AGE: state => state.game.properties.age,
CHR: (state: FlatPropertiesTarget) => state.game.properties.charm, CHR: state => state.game.properties.charm,
INT: (state: FlatPropertiesTarget) => state.game.properties.intelligence, INT: state => state.game.properties.intelligence,
STR: (state: FlatPropertiesTarget) => state.game.properties.strength, STR: state => state.game.properties.strength,
MNY: (state: FlatPropertiesTarget) => state.game.properties.money, MNY: state => state.game.properties.money,
SPR: (state: FlatPropertiesTarget) => state.game.properties.spirit, SPR: state => state.game.properties.spirit,
LIF: (state: FlatPropertiesTarget) => state.game.life, LIF: state => state.game.life,
TLT: (state: FlatPropertiesTarget) => state.game.talents, TLT: state => state.game.talents,
EVT: (state: FlatPropertiesTarget) => state.game.events, EVT: state => state.game.events,
LAGE: (state: FlatPropertiesTarget) => state.game.lowest.age, LAGE: state => state.game.lowest.age,
HAGE: (state: FlatPropertiesTarget) => state.game.highest.age, HAGE: state => state.game.highest.age,
LCHR: (state: FlatPropertiesTarget) => state.game.lowest.charm, LCHR: state => state.game.lowest.charm,
HCHR: (state: FlatPropertiesTarget) => state.game.highest.charm, HCHR: state => state.game.highest.charm,
LINT: (state: FlatPropertiesTarget) => state.game.lowest.intelligence, LINT: state => state.game.lowest.intelligence,
HINT: (state: FlatPropertiesTarget) => state.game.highest.intelligence, HINT: state => state.game.highest.intelligence,
LSTR: (state: FlatPropertiesTarget) => state.game.lowest.strength, LSTR: state => state.game.lowest.strength,
HSTR: (state: FlatPropertiesTarget) => state.game.highest.strength, HSTR: state => state.game.highest.strength,
LMNY: (state: FlatPropertiesTarget) => state.game.lowest.money, LMNY: state => state.game.lowest.money,
HMNY: (state: FlatPropertiesTarget) => state.game.highest.money, HMNY: state => state.game.highest.money,
LSPR: (state: FlatPropertiesTarget) => state.game.lowest.spirit, LSPR: state => state.game.lowest.spirit,
HSPR: (state: FlatPropertiesTarget) => state.game.highest.spirit, HSPR: state => state.game.highest.spirit,
TMS: (state: FlatPropertiesTarget) => state.profile.times, TMS: state => state.profile.times,
AEVT: (state: FlatPropertiesTarget) => state.profile.events, AEVT: state => state.profile.events,
ATLT: (state: FlatPropertiesTarget) => state.profile.talents, ATLT: state => state.profile.talents,
AACH: (state: FlatPropertiesTarget) => state.profile.achievements, AACH: state => state.profile.achievements,
SUM: (state: FlatPropertiesTarget) => { SUM: state => {
const { age, ...others } = state.game.highest const { age, ...others } = state.game.highest
const s = sum(Object.values(others)) const s = sum(Object.values(others))
return Math.floor(s * 2 + age / 2) return Math.floor(s * 2 + age / 2)
}, },
} } as Record<keyof FlatState, FlatMapper<keyof FlatState>>
const flatPropertiesHandle = { const flatPropertiesHandle = {
get(target: FlatPropertiesTarget, prop: string) { get(target: FlatPropertiesTarget, prop: keyof FlatState) {
if (prop in FlatMappers) { return FlatMappers[prop]?.(target)
return FlatMappers[prop as keyof typeof FlatMappers](target)
}
},
set() {
return true
}, },
set: () => true,
} }
export function createFlatState(game: GameState, profile: ProfileState) { export function createFlatState(game: GameState, profile: ProfileState) {