mirror of
https://github.com/motajs/template.git
synced 2026-05-20 09:11:10 +08:00
refactor: 将 Layer 0 单独放到一个包
This commit is contained in:
parent
bf781c5ee8
commit
8f4c4b7df2
11
dev.md
11
dev.md
@ -128,8 +128,9 @@
|
|||||||
|
|
||||||
**Layer 2 — 执行层**:直接引用 Layer 1,负责产生影响游戏进程的动作,如玩家控制、战斗计算等。本层内容不会进入存档,仅通过修改 Layer 1 的数据来影响游戏状态,并通过统一接口 `ICoreState` 对外暴露执行能力。
|
**Layer 2 — 执行层**:直接引用 Layer 1,负责产生影响游戏进程的动作,如玩家控制、战斗计算等。本层内容不会进入存档,仅通过修改 Layer 1 的数据来影响游戏状态,并通过统一接口 `ICoreState` 对外暴露执行能力。
|
||||||
|
|
||||||
| 包 | 层级 | 说明 |
|
| 包 | 层级 | 说明 |
|
||||||
| ------------------- | ----------------- | ------------------------------------------------------------------------------- |
|
| ------------------- | ------- | ------------------------------------------------------------------------------- |
|
||||||
| `@user/data-base` | Layer 0 / Layer 1 | 公共层与数据层,定义 `IStateBase` 及各类游戏数据(地图、怪物、玩家属性等) |
|
| `@user/data-common | Layer 0 | 公共层,定义 `IDataCommon` 及公共无依赖接口 |
|
||||||
| `@user/data-state` | — | 数据端的顶层模块,指导 Layer 2 的执行行为,不直接参与执行 |
|
| `@user/data-base` | Layer 1 | 数据层,定义 `IStateBase` 及可存档游戏数据(地图、怪物、玩家属性等) |
|
||||||
| `@user/data-system` | Layer 2 | 执行层,定义 `ICoreState`,依赖数据层实现玩家控制、战斗计算等影响游戏进程的动作 |
|
| `@user/data-system` | Layer 2 | 执行层,定义 `ICoreState`,依赖数据层实现玩家控制、战斗计算等影响游戏进程的动作 |
|
||||||
|
| `@user/data-state` | — | 数据端的顶层模块,指导 Layer 2 的执行行为,不直接参与执行 |
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@user/data-base",
|
"name": "@user/data-base",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@user/data-common": "workspace:*",
|
||||||
"@motajs/common": "workspace:*",
|
"@motajs/common": "workspace:*",
|
||||||
"@motajs/types": "workspace:*",
|
"@motajs/types": "workspace:*",
|
||||||
"@motajs/loader": "workspace:*"
|
"@motajs/loader": "workspace:*"
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { logger } from '@motajs/common';
|
import { logger } from '@motajs/common';
|
||||||
import { SaveCompression } from '../common';
|
import { SaveCompression } from '@user/data-common';
|
||||||
import { IEnemy, IEnemySaveState, IReadonlyEnemy, ISpecial } from './types';
|
import { IEnemy, IEnemySaveState, IReadonlyEnemy, ISpecial } from './types';
|
||||||
|
|
||||||
export class Enemy<TAttr> implements IEnemy<TAttr> {
|
export class Enemy<TAttr> implements IEnemy<TAttr> {
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import {
|
|||||||
SpecialCreation,
|
SpecialCreation,
|
||||||
IEnemySaveState
|
IEnemySaveState
|
||||||
} from './types';
|
} from './types';
|
||||||
import { SaveCompression } from '../common';
|
import { SaveCompression } from '@user/data-common';
|
||||||
|
|
||||||
export class EnemyManager<TAttr> implements IEnemyManager<TAttr> {
|
export class EnemyManager<TAttr> implements IEnemyManager<TAttr> {
|
||||||
/** 特殊属性注册表,code -> 创建函数 */
|
/** 特殊属性注册表,code -> 创建函数 */
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { isEqual } from 'lodash-es';
|
import { isEqual } from 'lodash-es';
|
||||||
import { SaveCompression } from '../common';
|
import { SaveCompression } from '@user/data-common';
|
||||||
import { ISpecial, SpecialCreation } from './types';
|
import { ISpecial, SpecialCreation } from './types';
|
||||||
|
|
||||||
// TODO: 颜色参数
|
// TODO: 颜色参数
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { ISaveableContent } from '../common';
|
import { ISaveableContent } from '@user/data-common';
|
||||||
|
|
||||||
//#region 怪物基础
|
//#region 怪物基础
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
//#region 字段
|
//#region 字段
|
||||||
|
|
||||||
import { ISaveableContent } from '../common';
|
import { ISaveableContent } from '@user/data-common';
|
||||||
|
|
||||||
export interface IFlagCommonField<T> {
|
export interface IFlagCommonField<T> {
|
||||||
/** 此字段所处的 Flag 系统 */
|
/** 此字段所处的 Flag 系统 */
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { logger } from '@motajs/common';
|
import { logger } from '@motajs/common';
|
||||||
import { SaveCompression } from '../common';
|
import { SaveCompression } from '@user/data-common';
|
||||||
import { IHeroAttribute, IHeroModifier } from './types';
|
import { IHeroAttribute, IHeroModifier } from './types';
|
||||||
|
|
||||||
export abstract class BaseHeroModifier<T, V> implements IHeroModifier<T, V, V> {
|
export abstract class BaseHeroModifier<T, V> implements IHeroModifier<T, V, V> {
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
import { Hookable, HookController, IHookController } from '@motajs/common';
|
import { Hookable, HookController, IHookController } from '@motajs/common';
|
||||||
import { isNil } from 'lodash-es';
|
import { isNil } from 'lodash-es';
|
||||||
import { getFaceMovement, nextFaceDirection } from '../common/utils';
|
import { getFaceMovement, nextFaceDirection } from '@user/data-common';
|
||||||
import { IHeroFollower, IHeroMover, IHeroMovingHooks } from './types';
|
import { IHeroFollower, IHeroMover, IHeroMovingHooks } from './types';
|
||||||
import { FaceDirection } from '../common';
|
import { FaceDirection } from '@user/data-common';
|
||||||
|
|
||||||
const DEFAULT_HERO_IMAGE: ImageIds = 'hero.png';
|
const DEFAULT_HERO_IMAGE: ImageIds = 'hero.png';
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import {
|
|||||||
IModifierStateSave,
|
IModifierStateSave,
|
||||||
IReadonlyHeroAttribute
|
IReadonlyHeroAttribute
|
||||||
} from './types';
|
} from './types';
|
||||||
import { SaveCompression } from '../common';
|
import { SaveCompression } from '@user/data-common';
|
||||||
import { logger } from '@motajs/common';
|
import { logger } from '@motajs/common';
|
||||||
|
|
||||||
export class HeroState<THero> implements IHeroState<THero> {
|
export class HeroState<THero> implements IHeroState<THero> {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { IFacedTileLocator, IHookBase, IHookable } from '@motajs/common';
|
import { IFacedTileLocator, IHookBase, IHookable } from '@motajs/common';
|
||||||
import { FaceDirection, ISaveableContent } from '../common';
|
import { FaceDirection, ISaveableContent } from '@user/data-common';
|
||||||
|
|
||||||
//#region 勇士属性
|
//#region 勇士属性
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,8 @@
|
|||||||
export * from './common';
|
|
||||||
export * from './enemy';
|
export * from './enemy';
|
||||||
export * from './flag';
|
export * from './flag';
|
||||||
export * from './hero';
|
export * from './hero';
|
||||||
export * from './load';
|
export * from './load';
|
||||||
export * from './map';
|
export * from './map';
|
||||||
export * from './store';
|
|
||||||
|
|
||||||
export * from './game';
|
export * from './game';
|
||||||
export * from './types';
|
export * from './types';
|
||||||
|
|||||||
@ -11,13 +11,15 @@ import {
|
|||||||
IDynamicTile,
|
IDynamicTile,
|
||||||
IMapLayer
|
IMapLayer
|
||||||
} from './types';
|
} from './types';
|
||||||
import { FaceDirection, degradeFace } from '../common';
|
import { FaceDirection, IDataCommon, degradeFace } from '@user/data-common';
|
||||||
import { DynamicTile } from './dynamicTile';
|
import { DynamicTile } from './dynamicTile';
|
||||||
|
|
||||||
export class DynamicLayer
|
export class DynamicLayer
|
||||||
extends Hookable<IDynamicLayerHooks>
|
extends Hookable<IDynamicLayerHooks>
|
||||||
implements IDynamicLayer
|
implements IDynamicLayer
|
||||||
{
|
{
|
||||||
|
readonly state: IDataCommon;
|
||||||
|
|
||||||
/** 坐标到动态图块集合的映射,外层 key = y,内层 key = x,不使用 index 是为了支持地图外图块 */
|
/** 坐标到动态图块集合的映射,外层 key = y,内层 key = x,不使用 index 是为了支持地图外图块 */
|
||||||
private readonly tilePosMap: Map<number, Map<number, Set<IDynamicTile>>> =
|
private readonly tilePosMap: Map<number, Map<number, Set<IDynamicTile>>> =
|
||||||
new Map();
|
new Map();
|
||||||
@ -26,6 +28,7 @@ export class DynamicLayer
|
|||||||
|
|
||||||
constructor(public readonly layer: IMapLayer) {
|
constructor(public readonly layer: IMapLayer) {
|
||||||
super();
|
super();
|
||||||
|
this.state = layer.state;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected createController(
|
protected createController(
|
||||||
|
|||||||
@ -1,14 +1,16 @@
|
|||||||
import { isNil } from 'lodash-es';
|
import { isNil } from 'lodash-es';
|
||||||
import {
|
import {
|
||||||
FaceDirection,
|
FaceDirection,
|
||||||
|
IDataCommon,
|
||||||
IMoverController,
|
IMoverController,
|
||||||
IObjectMover,
|
IObjectMover,
|
||||||
IRoleFaceBinder
|
IRoleFaceBinder
|
||||||
} from '../common';
|
} from '@user/data-common';
|
||||||
import { IDynamicLayer, IDynamicTile } from './types';
|
import { IDynamicLayer, IDynamicTile } from './types';
|
||||||
import { DynamicTileMover } from './mover';
|
import { DynamicTileMover } from './mover';
|
||||||
|
|
||||||
export class DynamicTile implements IDynamicTile {
|
export class DynamicTile implements IDynamicTile {
|
||||||
|
readonly state: IDataCommon;
|
||||||
readonly mover: IObjectMover<IDynamicTile>;
|
readonly mover: IObjectMover<IDynamicTile>;
|
||||||
triggerType: number;
|
triggerType: number;
|
||||||
|
|
||||||
@ -21,6 +23,7 @@ export class DynamicTile implements IDynamicTile {
|
|||||||
public y: number,
|
public y: number,
|
||||||
public readonly layer: IDynamicLayer
|
public readonly layer: IDynamicLayer
|
||||||
) {
|
) {
|
||||||
|
this.state = layer.state;
|
||||||
this.mover = new DynamicTileMover(this);
|
this.mover = new DynamicTileMover(this);
|
||||||
this.triggerType = -1;
|
this.triggerType = -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import {
|
|||||||
IMapLayerHookController,
|
IMapLayerHookController,
|
||||||
IMapLayerHooks
|
IMapLayerHooks
|
||||||
} from './types';
|
} from './types';
|
||||||
import { ITileStore } from '../store';
|
import { IDataCommon, ITileStore } from '@user/data-common';
|
||||||
import { MapLayer } from './mapLayer';
|
import { MapLayer } from './mapLayer';
|
||||||
|
|
||||||
export class LayerState
|
export class LayerState
|
||||||
@ -39,6 +39,7 @@ export class LayerState
|
|||||||
private dirty: boolean = false;
|
private dirty: boolean = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
public readonly state: IDataCommon,
|
||||||
public readonly tileStore: ITileStore,
|
public readonly tileStore: ITileStore,
|
||||||
public width: number,
|
public width: number,
|
||||||
public height: number
|
public height: number
|
||||||
@ -52,6 +53,7 @@ export class LayerState
|
|||||||
array,
|
array,
|
||||||
this.width,
|
this.width,
|
||||||
this.height,
|
this.height,
|
||||||
|
this,
|
||||||
this.tileStore
|
this.tileStore
|
||||||
);
|
);
|
||||||
this.layerList.add(layer);
|
this.layerList.add(layer);
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { isNil } from 'lodash-es';
|
import { isNil } from 'lodash-es';
|
||||||
import {
|
import {
|
||||||
IDynamicLayer,
|
IDynamicLayer,
|
||||||
|
ILayerState,
|
||||||
IMapLayer,
|
IMapLayer,
|
||||||
IMapLayerData,
|
IMapLayerData,
|
||||||
IMapLayerHookController,
|
IMapLayerHookController,
|
||||||
@ -8,7 +9,7 @@ import {
|
|||||||
} from './types';
|
} from './types';
|
||||||
import { Hookable, HookController, logger } from '@motajs/common';
|
import { Hookable, HookController, logger } from '@motajs/common';
|
||||||
import { DynamicLayer } from './dynamicLayer';
|
import { DynamicLayer } from './dynamicLayer';
|
||||||
import { ITileStore } from '../store';
|
import { IDataCommon, ITileStore } from '@user/data-common';
|
||||||
|
|
||||||
// todo: 提供 core.setBlock 等方法的替代方法,同时添加 setBlockList,以及前景背景的接口
|
// todo: 提供 core.setBlock 等方法的替代方法,同时添加 setBlockList,以及前景背景的接口
|
||||||
|
|
||||||
@ -16,6 +17,8 @@ export class MapLayer
|
|||||||
extends Hookable<IMapLayerHooks, IMapLayerHookController>
|
extends Hookable<IMapLayerHooks, IMapLayerHookController>
|
||||||
implements IMapLayer
|
implements IMapLayer
|
||||||
{
|
{
|
||||||
|
readonly state: IDataCommon;
|
||||||
|
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
empty: boolean = true;
|
empty: boolean = true;
|
||||||
@ -34,9 +37,11 @@ export class MapLayer
|
|||||||
array: Uint32Array,
|
array: Uint32Array,
|
||||||
width: number,
|
width: number,
|
||||||
height: number,
|
height: number,
|
||||||
|
public readonly layerState: ILayerState,
|
||||||
private readonly tileStore: ITileStore
|
private readonly tileStore: ITileStore
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
this.state = layerState.state;
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
const area = width * height;
|
const area = width * height;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { logger } from '@motajs/common';
|
import { logger } from '@motajs/common';
|
||||||
import { SaveCompression } from '../common';
|
import { IDataCommon, SaveCompression } from '@user/data-common';
|
||||||
import { ITileStore } from '../store';
|
import { ITileStore } from '@user/data-common';
|
||||||
import {
|
import {
|
||||||
ILayerState,
|
ILayerState,
|
||||||
ILayerStateSave,
|
ILayerStateSave,
|
||||||
@ -32,7 +32,10 @@ export class MapStore implements IMapStore {
|
|||||||
/** 自动分区激活器开关 */
|
/** 自动分区激活器开关 */
|
||||||
private autoActivitorEnabled: boolean = false;
|
private autoActivitorEnabled: boolean = false;
|
||||||
|
|
||||||
constructor(private readonly tileStore: ITileStore) {}
|
constructor(
|
||||||
|
private readonly tileStore: ITileStore,
|
||||||
|
public readonly state: IDataCommon
|
||||||
|
) {}
|
||||||
|
|
||||||
//#region 楼层管理
|
//#region 楼层管理
|
||||||
|
|
||||||
@ -42,7 +45,7 @@ export class MapStore implements IMapStore {
|
|||||||
} else {
|
} else {
|
||||||
this.maps.push(id);
|
this.maps.push(id);
|
||||||
}
|
}
|
||||||
const state = new LayerState(this.tileStore, width, height);
|
const state = new LayerState(this.state, this.tileStore, width, height);
|
||||||
// 若 refData 已存在,新楼层直接视为全脏
|
// 若 refData 已存在,新楼层直接视为全脏
|
||||||
if (this.refData !== null) {
|
if (this.refData !== null) {
|
||||||
state.setDirty(true);
|
state.setDirty(true);
|
||||||
|
|||||||
@ -4,8 +4,9 @@ import {
|
|||||||
ObjectMover,
|
ObjectMover,
|
||||||
ObjectMoveStep,
|
ObjectMoveStep,
|
||||||
ObjectMoveStepType
|
ObjectMoveStepType
|
||||||
} from '../common';
|
} from '@user/data-common';
|
||||||
import { IDynamicTile } from './types';
|
import { IDynamicTile } from './types';
|
||||||
|
import { DYNAMIC_MOVER_FACE } from '../shared';
|
||||||
|
|
||||||
//#region 动态图块
|
//#region 动态图块
|
||||||
|
|
||||||
@ -16,7 +17,8 @@ const enum DynamicMoveCode {
|
|||||||
|
|
||||||
export class DynamicTileMover extends ObjectMover<IDynamicTile> {
|
export class DynamicTileMover extends ObjectMover<IDynamicTile> {
|
||||||
constructor(public readonly tile: IDynamicTile) {
|
constructor(public readonly tile: IDynamicTile) {
|
||||||
super();
|
const face = tile.state.faceManager;
|
||||||
|
super(face.get(DYNAMIC_MOVER_FACE)!);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected onMoveStart(): Promise<void> {
|
protected onMoveStart(): Promise<void> {
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
import { IHookable, IHookBase, IHookController } from '@motajs/common';
|
import { IHookable, IHookBase, IHookController } from '@motajs/common';
|
||||||
import {
|
import {
|
||||||
FaceDirection,
|
FaceDirection,
|
||||||
|
IDataCommonExtended,
|
||||||
IMoverController,
|
IMoverController,
|
||||||
IObjectMovable,
|
IObjectMovable,
|
||||||
IObjectMover,
|
IObjectMover,
|
||||||
IRoleFaceBinder,
|
IRoleFaceBinder,
|
||||||
ISaveableContent
|
ISaveableContent
|
||||||
} from '../common';
|
} from '@user/data-common';
|
||||||
import { ITileStore } from '../store';
|
import { ITileStore } from '@user/data-common';
|
||||||
|
|
||||||
//#region 静态图层
|
//#region 静态图层
|
||||||
|
|
||||||
@ -69,10 +70,10 @@ export interface IMapLayerHookController extends IHookController<IMapLayerHooks>
|
|||||||
getMapData(): Readonly<IMapLayerData>;
|
getMapData(): Readonly<IMapLayerData>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IMapLayer extends IHookable<
|
export interface IMapLayer
|
||||||
IMapLayerHooks,
|
extends
|
||||||
IMapLayerHookController
|
IHookable<IMapLayerHooks, IMapLayerHookController>,
|
||||||
> {
|
IDataCommonExtended {
|
||||||
/** 地图宽度 */
|
/** 地图宽度 */
|
||||||
readonly width: number;
|
readonly width: number;
|
||||||
/** 地图高度 */
|
/** 地图高度 */
|
||||||
@ -85,6 +86,8 @@ export interface IMapLayer extends IHookable<
|
|||||||
/** 图层纵深 */
|
/** 图层纵深 */
|
||||||
readonly zIndex: number;
|
readonly zIndex: number;
|
||||||
|
|
||||||
|
/** 当前图层所属的地图状态对象 */
|
||||||
|
readonly layerState: ILayerState;
|
||||||
/** 此图层对应的动态图块图层,z 层级与静态图块一致 */
|
/** 此图层对应的动态图块图层,z 层级与静态图块一致 */
|
||||||
readonly dynamicLayer: IDynamicLayer;
|
readonly dynamicLayer: IDynamicLayer;
|
||||||
|
|
||||||
@ -261,7 +264,8 @@ export interface ILayerStateHooks extends IHookBase {
|
|||||||
onResizeLayer(layer: IMapLayer, width: number, height: number): void;
|
onResizeLayer(layer: IMapLayer, width: number, height: number): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ILayerState extends IHookable<ILayerStateHooks> {
|
export interface ILayerState
|
||||||
|
extends IHookable<ILayerStateHooks>, IDataCommonExtended {
|
||||||
/** 地图列表 */
|
/** 地图列表 */
|
||||||
readonly layerList: Set<IMapLayer>;
|
readonly layerList: Set<IMapLayer>;
|
||||||
/** 当前楼层共享的图块定义 store */
|
/** 当前楼层共享的图块定义 store */
|
||||||
@ -395,7 +399,8 @@ export interface IMapAreaInterval {
|
|||||||
|
|
||||||
export type MapArea = IMapAreaInterval[];
|
export type MapArea = IMapAreaInterval[];
|
||||||
|
|
||||||
export interface IMapStore extends ISaveableContent<IMapStoreSave> {
|
export interface IMapStore
|
||||||
|
extends ISaveableContent<IMapStoreSave>, IDataCommonExtended {
|
||||||
/** 所有楼层的 id 有序数组 */
|
/** 所有楼层的 id 有序数组 */
|
||||||
readonly maps: ReadonlyArray<string>;
|
readonly maps: ReadonlyArray<string>;
|
||||||
|
|
||||||
@ -524,7 +529,8 @@ export interface IDynamicLayerHooks extends IHookBase {
|
|||||||
onUpdateTilePosition(tile: IDynamicTile, layer: IDynamicLayer): void;
|
onUpdateTilePosition(tile: IDynamicTile, layer: IDynamicLayer): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IDynamicLayer extends IHookable<IDynamicLayerHooks> {
|
export interface IDynamicLayer
|
||||||
|
extends IHookable<IDynamicLayerHooks>, IDataCommonExtended {
|
||||||
/** 当前动态图层所属的静态图层 */
|
/** 当前动态图层所属的静态图层 */
|
||||||
readonly layer: IMapLayer;
|
readonly layer: IMapLayer;
|
||||||
|
|
||||||
@ -598,7 +604,7 @@ export interface IDynamicLayer extends IHookable<IDynamicLayerHooks> {
|
|||||||
updateDynamicTile(tile: IDynamicTile): void;
|
updateDynamicTile(tile: IDynamicTile): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IDynamicTile extends IObjectMovable {
|
export interface IDynamicTile extends IObjectMovable, IDataCommonExtended {
|
||||||
/** 当前图块数字 */
|
/** 当前图块数字 */
|
||||||
readonly num: number;
|
readonly num: number;
|
||||||
/** 当前动态图块携带的触发器类型,-1 表示无触发器 */
|
/** 当前动态图块携带的触发器类型,-1 表示无触发器 */
|
||||||
|
|||||||
4
packages-user/data-base/src/shared.ts
Normal file
4
packages-user/data-base/src/shared.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import { FaceGroup } from '@user/data-common';
|
||||||
|
|
||||||
|
/** 动态图块所使用的默认移动组,不知道干什么的就别动 */
|
||||||
|
export const DYNAMIC_MOVER_FACE = FaceGroup.Dir8;
|
||||||
@ -1,23 +1,15 @@
|
|||||||
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 { IFaceManager, IRoleFaceBinder, ISaveableContent } from './common';
|
|
||||||
import { IMapStore } from './map';
|
import { IMapStore } from './map';
|
||||||
import { ITileStore } from './store';
|
import { IDataCommon, ISaveableContent } from '@user/data-common';
|
||||||
|
|
||||||
export interface IStateSaveData {
|
export interface IStateSaveData {
|
||||||
/** 跟随者列表 */
|
/** 跟随者列表 */
|
||||||
readonly followers: readonly IHeroFollower[];
|
readonly followers: readonly IHeroFollower[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IStateBase<TEnemy, THero> {
|
export interface IStateBase<TEnemy, THero> extends IDataCommon {
|
||||||
/** 朝向绑定 */
|
|
||||||
readonly roleFace: IRoleFaceBinder;
|
|
||||||
/** 朝向管理 */
|
|
||||||
readonly faceManager: IFaceManager;
|
|
||||||
/** 图块定义存储 */
|
|
||||||
readonly tileStore: ITileStore;
|
|
||||||
|
|
||||||
/** 地图状态 */
|
/** 地图状态 */
|
||||||
readonly maps: IMapStore;
|
readonly maps: IMapStore;
|
||||||
/** 勇士状态 */
|
/** 勇士状态 */
|
||||||
|
|||||||
6
packages-user/data-common/package.json
Normal file
6
packages-user/data-common/package.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"name": "@user/data-common",
|
||||||
|
"dependencies": {
|
||||||
|
"@motajs/common": "workspace:*"
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,5 +1,5 @@
|
|||||||
import { logger } from '@motajs/common';
|
import { logger } from '@motajs/common';
|
||||||
import { IFaceData, IRoleFaceBinder } from './types';
|
import { IFaceData, IRoleFaceBinder } from '../common';
|
||||||
import { isNil } from 'lodash-es';
|
import { isNil } from 'lodash-es';
|
||||||
import { FaceDirection } from '.';
|
import { FaceDirection } from '.';
|
||||||
|
|
||||||
@ -2,7 +2,7 @@ import { FaceDirection } from './types';
|
|||||||
|
|
||||||
//#region 接口与枚举
|
//#region 接口与枚举
|
||||||
|
|
||||||
export const enum InternalFaceGroup {
|
export const enum FaceGroup {
|
||||||
/** 四方向(上下左右) */
|
/** 四方向(上下左右) */
|
||||||
Dir4,
|
Dir4,
|
||||||
/** 八方向(上下左右+斜向) */
|
/** 八方向(上下左右+斜向) */
|
||||||
4
packages-user/data-common/src/index.ts
Normal file
4
packages-user/data-common/src/index.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export * from './common';
|
||||||
|
export * from './store';
|
||||||
|
|
||||||
|
export * from './types';
|
||||||
16
packages-user/data-common/src/types.ts
Normal file
16
packages-user/data-common/src/types.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { IFaceManager, IRoleFaceBinder } from './common';
|
||||||
|
import { ITileStore } from './store';
|
||||||
|
|
||||||
|
export interface IDataCommon {
|
||||||
|
/** 图块定义存储 */
|
||||||
|
readonly tileStore: ITileStore<MapDataOf<keyof NumberToId>>;
|
||||||
|
/** 朝向绑定 */
|
||||||
|
readonly roleFace: IRoleFaceBinder;
|
||||||
|
/** 朝向管理 */
|
||||||
|
readonly faceManager: IFaceManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IDataCommonExtended {
|
||||||
|
/** 当前对象对应的基本数据端对象(Layer 0 对象) */
|
||||||
|
readonly state: IDataCommon;
|
||||||
|
}
|
||||||
@ -3,6 +3,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@motajs/types": "workspace:*",
|
"@motajs/types": "workspace:*",
|
||||||
"@motajs/common": "workspace:*",
|
"@motajs/common": "workspace:*",
|
||||||
|
"@user/data-common": "workspace:*",
|
||||||
"@user/data-base": "workspace:*",
|
"@user/data-base": "workspace:*",
|
||||||
"@user/data-system": "workspace:*",
|
"@user/data-system": "workspace:*",
|
||||||
"@user/data-utils": "workspace:*"
|
"@user/data-utils": "workspace:*"
|
||||||
|
|||||||
@ -1,4 +1,18 @@
|
|||||||
import { ICoreState, ISaveableExecutor } from './types';
|
import { ICoreState, ISaveableExecutor } from './types';
|
||||||
|
import {
|
||||||
|
IRoleFaceBinder,
|
||||||
|
IFaceManager,
|
||||||
|
ITileStore,
|
||||||
|
ISaveableContent,
|
||||||
|
TileStore,
|
||||||
|
SaveCompression,
|
||||||
|
RoleFaceBinder,
|
||||||
|
FaceManager,
|
||||||
|
Dir4FaceHandler,
|
||||||
|
Dir8FaceHandler,
|
||||||
|
FaceGroup,
|
||||||
|
FaceDirection
|
||||||
|
} from '@user/data-common';
|
||||||
import {
|
import {
|
||||||
EnemyManager,
|
EnemyManager,
|
||||||
HeroMover,
|
HeroMover,
|
||||||
@ -11,22 +25,16 @@ import {
|
|||||||
IMotaDataLoader,
|
IMotaDataLoader,
|
||||||
MotaDataLoader,
|
MotaDataLoader,
|
||||||
loading,
|
loading,
|
||||||
IRoleFaceBinder,
|
|
||||||
RoleFaceBinder,
|
|
||||||
FaceDirection,
|
|
||||||
ISaveableContent,
|
|
||||||
SaveCompression,
|
|
||||||
IReadonlyEnemy,
|
IReadonlyEnemy,
|
||||||
IMapStore,
|
IMapStore,
|
||||||
MapStore,
|
MapStore
|
||||||
IFaceManager,
|
|
||||||
FaceManager,
|
|
||||||
InternalFaceGroup,
|
|
||||||
Dir4FaceHandler,
|
|
||||||
Dir8FaceHandler,
|
|
||||||
ITileStore,
|
|
||||||
TileStore
|
|
||||||
} from '@user/data-base';
|
} from '@user/data-base';
|
||||||
|
import {
|
||||||
|
DamageSystem,
|
||||||
|
EnemyContext,
|
||||||
|
IEnemyContext,
|
||||||
|
MapDamage
|
||||||
|
} from '@user/data-system';
|
||||||
import {
|
import {
|
||||||
CommonAuraConverter,
|
CommonAuraConverter,
|
||||||
EnemyLegacyBridge,
|
EnemyLegacyBridge,
|
||||||
@ -55,29 +63,25 @@ 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 { ISaveSystem, SaveSystem } from './save';
|
import { ISaveSystem, SaveSystem } from './save';
|
||||||
import {
|
|
||||||
DamageSystem,
|
|
||||||
EnemyContext,
|
|
||||||
IEnemyContext,
|
|
||||||
MapDamage
|
|
||||||
} from '@user/data-system';
|
|
||||||
|
|
||||||
export class CoreState implements ICoreState {
|
export class CoreState implements ICoreState {
|
||||||
// 全局内容
|
// Layer 0 内容
|
||||||
readonly roleFace: IRoleFaceBinder;
|
readonly roleFace: IRoleFaceBinder;
|
||||||
readonly faceManager: IFaceManager;
|
readonly faceManager: IFaceManager;
|
||||||
readonly tileStore: ITileStore<LegacyTileData>;
|
readonly tileStore: ITileStore<LegacyTileData>;
|
||||||
|
|
||||||
// 可存档内容
|
// Layer 1 内容
|
||||||
readonly maps: IMapStore;
|
readonly maps: IMapStore;
|
||||||
readonly hero: IHeroState<IHeroAttr>;
|
readonly hero: IHeroState<IHeroAttr>;
|
||||||
readonly enemyManager: IEnemyManager<IEnemyAttr>;
|
readonly enemyManager: IEnemyManager<IEnemyAttr>;
|
||||||
readonly flags: IFlagSystem;
|
readonly flags: IFlagSystem;
|
||||||
|
|
||||||
// 状态内容
|
// Layer 2 内容
|
||||||
|
readonly enemyContext: IEnemyContext<IEnemyAttr, IHeroAttr>;
|
||||||
|
|
||||||
|
// 用户层内容
|
||||||
readonly loadProgress: ILoadProgressTotal;
|
readonly loadProgress: ILoadProgressTotal;
|
||||||
readonly dataLoader: IMotaDataLoader;
|
readonly dataLoader: IMotaDataLoader;
|
||||||
readonly enemyContext: IEnemyContext<IEnemyAttr, IHeroAttr>;
|
|
||||||
readonly saveSystem: ISaveSystem;
|
readonly saveSystem: ISaveSystem;
|
||||||
|
|
||||||
/** 可存档对象映射 */
|
/** 可存档对象映射 */
|
||||||
@ -94,7 +98,7 @@ export class CoreState implements ICoreState {
|
|||||||
const tileStore = new TileStore<LegacyTileData>();
|
const tileStore = new TileStore<LegacyTileData>();
|
||||||
tileStore.attachLegacyConverter(new TileLegacyBridge());
|
tileStore.attachLegacyConverter(new TileLegacyBridge());
|
||||||
this.tileStore = tileStore;
|
this.tileStore = tileStore;
|
||||||
this.maps = new MapStore(tileStore);
|
this.maps = new MapStore(tileStore, this);
|
||||||
|
|
||||||
this.loadProgress = new LoadProgressTotal();
|
this.loadProgress = new LoadProgressTotal();
|
||||||
this.dataLoader = new MotaDataLoader(this.loadProgress);
|
this.dataLoader = new MotaDataLoader(this.loadProgress);
|
||||||
@ -166,9 +170,9 @@ export class CoreState implements ICoreState {
|
|||||||
this.faceManager = new FaceManager();
|
this.faceManager = new FaceManager();
|
||||||
const dir4 = new Dir4FaceHandler();
|
const dir4 = new Dir4FaceHandler();
|
||||||
const dir8 = new Dir8FaceHandler();
|
const dir8 = new Dir8FaceHandler();
|
||||||
this.faceManager.register(InternalFaceGroup.Dir4, dir4);
|
this.faceManager.register(FaceGroup.Dir4, dir4);
|
||||||
this.faceManager.registerById('dir4', dir4);
|
this.faceManager.registerById('dir4', dir4);
|
||||||
this.faceManager.register(InternalFaceGroup.Dir8, dir8);
|
this.faceManager.register(FaceGroup.Dir8, dir8);
|
||||||
this.faceManager.registerById('dir8', dir8);
|
this.faceManager.registerById('dir8', dir8);
|
||||||
|
|
||||||
this.flags = new FlagSystem();
|
this.flags = new FlagSystem();
|
||||||
|
|||||||
@ -19,15 +19,14 @@ import {
|
|||||||
IMapDamageView
|
IMapDamageView
|
||||||
} from '@user/data-system';
|
} from '@user/data-system';
|
||||||
import {
|
import {
|
||||||
IFaceHandler,
|
|
||||||
ISpecial,
|
ISpecial,
|
||||||
IReadonlyHeroAttribute,
|
IReadonlyHeroAttribute,
|
||||||
IReadonlyEnemy,
|
IReadonlyEnemy
|
||||||
InternalFaceGroup
|
|
||||||
} from '@user/data-base';
|
} from '@user/data-base';
|
||||||
import { IZoneValue } from './special';
|
import { IZoneValue } from './special';
|
||||||
import { IEnemyAttr, MapDamageType } from './types';
|
import { IEnemyAttr, MapDamageType } from './types';
|
||||||
import { IHeroAttr } from '../hero';
|
import { IHeroAttr } from '../hero';
|
||||||
|
import { IFaceHandler, FaceGroup } from '@user/data-common';
|
||||||
|
|
||||||
const RECT_RANGE = new RectRange();
|
const RECT_RANGE = new RectRange();
|
||||||
const MANHATTAN_RANGE = new ManhattanRange();
|
const MANHATTAN_RANGE = new ManhattanRange();
|
||||||
@ -312,7 +311,7 @@ export class MainMapDamageConverter implements IMapDamageConverter<
|
|||||||
|
|
||||||
const laser = enemy.getSpecial<number>(24);
|
const laser = enemy.getSpecial<number>(24);
|
||||||
if (laser) {
|
if (laser) {
|
||||||
const face = handler.data.faceManager.get(InternalFaceGroup.Dir4)!;
|
const face = handler.data.faceManager.get(FaceGroup.Dir4)!;
|
||||||
views.push(new LaserDamageView(context, locator, laser, face));
|
views.push(new LaserDamageView(context, locator, laser, face));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
import EventEmitter from 'eventemitter3';
|
import EventEmitter from 'eventemitter3';
|
||||||
import { backDir, toDir } from './utils';
|
import { backDir, toDir } from './utils';
|
||||||
import { fromDirectionString, loading } from '@user/data-base';
|
import { loading } from '@user/data-base';
|
||||||
import type { HeroKeyMover } from '@user/client-modules';
|
import type { HeroKeyMover } from '@user/client-modules';
|
||||||
import { sleep } from '@motajs/common';
|
import { sleep } from '@motajs/common';
|
||||||
import { state } from '..';
|
import { state } from '..';
|
||||||
|
import { fromDirectionString } from '@user/data-common';
|
||||||
|
|
||||||
// todo: 转身功能
|
// todo: 转身功能
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,8 @@
|
|||||||
import { ITileLegacyConverter, ITileRawData, TileType } from '@user/data-base';
|
import {
|
||||||
|
ITileLegacyConverter,
|
||||||
|
ITileRawData,
|
||||||
|
TileType
|
||||||
|
} from '@user/data-common';
|
||||||
|
|
||||||
export type LegacyTileData = MapDataOf<keyof NumberToId>;
|
export type LegacyTileData = MapDataOf<keyof NumberToId>;
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import {
|
|||||||
ISaveSystem,
|
ISaveSystem,
|
||||||
ISaveSystemConfig
|
ISaveSystemConfig
|
||||||
} from './types';
|
} from './types';
|
||||||
import { ISaveableContent, SaveCompression } from '@user/data-base';
|
import { ISaveableContent, SaveCompression } from '@user/data-common';
|
||||||
import { isNil } from 'lodash-es';
|
import { isNil } from 'lodash-es';
|
||||||
|
|
||||||
interface ISaveRecord {
|
interface ISaveRecord {
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { ISaveableContent, SaveCompression } from '@user/data-base';
|
import { ISaveableContent, SaveCompression } from '@user/data-common';
|
||||||
import { Dexie, Table } from 'dexie';
|
import { Dexie, Table } from 'dexie';
|
||||||
|
|
||||||
export interface IGlobalTrasaction {
|
export interface IGlobalTrasaction {
|
||||||
|
|||||||
@ -1,13 +1,10 @@
|
|||||||
import {
|
import { IMotaDataLoader, IStateBase } from '@user/data-base';
|
||||||
IEnemyContext,
|
|
||||||
IMotaDataLoader,
|
|
||||||
ISaveableContent,
|
|
||||||
IStateBase
|
|
||||||
} from '@user/data-base';
|
|
||||||
import { IEnemyAttr } from './enemy';
|
import { IEnemyAttr } from './enemy';
|
||||||
import { IHeroAttr } from './hero';
|
import { IHeroAttr } from './hero';
|
||||||
import { ILoadProgressTotal } from '@motajs/loader';
|
import { ILoadProgressTotal } from '@motajs/loader';
|
||||||
import { ISaveSystem } from './save';
|
import { ISaveSystem } from './save';
|
||||||
|
import { IEnemyContext } from '@user/data-system';
|
||||||
|
import { ISaveableContent } from '@user/data-common';
|
||||||
|
|
||||||
export interface ISaveableExecutor<T, TEnemy = IEnemyAttr, THero = IHeroAttr> {
|
export interface ISaveableExecutor<T, TEnemy = IEnemyAttr, THero = IHeroAttr> {
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -19,11 +19,10 @@ import {
|
|||||||
IEnemy,
|
IEnemy,
|
||||||
IReadonlyEnemy,
|
IReadonlyEnemy,
|
||||||
ISpecial,
|
ISpecial,
|
||||||
IStateBase,
|
IStateBase
|
||||||
ILocationIndexer,
|
|
||||||
MapLocIndexer
|
|
||||||
} from '@user/data-base';
|
} from '@user/data-base';
|
||||||
import { EnemyView } from './enemy';
|
import { EnemyView } from './enemy';
|
||||||
|
import { ILocationIndexer, MapLocIndexer } from '@user/data-common';
|
||||||
|
|
||||||
export class EnemyContext<TEnemy, THero> implements IEnemyContext<
|
export class EnemyContext<TEnemy, THero> implements IEnemyContext<
|
||||||
TEnemy,
|
TEnemy,
|
||||||
|
|||||||
@ -9,7 +9,8 @@ import {
|
|||||||
IMapDamageReducer,
|
IMapDamageReducer,
|
||||||
IMapDamageView
|
IMapDamageView
|
||||||
} from './types';
|
} from './types';
|
||||||
import { ILocationHelper, IStateBase } from '@user/data-base';
|
import { IStateBase } from '@user/data-base';
|
||||||
|
import { ILocationHelper } from '@user/data-common';
|
||||||
|
|
||||||
interface IPointInfo {
|
interface IPointInfo {
|
||||||
/** 该点所有的地图伤害 */
|
/** 该点所有的地图伤害 */
|
||||||
|
|||||||
@ -5,9 +5,9 @@ import {
|
|||||||
ISpecial,
|
ISpecial,
|
||||||
IReadonlyHeroAttribute,
|
IReadonlyHeroAttribute,
|
||||||
IHeroAttribute,
|
IHeroAttribute,
|
||||||
IStateBase,
|
IStateBase
|
||||||
ILocationHelper
|
|
||||||
} from '@user/data-base';
|
} from '@user/data-base';
|
||||||
|
import { ILocationHelper } from '@user/data-common';
|
||||||
|
|
||||||
//#region 辅助接口
|
//#region 辅助接口
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
import type { TimingFn } from 'mutate-animate';
|
import type { TimingFn } from 'mutate-animate';
|
||||||
import { heroMoveCollection, MoveStep, state } from '@user/data-state';
|
import { heroMoveCollection, MoveStep, state } from '@user/data-state';
|
||||||
import { fromDirectionString, hook, loading } from '@user/data-base';
|
import { hook, loading } from '@user/data-base';
|
||||||
import { Patch, PatchClass } from '@motajs/legacy-common';
|
import { Patch, PatchClass } from '@motajs/legacy-common';
|
||||||
import { isNil } from 'lodash-es';
|
import { isNil } from 'lodash-es';
|
||||||
|
import { fromDirectionString } from '@user/data-common';
|
||||||
|
|
||||||
// 向后兼容用,会充当两个版本间过渡的作用
|
// 向后兼容用,会充当两个版本间过渡的作用
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { FaceDirection } from '@user/data-base';
|
import { FaceDirection } from '@user/data-common';
|
||||||
|
|
||||||
export interface ISearchable4Dir {
|
export interface ISearchable4Dir {
|
||||||
/** 获取上侧元素 */
|
/** 获取上侧元素 */
|
||||||
|
|||||||
@ -288,6 +288,15 @@ importers:
|
|||||||
'@motajs/types':
|
'@motajs/types':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../../packages/types
|
version: link:../../packages/types
|
||||||
|
'@user/data-common':
|
||||||
|
specifier: workspace:*
|
||||||
|
version: link:../data-common
|
||||||
|
|
||||||
|
packages-user/data-common:
|
||||||
|
dependencies:
|
||||||
|
'@motajs/common':
|
||||||
|
specifier: workspace:*
|
||||||
|
version: link:../../packages/common
|
||||||
|
|
||||||
packages-user/data-fallback:
|
packages-user/data-fallback:
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user