v0.1.7: 仙门之钥(门面化/能力注册表/数据包/开发者面板)
- GameFacade 统一门面:act(23 种动作白名单)/query(6 类只读快照)/subscribe(七大事件协议)/ about(版本+模块清单+数据包指纹);UI store 接入门面(act 直达,散装调用收口) - CapabilityRegistry:12 张能力卡(id/name/version/desc/hooks),world.systems 启停即拔插, 时钟按能力开关过滤(禁修炼则无人精进…沙盒玩法);sysChanged 广播 - DataPackRegistry:默认包与静态数据同引用(金钟罩零漂移),override/reset/fingerprint, 高频读口 6 处迁移 pack()——未来 MOD=注入数据包覆写 - 开发者面板:设置页系统仪表盘(清单+启停开关+警示文案) - 测试 225→239(能力清单/拔插分殊四路/广播幂等/包覆盖物价/act 目录/query/协议退订/about/ 金钟罩复验零漂移)
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
import { ITEMS, ARTIFACT_POWER } from './items'
|
||||
import { TECHNIQUES } from './techniques'
|
||||
import { BUILDINGS } from './buildings'
|
||||
import { MISSIONS, ENEMIES } from './secrets'
|
||||
import { NPCS } from './npcs'
|
||||
import { EVENTS } from './events'
|
||||
import { POSTS } from './posts'
|
||||
import { TRAITS } from './traits'
|
||||
import { ROOT_GRADES, ROOT_GRADE_NAMES, ELEMENT_LIST } from './elements'
|
||||
import { MAJORS, MAJOR_ORDER } from './realms'
|
||||
|
||||
export interface DataPack {
|
||||
items: typeof ITEMS
|
||||
artifacts: typeof ARTIFACT_POWER
|
||||
techniques: typeof TECHNIQUES
|
||||
buildings: typeof BUILDINGS
|
||||
missions: typeof MISSIONS
|
||||
enemies: typeof ENEMIES
|
||||
npcs: typeof NPCS
|
||||
events: typeof EVENTS
|
||||
posts: typeof POSTS
|
||||
traits: typeof TRAITS
|
||||
rootGrades: typeof ROOT_GRADES
|
||||
rootGradeNames: typeof ROOT_GRADE_NAMES
|
||||
elements: typeof ELEMENT_LIST
|
||||
majors: typeof MAJORS
|
||||
majorOrder: typeof MAJOR_ORDER
|
||||
}
|
||||
|
||||
/** 默认包:与库内静态数据**同引用**(保证确定性指纹不变);未来 MOD 通过注入覆盖 */
|
||||
export const DEFAULT_PACK: DataPack = {
|
||||
items: ITEMS,
|
||||
artifacts: ARTIFACT_POWER,
|
||||
techniques: TECHNIQUES,
|
||||
buildings: BUILDINGS,
|
||||
missions: MISSIONS,
|
||||
enemies: ENEMIES,
|
||||
npcs: NPCS,
|
||||
events: EVENTS,
|
||||
posts: POSTS,
|
||||
traits: TRAITS,
|
||||
rootGrades: ROOT_GRADES,
|
||||
rootGradeNames: ROOT_GRADE_NAMES,
|
||||
elements: ELEMENT_LIST,
|
||||
majors: MAJORS,
|
||||
majorOrder: MAJOR_ORDER
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据包注册表:默认 `pack()` 返回 DEFAULT_PACK(引用共享)。
|
||||
* setPack(partial) 覆写后立即生效;resetPack() 回到默认。返回的数据包指纹可用于版本校验。
|
||||
*/
|
||||
export class DataPackRegistry {
|
||||
private data: DataPack = DEFAULT_PACK
|
||||
|
||||
current(): DataPack {
|
||||
return this.data
|
||||
}
|
||||
|
||||
override(partial: Partial<DataPack>): DataPack {
|
||||
this.data = { ...DEFAULT_PACK, ...partial }
|
||||
return this.data
|
||||
}
|
||||
|
||||
reset(): DataPack {
|
||||
this.data = DEFAULT_PACK
|
||||
return this.data
|
||||
}
|
||||
|
||||
fingerprint(): string {
|
||||
const key = ['items', 'techniques', 'buildings', 'missions', 'events', 'npcs'] as const
|
||||
let h = 7
|
||||
for (const k of key) {
|
||||
const o = this.data[k] as unknown as Record<string, unknown>
|
||||
const len = Object.keys(o ?? {}).length
|
||||
h = Math.imul(h ^ len, 31)
|
||||
}
|
||||
return (h >>> 0).toString(16)
|
||||
}
|
||||
}
|
||||
|
||||
export const PACK = new DataPackRegistry()
|
||||
|
||||
/** 便捷读口(引擎唯一访问方式) */
|
||||
export function pack(): DataPack {
|
||||
return PACK.current()
|
||||
}
|
||||
Reference in New Issue
Block a user