Compare commits

...

2 Commits

Author SHA1 Message Date
AncTe
c1b721774e
Merge 4bf39062a8 into 1a569804d8 2026-07-17 14:42:28 +00:00
4bf39062a8 feat: MapStore 2026-07-17 22:42:16 +08:00
14 changed files with 74 additions and 15 deletions

View File

@ -6,14 +6,14 @@ import {
ILayerStateSave,
IMapLayer,
IMapLayerSave,
IMapStore,
IMapState,
IMapStoreSave,
MapArea
} from './types';
import { LayerState } from './layerState';
import { uniq } from 'lodash-es';
export class MapStore implements IMapStore {
export class MapState implements IMapState {
/** 楼层 id 到状态对象的映射 */
private readonly mapData: Map<string, LayerState> = new Map();

View File

@ -425,7 +425,7 @@ export interface IMapAreaInterval {
export type MapArea = IMapAreaInterval[];
export interface IMapStore
export interface IMapState
extends ISaveableContent<IMapStoreSave>, IDataCommonExtended {
/** 所有楼层的 id 有序数组 */
readonly maps: ReadonlyArray<string>;

View File

@ -1,7 +1,7 @@
import { IHeroFollower, IHeroState } from './hero';
import { IEnemyManager } from './enemy';
import { IFlagSystem } from './flag';
import { IMapStore } from './map';
import { IMapState } from './map';
import {
IDataCommon,
IEnemyAttr,
@ -16,7 +16,7 @@ export interface IStateSaveData {
export interface IStateBase extends IDataCommon {
/** 地图状态 */
readonly maps: IMapStore;
readonly maps: IMapState;
/** 勇士状态 */
readonly hero: IHeroState<IHeroAttr>;

View File

@ -0,0 +1,14 @@
import { IMapRawData, IMapStore } from './types';
export class MapStore implements IMapStore {
/** 地图存储映射 */
private readonly maps: Map<string, IMapRawData> = new Map();
getMap(floorId: string): IMapRawData | null {
return this.maps.get(floorId) ?? null;
}
addMap(map: IMapRawData): void {
this.maps.set(map.floorId, map);
}
}

View File

@ -68,7 +68,7 @@ export interface ITileLegacyConverter<TLegacy> {
fromLegacy(num: number, legacy: TLegacy): ITileRawData;
}
export interface ITileStore<TLegacy> {
export interface ITileStore<TLegacy = unknown> {
/**
*
* @param num
@ -250,3 +250,32 @@ export interface IItemStore<THero, TLegacy> {
}
//#endregion
//#region map
export interface IMapRawData {
/** 楼层 id */
readonly floorId: string;
/** 地图宽度 */
readonly width: number;
/** 地图数组 */
readonly map: Record<number, number[]>;
/** 每个地图图层的字符串别名 */
readonly layerAlias: Record<number, string>;
}
export interface IMapStore {
/**
* id
* @param floorId id
*/
getMap(floorId: string): IMapRawData | null;
/**
*
* @param map
*/
addMap(map: IMapRawData): void;
}
//#endregion

View File

@ -1,6 +1,6 @@
import { ITileLocator } from '@motajs/common';
import { IFaceManager, IRoleFaceBinder } from './common';
import { IItemStore, ITileStore } from './store';
import { IItemStore, IMapStore, ITileStore } from './store';
import { ISaveSystem } from './save';
export interface IEnemyAttr {
@ -48,6 +48,8 @@ export interface IDataCommon {
readonly tileStore: ITileStore<MapDataOf<keyof NumberToId>>;
/** 道具定义存储 */
readonly itemStore: IItemStore<IHeroAttr, Item<AllIdsOf<'items'>>>;
/** 地图定义存储 */
readonly mapStore: IMapStore;
/** 朝向绑定 */
readonly roleFace: IRoleFaceBinder;
/** 朝向管理 */

View File

@ -17,7 +17,8 @@ import {
ISaveSystem,
SaveSystem,
IItemStore,
ItemStore
ItemStore,
IMapStore
} from '@user/data-common';
import {
EnemyManager,
@ -31,8 +32,8 @@ import {
MotaDataLoader,
loading,
IReadonlyEnemy,
IMapStore,
MapStore
IMapState,
MapState
} from '@user/data-base';
import {
DamageSystem,
@ -75,6 +76,7 @@ import { ILoadProgressTotal, LoadProgressTotal } from '@motajs/loader';
import { isNil } from 'lodash-es';
import { logger } from '@motajs/common';
import { DefaultHeroMoveTopImpl } from './hero';
import { MapStore } from '../../data-common/src/store/mapStore';
export class CoreState implements ICoreState {
// Layer 0 公共层,最底层的接口,不会依赖任何其他内容,一般是工具性接口及不需要存档的数据
@ -83,9 +85,10 @@ export class CoreState implements ICoreState {
readonly faceManager: IFaceManager;
readonly tileStore: ITileStore<LegacyTileData>;
readonly itemStore: IItemStore<IHeroAttr, LegacyItemData>;
readonly mapStore: IMapStore;
// Layer 1 数据层,所有可存档内容都在这,一般用于数据存储
readonly maps: IMapStore;
readonly maps: IMapState;
readonly hero: IHeroState<IHeroAttr>;
readonly enemyManager: IEnemyManager<IEnemyAttr>;
readonly flags: IFlagSystem;
@ -138,9 +141,12 @@ export class CoreState implements ICoreState {
tileStore.attachLegacyConverter(new TileLegacyBridge());
this.tileStore = tileStore;
// 道具
const itemStore = new ItemStore<LegacyItemData>();
const itemStore = new ItemStore<IHeroAttr, LegacyItemData>();
itemStore.attachLegacyConverter(new ItemLegacyBridge(this));
this.itemStore = itemStore;
// 地图
const mapStore = new MapStore();
this.mapStore = mapStore;
//#endregion
@ -150,7 +156,7 @@ export class CoreState implements ICoreState {
this.flags = new FlagSystem();
// 地图
this.maps = new MapStore(tileStore, this);
this.maps = new MapState(tileStore, this);
// 勇士
const heroAttribute = new HeroAttribute(HERO_DEFAULT_ATTRIBUTE);

View File

@ -1,7 +1,7 @@
import {
IHeroMoveTopHandler,
IHeroMoveTopImpl,
IMapStore
IMapState
} from '@user/data-base';
import { FaceDirection, PassBit } from '@user/data-common';
import {
@ -13,7 +13,7 @@ import { isNil } from 'lodash-es';
export class DefaultHeroMoveTopImpl implements IHeroMoveTopImpl {
/** 地图存储对象 */
private readonly maps: IMapStore;
private readonly maps: IMapState;
/** 触发器收集器对象 */
private readonly collector: ITriggerCollector;

0
src/content/core.jsonc Normal file
View File

1
src/content/enemy.jsonc Normal file
View File

@ -0,0 +1 @@
{}

3
src/content/item.jsonc Normal file
View File

@ -0,0 +1,3 @@
// Type: packages-user/data-common/src/store/types IItemRawData
// ItemEffect: ./item.ts
{}

0
src/content/item.ts Normal file
View File

View File

@ -0,0 +1,2 @@
// Type: packages-user/data-base/src/map/types.ts
{}

2
src/content/tile.jsonc Normal file
View File

@ -0,0 +1,2 @@
// Type: packages-user/data-common/src/store/types ITileRawData
{}