mirror of
https://github.com/motajs/template.git
synced 2026-05-02 12:23:13 +08:00
refactor: 地图存档的加载适配
This commit is contained in:
parent
70a58ef4dc
commit
c43bfa2ab0
@ -114,7 +114,7 @@ export class ClientCore implements IClientCore {
|
||||
// 使用分频器,用户可以在设置中调整,如果设备性能较差调高分频有助于提高性能表现
|
||||
excitaion: excitationDivider
|
||||
});
|
||||
this.mainMapRenderer = new MapRenderer(this.materials, data.layer);
|
||||
this.mainMapRenderer = new MapRenderer(this.materials, data.maps);
|
||||
this.mainMapExtension = new MapExtensionManager(this.mainMapRenderer);
|
||||
|
||||
// 兼容层
|
||||
@ -133,7 +133,7 @@ export class ClientCore implements IClientCore {
|
||||
await this.materials.trackedAsset.then();
|
||||
|
||||
this.mainMapRenderer.useAsset(this.materials.trackedAsset);
|
||||
const layer = this.data.layer.getLayerByAlias('event');
|
||||
const layer = this.data.maps.getLayerByAlias('event');
|
||||
if (layer) {
|
||||
this.mainMapExtension.addHero(this.data.hero.mover, layer);
|
||||
this.mainMapExtension.addDoor(layer);
|
||||
|
||||
@ -243,7 +243,7 @@ const MainScene = defineComponent(() => {
|
||||
>
|
||||
<map-render
|
||||
renderer={mainMapRenderer}
|
||||
layerState={state.layer}
|
||||
layerState={state.maps}
|
||||
extension={mainMapExtension}
|
||||
loc={[0, 0, MAP_WIDTH, MAP_HEIGHT]}
|
||||
/>
|
||||
|
||||
@ -18,7 +18,7 @@ export interface IStateBase<TEnemy, THero> {
|
||||
readonly numberIdMap: Map<number, string>;
|
||||
|
||||
/** 地图状态 */
|
||||
readonly layer: IMapStore;
|
||||
readonly maps: IMapStore;
|
||||
/** 勇士状态 */
|
||||
readonly hero: IHeroState<THero>;
|
||||
|
||||
|
||||
@ -16,16 +16,14 @@ import {
|
||||
MotaDataLoader,
|
||||
loading,
|
||||
IRoleFaceBinder,
|
||||
ILayerState,
|
||||
LayerState,
|
||||
RoleFaceBinder,
|
||||
FaceDirection,
|
||||
ISaveableContent,
|
||||
IStateSaveData,
|
||||
SaveCompression,
|
||||
IReadonlyEnemy
|
||||
IReadonlyEnemy,
|
||||
IMapStore,
|
||||
MapStore
|
||||
} from '@user/data-base';
|
||||
import { IEnemyAttr } from './enemy';
|
||||
import {
|
||||
CommonAuraConverter,
|
||||
EnemyLegacyBridge,
|
||||
@ -34,16 +32,25 @@ import {
|
||||
MainEnemyFinalEffect,
|
||||
MainMapDamageConverter,
|
||||
MainMapDamageReducer,
|
||||
registerSpecials
|
||||
registerSpecials,
|
||||
MainEnemyComparer,
|
||||
IEnemyAttr
|
||||
} from './enemy';
|
||||
import { HERO_DEFAULT_ATTRIBUTE, TILE_HEIGHT, TILE_WIDTH } from './shared';
|
||||
import {
|
||||
BG2_ZINDEX,
|
||||
BG_ZINDEX,
|
||||
EVENT_ZINDEX,
|
||||
FG2_ZINDEX,
|
||||
FG_ZINDEX,
|
||||
HERO_DEFAULT_ATTRIBUTE,
|
||||
TILE_HEIGHT,
|
||||
TILE_WIDTH
|
||||
} from './shared';
|
||||
import { IHeroAttr } from './hero';
|
||||
import { ILoadProgressTotal, LoadProgressTotal } from '@motajs/loader';
|
||||
import { isNil } from 'lodash-es';
|
||||
import { logger } from '@motajs/common';
|
||||
import { ISaveSystem } from './save';
|
||||
import { SaveSystem } from './save/system';
|
||||
import { MainEnemyComparer } from './enemy/comparer';
|
||||
import { ISaveSystem, SaveSystem } from './save';
|
||||
|
||||
export class CoreState implements ICoreState {
|
||||
// 全局内容
|
||||
@ -52,7 +59,7 @@ export class CoreState implements ICoreState {
|
||||
readonly numberIdMap: Map<number, string>;
|
||||
|
||||
// 可存档内容
|
||||
readonly layer: ILayerState;
|
||||
readonly maps: IMapStore;
|
||||
readonly hero: IHeroState<IHeroAttr>;
|
||||
readonly enemyManager: IEnemyManager<IEnemyAttr>;
|
||||
readonly flags: IFlagSystem;
|
||||
@ -74,7 +81,7 @@ export class CoreState implements ICoreState {
|
||||
> = new Map();
|
||||
|
||||
constructor() {
|
||||
this.layer = new LayerState();
|
||||
this.maps = new MapStore();
|
||||
this.roleFace = new RoleFaceBinder();
|
||||
this.idNumberMap = new Map();
|
||||
this.numberIdMap = new Map();
|
||||
@ -149,9 +156,16 @@ export class CoreState implements ICoreState {
|
||||
// 加载先使用兼容层实现
|
||||
loading.once('loaded', () => {
|
||||
this.initEnemyManager(enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80);
|
||||
this.initMapStore(
|
||||
core.floorIds,
|
||||
core.floors as Record<FloorIds, ResolvedFloor>
|
||||
);
|
||||
});
|
||||
|
||||
this.addSaveableContent('flags', this.flags);
|
||||
this.addSaveableContent('@system/hero', this.hero);
|
||||
this.addSaveableContent('@system/flags', this.flags);
|
||||
this.addSaveableContent('@system/maps', this.maps);
|
||||
this.addSaveableContent('@system/enemy', this.enemyManager);
|
||||
|
||||
//#endregion
|
||||
}
|
||||
@ -193,12 +207,86 @@ export class CoreState implements ICoreState {
|
||||
manager.compareWith(reference);
|
||||
}
|
||||
|
||||
private initMapStore(
|
||||
floors: FloorIds[],
|
||||
data: Record<FloorIds, ResolvedFloor>
|
||||
) {
|
||||
const reference = new Map<string, Map<number, Uint32Array>>();
|
||||
for (const id of floors) {
|
||||
const floor = data[id];
|
||||
const state = this.maps.createLayerState(id);
|
||||
const bg = state.addLayer(floor.width, floor.height);
|
||||
const bg2 = state.addLayer(floor.width, floor.height);
|
||||
const event = state.addLayer(floor.width, floor.height);
|
||||
const fg = state.addLayer(floor.width, floor.height);
|
||||
const fg2 = state.addLayer(floor.width, floor.height);
|
||||
bg.setZIndex(BG_ZINDEX);
|
||||
bg2.setZIndex(BG2_ZINDEX);
|
||||
event.setZIndex(EVENT_ZINDEX);
|
||||
fg.setZIndex(FG_ZINDEX);
|
||||
fg2.setZIndex(FG2_ZINDEX);
|
||||
state.setLayerAlias(bg, 'bg');
|
||||
state.setLayerAlias(bg2, 'bg2');
|
||||
state.setLayerAlias(event, 'event');
|
||||
state.setLayerAlias(fg, 'fg');
|
||||
state.setLayerAlias(fg2, 'fg2');
|
||||
state.setActiveStatus(false);
|
||||
|
||||
const size = floor.width * floor.height;
|
||||
const ref = new Map<number, Uint32Array>();
|
||||
|
||||
if (floor.bgmap && floor.bgmap.length > 0) {
|
||||
const arr = new Uint32Array(floor.bgmap.flat());
|
||||
bg.setMapRef(arr);
|
||||
ref.set(BG_ZINDEX, new Uint32Array(arr));
|
||||
} else {
|
||||
ref.set(BG_ZINDEX, new Uint32Array(size));
|
||||
}
|
||||
|
||||
if (floor.bg2map && floor.bg2map.length > 0) {
|
||||
const arr = new Uint32Array(floor.bg2map.flat());
|
||||
bg2.setMapRef(arr);
|
||||
ref.set(BG2_ZINDEX, new Uint32Array(arr));
|
||||
} else {
|
||||
ref.set(BG2_ZINDEX, new Uint32Array(size));
|
||||
}
|
||||
|
||||
if (floor.map && floor.map.length > 0) {
|
||||
const arr = new Uint32Array(floor.map.flat());
|
||||
event.setMapRef(arr);
|
||||
ref.set(EVENT_ZINDEX, new Uint32Array(arr));
|
||||
} else {
|
||||
ref.set(EVENT_ZINDEX, new Uint32Array(size));
|
||||
}
|
||||
|
||||
if (floor.fgmap && floor.fgmap.length > 0) {
|
||||
const arr = new Uint32Array(floor.fgmap.flat());
|
||||
fg.setMapRef(arr);
|
||||
ref.set(FG_ZINDEX, new Uint32Array(arr));
|
||||
} else {
|
||||
ref.set(FG_ZINDEX, new Uint32Array(size));
|
||||
}
|
||||
|
||||
if (floor.fg2map && floor.fg2map.length > 0) {
|
||||
const arr = new Uint32Array(floor.fg2map.flat());
|
||||
fg2.setMapRef(arr);
|
||||
ref.set(FG2_ZINDEX, new Uint32Array(arr));
|
||||
} else {
|
||||
ref.set(FG2_ZINDEX, new Uint32Array(size));
|
||||
}
|
||||
|
||||
reference.set(id, ref);
|
||||
}
|
||||
this.maps.compareWith(reference);
|
||||
}
|
||||
|
||||
addSaveableContent(id: string, content: ISaveableContent<unknown>): void {
|
||||
if (this.saveables.has(id)) {
|
||||
logger.warn(112, id);
|
||||
return;
|
||||
}
|
||||
this.saveables.set(id, content);
|
||||
this.addedSaveables.add(content);
|
||||
}
|
||||
|
||||
getSaveableContent<T>(id: string): ISaveableContent<T> | null {
|
||||
@ -222,17 +310,4 @@ export class CoreState implements ICoreState {
|
||||
this.executors.set(content, executor);
|
||||
}
|
||||
}
|
||||
|
||||
saveState(): IStateSaveData {
|
||||
return structuredClone({
|
||||
followers: this.hero.mover.followers
|
||||
});
|
||||
}
|
||||
|
||||
loadState(data: IStateSaveData): void {
|
||||
this.hero.mover.removeAllFollowers();
|
||||
data.followers.forEach(v => {
|
||||
this.hero.mover.addFollower(v.num, v.identifier);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
export * from './aura';
|
||||
export * from './calculator';
|
||||
export * from './comparer';
|
||||
export * from './damage';
|
||||
export * from './final';
|
||||
export * from './legacy';
|
||||
|
||||
@ -1,27 +1,9 @@
|
||||
import { FaceDirection, loading } from '@user/data-base';
|
||||
import { isNil } from 'lodash-es';
|
||||
import { ICoreState } from './types';
|
||||
import { TILE_HEIGHT, TILE_WIDTH } from './shared';
|
||||
import { state } from './ins';
|
||||
|
||||
function createCoreState(state: ICoreState) {
|
||||
//#region 地图部分
|
||||
|
||||
const width = TILE_WIDTH;
|
||||
const height = TILE_HEIGHT;
|
||||
const bg = state.layer.addLayer(width, height);
|
||||
const bg2 = state.layer.addLayer(width, height);
|
||||
const event = state.layer.addLayer(width, height);
|
||||
const fg = state.layer.addLayer(width, height);
|
||||
const fg2 = state.layer.addLayer(width, height);
|
||||
state.layer.setLayerAlias(bg, 'bg');
|
||||
state.layer.setLayerAlias(bg2, 'bg2');
|
||||
state.layer.setLayerAlias(event, 'event');
|
||||
state.layer.setLayerAlias(fg, 'fg');
|
||||
state.layer.setLayerAlias(fg2, 'fg2');
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region 图块部分
|
||||
|
||||
const data = Object.entries(core.maps.blocksInfo);
|
||||
|
||||
@ -1 +1,2 @@
|
||||
export * from './system';
|
||||
export * from './types';
|
||||
|
||||
@ -1,10 +1,27 @@
|
||||
import { IHeroAttr } from './hero';
|
||||
|
||||
//#region 地图相关
|
||||
|
||||
/** 每个地图的默认宽度 */
|
||||
export const TILE_WIDTH = 13;
|
||||
/** 每个地图的默认高度 */
|
||||
export const TILE_HEIGHT = 13;
|
||||
|
||||
// 图层纵深,这些纵深与渲染系统的纵深没有关系,仅在地图图层之间生效
|
||||
|
||||
/** 背景层纵深 */
|
||||
export const BG_ZINDEX = 0;
|
||||
/** 背景层2纵深 */
|
||||
export const BG2_ZINDEX = 10;
|
||||
/** 事件层纵深 */
|
||||
export const EVENT_ZINDEX = 20;
|
||||
/** 前景层纵深 */
|
||||
export const FG_ZINDEX = 30;
|
||||
/** 前景层2纵深 */
|
||||
export const FG2_ZINDEX = 40;
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region 勇士相关
|
||||
|
||||
/** 默认的勇士图片 */
|
||||
|
||||
@ -30,7 +30,8 @@ export interface ICoreState extends IStateBase<IEnemyAttr, IHeroAttr> {
|
||||
readonly saveSystem: ISaveSystem;
|
||||
|
||||
/**
|
||||
* 将某个存档执行器绑定至指定的可存档对象,一个可存档对象只能绑定一个执行器,但一个执行器可以绑定多个可存档对象
|
||||
* 将某个存档执行器绑定至指定的可存档对象,一个可存档对象只能绑定一个执行器,
|
||||
* 但一个执行器可以绑定多个可存档对象,主要用来在读档后进行一些全局性的操作
|
||||
* @param content 可存档对象或其注册 id
|
||||
* @param executor 可存档对象对应的执行器
|
||||
*/
|
||||
|
||||
@ -324,7 +324,7 @@ export function initFallback() {
|
||||
callback?.();
|
||||
};
|
||||
|
||||
const layer = state.layer.getLayerByAlias('event')!;
|
||||
const layer = state.maps.getLayerByAlias('event')!;
|
||||
layer.openDoor(x, y).then(cb);
|
||||
|
||||
const animate = fallbackIds++;
|
||||
@ -373,7 +373,7 @@ export function initFallback() {
|
||||
cb();
|
||||
} else {
|
||||
const num = state.idNumberMap.get(id)!;
|
||||
const layer = state.layer.getLayerByAlias('event')!;
|
||||
const layer = state.maps.getLayerByAlias('event')!;
|
||||
layer.closeDoor(num, x, y).then(cb);
|
||||
|
||||
const animate = fallbackIds++;
|
||||
@ -514,11 +514,11 @@ export function initFallback() {
|
||||
// 先使用 mainMapRenderer 妥协
|
||||
const { client } = Mota.require('@user/client-modules');
|
||||
const renderer = client.mainMapRenderer;
|
||||
if (renderer.layerState !== state.layer) {
|
||||
if (renderer.layerState !== state.maps) {
|
||||
callback?.();
|
||||
return;
|
||||
}
|
||||
const layer = state.layer.getLayerByAlias('event');
|
||||
const layer = state.maps.getLayerByAlias('event');
|
||||
if (!layer) {
|
||||
callback?.();
|
||||
return;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user