mirror of
https://github.com/motajs/template.git
synced 2026-05-18 15:41:09 +08:00
refactor: 统一三个数据层的接口风格
This commit is contained in:
parent
8f4c4b7df2
commit
b779e62eb2
2
dev.md
2
dev.md
@ -122,7 +122,7 @@
|
||||
|
||||
数据端目前正在从旧引擎进行彻底性重构,分为三层:
|
||||
|
||||
**Layer 0 — 公共层**:包含公共接口、工具函数等内容,不依赖任何外部游戏逻辑,可被任意高层直接引用。内容较少,与 Layer 1 共同放在 `@user/data-base` 中,不单独开包。
|
||||
**Layer 0 — 公共层**:包含公共接口、工具函数等内容,不依赖任何外部游戏逻辑,可被任意高层直接引用。包含统一接口 `IDataCommon`。
|
||||
|
||||
**Layer 1 — 数据层**:包含所有会影响游戏存档与流程的数据内容,如地图、怪物、玩家属性等。本层通过统一接口 `IStateBase` 对外暴露数据访问能力,各类数据模块均以此接口为核心组织。
|
||||
|
||||
|
||||
@ -34,3 +34,8 @@ export interface IStateBase<TEnemy, THero> extends IDataCommon {
|
||||
*/
|
||||
getSaveableContent<T>(id: string): ISaveableContent<T> | null;
|
||||
}
|
||||
|
||||
export interface IStateBaseExtended<TEnemy = unknown, THero = unknown> {
|
||||
/** 当前对象对应的数据层对象(Layer 1 对象) */
|
||||
readonly state: IStateBase<TEnemy, THero>;
|
||||
}
|
||||
|
||||
@ -11,6 +11,6 @@ export interface IDataCommon {
|
||||
}
|
||||
|
||||
export interface IDataCommonExtended {
|
||||
/** 当前对象对应的基本数据端对象(Layer 0 对象) */
|
||||
/** 当前对象对应的公共层对象(Layer 0 对象) */
|
||||
readonly state: IDataCommon;
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ import { IEnemyAttr } from './enemy';
|
||||
import { IHeroAttr } from './hero';
|
||||
import { ILoadProgressTotal } from '@motajs/loader';
|
||||
import { ISaveSystem } from './save';
|
||||
import { IEnemyContext } from '@user/data-system';
|
||||
import { IStateSystem } from '@user/data-system';
|
||||
import { ISaveableContent } from '@user/data-common';
|
||||
|
||||
export interface ISaveableExecutor<T, TEnemy = IEnemyAttr, THero = IHeroAttr> {
|
||||
@ -15,14 +15,11 @@ export interface ISaveableExecutor<T, TEnemy = IEnemyAttr, THero = IHeroAttr> {
|
||||
afterLoad(data: T, state: IStateBase<TEnemy, THero>): void;
|
||||
}
|
||||
|
||||
export interface ICoreState extends IStateBase<IEnemyAttr, IHeroAttr> {
|
||||
export interface ICoreState extends IStateSystem<IEnemyAttr, IHeroAttr> {
|
||||
/** 加载进度对象 */
|
||||
readonly loadProgress: ILoadProgressTotal;
|
||||
/** 数据端加载对象 */
|
||||
readonly dataLoader: IMotaDataLoader;
|
||||
/** 怪物上下文 */
|
||||
readonly enemyContext: IEnemyContext<IEnemyAttr, IHeroAttr>;
|
||||
|
||||
/** 存档系统 */
|
||||
readonly saveSystem: ISaveSystem;
|
||||
|
||||
|
||||
@ -1,2 +1,4 @@
|
||||
export * from './combat';
|
||||
export * from './trigger';
|
||||
|
||||
export * from './types';
|
||||
|
||||
12
packages-user/data-system/src/types.ts
Normal file
12
packages-user/data-system/src/types.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { IStateBase } from '@user/data-base';
|
||||
import { IEnemyContext } from './combat';
|
||||
|
||||
export interface IStateSystem<TEnemy, THero> extends IStateBase<TEnemy, THero> {
|
||||
/** 怪物上下文 */
|
||||
readonly enemyContext: IEnemyContext<TEnemy, THero>;
|
||||
}
|
||||
|
||||
export interface IStateSystemExtended<TEnemy = unknown, THero = unknown> {
|
||||
/** 当前对象对应的执行层对象(Layer 2 对象) */
|
||||
readonly state: IStateSystem<TEnemy, THero>;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user