文档及教程更新
This commit is contained in:
@@ -2,27 +2,6 @@
|
||||
* 框架核心类型定义
|
||||
*/
|
||||
|
||||
/** 更新顺序比较器接口 */
|
||||
export interface IUpdateOrderComparable {
|
||||
updateOrder: number;
|
||||
}
|
||||
|
||||
/** 日志类型枚举 */
|
||||
export enum LogType {
|
||||
Error = 0,
|
||||
Assert = 1,
|
||||
Warning = 2,
|
||||
Log = 3,
|
||||
Exception = 4
|
||||
}
|
||||
|
||||
/** 组件变换类型枚举 */
|
||||
export enum ComponentTransform {
|
||||
Position = 1,
|
||||
Scale = 2,
|
||||
Rotation = 4
|
||||
}
|
||||
|
||||
/**
|
||||
* 组件接口
|
||||
*
|
||||
@@ -51,136 +30,14 @@ export interface IComponent {
|
||||
}
|
||||
|
||||
/**
|
||||
* 实体接口
|
||||
* 系统基础接口
|
||||
*
|
||||
* 定义实体的基本契约,所有实体都应该实现此接口
|
||||
*/
|
||||
export interface IEntity {
|
||||
/** 实体唯一标识符 */
|
||||
readonly id: string | number;
|
||||
/** 实体名称 */
|
||||
name: string;
|
||||
/** 实体激活状态 */
|
||||
active: boolean;
|
||||
/** 实体启用状态 */
|
||||
enabled: boolean;
|
||||
/** 实体是否已销毁 */
|
||||
readonly isDestroyed: boolean;
|
||||
/** 更新顺序 */
|
||||
updateOrder: number;
|
||||
/** 实体标签 */
|
||||
tag: number;
|
||||
|
||||
/** 添加组件 */
|
||||
addComponent<T extends IComponent>(component: T): T;
|
||||
/** 创建并添加组件 */
|
||||
createComponent<T extends IComponent>(componentType: ComponentType<T>, ...args: any[]): T;
|
||||
/** 获取组件 */
|
||||
getComponent<T extends IComponent>(type: ComponentType<T>): T | null;
|
||||
/** 获取或创建组件 */
|
||||
getOrCreateComponent<T extends IComponent>(type: ComponentType<T>, ...args: any[]): T;
|
||||
/** 移除组件 */
|
||||
removeComponent(component: IComponent): void;
|
||||
/** 通过类型移除组件 */
|
||||
removeComponentByType<T extends IComponent>(type: ComponentType<T>): T | null;
|
||||
/** 检查是否有组件 */
|
||||
hasComponent<T extends IComponent>(type: ComponentType<T>): boolean;
|
||||
/** 获取所有指定类型的组件 */
|
||||
getComponents<T extends IComponent>(type: ComponentType<T>): T[];
|
||||
|
||||
/** 添加子实体 */
|
||||
addChild(child: IEntity): IEntity;
|
||||
/** 移除子实体 */
|
||||
removeChild(child: IEntity): boolean;
|
||||
/** 查找子实体 */
|
||||
findChild(name: string, recursive?: boolean): IEntity | null;
|
||||
|
||||
/** 更新实体 */
|
||||
update(): void;
|
||||
/** 销毁实体 */
|
||||
destroy(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* 实体基础接口(向后兼容)
|
||||
*
|
||||
* 为现有的Entity类提供更灵活的类型定义
|
||||
*/
|
||||
export interface IEntityBase {
|
||||
/** 实体唯一标识符 */
|
||||
readonly id: string | number;
|
||||
/** 实体名称 */
|
||||
name: string;
|
||||
/** 实体激活状态 */
|
||||
active: boolean;
|
||||
/** 实体启用状态 */
|
||||
enabled: boolean;
|
||||
/** 实体是否已销毁 */
|
||||
readonly isDestroyed: boolean;
|
||||
/** 更新顺序 */
|
||||
updateOrder: number;
|
||||
/** 实体标签 */
|
||||
tag: number;
|
||||
|
||||
/** 添加组件(泛型版本) */
|
||||
addComponent<T>(component: T): T;
|
||||
/** 获取组件(泛型版本) */
|
||||
getComponent<T>(type: ComponentClass<T>): T | null;
|
||||
/** 检查是否有组件(泛型版本) */
|
||||
hasComponent<T>(type: ComponentClass<T>): boolean;
|
||||
|
||||
/** 添加子实体 */
|
||||
addChild(child: any): any;
|
||||
/** 移除子实体 */
|
||||
removeChild(child: any): boolean;
|
||||
/** 查找子实体 */
|
||||
findChild(name: string, recursive?: boolean): any;
|
||||
|
||||
/** 更新实体 */
|
||||
update(): void;
|
||||
/** 销毁实体 */
|
||||
destroy(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统接口
|
||||
*
|
||||
* 定义系统的基本契约,所有系统都应该实现此接口
|
||||
*/
|
||||
export interface ISystem {
|
||||
/** 系统名称 */
|
||||
readonly systemName: string;
|
||||
/** 系统处理的实体列表 */
|
||||
readonly entities: readonly IEntity[];
|
||||
/** 更新顺序/优先级 */
|
||||
updateOrder: number;
|
||||
/** 系统启用状态 */
|
||||
enabled: boolean;
|
||||
|
||||
/** 系统初始化 */
|
||||
initialize(): void;
|
||||
/** 更新系统(主要处理阶段) */
|
||||
update(): void;
|
||||
/** 延迟更新系统 */
|
||||
lateUpdate?(): void;
|
||||
|
||||
/** 当实体添加到系统时的回调 */
|
||||
onEntityAdded?(entity: IEntity): void;
|
||||
/** 当实体从系统移除时的回调 */
|
||||
onEntityRemoved?(entity: IEntity): void;
|
||||
/** 当实体组件发生变化时的回调 */
|
||||
onEntityChanged?(entity: IEntity): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统基础接口(向后兼容)
|
||||
*
|
||||
* 为现有的EntitySystem类提供更灵活的类型定义
|
||||
* 为现有的EntitySystem类提供类型定义
|
||||
*/
|
||||
export interface ISystemBase {
|
||||
/** 系统名称 */
|
||||
readonly systemName: string;
|
||||
/** 系统处理的实体列表(泛型版本) */
|
||||
/** 系统处理的实体列表 */
|
||||
readonly entities: readonly any[];
|
||||
/** 更新顺序/优先级 */
|
||||
updateOrder: number;
|
||||
@@ -195,39 +52,6 @@ export interface ISystemBase {
|
||||
lateUpdate?(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* 场景接口
|
||||
*
|
||||
* 定义场景的基本契约
|
||||
*/
|
||||
export interface IScene {
|
||||
/** 场景名称 */
|
||||
name: string;
|
||||
/** 场景中的实体列表 */
|
||||
readonly entities: readonly IEntity[];
|
||||
/** 场景中的系统列表 */
|
||||
readonly systems: readonly ISystem[];
|
||||
|
||||
/** 创建实体 */
|
||||
createEntity(name: string): IEntity;
|
||||
/** 添加实体到场景 */
|
||||
addEntity(entity: IEntity): void;
|
||||
/** 从场景移除实体 */
|
||||
removeEntity(entity: IEntity): void;
|
||||
/** 查找实体 */
|
||||
findEntity(name: string): IEntity | null;
|
||||
|
||||
/** 添加系统到场景 */
|
||||
addSystem<T extends ISystem>(system: T): T;
|
||||
/** 从场景移除系统 */
|
||||
removeSystem(system: ISystem): void;
|
||||
/** 获取系统 */
|
||||
getSystem<T extends ISystem>(systemType: new (...args: any[]) => T): T | null;
|
||||
|
||||
/** 更新场景 */
|
||||
update(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* 组件类型定义
|
||||
*
|
||||
@@ -235,170 +59,6 @@ export interface IScene {
|
||||
*/
|
||||
export type ComponentType<T extends IComponent = IComponent> = new (...args: any[]) => T;
|
||||
|
||||
/**
|
||||
* 原始组件类型(向后兼容)
|
||||
*
|
||||
* 用于与现有Component类的兼容
|
||||
*/
|
||||
export type ComponentClass<T = any> = new (...args: any[]) => T;
|
||||
|
||||
/**
|
||||
* 实体查询匹配器接口
|
||||
*
|
||||
* 用于查询符合特定条件的实体
|
||||
*/
|
||||
export interface IMatcher {
|
||||
/** 必须包含的组件类型 */
|
||||
all(...componentTypes: ComponentType[]): IMatcher;
|
||||
/** 至少包含其中一个组件类型 */
|
||||
any(...componentTypes: ComponentType[]): IMatcher;
|
||||
/** 不能包含的组件类型 */
|
||||
exclude(...componentTypes: ComponentType[]): IMatcher;
|
||||
/** 检查实体是否匹配 */
|
||||
isInterestedEntity(entity: IEntity): boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 性能监控接口
|
||||
*/
|
||||
export interface IPerformanceData {
|
||||
/** 执行时间(毫秒) */
|
||||
executionTime: number;
|
||||
/** 调用次数 */
|
||||
callCount: number;
|
||||
/** 平均执行时间 */
|
||||
averageTime: number;
|
||||
/** 最大执行时间 */
|
||||
maxTime: number;
|
||||
/** 最小执行时间 */
|
||||
minTime: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生命周期管理接口
|
||||
*/
|
||||
export interface ILifecycle {
|
||||
/** 初始化 */
|
||||
initialize?(): void;
|
||||
/** 启动 */
|
||||
start?(): void;
|
||||
/** 更新 */
|
||||
update?(): void;
|
||||
/** 延迟更新 */
|
||||
lateUpdate?(): void;
|
||||
/** 停止 */
|
||||
stop?(): void;
|
||||
/** 销毁 */
|
||||
destroy?(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* 实体管理器接口
|
||||
*
|
||||
* 提供统一的实体管理和查询机制,支持高效的实体操作
|
||||
*/
|
||||
export interface IEntityManager {
|
||||
/** 所有实体数量 */
|
||||
readonly entityCount: number;
|
||||
/** 激活的实体数量 */
|
||||
readonly activeEntityCount: number;
|
||||
|
||||
/** 创建实体 */
|
||||
createEntity(name?: string): IEntity;
|
||||
/** 销毁实体 */
|
||||
destroyEntity(entity: IEntity | string | number): boolean;
|
||||
/** 批量销毁实体 */
|
||||
destroyEntities(entities: (IEntity | string | number)[]): number;
|
||||
/** 销毁所有实体 */
|
||||
destroyAllEntities(): number;
|
||||
|
||||
/** 根据ID获取实体 */
|
||||
getEntity(id: string | number): IEntity | null;
|
||||
/** 根据名称获取实体 */
|
||||
getEntityByName(name: string): IEntity | null;
|
||||
/** 根据名称获取所有实体 */
|
||||
getEntitiesByName(name: string): IEntity[];
|
||||
/** 根据标签获取实体 */
|
||||
getEntitiesByTag(tag: number): IEntity[];
|
||||
/** 获取所有实体 */
|
||||
getAllEntities(): IEntity[];
|
||||
/** 获取所有激活的实体 */
|
||||
getActiveEntities(): IEntity[];
|
||||
|
||||
/** 获取拥有指定组件的实体 */
|
||||
getEntitiesWithComponent<T extends IComponent>(componentType: ComponentType<T>): IEntity[];
|
||||
/** 获取拥有指定组件的实体及其组件 */
|
||||
getEntitiesWithComponentData<T extends IComponent>(componentType: ComponentType<T>): Array<{entity: IEntity, component: T}>;
|
||||
/** 获取拥有所有指定组件的实体 */
|
||||
getEntitiesWithComponents(...componentTypes: ComponentType[]): IEntity[];
|
||||
/** 获取拥有任一指定组件的实体 */
|
||||
getEntitiesWithAnyComponent(...componentTypes: ComponentType[]): IEntity[];
|
||||
/** 获取不包含指定组件的实体 */
|
||||
getEntitiesWithoutComponent<T extends IComponent>(componentType: ComponentType<T>): IEntity[];
|
||||
|
||||
/** 对所有实体执行操作 */
|
||||
forEachEntity(action: (entity: IEntity) => void): void;
|
||||
/** 对符合条件的实体执行操作 */
|
||||
forEachEntityWhere(predicate: (entity: IEntity) => boolean, action: (entity: IEntity) => void): void;
|
||||
/** 对拥有指定组件的实体执行操作 */
|
||||
forEachEntityWithComponent<T extends IComponent>(
|
||||
componentType: ComponentType<T>,
|
||||
action: (entity: IEntity, component: T) => void
|
||||
): void;
|
||||
|
||||
/** 查找第一个符合条件的实体 */
|
||||
findEntity(predicate: (entity: IEntity) => boolean): IEntity | null;
|
||||
/** 查找所有符合条件的实体 */
|
||||
findEntities(predicate: (entity: IEntity) => boolean): IEntity[];
|
||||
|
||||
/** 获取统计信息 */
|
||||
getStatistics(): {
|
||||
totalEntities: number;
|
||||
activeEntities: number;
|
||||
destroyedEntities: number;
|
||||
entitiesByTag: Map<number, number>;
|
||||
componentsCount: Map<string, number>;
|
||||
};
|
||||
|
||||
/** 清理已销毁的实体 */
|
||||
cleanup(): number;
|
||||
/** 压缩存储空间 */
|
||||
compact(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* 实体查询构建器接口
|
||||
*
|
||||
* 提供流式API构建复杂的实体查询条件
|
||||
*/
|
||||
export interface IEntityQueryBuilder {
|
||||
/** 必须包含所有指定组件 */
|
||||
withAll(...componentTypes: ComponentType[]): IEntityQueryBuilder;
|
||||
/** 必须包含任一指定组件 */
|
||||
withAny(...componentTypes: ComponentType[]): IEntityQueryBuilder;
|
||||
/** 必须不包含指定组件 */
|
||||
without(...componentTypes: ComponentType[]): IEntityQueryBuilder;
|
||||
/** 必须包含指定标签 */
|
||||
withTag(tag: number): IEntityQueryBuilder;
|
||||
/** 必须不包含指定标签 */
|
||||
withoutTag(tag: number): IEntityQueryBuilder;
|
||||
/** 必须处于激活状态 */
|
||||
active(): IEntityQueryBuilder;
|
||||
/** 必须处于启用状态 */
|
||||
enabled(): IEntityQueryBuilder;
|
||||
/** 自定义过滤条件 */
|
||||
where(predicate: (entity: IEntity) => boolean): IEntityQueryBuilder;
|
||||
|
||||
/** 执行查询,返回所有匹配的实体 */
|
||||
execute(): IEntity[];
|
||||
/** 执行查询,返回第一个匹配的实体 */
|
||||
first(): IEntity | null;
|
||||
/** 执行查询,返回匹配实体的数量 */
|
||||
count(): number;
|
||||
/** 对查询结果执行操作 */
|
||||
forEach(action: (entity: IEntity) => void): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* 事件总线接口
|
||||
* 提供类型安全的事件发布订阅机制
|
||||
|
||||
Reference in New Issue
Block a user