update: state FlatState

This commit is contained in:
Vick Scarlet
2026-07-30 20:29:08 +08:00
parent 72bf21d592
commit f60e279f62
2 changed files with 14 additions and 17 deletions
+5 -7
View File
@@ -42,8 +42,8 @@ function getPropertiesFromCondition(condition: string): Set<string> {
return properties
}
describe('策划配置条件完整覆盖率测试', () => {
test('event [include, exclude, branch]', () => {
describe('FlatState', () => {
test('[Cover] event(include, exclude, branch)', () => {
const unmappedKeys = new Set<string>()
for (const item of events.values()) {
const conditionsToTrack: { label: string; text: string }[] = []
@@ -85,7 +85,7 @@ describe('策划配置条件完整覆盖率测试', () => {
expect(unmappedKeys.size).toBe(0)
})
test('talent [condition]', () => {
test('[Cover] talent(condition)', () => {
const unmappedKeys = new Set<string>()
const allTalentItems = talents.values()
@@ -111,7 +111,7 @@ describe('策划配置条件完整覆盖率测试', () => {
expect(unmappedKeys.size).toBe(0)
})
test('achievement [condition]', () => {
test('[Cover] achievement(condition)', () => {
const unmappedKeys = new Set<string>()
const allAchievementItems = achievements.values()
@@ -136,10 +136,8 @@ describe('策划配置条件完整覆盖率测试', () => {
expect(unmappedKeys.size).toBe(0)
})
})
describe('FlatProperties', () => {
test('check key', () => {
test('get', () => {
const game = {
lowest: {
age: 1,
+9 -10
View File
@@ -85,13 +85,15 @@ export interface FlatState {
SUM: number
}
interface FlatPropertiesTarget {
type FlatStateKey = keyof FlatState
interface FlatTarget {
game: GameState
profile: ProfileState
}
type FlatMapper<Key extends keyof FlatState> = (
state: FlatPropertiesTarget,
type FlatMapper<Key extends FlatStateKey> = (
state: FlatTarget,
) => FlatState[Key]
const FlatMappers = {
@@ -125,20 +127,17 @@ const FlatMappers = {
const s = sum(Object.values(others))
return Math.floor(s * 2 + age / 2)
},
} as Record<keyof FlatState, FlatMapper<keyof FlatState>>
} as { [Key in FlatStateKey]: FlatMapper<Key> }
const flatPropertiesHandle = {
get(target: FlatPropertiesTarget, prop: keyof FlatState) {
const flatStateHandle = {
get<Key extends FlatStateKey>(target: FlatTarget, prop: Key) {
return FlatMappers[prop]?.(target)
},
set: () => true,
}
export function createFlatState(game: GameState, profile: ProfileState) {
return new Proxy(
{ game, profile },
flatPropertiesHandle,
) as unknown as FlatState
return new Proxy({ game, profile }, flatStateHandle) as unknown as FlatState
}
export interface Effect {