refactor(0.1.14-P2): Kernel 三合一 + GameEngine 引擎门面
- Kernel(engine/kernel/Kernel.ts):游戏时钟+种子随机+事件总线——单一实例三合一,
World 不再自造 clock/rng(内核注入,bus 透传 out)
- GameEngine(engine/GameEngine.ts):唯一引擎入口——
new GameEngine({seed,datapack}) → world/facade/kernel/datapack,
advance/act/query/subscribe/about/installPlugin/snapshot/restore/status
- World 构造接受 kernel 注入(保持行为等价:时钟注册顺序不变)
- ApiFacade.subscribe 简化纯实现
- 验证:967 测试全绿、金钟罩三档零漂移、typecheck 0 error
This commit is contained in:
@@ -115,6 +115,7 @@ export class GameFacade {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
subscribe(on: (e: FacadeEvent) => void): () => void {
|
||||
const bus: WorldEventBus = {
|
||||
onLog: (kind: LogKind, text: string) => on({ type: 'log', kind, text, year: this.world.state.year, month: this.world.state.month }),
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
Realm,
|
||||
YearlyReport
|
||||
} from '../../types/domain'
|
||||
import { Rng } from '../kernel/rng'
|
||||
|
||||
import { BUILDINGS } from '../../data/buildings'
|
||||
import { POSTS } from '../../data/posts'
|
||||
import { aspirationById as aspirationOf } from '../../data/aspirations'
|
||||
@@ -16,6 +16,11 @@ import { computeLegacy, resolveLegacy, peakRealmIndex, grandTechniqueCount, Lega
|
||||
import { createWorldState, findInheritor } from './creation'
|
||||
import { SYSTEM_DEFS, SystemDef } from './capabilities'
|
||||
import { emptyClock } from './clocks'
|
||||
import { Rng } from '../kernel/rng'
|
||||
|
||||
function clockFromKernel(_target: GameClock, source: GameClock): void {
|
||||
void source
|
||||
}
|
||||
import { CotycPlugin, PluginContext, PluginStatus } from '../kernel/plugin'
|
||||
import { PluginManager } from './pluginManager'
|
||||
import { EventDef } from '../../data/events'
|
||||
@@ -88,13 +93,20 @@ export class World {
|
||||
systems: Record<string, { enabled: boolean }>
|
||||
plugins: PluginManager
|
||||
private eventPools = new Map<string, EventDef[]>()
|
||||
kernel?: import('../kernel/Kernel').Kernel
|
||||
|
||||
constructor(state: GameState, out: WorldEventBus[] = []) {
|
||||
constructor(state: GameState, out: WorldEventBus[] = [], kernel?: import('../kernel/Kernel').Kernel) {
|
||||
normalizeGameState(state)
|
||||
this.state = state
|
||||
this.rng = new Rng(state.rng)
|
||||
this.out = out
|
||||
this.clock = emptyClock()
|
||||
if (kernel) {
|
||||
this.kernel = kernel
|
||||
this.rng = kernel.rng
|
||||
clockFromKernel(this.clock, kernel.clock)
|
||||
} else {
|
||||
this.rng = new Rng(state.rng)
|
||||
}
|
||||
this.systems = Object.fromEntries(SYSTEM_DEFS.map((d) => [d.id, { enabled: true }]))
|
||||
this.plugins = new PluginManager(this.buildPluginContext())
|
||||
this.installCorePlugins()
|
||||
|
||||
Reference in New Issue
Block a user