feat: 楼层切换

This commit is contained in:
AncTe committed 2026-07-26 20:22:36 +08:00
1 parent 4bf39062a8
commit f4c77d152f
15 files changed
+449 -23

No files matched your search

+1 -1
View File
@@ -1,5 +1,5 @@
export * from './layerState';
export * from './mapLayer';
export * from './mapStore';
export * from './mapState';
export * from './mover';
export * from './types';
@@ -1,5 +1,5 @@
import { logger } from '@motajs/common';
import { IDataCommon, SaveCompression } from '@user/data-common';
import { IDataCommon, IMapRawData, SaveCompression } from '@user/data-common';
import { ITileStore } from '@user/data-common';
import {
ILayerState,
@@ -11,7 +11,7 @@ import {
MapArea
} from './types';
import { LayerState } from './layerState';
import { uniq } from 'lodash-es';
import { isNil, uniq } from 'lodash-es';
export class MapState implements IMapState {
/** 楼层 id 到状态对象的映射 */
@@ -39,6 +39,56 @@ export class MapState implements IMapState {
//#region 楼层管理
fromRaw(raw: IMapRawData): ILayerState | null {
let length = 0;
const entries = Object.entries(raw.map);
for (const [_, map] of Object.entries(raw.map)) {
if (length > 0 && map.length !== length) {
logger.error(60, map.length.toString(), length.toString());
return null;
} else {
length = map.length;
}
}
if (length % raw.width !== 0) {
logger.error(61, length.toString(), raw.width.toString());
return null;
}
// 设置楼层图块数据
const height = length / raw.width;
const state = this.createLayerState(raw.floorId, raw.width, height);
for (const [zIndex, map] of entries) {
const z = Number(zIndex);
if (isNaN(z)) {
logger.error(62, 'IMapRawData.map', String(zIndex));
continue;
}
const layer = state.addLayer();
const alias = raw.layerAlias[z];
layer.setMapRef(new Uint32Array(map));
layer.setZIndex(z);
state.setLayerAlias(layer, alias);
// 设置图块静态触发器
const extra = raw.blockData[z];
for (const [index, data] of Object.entries(extra)) {
const indexNum = Number(index);
if (isNaN(indexNum)) {
logger.error(62, 'IMapRawData.blockData', String(index));
continue;
}
if (!isNil(data.trigger)) {
const x = indexNum % raw.width;
const y = Math.floor(indexNum / raw.width);
layer.setTriggerType(data.trigger, x, y);
}
}
}
return state;
}
createLayerState(id: string, width: number, height: number): ILayerState {
if (this.mapData.has(id)) {
logger.warn(121, id);
+1 -1
View File
@@ -18,7 +18,7 @@ const enum DynamicMoveCode {
export class DynamicTileMover extends ObjectMover<IDynamicTile> {
constructor(public readonly tile: IDynamicTile) {
const face = tile.state.faceManager;
super(face.get(DYNAMIC_MOVER_FACE)!);
super(face.get(DYNAMIC_MOVER_FACE)!, tile.getCurrentFaceDirection());
}
protected onMoveStart(): Promise<void> {
+18 -1
View File
@@ -1,7 +1,14 @@
import { IHookable, IHookBase, IHookController } from '@motajs/common';
import {
IHookable,
IHookBase,
IHookController,
ITileLocator
} from '@motajs/common';
import {
FaceDirection,
IDataCommonExtended,
IMapBlockRawData,
IMapRawData,
IMoverController,
IObjectMovable,
IObjectMover,
@@ -21,6 +28,8 @@ export interface IMapLayerData {
}
export interface ILayerLocation {
/** 该点的位置 */
readonly locator: ITileLocator;
/** 该点的静态图块数字 */
readonly tile: number;
/** 该点的静态图块信息 */
@@ -29,6 +38,8 @@ export interface ILayerLocation {
readonly trigger: number;
/** 该点包含的所有动态图块 */
readonly dynamics: Iterable<IDynamicTile>;
/** 该点的静态图块原始数据 */
readonly block: IMapBlockRawData;
}
export interface IMapLayerHooks extends IHookBase {
@@ -442,6 +453,12 @@ export interface IMapState
*/
getActiveMap(id: string): ILayerState | null;
/**
* 从楼层原始数据生成楼层状态
* @param raw 楼层原始数据
*/
fromRaw(raw: IMapRawData): ILayerState | null;
/**
* 创建并注册一个空白楼层,若 id 已存在则警告并覆盖,返回楼层状态对象
* @param id 楼层 id