diff --git a/packages-user/data-base/src/hero/equipment.ts b/packages-user/data-base/src/hero/equipment.ts index d38b59b..454ba79 100644 --- a/packages-user/data-base/src/hero/equipment.ts +++ b/packages-user/data-base/src/hero/equipment.ts @@ -353,7 +353,7 @@ export class HeroEquipment implements IHeroEquipment { }); // 由于装备修饰器不进存档,所以此时的勇士处于没有任何装备修饰器的状态,故可以安全清除 this.equips.clear(); - // 读档期间的重新装备不应写入录像,故用禁用窗口包裹 + const replay = this.state.replaySystem; replay.disable(); for (const [index, uid] of state.equipped) { diff --git a/packages-user/data-base/src/hero/location.ts b/packages-user/data-base/src/hero/location.ts index 52099f9..2f68b10 100644 --- a/packages-user/data-base/src/hero/location.ts +++ b/packages-user/data-base/src/hero/location.ts @@ -53,7 +53,7 @@ export class HeroLocation @shouldReplay('Setting hero floor should be replayed.') setFloor(map: IGameMap | null): void { - this.floorId = map ? map.floorId : undefined; + this.floorId = map?.floorId ?? void 0; this.map = map; this.forEachHook(hook => hook.onSetFloor?.(map)); } diff --git a/packages-user/data-base/src/map/mapLayer.ts b/packages-user/data-base/src/map/mapLayer.ts index 8fe5a25..f50c305 100644 --- a/packages-user/data-base/src/map/mapLayer.ts +++ b/packages-user/data-base/src/map/mapLayer.ts @@ -17,8 +17,9 @@ import { Hookable, HookController, ITileLocator, logger } from '@motajs/common'; import { FaceDirection, IDataCommon, - ILocationIndexer, + ILocationHelper, IRoleFaceBinder, + MapLocIndexer, SaveCompression, shouldReplay } from '@user/data-common'; @@ -31,7 +32,7 @@ export class MapLayer implements IResizableMapLayer { readonly state: IDataCommon; - readonly indexer: ILocationIndexer; + readonly indexer: ILocationHelper; width: number; height: number; @@ -77,7 +78,7 @@ export class MapLayer expired: false, array: this.mapArray }; - this.indexer = map.indexer as ILocationIndexer; + this.indexer = map.indexer; } protected createController( @@ -528,20 +529,16 @@ export class MapLayer /** * 裁剪超出新图层范围的点事件,并按新宽度重建索引 * @param oldWidth 变更前的图层宽度,用于解码旧索引 - * @param width 新图层宽度 - * @param height 新图层高度 */ - private cropPointEvents( - oldWidth: number, - width: number, - height: number - ): void { + private cropPointEvents(oldWidth: number): void { + const oldIndex = new MapLocIndexer(); + oldIndex.setWidth(oldWidth); for (const [index, eventView] of [...this.pointEvents]) { - const x = index % oldWidth; - const y = Math.floor(index / oldWidth); + const { x, y } = oldIndex.locator(index); this.pointEvents.delete(index); - if (x < width && y < height) { - this.pointEvents.set(y * width + x, eventView); + if (this.inMap(x, y)) { + const index = this.indexer.index(x, y); + this.pointEvents.set(index, eventView); } } } @@ -561,7 +558,6 @@ export class MapLayer const beforeArea = beforeWidth * beforeHeight; this.width = width; this.height = height; - this.indexer.setWidth(width); const area = width * height; const newArray = new Uint32Array(area); this.mapArray = newArray; @@ -583,7 +579,7 @@ export class MapLayer }; // 其他杂项清理 - this.cropPointEvents(beforeWidth, width, height); + this.cropPointEvents(beforeWidth); this.staticTileCache.clear(); this.forEachHook(hook => { hook.onResize?.(width, height); @@ -605,7 +601,6 @@ export class MapLayer this.mapData.expired = true; this.width = width; this.height = height; - this.indexer.setWidth(width); this.mapArray = new Uint32Array(width * height); this.mapData = { expired: false, diff --git a/packages-user/data-base/src/map/tile.ts b/packages-user/data-base/src/map/tile.ts index 0ab1fe9..6146a29 100644 --- a/packages-user/data-base/src/map/tile.ts +++ b/packages-user/data-base/src/map/tile.ts @@ -40,9 +40,6 @@ export abstract class MapTileBase abstract set(num: number): void; - /** - * 根据当前图块原始数据恢复默认事件并建立干净基准 - */ restoreDefaultEvents(): void { const eventView = this.tileEvent(); eventView.clear(); diff --git a/packages-user/data-common/src/replay/sandbox.ts b/packages-user/data-common/src/replay/sandbox.ts index aed2ac6..8ccf577 100644 --- a/packages-user/data-common/src/replay/sandbox.ts +++ b/packages-user/data-common/src/replay/sandbox.ts @@ -295,13 +295,12 @@ export class ReplaySandbox } async step(): Promise { - if ( - this.playing && - !this.appendingStep && - !this.reader.expired && - !this.ended - ) { - this.appendingStep = this.reader.read(); + if (!this.playing && !this.ended) { + if (!this.reader.expired && !this.appendingStep) { + this.playing = true; + this.pausing = true; + this.appendingStep = this.reader.read(); + } } const res = await this.replayStep(); if (res.success) {