mirror of
https://github.com/VickScarlet/lifeRestart.git
synced 2026-08-29 10:04:43 +08:00
update: talent, state props
This commit is contained in:
@@ -5,13 +5,11 @@ import achievements from '@remake/data/achievement'
|
||||
import events from '@remake/data/event'
|
||||
import talents from '@remake/data/talent'
|
||||
|
||||
import { createFlatState } from './state'
|
||||
|
||||
const A = ['AGE', 'CHR', 'INT', 'STR', 'MNY', 'SPR', 'LIF', 'TLT', 'EVT', 'TMS']
|
||||
const B = ['HAGE', 'HCHR', 'HINT', 'HSTR', 'HMNY', 'HSPR']
|
||||
const C = ['LAGE', 'LCHR', 'LINT', 'LSTR', 'LMNY', 'LSPR']
|
||||
const D = ['AEVT', 'ATLT', 'SUM']
|
||||
const FlatProperties = new Set([...A, ...B, ...C, ...D])
|
||||
import type { GameState, ProfileState, Properties } from './state'
|
||||
import { createFlatState, createHLProperties, propsEffect } from './state'
|
||||
import { SupportedFlatStateKeys } from './state'
|
||||
import { enableMapSet } from 'immer'
|
||||
enableMapSet()
|
||||
|
||||
/**
|
||||
* 核心递归辅助函数:从多维语法树节点中提取所有属性名
|
||||
@@ -42,8 +40,8 @@ function getPropertiesFromCondition(condition: string): Set<string> {
|
||||
return properties
|
||||
}
|
||||
|
||||
describe('FlatState', () => {
|
||||
test('[Cover] event(include, exclude, branch)', () => {
|
||||
describe('State', () => {
|
||||
test('flat cover event(include, exclude, branch)', () => {
|
||||
const unmappedKeys = new Set<string>()
|
||||
for (const item of events.values()) {
|
||||
const conditionsToTrack: { label: string; text: string }[] = []
|
||||
@@ -68,7 +66,7 @@ describe('FlatState', () => {
|
||||
for (const { label, text } of conditionsToTrack) {
|
||||
const usedProperties = getPropertiesFromCondition(text)
|
||||
for (const key of usedProperties) {
|
||||
if (!FlatProperties.has(key)) {
|
||||
if (!SupportedFlatStateKeys.has(key)) {
|
||||
unmappedKeys.add(
|
||||
`[事件 ID: ${item.id}] 的 "${label}" 字段使用了未定义的键名: "${key}" (完整条件: "${text}")`,
|
||||
)
|
||||
@@ -85,7 +83,7 @@ describe('FlatState', () => {
|
||||
expect(unmappedKeys.size).toBe(0)
|
||||
})
|
||||
|
||||
test('[Cover] talent(condition)', () => {
|
||||
test('flat cover talent(condition)', () => {
|
||||
const unmappedKeys = new Set<string>()
|
||||
const allTalentItems = talents.values()
|
||||
|
||||
@@ -95,7 +93,7 @@ describe('FlatState', () => {
|
||||
|
||||
const usedProperties = getPropertiesFromCondition(conditionStr)
|
||||
for (const key of usedProperties) {
|
||||
if (!FlatProperties.has(key)) {
|
||||
if (!SupportedFlatStateKeys.has(key)) {
|
||||
unmappedKeys.add(
|
||||
`[天赋 ID: ${item.id}] 使用了未定义的键名: "${key}" (完整条件: "${conditionStr}")`,
|
||||
)
|
||||
@@ -111,7 +109,7 @@ describe('FlatState', () => {
|
||||
expect(unmappedKeys.size).toBe(0)
|
||||
})
|
||||
|
||||
test('[Cover] achievement(condition)', () => {
|
||||
test('flat cover achievement(condition)', () => {
|
||||
const unmappedKeys = new Set<string>()
|
||||
const allAchievementItems = achievements.values()
|
||||
|
||||
@@ -121,7 +119,7 @@ describe('FlatState', () => {
|
||||
|
||||
const usedProperties = getPropertiesFromCondition(conditionStr)
|
||||
for (const key of usedProperties) {
|
||||
if (!FlatProperties.has(key)) {
|
||||
if (!SupportedFlatStateKeys.has(key)) {
|
||||
unmappedKeys.add(
|
||||
`[成就 ID: ${item.id}] 使用了未定义的键名: "${key}" (完整条件: "${conditionStr}")`,
|
||||
)
|
||||
@@ -137,37 +135,39 @@ describe('FlatState', () => {
|
||||
expect(unmappedKeys.size).toBe(0)
|
||||
})
|
||||
|
||||
test('get', () => {
|
||||
test('flat get', () => {
|
||||
const game = {
|
||||
lowest: {
|
||||
age: 1,
|
||||
charm: 2,
|
||||
intelligence: 3,
|
||||
strength: 4,
|
||||
money: 5,
|
||||
spirit: 6,
|
||||
},
|
||||
properties: {
|
||||
age: 11,
|
||||
charm: 12,
|
||||
intelligence: 13,
|
||||
strength: 14,
|
||||
money: 15,
|
||||
spirit: 16,
|
||||
},
|
||||
highest: {
|
||||
age: 21,
|
||||
charm: 22,
|
||||
intelligence: 23,
|
||||
strength: 24,
|
||||
money: 25,
|
||||
spirit: 26,
|
||||
props: {
|
||||
lowest: {
|
||||
age: 1,
|
||||
charm: 2,
|
||||
intelligence: 3,
|
||||
strength: 4,
|
||||
money: 5,
|
||||
spirit: 6,
|
||||
},
|
||||
current: {
|
||||
age: 11,
|
||||
charm: 12,
|
||||
intelligence: 13,
|
||||
strength: 14,
|
||||
money: 15,
|
||||
spirit: 16,
|
||||
},
|
||||
highest: {
|
||||
age: 21,
|
||||
charm: 22,
|
||||
intelligence: 23,
|
||||
strength: 24,
|
||||
money: 25,
|
||||
spirit: 26,
|
||||
},
|
||||
},
|
||||
life: 31,
|
||||
talents: new Set([33]),
|
||||
events: new Set([34, 35]),
|
||||
achievements: new Set([36]),
|
||||
}
|
||||
} as GameState
|
||||
|
||||
const profile = {
|
||||
times: 41,
|
||||
@@ -175,30 +175,30 @@ describe('FlatState', () => {
|
||||
talents: new Set([43]),
|
||||
achievements: new Set([44]),
|
||||
events: new Set([45, 46]),
|
||||
}
|
||||
} as ProfileState
|
||||
|
||||
const flatState = createFlatState(game, profile)
|
||||
expect(flatState['AGE']).toBe(game.properties.age)
|
||||
expect(flatState['CHR']).toBe(game.properties.charm)
|
||||
expect(flatState['INT']).toBe(game.properties.intelligence)
|
||||
expect(flatState['STR']).toBe(game.properties.strength)
|
||||
expect(flatState['MNY']).toBe(game.properties.money)
|
||||
expect(flatState['SPR']).toBe(game.properties.spirit)
|
||||
expect(flatState['AGE']).toBe(game.props.current.age)
|
||||
expect(flatState['CHR']).toBe(game.props.current.charm)
|
||||
expect(flatState['INT']).toBe(game.props.current.intelligence)
|
||||
expect(flatState['STR']).toBe(game.props.current.strength)
|
||||
expect(flatState['MNY']).toBe(game.props.current.money)
|
||||
expect(flatState['SPR']).toBe(game.props.current.spirit)
|
||||
expect(flatState['HAGE']).toBe(game.props.highest.age)
|
||||
expect(flatState['HCHR']).toBe(game.props.highest.charm)
|
||||
expect(flatState['HINT']).toBe(game.props.highest.intelligence)
|
||||
expect(flatState['HSTR']).toBe(game.props.highest.strength)
|
||||
expect(flatState['HMNY']).toBe(game.props.highest.money)
|
||||
expect(flatState['HSPR']).toBe(game.props.highest.spirit)
|
||||
expect(flatState['LAGE']).toBe(game.props.lowest.age)
|
||||
expect(flatState['LCHR']).toBe(game.props.lowest.charm)
|
||||
expect(flatState['LINT']).toBe(game.props.lowest.intelligence)
|
||||
expect(flatState['LSTR']).toBe(game.props.lowest.strength)
|
||||
expect(flatState['LMNY']).toBe(game.props.lowest.money)
|
||||
expect(flatState['LSPR']).toBe(game.props.lowest.spirit)
|
||||
expect(flatState['LIF']).toBe(game.life)
|
||||
expect(flatState['TLT']).toEqual(game.talents)
|
||||
expect(flatState['EVT']).toEqual(game.events)
|
||||
expect(flatState['LAGE']).toBe(game.lowest.age)
|
||||
expect(flatState['HAGE']).toBe(game.highest.age)
|
||||
expect(flatState['LCHR']).toBe(game.lowest.charm)
|
||||
expect(flatState['HCHR']).toBe(game.highest.charm)
|
||||
expect(flatState['LINT']).toBe(game.lowest.intelligence)
|
||||
expect(flatState['HINT']).toBe(game.highest.intelligence)
|
||||
expect(flatState['LSTR']).toBe(game.lowest.strength)
|
||||
expect(flatState['HSTR']).toBe(game.highest.strength)
|
||||
expect(flatState['LMNY']).toBe(game.lowest.money)
|
||||
expect(flatState['HMNY']).toBe(game.highest.money)
|
||||
expect(flatState['LSPR']).toBe(game.lowest.spirit)
|
||||
expect(flatState['HSPR']).toBe(game.highest.spirit)
|
||||
expect(flatState['TMS']).toBe(profile.times)
|
||||
expect(flatState['AEVT']).toEqual(profile.events)
|
||||
expect(flatState['ATLT']).toEqual(profile.talents)
|
||||
@@ -207,4 +207,36 @@ describe('FlatState', () => {
|
||||
Math.floor((22 + 23 + 24 + 25 + 26) * 2 + 21 / 2),
|
||||
)
|
||||
})
|
||||
|
||||
const allocation = { charm: 5, intelligence: 5, strength: 5, money: 5 }
|
||||
test('createHLProperties', () => {
|
||||
const props = createHLProperties(allocation)
|
||||
expect(props.current.charm).toBe(allocation.charm)
|
||||
expect(props.current.intelligence).toBe(allocation.intelligence)
|
||||
expect(props.current.strength).toBe(allocation.strength)
|
||||
expect(props.current.money).toBe(allocation.money)
|
||||
expect(props.current.age).toBe(-1)
|
||||
expect(props.current.spirit).toBe(0)
|
||||
})
|
||||
|
||||
test('propsEffect', () => {
|
||||
const props = createHLProperties(allocation)
|
||||
const effect = {
|
||||
age: 6,
|
||||
charm: -2,
|
||||
intelligence: 3,
|
||||
strength: 4,
|
||||
money: -5,
|
||||
spirit: 7,
|
||||
}
|
||||
const effected = propsEffect(props, effect)
|
||||
for (const key in effect) {
|
||||
const k = key as keyof Properties
|
||||
const c = props.current[k]
|
||||
const be = c + effect[k]
|
||||
expect(c).toBe(be)
|
||||
expect(effected.highest[k]).toBe(Math.max(c, be))
|
||||
expect(effected.lowest[k]).toBe(Math.min(c, be))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user