mirror of
https://github.com/motajs/template.git
synced 2026-10-01 08:00:17 +08:00
refactor: map
This commit is contained in:
parent
b262918082
commit
7c155be5ce
@ -318,19 +318,19 @@ describe('MapState activation and areas', () => {
|
||||
new Set([[{ start: 0, end: 0 }], [{ start: 1, end: 1 }]])
|
||||
);
|
||||
|
||||
mapState.notifyEnterFloor('A');
|
||||
mapState.autoActivateFloor('A');
|
||||
expect(mapState.isMapActive('A')).toBe(false);
|
||||
|
||||
mapState.useAutoActivitor(true);
|
||||
mapState.notifyEnterFloor('A');
|
||||
mapState.autoActivateFloor('A');
|
||||
expect(mapState.isMapActive('A')).toBe(true);
|
||||
|
||||
mapState.notifyEnterFloor('B');
|
||||
mapState.autoActivateFloor('B');
|
||||
expect(mapState.isMapActive('A')).toBe(false);
|
||||
expect(mapState.isMapActive('B')).toBe(true);
|
||||
|
||||
mapState.useAutoActivitor(false);
|
||||
mapState.notifyEnterFloor('A');
|
||||
mapState.autoActivateFloor('A');
|
||||
expect(mapState.isMapActive('A')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@ -4,7 +4,6 @@ import {
|
||||
SaveCompression,
|
||||
shouldReplay
|
||||
} from '@user/data-common';
|
||||
import { ITileStore } from '@user/data-common';
|
||||
import {
|
||||
IGameMap,
|
||||
IGameMapSave,
|
||||
@ -34,10 +33,7 @@ export class MapState implements IMapState {
|
||||
/** 自动分区激活器开关 */
|
||||
private autoActivitorEnabled: boolean = false;
|
||||
|
||||
constructor(
|
||||
private readonly tileStore: ITileStore,
|
||||
public readonly state: IDataCommon
|
||||
) {}
|
||||
constructor(readonly state: IDataCommon) {}
|
||||
|
||||
//#region 楼层管理
|
||||
|
||||
@ -72,11 +68,10 @@ export class MapState implements IMapState {
|
||||
const state = this.createMap(raw.floorId, raw.width, height);
|
||||
for (const [zIndex, map] of entries) {
|
||||
const z = Number(zIndex);
|
||||
const layer = state.addLayer();
|
||||
const alias = raw.layerAlias[z];
|
||||
const layer = state.addLayer(alias);
|
||||
layer.setMapRef(new Uint32Array(map));
|
||||
layer.setZIndex(z);
|
||||
state.setLayerAlias(layer, alias);
|
||||
|
||||
// 设置坐标点事件
|
||||
const events = raw.events[z];
|
||||
@ -106,8 +101,7 @@ export class MapState implements IMapState {
|
||||
} else {
|
||||
this.maps.push(id);
|
||||
}
|
||||
const tile = this.tileStore;
|
||||
const state = new GameMap(this.state, tile, id, width, height);
|
||||
const state = new GameMap(this.state, id, width, height);
|
||||
// 若已设置参考基准,新楼层直接视为全脏
|
||||
if (this.compared) {
|
||||
state.markDirty(true);
|
||||
@ -162,7 +156,7 @@ export class MapState implements IMapState {
|
||||
this.autoActivitorEnabled = enable;
|
||||
}
|
||||
|
||||
notifyEnterFloor(id: string): void {
|
||||
autoActivateFloor(id: string): void {
|
||||
if (!this.autoActivitorEnabled) return;
|
||||
const idx = this.maps.indexOf(id);
|
||||
if (idx === -1) return;
|
||||
|
||||
@ -33,65 +33,44 @@ export class DynamicTileMover extends ObjectMover<IDynamicTile> {
|
||||
}
|
||||
|
||||
@shouldReplay('Dynamic tile moving step should be replayed.')
|
||||
protected onStepEnd(
|
||||
protected async onStepEnd(
|
||||
code: number,
|
||||
step: ObjectMoveStep,
|
||||
tile: IDynamicTile
|
||||
): Promise<ITileLocator> {
|
||||
if (code !== DynamicMoveCode.Success) {
|
||||
logger.warn(126, 'DynamicMoveCode.Success (0)', code.toString());
|
||||
return Promise.resolve({ x: tile.x, y: tile.y });
|
||||
return { x: tile.x, y: tile.y };
|
||||
}
|
||||
const locator: ITileLocator = {
|
||||
x: tile.x,
|
||||
y: tile.y
|
||||
};
|
||||
const handler = tile.state.faceManager.get(FaceGroup.Dir8);
|
||||
if (!handler) {
|
||||
logger.warn(192);
|
||||
return Promise.resolve({ x: tile.x, y: tile.y });
|
||||
return { x: tile.x, y: tile.y };
|
||||
}
|
||||
switch (step.type) {
|
||||
case ObjectMoveType.Dir: {
|
||||
const { x, y } = handler.movement(step.move);
|
||||
tile.setFaceDirection(step.move);
|
||||
locator.x += x;
|
||||
locator.y += y;
|
||||
break;
|
||||
}
|
||||
case ObjectMoveType.DirFace: {
|
||||
const { x, y } = handler.movement(step.move);
|
||||
tile.setFaceDirection(step.face);
|
||||
locator.x += x;
|
||||
locator.y += y;
|
||||
break;
|
||||
}
|
||||
case ObjectMoveType.Face: {
|
||||
tile.setFaceDirection(step.value);
|
||||
break;
|
||||
}
|
||||
case ObjectMoveType.Dir:
|
||||
case ObjectMoveType.DirFace:
|
||||
case ObjectMoveType.Special: {
|
||||
const { x, y } = handler.movement(this.moveDirection);
|
||||
tile.setFaceDirection(this.faceDirection);
|
||||
locator.x += x;
|
||||
locator.y += y;
|
||||
break;
|
||||
return { x: tile.x + x, y: tile.y + y };
|
||||
}
|
||||
case ObjectMoveType.Face: {
|
||||
tile.setFaceDirection(step.value);
|
||||
return { x: tile.x, y: tile.y };
|
||||
}
|
||||
case ObjectMoveType.Teleport:
|
||||
case ObjectMoveType.Jump: {
|
||||
const { x, y, rel } = step;
|
||||
tile.setFaceDirection(this.faceDirection);
|
||||
if (rel) {
|
||||
locator.x += x;
|
||||
locator.y += y;
|
||||
} else {
|
||||
locator.x = x;
|
||||
locator.y = y;
|
||||
}
|
||||
break;
|
||||
const nx = rel ? tile.x + x : x;
|
||||
const ny = rel ? tile.y + y : y;
|
||||
return { x: nx, y: ny };
|
||||
}
|
||||
default: {
|
||||
return { x: tile.x, y: tile.y };
|
||||
}
|
||||
}
|
||||
return Promise.resolve(locator);
|
||||
}
|
||||
|
||||
protected onStepSettled(): Promise<void> {
|
||||
|
||||
@ -41,16 +41,14 @@ export class StaticTile
|
||||
}
|
||||
|
||||
saveState(): Readonly<IStaticBlockSave> {
|
||||
let save: IStaticBlockSave;
|
||||
const eventView = this.tileEvent();
|
||||
if (eventView.dirty()) {
|
||||
save = {
|
||||
return {
|
||||
events: new Map(eventView.get())
|
||||
};
|
||||
} else {
|
||||
save = {};
|
||||
return {};
|
||||
}
|
||||
return save;
|
||||
}
|
||||
|
||||
loadState(save: Readonly<IStaticBlockSave>): void {
|
||||
|
||||
@ -834,7 +834,7 @@ export interface IMapState
|
||||
* 那么会自动取消激活当前分区,然后激活新进入的分区。此函数一般不需要手动调用。
|
||||
* @param id 楼层 id
|
||||
*/
|
||||
notifyEnterFloor(id: string): void;
|
||||
autoActivateFloor(id: string): void;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
Loading…
Reference in New Issue
Block a user