结构(旧 game/core+engine → 新 engine/ 域): - engine/kernel/ 时钟/随机/插件协议/fxqueue/timesense/format/urgency/guide/names(原 core) - engine/narrative/ legacy/报告/列传/谱系/年轴(原 core 叙事族) - engine/runtime/ World/creation/pcgen/ApiFacade/capabilities/pluginManager/boot/clocks + Systems/*(12 系统) - engine/sim/ Market(未来 WorldSim 同行) - 旧 game/core、engine/systems、engine/world.ts 等路径全部废弃(无 re-export 兼容层) 验证:35 套件/967 测试全绿(金钟罩三档零漂移=纯搬迁无行为变化) typecheck 0 error
56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
import { GameState } from '../../types/domain'
|
|
|
|
export interface AxisEvent {
|
|
year: number
|
|
kind: '突破' | '大比' | '渡劫' | '婚' | '殇' | '战' | '飞升'
|
|
label: string
|
|
}
|
|
|
|
export interface AxisCell {
|
|
from: number
|
|
to: number
|
|
events: AxisEvent[]
|
|
births: number
|
|
deaths: number
|
|
}
|
|
|
|
/** 横轴年表:十年一格,把族簿大事压缩进一根时间轴 */
|
|
export function yearAxis(s: GameState, decadeSize = 10): AxisCell[] {
|
|
const startYear = Math.max(1, Math.min(...s.chronicle.map((e) => e.year).concat(1)))
|
|
const endYear = Math.max(startYear, s.year)
|
|
const cells = new Map<number, AxisCell>()
|
|
const cellOf = (year: number): AxisCell => {
|
|
const from = Math.floor((year - 1) / decadeSize) * decadeSize + 1
|
|
if (!cells.has(from)) cells.set(from, { from, to: Math.min(from + decadeSize - 1, endYear), events: [], births: 0, deaths: 0 })
|
|
return cells.get(from)!
|
|
}
|
|
|
|
for (const e of s.chronicle) {
|
|
if (e.year < startYear) continue
|
|
const cell = cellOf(e.year)
|
|
const kind: AxisEvent['kind'] | null =
|
|
e.category === 'breakthrough'
|
|
? /渡劫|天劫/.test(e.text)
|
|
? '渡劫'
|
|
: '突破'
|
|
: e.category === 'birth'
|
|
? null
|
|
: e.category === 'death'
|
|
? /飞升/.test(e.text) ? '飞升' : '殇'
|
|
: e.category === 'marriage'
|
|
? '婚'
|
|
: e.category === 'battle'
|
|
? '战'
|
|
: null
|
|
if (kind) cell.events.push({ year: e.year, kind, label: e.text.slice(0, 26) })
|
|
if (e.category === 'birth') cell.births++
|
|
if (e.category === 'death') cell.deaths++
|
|
}
|
|
|
|
return [...cells.entries()].sort((a, b) => a[0] - b[0]).map(([, c]) => c)
|
|
}
|
|
|
|
export function decadeLabel(from: number, to: number): string {
|
|
return from === to ? `${from}年` : `${from}-${to}年`
|
|
}
|