refactor: data-common/common

This commit is contained in:
AncTe committed 2026-09-23 16:04:50 +08:00
1 parent 9fb04e3129
commit 1fb92c3976
12 files changed
+51 -233

No files matched your search

@@ -1,4 +1,3 @@
import { isNil } from 'lodash-es';
import {
FaceDirection,
IMoverController,
@@ -76,12 +75,7 @@ export class DynamicTile
}
getCurrentFaceDirection(): FaceDirection {
const curr = this.layer.faceBinder.getFaceDirection(this.tileNum);
if (isNil(curr)) {
return FaceDirection.Unknown;
} else {
return curr;
}
return this.layer.faceBinder.getFaceDirection(this.tileNum);
}
@shouldReplay('Transfering dynamic tile to static should be replayed.')
+1 -9
View File
@@ -15,7 +15,6 @@ import {
} from './types';
import { Hookable, HookController, ITileLocator, logger } from '@motajs/common';
import {
degradeFace,
FaceDirection,
IDataCommon,
IRoleFaceBinder,
@@ -525,14 +524,7 @@ export class MapLayer
@shouldReplay('Setting map layer block direction should be replayed.')
setDynamicDirection(tile: IDynamicTile, direction: FaceDirection): number {
const numBefore = tile.num();
tile.setFaceDirection(direction);
if (tile.num() !== numBefore) return tile.num();
const degraded = degradeFace(direction);
if (degraded !== direction) {
tile.setFaceDirection(degraded);
}
return tile.num();
return tile.setFaceDirection(direction);
}
@shouldReplay('Updating dynamic tile position should be replayed.')
+9 -4
View File
@@ -1,6 +1,6 @@
import { ITileLocator, logger } from '@motajs/common';
import {
getFaceMovement,
FaceGroup,
ObjectMover,
ObjectMoveStep,
ObjectMoveType,
@@ -46,16 +46,21 @@ export class DynamicTileMover extends ObjectMover<IDynamicTile> {
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 });
}
switch (step.type) {
case ObjectMoveType.Dir: {
const { x, y } = getFaceMovement(step.move);
const { x, y } = handler.movement(step.move);
tile.setFaceDirection(step.move);
locator.x += x;
locator.y += y;
break;
}
case ObjectMoveType.DirFace: {
const { x, y } = getFaceMovement(step.move);
const { x, y } = handler.movement(step.move);
tile.setFaceDirection(step.face);
locator.x += x;
locator.y += y;
@@ -66,7 +71,7 @@ export class DynamicTileMover extends ObjectMover<IDynamicTile> {
break;
}
case ObjectMoveType.Special: {
const { x, y } = getFaceMovement(this.moveDirection);
const { x, y } = handler.movement(this.moveDirection);
tile.setFaceDirection(this.faceDirection);
locator.x += x;
locator.y += y;
+9 -1
View File
@@ -1,6 +1,7 @@
import { ITileLocator } from '@motajs/common';
import {
FaceDirection,
FaceGroup,
IDataCommon,
IDataCommonExtended,
ISaveableContent,
@@ -58,10 +59,17 @@ export abstract class MapTileBase<TSave extends IMapBlockSaveBase>
const cur = this.num();
const next = this.layer.faceBinder.getFaceOf(cur, direction);
if (next) {
// 先尝试在 dir8 中寻找
this.set(next.identifier);
return next.identifier;
} else {
return cur;
// 找不到则降级到 dir4
const handler = this.state.faceManager.get(FaceGroup.Dir4);
if (!handler) return cur;
const degraded = handler.degrade(direction);
const next = this.layer.faceBinder.getFaceOf(cur, degraded);
if (next) return next.identifier;
else return cur;
}
}