mirror of
https://github.com/VickScarlet/lifeRestart.git
synced 2026-08-29 18:14:41 +08:00
update: state FlatState
This commit is contained in:
@@ -42,8 +42,8 @@ function getPropertiesFromCondition(condition: string): Set<string> {
|
|||||||
return properties
|
return properties
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('策划配置条件完整覆盖率测试', () => {
|
describe('FlatState', () => {
|
||||||
test('event [include, exclude, branch]', () => {
|
test('[Cover] event(include, exclude, branch)', () => {
|
||||||
const unmappedKeys = new Set<string>()
|
const unmappedKeys = new Set<string>()
|
||||||
for (const item of events.values()) {
|
for (const item of events.values()) {
|
||||||
const conditionsToTrack: { label: string; text: string }[] = []
|
const conditionsToTrack: { label: string; text: string }[] = []
|
||||||
@@ -85,7 +85,7 @@ describe('策划配置条件完整覆盖率测试', () => {
|
|||||||
expect(unmappedKeys.size).toBe(0)
|
expect(unmappedKeys.size).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('talent [condition]', () => {
|
test('[Cover] talent(condition)', () => {
|
||||||
const unmappedKeys = new Set<string>()
|
const unmappedKeys = new Set<string>()
|
||||||
const allTalentItems = talents.values()
|
const allTalentItems = talents.values()
|
||||||
|
|
||||||
@@ -111,7 +111,7 @@ describe('策划配置条件完整覆盖率测试', () => {
|
|||||||
expect(unmappedKeys.size).toBe(0)
|
expect(unmappedKeys.size).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('achievement [condition]', () => {
|
test('[Cover] achievement(condition)', () => {
|
||||||
const unmappedKeys = new Set<string>()
|
const unmappedKeys = new Set<string>()
|
||||||
const allAchievementItems = achievements.values()
|
const allAchievementItems = achievements.values()
|
||||||
|
|
||||||
@@ -136,10 +136,8 @@ describe('策划配置条件完整覆盖率测试', () => {
|
|||||||
|
|
||||||
expect(unmappedKeys.size).toBe(0)
|
expect(unmappedKeys.size).toBe(0)
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
describe('FlatProperties', () => {
|
test('get', () => {
|
||||||
test('check key', () => {
|
|
||||||
const game = {
|
const game = {
|
||||||
lowest: {
|
lowest: {
|
||||||
age: 1,
|
age: 1,
|
||||||
|
|||||||
@@ -85,13 +85,15 @@ export interface FlatState {
|
|||||||
SUM: number
|
SUM: number
|
||||||
}
|
}
|
||||||
|
|
||||||
interface FlatPropertiesTarget {
|
type FlatStateKey = keyof FlatState
|
||||||
|
|
||||||
|
interface FlatTarget {
|
||||||
game: GameState
|
game: GameState
|
||||||
profile: ProfileState
|
profile: ProfileState
|
||||||
}
|
}
|
||||||
|
|
||||||
type FlatMapper<Key extends keyof FlatState> = (
|
type FlatMapper<Key extends FlatStateKey> = (
|
||||||
state: FlatPropertiesTarget,
|
state: FlatTarget,
|
||||||
) => FlatState[Key]
|
) => FlatState[Key]
|
||||||
|
|
||||||
const FlatMappers = {
|
const FlatMappers = {
|
||||||
@@ -125,20 +127,17 @@ const FlatMappers = {
|
|||||||
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>>
|
} as { [Key in FlatStateKey]: FlatMapper<Key> }
|
||||||
|
|
||||||
const flatPropertiesHandle = {
|
const flatStateHandle = {
|
||||||
get(target: FlatPropertiesTarget, prop: keyof FlatState) {
|
get<Key extends FlatStateKey>(target: FlatTarget, prop: Key) {
|
||||||
return FlatMappers[prop]?.(target)
|
return FlatMappers[prop]?.(target)
|
||||||
},
|
},
|
||||||
set: () => true,
|
set: () => true,
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createFlatState(game: GameState, profile: ProfileState) {
|
export function createFlatState(game: GameState, profile: ProfileState) {
|
||||||
return new Proxy(
|
return new Proxy({ game, profile }, flatStateHandle) as unknown as FlatState
|
||||||
{ game, profile },
|
|
||||||
flatPropertiesHandle,
|
|
||||||
) as unknown as FlatState
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Effect {
|
export interface Effect {
|
||||||
|
|||||||
Reference in New Issue
Block a user