mirror of
https://github.com/motajs/template.git
synced 2026-08-14 20:52:29 +08:00
Compare commits
2 Commits
5e611d3a00
...
c1b721774e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c1b721774e | ||
| 4bf39062a8 |
@ -6,14 +6,14 @@ import {
|
|||||||
ILayerStateSave,
|
ILayerStateSave,
|
||||||
IMapLayer,
|
IMapLayer,
|
||||||
IMapLayerSave,
|
IMapLayerSave,
|
||||||
IMapStore,
|
IMapState,
|
||||||
IMapStoreSave,
|
IMapStoreSave,
|
||||||
MapArea
|
MapArea
|
||||||
} from './types';
|
} from './types';
|
||||||
import { LayerState } from './layerState';
|
import { LayerState } from './layerState';
|
||||||
import { uniq } from 'lodash-es';
|
import { uniq } from 'lodash-es';
|
||||||
|
|
||||||
export class MapStore implements IMapStore {
|
export class MapState implements IMapState {
|
||||||
/** 楼层 id 到状态对象的映射 */
|
/** 楼层 id 到状态对象的映射 */
|
||||||
private readonly mapData: Map<string, LayerState> = new Map();
|
private readonly mapData: Map<string, LayerState> = new Map();
|
||||||
|
|
||||||
|
|||||||
@ -425,7 +425,7 @@ export interface IMapAreaInterval {
|
|||||||
|
|
||||||
export type MapArea = IMapAreaInterval[];
|
export type MapArea = IMapAreaInterval[];
|
||||||
|
|
||||||
export interface IMapStore
|
export interface IMapState
|
||||||
extends ISaveableContent<IMapStoreSave>, IDataCommonExtended {
|
extends ISaveableContent<IMapStoreSave>, IDataCommonExtended {
|
||||||
/** 所有楼层的 id 有序数组 */
|
/** 所有楼层的 id 有序数组 */
|
||||||
readonly maps: ReadonlyArray<string>;
|
readonly maps: ReadonlyArray<string>;
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { IHeroFollower, IHeroState } from './hero';
|
import { IHeroFollower, IHeroState } from './hero';
|
||||||
import { IEnemyManager } from './enemy';
|
import { IEnemyManager } from './enemy';
|
||||||
import { IFlagSystem } from './flag';
|
import { IFlagSystem } from './flag';
|
||||||
import { IMapStore } from './map';
|
import { IMapState } from './map';
|
||||||
import {
|
import {
|
||||||
IDataCommon,
|
IDataCommon,
|
||||||
IEnemyAttr,
|
IEnemyAttr,
|
||||||
@ -16,7 +16,7 @@ export interface IStateSaveData {
|
|||||||
|
|
||||||
export interface IStateBase extends IDataCommon {
|
export interface IStateBase extends IDataCommon {
|
||||||
/** 地图状态 */
|
/** 地图状态 */
|
||||||
readonly maps: IMapStore;
|
readonly maps: IMapState;
|
||||||
/** 勇士状态 */
|
/** 勇士状态 */
|
||||||
readonly hero: IHeroState<IHeroAttr>;
|
readonly hero: IHeroState<IHeroAttr>;
|
||||||
|
|
||||||
|
|||||||
14
packages-user/data-common/src/store/mapStore.ts
Normal file
14
packages-user/data-common/src/store/mapStore.ts
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -68,7 +68,7 @@ export interface ITileLegacyConverter<TLegacy> {
|
|||||||
fromLegacy(num: number, legacy: TLegacy): ITileRawData;
|
fromLegacy(num: number, legacy: TLegacy): ITileRawData;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ITileStore<TLegacy> {
|
export interface ITileStore<TLegacy = unknown> {
|
||||||
/**
|
/**
|
||||||
* 获取指定图块数字对应的完整原始定义
|
* 获取指定图块数字对应的完整原始定义
|
||||||
* @param num 图块数字
|
* @param num 图块数字
|
||||||
@ -250,3 +250,32 @@ export interface IItemStore<THero, TLegacy> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//#endregion
|
//#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
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { ITileLocator } from '@motajs/common';
|
import { ITileLocator } from '@motajs/common';
|
||||||
import { IFaceManager, IRoleFaceBinder } from './common';
|
import { IFaceManager, IRoleFaceBinder } from './common';
|
||||||
import { IItemStore, ITileStore } from './store';
|
import { IItemStore, IMapStore, ITileStore } from './store';
|
||||||
import { ISaveSystem } from './save';
|
import { ISaveSystem } from './save';
|
||||||
|
|
||||||
export interface IEnemyAttr {
|
export interface IEnemyAttr {
|
||||||
@ -48,6 +48,8 @@ export interface IDataCommon {
|
|||||||
readonly tileStore: ITileStore<MapDataOf<keyof NumberToId>>;
|
readonly tileStore: ITileStore<MapDataOf<keyof NumberToId>>;
|
||||||
/** 道具定义存储 */
|
/** 道具定义存储 */
|
||||||
readonly itemStore: IItemStore<IHeroAttr, Item<AllIdsOf<'items'>>>;
|
readonly itemStore: IItemStore<IHeroAttr, Item<AllIdsOf<'items'>>>;
|
||||||
|
/** 地图定义存储 */
|
||||||
|
readonly mapStore: IMapStore;
|
||||||
/** 朝向绑定 */
|
/** 朝向绑定 */
|
||||||
readonly roleFace: IRoleFaceBinder;
|
readonly roleFace: IRoleFaceBinder;
|
||||||
/** 朝向管理 */
|
/** 朝向管理 */
|
||||||
|
|||||||
@ -17,7 +17,8 @@ import {
|
|||||||
ISaveSystem,
|
ISaveSystem,
|
||||||
SaveSystem,
|
SaveSystem,
|
||||||
IItemStore,
|
IItemStore,
|
||||||
ItemStore
|
ItemStore,
|
||||||
|
IMapStore
|
||||||
} from '@user/data-common';
|
} from '@user/data-common';
|
||||||
import {
|
import {
|
||||||
EnemyManager,
|
EnemyManager,
|
||||||
@ -31,8 +32,8 @@ import {
|
|||||||
MotaDataLoader,
|
MotaDataLoader,
|
||||||
loading,
|
loading,
|
||||||
IReadonlyEnemy,
|
IReadonlyEnemy,
|
||||||
IMapStore,
|
IMapState,
|
||||||
MapStore
|
MapState
|
||||||
} from '@user/data-base';
|
} from '@user/data-base';
|
||||||
import {
|
import {
|
||||||
DamageSystem,
|
DamageSystem,
|
||||||
@ -75,6 +76,7 @@ import { ILoadProgressTotal, LoadProgressTotal } from '@motajs/loader';
|
|||||||
import { isNil } from 'lodash-es';
|
import { isNil } from 'lodash-es';
|
||||||
import { logger } from '@motajs/common';
|
import { logger } from '@motajs/common';
|
||||||
import { DefaultHeroMoveTopImpl } from './hero';
|
import { DefaultHeroMoveTopImpl } from './hero';
|
||||||
|
import { MapStore } from '../../data-common/src/store/mapStore';
|
||||||
|
|
||||||
export class CoreState implements ICoreState {
|
export class CoreState implements ICoreState {
|
||||||
// Layer 0 公共层,最底层的接口,不会依赖任何其他内容,一般是工具性接口及不需要存档的数据
|
// Layer 0 公共层,最底层的接口,不会依赖任何其他内容,一般是工具性接口及不需要存档的数据
|
||||||
@ -83,9 +85,10 @@ export class CoreState implements ICoreState {
|
|||||||
readonly faceManager: IFaceManager;
|
readonly faceManager: IFaceManager;
|
||||||
readonly tileStore: ITileStore<LegacyTileData>;
|
readonly tileStore: ITileStore<LegacyTileData>;
|
||||||
readonly itemStore: IItemStore<IHeroAttr, LegacyItemData>;
|
readonly itemStore: IItemStore<IHeroAttr, LegacyItemData>;
|
||||||
|
readonly mapStore: IMapStore;
|
||||||
|
|
||||||
// Layer 1 数据层,所有可存档内容都在这,一般用于数据存储
|
// Layer 1 数据层,所有可存档内容都在这,一般用于数据存储
|
||||||
readonly maps: IMapStore;
|
readonly maps: IMapState;
|
||||||
readonly hero: IHeroState<IHeroAttr>;
|
readonly hero: IHeroState<IHeroAttr>;
|
||||||
readonly enemyManager: IEnemyManager<IEnemyAttr>;
|
readonly enemyManager: IEnemyManager<IEnemyAttr>;
|
||||||
readonly flags: IFlagSystem;
|
readonly flags: IFlagSystem;
|
||||||
@ -138,9 +141,12 @@ export class CoreState implements ICoreState {
|
|||||||
tileStore.attachLegacyConverter(new TileLegacyBridge());
|
tileStore.attachLegacyConverter(new TileLegacyBridge());
|
||||||
this.tileStore = tileStore;
|
this.tileStore = tileStore;
|
||||||
// 道具
|
// 道具
|
||||||
const itemStore = new ItemStore<LegacyItemData>();
|
const itemStore = new ItemStore<IHeroAttr, LegacyItemData>();
|
||||||
itemStore.attachLegacyConverter(new ItemLegacyBridge(this));
|
itemStore.attachLegacyConverter(new ItemLegacyBridge(this));
|
||||||
this.itemStore = itemStore;
|
this.itemStore = itemStore;
|
||||||
|
// 地图
|
||||||
|
const mapStore = new MapStore();
|
||||||
|
this.mapStore = mapStore;
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
@ -150,7 +156,7 @@ export class CoreState implements ICoreState {
|
|||||||
this.flags = new FlagSystem();
|
this.flags = new FlagSystem();
|
||||||
|
|
||||||
// 地图
|
// 地图
|
||||||
this.maps = new MapStore(tileStore, this);
|
this.maps = new MapState(tileStore, this);
|
||||||
|
|
||||||
// 勇士
|
// 勇士
|
||||||
const heroAttribute = new HeroAttribute(HERO_DEFAULT_ATTRIBUTE);
|
const heroAttribute = new HeroAttribute(HERO_DEFAULT_ATTRIBUTE);
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
IHeroMoveTopHandler,
|
IHeroMoveTopHandler,
|
||||||
IHeroMoveTopImpl,
|
IHeroMoveTopImpl,
|
||||||
IMapStore
|
IMapState
|
||||||
} from '@user/data-base';
|
} from '@user/data-base';
|
||||||
import { FaceDirection, PassBit } from '@user/data-common';
|
import { FaceDirection, PassBit } from '@user/data-common';
|
||||||
import {
|
import {
|
||||||
@ -13,7 +13,7 @@ import { isNil } from 'lodash-es';
|
|||||||
|
|
||||||
export class DefaultHeroMoveTopImpl implements IHeroMoveTopImpl {
|
export class DefaultHeroMoveTopImpl implements IHeroMoveTopImpl {
|
||||||
/** 地图存储对象 */
|
/** 地图存储对象 */
|
||||||
private readonly maps: IMapStore;
|
private readonly maps: IMapState;
|
||||||
/** 触发器收集器对象 */
|
/** 触发器收集器对象 */
|
||||||
private readonly collector: ITriggerCollector;
|
private readonly collector: ITriggerCollector;
|
||||||
|
|
||||||
|
|||||||
0
src/content/core.jsonc
Normal file
0
src/content/core.jsonc
Normal file
1
src/content/enemy.jsonc
Normal file
1
src/content/enemy.jsonc
Normal file
@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
3
src/content/item.jsonc
Normal file
3
src/content/item.jsonc
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
// Type: packages-user/data-common/src/store/types IItemRawData
|
||||||
|
// ItemEffect: ./item.ts
|
||||||
|
{}
|
||||||
0
src/content/item.ts
Normal file
0
src/content/item.ts
Normal file
2
src/content/maps/MT0.jsonc
Normal file
2
src/content/maps/MT0.jsonc
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
// Type: packages-user/data-base/src/map/types.ts
|
||||||
|
{}
|
||||||
2
src/content/tile.jsonc
Normal file
2
src/content/tile.jsonc
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
// Type: packages-user/data-common/src/store/types ITileRawData
|
||||||
|
{}
|
||||||
Loading…
Reference in New Issue
Block a user