refactor: 统一三个数据层的接口风格

This commit is contained in:
unanmed 2026-05-17 21:38:29 +08:00
parent 8f4c4b7df2
commit b779e62eb2
6 changed files with 23 additions and 7 deletions

2
dev.md
View File

@ -122,7 +122,7 @@
数据端目前正在从旧引擎进行彻底性重构,分为三层:
**Layer 0 — 公共层**:包含公共接口、工具函数等内容,不依赖任何外部游戏逻辑,可被任意高层直接引用。内容较少,与 Layer 1 共同放在 `@user/data-base` 中,不单独开包
**Layer 0 — 公共层**:包含公共接口、工具函数等内容,不依赖任何外部游戏逻辑,可被任意高层直接引用。包含统一接口 `IDataCommon`
**Layer 1 — 数据层**:包含所有会影响游戏存档与流程的数据内容,如地图、怪物、玩家属性等。本层通过统一接口 `IStateBase` 对外暴露数据访问能力,各类数据模块均以此接口为核心组织。

View File

@ -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>;
}

View File

@ -11,6 +11,6 @@ export interface IDataCommon {
}
export interface IDataCommonExtended {
/** 当前对象对应的基本数据端对象Layer 0 对象) */
/** 当前对象对应的公共层对象Layer 0 对象) */
readonly state: IDataCommon;
}

View File

@ -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;

View File

@ -1,2 +1,4 @@
export * from './combat';
export * from './trigger';
export * from './types';

View 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>;
}