fix(03-10): restore compatibility loading path

- Remove Phase 3 legacy dependency and serialized loading adapters
- Restore SaveSystem, converter, bridge, and loading callback assembly
This commit is contained in:
AncTe committed 2026-09-11 13:52:54 +08:00
1 parent 4d094f988f
commit e4e39f7b2b
3 files changed
+35 -217

No files matched your search

+35 -65
View File
@@ -15,6 +15,7 @@ import {
IHeroAttr,
IEnemyAttr,
ISaveSystem,
SaveSystem,
GameEventStore,
IGameEventStore,
IItemStore,
@@ -22,7 +23,6 @@ import {
IMapStore,
MapStore,
IReplaySystem,
IMapRawData,
ReplaySystem
} from '@user/data-common';
import {
@@ -35,6 +35,7 @@ import {
FlagSystem,
IMotaDataLoader,
MotaDataLoader,
loading,
IReadonlyEnemy,
IMapState,
MapState
@@ -51,6 +52,7 @@ import {
} from '@user/data-system';
import {
CommonAuraConverter,
EnemyLegacyBridge,
GuardAuraConverter,
MainDamageCalculator,
MainEnemyFinalEffect,
@@ -70,12 +72,11 @@ import {
TILE_WIDTH
} from './shared';
import {
createLegacyDependencies,
ILegacyLoadData,
ILegacySerializedLoadData,
LOAD_SERIALIZED_DATA
} from './legacy/dependencies';
import { registerSerializedEvents } from './legacy/events';
ItemLegacyBridge,
LegacyItemData,
LegacyTileData,
TileLegacyBridge
} from './legacy';
import { ILoadProgressTotal, LoadProgressTotal } from '@motajs/loader';
import { isNil } from 'lodash-es';
import { DirectionMapper, IDirectionMapper, logger } from '@motajs/common';
@@ -88,8 +89,8 @@ export class CoreState implements ICoreState {
readonly saveSystem: ISaveSystem;
readonly roleFace: IRoleFaceBinder;
readonly faceManager: IFaceManager;
readonly tileStore: ITileStore;
readonly itemStore: IItemStore<IHeroAttr, unknown>;
readonly tileStore: ITileStore<LegacyTileData>;
readonly itemStore: IItemStore<IHeroAttr, LegacyItemData>;
readonly mapStore: IMapStore;
readonly eventStore: IGameEventStore;
readonly directionMapper: IDirectionMapper;
@@ -122,12 +123,10 @@ export class CoreState implements ICoreState {
> = new Map();
constructor() {
const legacy = createLegacyDependencies();
//#region L0 初始化
// 存档系统
this.saveSystem = legacy.saveSystem;
this.saveSystem = new SaveSystem();
// 配置存档系统,一般情况下不建议动,除非你知道你在干什么
this.saveSystem.config({
autosaveLevel: SaveCompression.LowCompression,
@@ -148,17 +147,12 @@ export class CoreState implements ICoreState {
this.faceManager.registerById('dir8', dir8);
// 图块
const tileStore = new TileStore();
if (legacy.tileConverter) {
tileStore.attachLegacyConverter(legacy.tileConverter);
}
const tileStore = new TileStore<LegacyTileData>();
tileStore.attachLegacyConverter(new TileLegacyBridge());
this.tileStore = tileStore;
// 道具
const itemStore = new ItemStore();
const itemConverter = legacy.createItemConverter(this);
if (itemConverter) {
itemStore.attachLegacyConverter(itemConverter);
}
const itemStore = new ItemStore<IHeroAttr, LegacyItemData>();
itemStore.attachLegacyConverter(new ItemLegacyBridge(this));
this.itemStore = itemStore;
// 地图
const mapStore = new MapStore();
@@ -188,7 +182,7 @@ export class CoreState implements ICoreState {
// 怪物管理器
const comparer = new MainEnemyComparer();
const enemyManager = new EnemyManager(legacy.enemyBridge);
const enemyManager = new EnemyManager(new EnemyLegacyBridge());
enemyManager.attachEnemyComparer(comparer);
enemyManager.setAttributeDefaults('hp', 0);
enemyManager.setAttributeDefaults('atk', 0);
@@ -235,9 +229,20 @@ export class CoreState implements ICoreState {
this.addSaveableContent('@system/flags', this.flags);
this.addSaveableContent('@system/maps', this.maps);
this.addSaveableContent('@system/enemy', this.enemyManager);
// 旧样板初始化只能经由内部边界进入,Node 路径不会注册加载回调
legacy.registerLoading(data => {
this.initLegacyData(data);
// 初始化存档数据库,不要动
loading.once('coreInit', () => {
this.saveSystem.init(`@game/${core.firstData.name}`);
});
// 加载初始化,先使用兼容层实现
loading.once('loaded', () => {
this.initTileStore(core.maps.blocksInfo);
this.initItemStore(core.items.items);
this.initEnemyManager(enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80);
this.initMapState(
core.floorIds,
core.floors as Record<FloorIds, ResolvedFloor>
);
});
// 勇士顶层初始化
@@ -260,32 +265,11 @@ export class CoreState implements ICoreState {
//#region 私有方法
private initLegacyData(data: ILegacyLoadData): void {
this.initTileStore(data.tiles);
this.initItemStore(data.items);
this.initEnemyManager(data.enemies);
if (data.serialized) {
this[LOAD_SERIALIZED_DATA](data.serialized);
} else {
this.initMapState(data.floors, data.maps);
}
}
/** 经内部加载边界注册序列化事件并绑定原始地图事件 id */
[LOAD_SERIALIZED_DATA](data: ILegacySerializedLoadData): void {
registerSerializedEvents(
this.eventStore,
this.eventSystem.executor.interpreter,
data.events
);
this.initRawMapState(data.maps);
}
/**
* 初始化图块存储对象
* @param data 旧样板图块定义对象
*/
private initTileStore(data: ILegacyLoadData['tiles']) {
private initTileStore(data: typeof core.maps.blocksInfo) {
const entries = Object.entries(data);
for (const [key, block] of entries) {
this.tileStore.fromLegacy(Number(key), block);
@@ -316,7 +300,7 @@ export class CoreState implements ICoreState {
* 初始化道具存储对象
* @param data 旧样板道具定义对象
*/
private initItemStore(data: ILegacyLoadData['items']) {
private initItemStore(data: typeof core.items.items) {
const entries = Object.entries(data);
for (const [id, legacy] of entries) {
const num = this.tileStore.idToNumber(id);
@@ -332,7 +316,7 @@ export class CoreState implements ICoreState {
* 初始化怪物管理器对象
* @param data 旧样板怪物存储对象
*/
private initEnemyManager(data: ILegacyLoadData['enemies']) {
private initEnemyManager(data: Record<EnemyIds, Enemy>) {
const manager = this.enemyManager;
const reference = new Map<number, IReadonlyEnemy<IEnemyAttr>>();
for (const [id, enemy] of Object.entries(structuredClone(data))) {
@@ -365,8 +349,8 @@ export class CoreState implements ICoreState {
}
private initMapState(
floors: ILegacyLoadData['floors'],
data: ILegacyLoadData['maps']
floors: FloorIds[],
data: Record<FloorIds, ResolvedFloor>
) {
const reference = new Map<string, Map<number, Uint32Array>>();
for (const id of floors) {
@@ -438,20 +422,6 @@ export class CoreState implements ICoreState {
this.maps.compareWith(reference);
}
private initRawMapState(data: readonly IMapRawData[]): void {
const reference = new Map<string, Map<number, Uint32Array>>();
for (const raw of data) {
const state = this.maps.fromRaw(raw);
if (!state) continue;
const ref = new Map<number, Uint32Array>();
for (const [zIndex, map] of Object.entries(raw.map)) {
ref.set(Number(zIndex), new Uint32Array(map));
}
reference.set(raw.floorId, ref);
}
this.maps.compareWith(reference);
}
//#endregion
//#region 存档方法