diff --git a/packages/core/src/Core/DI/Decorators.ts b/packages/core/src/Core/DI/Decorators.ts index 29996e30..04d192ed 100644 --- a/packages/core/src/Core/DI/Decorators.ts +++ b/packages/core/src/Core/DI/Decorators.ts @@ -18,7 +18,7 @@ const updatableMetadata = new WeakMap(); /** * 可注入元数据接口 */ -export interface InjectableMetadata { +export type InjectableMetadata = { /** * 是否可注入 */ @@ -39,7 +39,7 @@ export interface InjectableMetadata { /** * 可更新元数据接口 */ -export interface UpdatableMetadata { +export type UpdatableMetadata = { /** * 是否可更新 */ diff --git a/packages/core/src/Core/Plugin.ts b/packages/core/src/Core/Plugin.ts index e00c1d55..040441b1 100644 --- a/packages/core/src/Core/Plugin.ts +++ b/packages/core/src/Core/Plugin.ts @@ -51,7 +51,7 @@ export enum PluginState { * } * ``` */ -export interface IPlugin { +export type IPlugin = { /** * 插件唯一名称 * @@ -96,7 +96,7 @@ export interface IPlugin { /** * 插件元数据 */ -export interface IPluginMetadata { +export type IPluginMetadata = { /** * 插件名称 */ diff --git a/packages/core/src/Core/PluginServiceRegistry.ts b/packages/core/src/Core/PluginServiceRegistry.ts index dd903f41..c7a31839 100644 --- a/packages/core/src/Core/PluginServiceRegistry.ts +++ b/packages/core/src/Core/PluginServiceRegistry.ts @@ -28,7 +28,7 @@ * Note: __phantom is a required property to ensure TypeScript preserves generic * type information across packages. */ -export interface ServiceToken { +export type ServiceToken = { readonly id: symbol; readonly name: string; /** diff --git a/packages/core/src/Core/RuntimeModeService.ts b/packages/core/src/Core/RuntimeModeService.ts index ce00f50e..c36efffb 100644 --- a/packages/core/src/Core/RuntimeModeService.ts +++ b/packages/core/src/Core/RuntimeModeService.ts @@ -39,7 +39,7 @@ import { createServiceToken } from './PluginServiceRegistry'; * 运行时模式接口 * Runtime mode interface */ -export interface IRuntimeMode { +export type IRuntimeMode = { /** * 是否为编辑器模式 * Whether in editor mode @@ -110,7 +110,7 @@ type ModeChangeCallback = (mode: IRuntimeMode) => void; * 运行时模式服务配置 * Runtime mode service configuration */ -export interface RuntimeModeConfig { +export type RuntimeModeConfig = { /** 是否为编辑器模式 | Whether in editor mode */ isEditor?: boolean; /** 是否正在播放 | Whether playing */ diff --git a/packages/core/src/Core/ServiceContainer.ts b/packages/core/src/Core/ServiceContainer.ts index 015b9e7b..ab7c4433 100644 --- a/packages/core/src/Core/ServiceContainer.ts +++ b/packages/core/src/Core/ServiceContainer.ts @@ -7,7 +7,7 @@ const logger = createLogger('ServiceContainer'); * 服务基础接口 * 所有通过 ServiceContainer 管理的服务都应该实现此接口 */ -export interface IService { +export type IService = { /** * 释放服务占用的资源 * 当服务被注销或容器被清空时调用 diff --git a/packages/core/src/ECS/Core/ArchetypeSystem.ts b/packages/core/src/ECS/Core/ArchetypeSystem.ts index f951385a..0627c336 100644 --- a/packages/core/src/ECS/Core/ArchetypeSystem.ts +++ b/packages/core/src/ECS/Core/ArchetypeSystem.ts @@ -11,7 +11,7 @@ export type ArchetypeId = BitMask64Data; /** * 原型数据结构 */ -export interface Archetype { +export type Archetype = { /** 原型唯一标识符 */ id: ArchetypeId; /** 包含的组件类型 */ @@ -23,7 +23,7 @@ export interface Archetype { /** * 原型查询结果 */ -export interface ArchetypeQueryResult { +export type ArchetypeQueryResult = { /** 匹配的原型列表 */ archetypes: Archetype[]; /** 所有匹配实体的总数 */ diff --git a/packages/core/src/ECS/Core/CommandBuffer.ts b/packages/core/src/ECS/Core/CommandBuffer.ts index a100a6c3..7fbe63f6 100644 --- a/packages/core/src/ECS/Core/CommandBuffer.ts +++ b/packages/core/src/ECS/Core/CommandBuffer.ts @@ -25,7 +25,7 @@ export enum CommandType { * 延迟命令接口 * Deferred command interface */ -export interface DeferredCommand { +export type DeferredCommand = { /** 命令类型 | Command type */ type: CommandType; /** 目标实体 | Target entity */ diff --git a/packages/core/src/ECS/Core/ComponentStorage.ts b/packages/core/src/ECS/Core/ComponentStorage.ts index 45d9f5ab..b5d2d012 100644 --- a/packages/core/src/ECS/Core/ComponentStorage.ts +++ b/packages/core/src/ECS/Core/ComponentStorage.ts @@ -1,6 +1,7 @@ import { Component } from '../Component'; import { BitMask64Utils, BitMask64Data } from '../Utils/BigIntCompatibility'; -import { SoAStorage, SupportedTypedArray } from './SoAStorage'; +import { SoAStorage } from './SoAStorage'; +import type { SupportedTypedArray } from './SoAStorage'; import { createLogger } from '../../Utils/Logger'; import { getComponentTypeName, ComponentType } from '../Decorators'; import { ComponentRegistry, GlobalComponentRegistry } from './ComponentStorage/ComponentRegistry'; diff --git a/packages/core/src/ECS/Core/ComponentStorage/ComponentTypeUtils.ts b/packages/core/src/ECS/Core/ComponentStorage/ComponentTypeUtils.ts index c9095902..5f04c565 100644 --- a/packages/core/src/ECS/Core/ComponentStorage/ComponentTypeUtils.ts +++ b/packages/core/src/ECS/Core/ComponentStorage/ComponentTypeUtils.ts @@ -43,7 +43,7 @@ export const COMPONENT_EDITOR_OPTIONS = Symbol('ComponentEditorOptions'); * 组件编辑器选项 * Component editor options */ -export interface ComponentEditorOptions { +export type ComponentEditorOptions = { /** * 是否在 Inspector 中隐藏此组件 * Whether to hide this component in Inspector @@ -72,7 +72,7 @@ export interface ComponentEditorOptions { * 使用 Symbol 索引签名来类型安全地访问装饰器存储的元数据 * Uses Symbol index signature to safely access decorator-stored metadata */ -export interface ComponentTypeMetadata { +export type ComponentTypeMetadata = { readonly [COMPONENT_TYPE_NAME]?: string; readonly [COMPONENT_DEPENDENCIES]?: string[]; readonly [COMPONENT_EDITOR_OPTIONS]?: ComponentEditorOptions; @@ -82,7 +82,7 @@ export interface ComponentTypeMetadata { * 可写的组件类型元数据(用于装饰器设置) * Writable component type metadata (for decorator setting) */ -export interface WritableComponentTypeMetadata { +export type WritableComponentTypeMetadata = { [COMPONENT_TYPE_NAME]?: string; [COMPONENT_DEPENDENCIES]?: string[]; [COMPONENT_EDITOR_OPTIONS]?: ComponentEditorOptions; diff --git a/packages/core/src/ECS/Core/ComponentStorage/IComponentRegistry.ts b/packages/core/src/ECS/Core/ComponentStorage/IComponentRegistry.ts index 87e90761..167d8ff2 100644 --- a/packages/core/src/ECS/Core/ComponentStorage/IComponentRegistry.ts +++ b/packages/core/src/ECS/Core/ComponentStorage/IComponentRegistry.ts @@ -16,7 +16,7 @@ import type { ComponentType } from './ComponentTypeUtils'; * Component Registry Interface. * 组件注册表接口。 */ -export interface IComponentRegistry { +export type IComponentRegistry = { /** * Register component type and allocate bitmask. * 注册组件类型并分配位掩码。 diff --git a/packages/core/src/ECS/Core/EventSystem.ts b/packages/core/src/ECS/Core/EventSystem.ts index 8a7809bd..096bfa2b 100644 --- a/packages/core/src/ECS/Core/EventSystem.ts +++ b/packages/core/src/ECS/Core/EventSystem.ts @@ -13,7 +13,7 @@ export type AsyncEventHandler = (event: T) => Promise; /** * 事件监听器配置 */ -export interface EventListenerConfig { +export type EventListenerConfig = { /** 是否只执行一次 */ once?: boolean; /** 优先级(数字越大优先级越高) */ @@ -41,7 +41,7 @@ interface InternalEventListener { /** * 事件统计信息 */ -export interface EventStats { +export type EventStats = { /** 事件类型 */ eventType: string; /** 监听器数量 */ @@ -59,7 +59,7 @@ export interface EventStats { /** * 事件批处理配置 */ -export interface EventBatchConfig { +export type EventBatchConfig = { /** 批处理大小 */ batchSize: number; /** 批处理延迟(毫秒) */ diff --git a/packages/core/src/ECS/Core/Events/index.ts b/packages/core/src/ECS/Core/Events/index.ts index a8de6f02..e59ae784 100644 --- a/packages/core/src/ECS/Core/Events/index.ts +++ b/packages/core/src/ECS/Core/Events/index.ts @@ -1,2 +1,3 @@ export { EventBus, GlobalEventBus } from '../EventBus'; -export { TypeSafeEventSystem, EventListenerConfig, EventStats } from '../EventSystem'; +export { TypeSafeEventSystem } from '../EventSystem'; +export type { EventListenerConfig, EventStats } from '../EventSystem'; diff --git a/packages/core/src/ECS/Core/QuerySystem.ts b/packages/core/src/ECS/Core/QuerySystem.ts index b8ba3050..14f35d62 100644 --- a/packages/core/src/ECS/Core/QuerySystem.ts +++ b/packages/core/src/ECS/Core/QuerySystem.ts @@ -6,10 +6,12 @@ import { createLogger } from '../../Utils/Logger'; import { getComponentTypeName } from '../Decorators'; import { Archetype, ArchetypeSystem } from './ArchetypeSystem'; import { ReactiveQuery, ReactiveQueryConfig } from './ReactiveQuery'; -import { QueryCondition, QueryConditionType, QueryResult } from './QueryTypes'; +import type { QueryCondition, QueryResult } from './QueryTypes'; +import { QueryConditionType } from './QueryTypes'; import { CompiledQuery } from './Query/CompiledQuery'; -export { QueryCondition, QueryConditionType, QueryResult }; +export { QueryConditionType }; +export type { QueryCondition, QueryResult }; export { CompiledQuery }; /** diff --git a/packages/core/src/ECS/Core/QueryTypes.ts b/packages/core/src/ECS/Core/QueryTypes.ts index 64a5acd5..f5a6aeac 100644 --- a/packages/core/src/ECS/Core/QueryTypes.ts +++ b/packages/core/src/ECS/Core/QueryTypes.ts @@ -17,7 +17,7 @@ export enum QueryConditionType { /** * 查询条件接口 */ -export interface QueryCondition { +export type QueryCondition = { type: QueryConditionType; componentTypes: ComponentType[]; mask: BitMask64Data; @@ -26,7 +26,7 @@ export interface QueryCondition { /** * 实体查询结果接口 */ -export interface QueryResult { +export type QueryResult = { entities: readonly Entity[]; count: number; /** 查询执行时间(毫秒) */ diff --git a/packages/core/src/ECS/Core/ReactiveQuery.ts b/packages/core/src/ECS/Core/ReactiveQuery.ts index e680a9b5..1492ce3f 100644 --- a/packages/core/src/ECS/Core/ReactiveQuery.ts +++ b/packages/core/src/ECS/Core/ReactiveQuery.ts @@ -1,5 +1,6 @@ import { Entity } from '../Entity'; -import { QueryCondition, QueryConditionType } from './QueryTypes'; +import type { QueryCondition } from './QueryTypes'; +import { QueryConditionType } from './QueryTypes'; import { BitMask64Utils } from '../Utils/BigIntCompatibility'; import { createLogger } from '../../Utils/Logger'; @@ -20,7 +21,7 @@ export enum ReactiveQueryChangeType { /** * 响应式查询变化事件 */ -export interface ReactiveQueryChange { +export type ReactiveQueryChange = { /** 变化类型 */ type: ReactiveQueryChangeType; /** 变化的实体 */ @@ -41,7 +42,7 @@ export type ReactiveQueryListener = (change: ReactiveQueryChange) => void; /** * 响应式查询配置 */ -export interface ReactiveQueryConfig { +export type ReactiveQueryConfig = { /** 是否启用批量模式(减少通知频率) */ enableBatchMode?: boolean; /** 批量模式的延迟时间(毫秒) */ diff --git a/packages/core/src/ECS/Core/ReferenceTracker.ts b/packages/core/src/ECS/Core/ReferenceTracker.ts index e884e2d9..67cb93dc 100644 --- a/packages/core/src/ECS/Core/ReferenceTracker.ts +++ b/packages/core/src/ECS/Core/ReferenceTracker.ts @@ -54,7 +54,7 @@ const WeakRefImpl: IWeakRefConstructor = ( /** * Entity引用记录 */ -export interface EntityRefRecord { +export type EntityRefRecord = { component: IWeakRef; propertyKey: string; } diff --git a/packages/core/src/ECS/Core/SoAStorage.ts b/packages/core/src/ECS/Core/SoAStorage.ts index 53bc2916..8a880609 100644 --- a/packages/core/src/ECS/Core/SoAStorage.ts +++ b/packages/core/src/ECS/Core/SoAStorage.ts @@ -8,7 +8,7 @@ import { import { SoASerializer } from './SoASerializer'; // 重新导出类型,保持向后兼容 -export { SupportedTypedArray, TypedArrayTypeName } from './SoATypeRegistry'; +export type { SupportedTypedArray, TypedArrayTypeName } from './SoATypeRegistry'; export { SoATypeRegistry } from './SoATypeRegistry'; export { SoASerializer } from './SoASerializer'; diff --git a/packages/core/src/ECS/Core/SoATypeRegistry.ts b/packages/core/src/ECS/Core/SoATypeRegistry.ts index 593bf8e9..71f05de4 100644 --- a/packages/core/src/ECS/Core/SoATypeRegistry.ts +++ b/packages/core/src/ECS/Core/SoATypeRegistry.ts @@ -40,7 +40,7 @@ export type TypedArrayTypeName = /** * 字段元数据 */ -export interface FieldMetadata { +export type FieldMetadata = { name: string; type: 'number' | 'boolean' | 'string' | 'object'; arrayType?: TypedArrayTypeName; diff --git a/packages/core/src/ECS/Core/Storage/index.ts b/packages/core/src/ECS/Core/Storage/index.ts index b1757fa7..6b0879f6 100644 --- a/packages/core/src/ECS/Core/Storage/index.ts +++ b/packages/core/src/ECS/Core/Storage/index.ts @@ -1,4 +1,5 @@ -export { ComponentPool, ComponentPoolManager } from '../ComponentPool'; +export { ComponentPoolManager } from '../ComponentPool'; +export type { ComponentPool } from '../ComponentPool'; export { ComponentStorage, ComponentRegistry, GlobalComponentRegistry } from '../ComponentStorage'; export type { IComponentRegistry } from '../ComponentStorage'; export { EnableSoA, Float64, Float32, Int32, SerializeMap, SoAStorage } from '../SoAStorage'; diff --git a/packages/core/src/ECS/Core/StorageDecorators.ts b/packages/core/src/ECS/Core/StorageDecorators.ts index d2d270f7..d48a88ae 100644 --- a/packages/core/src/ECS/Core/StorageDecorators.ts +++ b/packages/core/src/ECS/Core/StorageDecorators.ts @@ -17,12 +17,8 @@ * ``` */ -// 从SoAStorage导入所有装饰器和类型 export { - // 启用装饰器 EnableSoA, - - // 数值类型装饰器 Float64, Float32, Int32, @@ -32,13 +28,10 @@ export { Int8, Uint8, Uint8Clamped, - - // 序列化装饰器 SerializeMap, SerializeSet, SerializeArray, - DeepCopy, - - // 类型定义 - SupportedTypedArray + DeepCopy } from './SoAStorage'; + +export type { SupportedTypedArray } from './SoAStorage'; diff --git a/packages/core/src/ECS/Core/SystemDependencyGraph.ts b/packages/core/src/ECS/Core/SystemDependencyGraph.ts index 705dfb3d..f22c36bb 100644 --- a/packages/core/src/ECS/Core/SystemDependencyGraph.ts +++ b/packages/core/src/ECS/Core/SystemDependencyGraph.ts @@ -48,7 +48,7 @@ interface GraphNode { * 系统依赖信息 * System dependency info */ -export interface SystemDependencyInfo { +export type SystemDependencyInfo = { /** 系统名称 | System name */ name: string; /** 在这些系统之前执行 | Execute before these systems */ diff --git a/packages/core/src/ECS/Core/SystemScheduler.ts b/packages/core/src/ECS/Core/SystemScheduler.ts index a48db72b..bcec61af 100644 --- a/packages/core/src/ECS/Core/SystemScheduler.ts +++ b/packages/core/src/ECS/Core/SystemScheduler.ts @@ -53,7 +53,7 @@ export const DEFAULT_STAGE_ORDER: readonly SystemStage[] = [ * 系统调度元数据 * System scheduling metadata */ -export interface SystemSchedulingMetadata { +export type SystemSchedulingMetadata = { /** 执行阶段 | Execution stage */ stage: SystemStage; /** 在这些系统之前执行 | Execute before these systems */ diff --git a/packages/core/src/ECS/Decorators/EntityRefDecorator.ts b/packages/core/src/ECS/Decorators/EntityRefDecorator.ts index b168de9b..5360c421 100644 --- a/packages/core/src/ECS/Decorators/EntityRefDecorator.ts +++ b/packages/core/src/ECS/Decorators/EntityRefDecorator.ts @@ -18,7 +18,7 @@ const ENTITY_REF_VALUES = Symbol('EntityRefValues'); /** * EntityRef元数据 */ -export interface EntityRefMetadata { +export type EntityRefMetadata = { properties: Set; } diff --git a/packages/core/src/ECS/Decorators/PropertyDecorator.ts b/packages/core/src/ECS/Decorators/PropertyDecorator.ts index 199dbe36..7039d6d0 100644 --- a/packages/core/src/ECS/Decorators/PropertyDecorator.ts +++ b/packages/core/src/ECS/Decorators/PropertyDecorator.ts @@ -1,4 +1,8 @@ -import 'reflect-metadata'; +/** + * 属性元数据存储 + * Property metadata storage + */ +const metadataStorage = new WeakMap>(); export type PropertyType = 'number' | 'integer' | 'string' | 'boolean' | 'color' | 'vector2' | 'vector3' | 'vector4' | 'enum' | 'asset' | 'array' | 'animationClips' | 'collisionLayer' | 'collisionMask' | 'entityRef'; @@ -21,7 +25,7 @@ export type EnumOption = string | { label: string; value: any }; * Action button configuration for property fields * 属性字段的操作按钮配置 */ -export interface PropertyAction { +export type PropertyAction = { /** Action identifier | 操作标识符 */ id: string; /** Button label | 按钮标签 */ @@ -36,7 +40,7 @@ export interface PropertyAction { * 控制关系声明 * Control relationship declaration */ -export interface PropertyControl { +export type PropertyControl = { /** 被控制的组件名称 | Target component name */ component: string; /** 被控制的属性名称 | Target property name */ @@ -253,25 +257,27 @@ export const PROPERTY_METADATA = Symbol.for('@esengine/property:metadata'); */ export function Property(options: PropertyOptions): PropertyDecorator { return (target: object, propertyKey: string | symbol) => { - const constructor = target.constructor; - const existingMetadata = Reflect.getMetadata(PROPERTY_METADATA, constructor) || {}; + const constructor = target.constructor as Function; + const existingMetadata = metadataStorage.get(constructor) || {}; existingMetadata[propertyKey as string] = options; - Reflect.defineMetadata(PROPERTY_METADATA, existingMetadata, constructor); + metadataStorage.set(constructor, existingMetadata); }; } /** * 获取组件类的所有属性元数据 + * Get all property metadata for a component class */ export function getPropertyMetadata(target: Function): Record | undefined { - return Reflect.getMetadata(PROPERTY_METADATA, target); + return metadataStorage.get(target) as Record | undefined; } /** * 检查组件类是否有属性元数据 + * Check if a component class has property metadata */ export function hasPropertyMetadata(target: Function): boolean { - return Reflect.hasMetadata(PROPERTY_METADATA, target); + return metadataStorage.has(target); } diff --git a/packages/core/src/ECS/Decorators/TypeDecorators.ts b/packages/core/src/ECS/Decorators/TypeDecorators.ts index c42422d4..92678243 100644 --- a/packages/core/src/ECS/Decorators/TypeDecorators.ts +++ b/packages/core/src/ECS/Decorators/TypeDecorators.ts @@ -30,7 +30,7 @@ export const SYSTEM_TYPE_NAME = Symbol('SystemTypeName'); * 系统类型元数据接口 * System type metadata interface */ -export interface SystemTypeMetadata { +export type SystemTypeMetadata = { readonly [SYSTEM_TYPE_NAME]?: string; readonly __systemMetadata__?: SystemMetadata; } @@ -74,7 +74,7 @@ type SystemConstructor = new (...args: an * 组件装饰器配置选项 * Component decorator options */ -export interface ComponentOptions { +export type ComponentOptions = { /** 依赖的其他组件名称列表 | List of required component names */ requires?: string[]; @@ -150,7 +150,7 @@ export function ECSComponent(typeName: string, options?: ComponentOptions) { * System 元数据配置 * System metadata configuration */ -export interface SystemMetadata { +export type SystemMetadata = { /** * 更新顺序(数值越小越先执行,默认0) * Update order (lower values execute first, default 0) diff --git a/packages/core/src/ECS/IScene.ts b/packages/core/src/ECS/IScene.ts index b5d5427a..80787b90 100644 --- a/packages/core/src/ECS/IScene.ts +++ b/packages/core/src/ECS/IScene.ts @@ -18,7 +18,7 @@ import type { IncrementalSnapshot, IncrementalSerializationOptions } from './Ser * * 定义场景应该实现的核心功能和属性,使用接口而非继承提供更灵活的实现方式。 */ -export interface IScene { +export type IScene = { /** * 场景名称 */ @@ -362,7 +362,7 @@ export interface IScene { /** * 场景工厂接口 */ -export interface ISceneFactory { +export type ISceneFactory = { /** * 创建场景实例 */ @@ -373,7 +373,7 @@ export interface ISceneFactory { * 场景配置接口 * Scene configuration interface */ -export interface ISceneConfig { +export type ISceneConfig = { /** * 场景名称 * Scene name diff --git a/packages/core/src/ECS/Serialization/ComponentSerializer.ts b/packages/core/src/ECS/Serialization/ComponentSerializer.ts index de240574..70ad274a 100644 --- a/packages/core/src/ECS/Serialization/ComponentSerializer.ts +++ b/packages/core/src/ECS/Serialization/ComponentSerializer.ts @@ -14,7 +14,7 @@ import type { SerializationContext, SerializedEntityRef } from './SerializationC export type { SerializableValue } from './ValueSerializer'; -export interface SerializedComponent { +export type SerializedComponent = { type: string; version: number; data: Record; diff --git a/packages/core/src/ECS/Serialization/EntitySerializer.ts b/packages/core/src/ECS/Serialization/EntitySerializer.ts index 09f88fa9..6fe81f95 100644 --- a/packages/core/src/ECS/Serialization/EntitySerializer.ts +++ b/packages/core/src/ECS/Serialization/EntitySerializer.ts @@ -15,7 +15,7 @@ import { SerializationContext } from './SerializationContext'; /** * 序列化后的实体数据 */ -export interface SerializedEntity { +export type SerializedEntity = { /** * 实体ID(运行时ID) * diff --git a/packages/core/src/ECS/Serialization/IncrementalSerializer.ts b/packages/core/src/ECS/Serialization/IncrementalSerializer.ts index 2e6a21ba..f9388b20 100644 --- a/packages/core/src/ECS/Serialization/IncrementalSerializer.ts +++ b/packages/core/src/ECS/Serialization/IncrementalSerializer.ts @@ -37,7 +37,7 @@ export enum ChangeOperation { /** * 实体变更记录 */ -export interface EntityChange { +export type EntityChange = { /** 操作类型 */ operation: ChangeOperation; /** 实体ID */ @@ -51,7 +51,7 @@ export interface EntityChange { /** * 组件变更记录 */ -export interface ComponentChange { +export type ComponentChange = { /** 操作类型 */ operation: ChangeOperation; /** 实体ID */ @@ -65,7 +65,7 @@ export interface ComponentChange { /** * 场景数据变更记录 */ -export interface SceneDataChange { +export type SceneDataChange = { /** 操作类型 */ operation: ChangeOperation; /** 变更的键 */ @@ -79,7 +79,7 @@ export interface SceneDataChange { /** * 增量序列化数据 */ -export interface IncrementalSnapshot { +export type IncrementalSnapshot = { /** 快照版本号 */ version: number; /** 时间戳 */ @@ -127,7 +127,7 @@ export type IncrementalSerializationFormat = 'json' | 'binary'; /** * 增量序列化选项 */ -export interface IncrementalSerializationOptions { +export type IncrementalSerializationOptions = { /** * 是否包含组件数据的深度对比 * 默认true,设为false可提升性能但可能漏掉组件内部字段变更 diff --git a/packages/core/src/ECS/Serialization/PrefabSerializer.ts b/packages/core/src/ECS/Serialization/PrefabSerializer.ts index ab1f6dd8..5638940e 100644 --- a/packages/core/src/ECS/Serialization/PrefabSerializer.ts +++ b/packages/core/src/ECS/Serialization/PrefabSerializer.ts @@ -35,7 +35,7 @@ export interface SerializedPrefabEntity extends SerializedEntity { * 预制体元数据 * Prefab metadata */ -export interface PrefabMetadata { +export type PrefabMetadata = { /** 预制体名称 | Prefab name */ name: string; /** 资产 GUID | Asset GUID */ @@ -58,7 +58,7 @@ export interface PrefabMetadata { * 组件类型注册条目 * Component type registry entry */ -export interface PrefabComponentTypeEntry { +export type PrefabComponentTypeEntry = { /** 组件类型名称 | Component type name */ typeName: string; /** 组件版本号 | Component version number */ @@ -69,7 +69,7 @@ export interface PrefabComponentTypeEntry { * 预制体数据格式 * Prefab data format */ -export interface PrefabData { +export type PrefabData = { /** 预制体格式版本号 | Prefab format version number */ version: number; /** 预制体元数据 | Prefab metadata */ @@ -84,7 +84,7 @@ export interface PrefabData { * 预制体创建选项 * Prefab creation options */ -export interface PrefabCreateOptions { +export type PrefabCreateOptions = { /** 预制体名称 | Prefab name */ name: string; /** 预制体描述 | Prefab description */ @@ -99,7 +99,7 @@ export interface PrefabCreateOptions { * 预制体实例化选项 * Prefab instantiation options */ -export interface PrefabInstantiateOptions { +export type PrefabInstantiateOptions = { /** 父实体 ID | Parent entity ID */ parentId?: number; /** 位置覆盖 | Position override */ diff --git a/packages/core/src/ECS/Serialization/SceneSerializer.ts b/packages/core/src/ECS/Serialization/SceneSerializer.ts index 6e60b642..ce4a55fa 100644 --- a/packages/core/src/ECS/Serialization/SceneSerializer.ts +++ b/packages/core/src/ECS/Serialization/SceneSerializer.ts @@ -38,7 +38,7 @@ export type MigrationFunction = ( /** * 场景序列化选项 */ -export interface SceneSerializationOptions { +export type SceneSerializationOptions = { /** * 要序列化的组件类型列表 * 如果未指定,则序列化所有可序列化的组件 @@ -69,7 +69,7 @@ export interface SceneSerializationOptions { /** * 场景反序列化选项 */ -export interface SceneDeserializationOptions { +export type SceneDeserializationOptions = { /** * 反序列化策略 * - 'merge': 合并到现有场景 @@ -97,7 +97,7 @@ export interface SceneDeserializationOptions { /** * 序列化后的场景数据 */ -export interface SerializedScene { +export type SerializedScene = { /** * 场景名称 */ diff --git a/packages/core/src/ECS/Serialization/SerializationContext.ts b/packages/core/src/ECS/Serialization/SerializationContext.ts index c39e5018..ac897b2d 100644 --- a/packages/core/src/ECS/Serialization/SerializationContext.ts +++ b/packages/core/src/ECS/Serialization/SerializationContext.ts @@ -6,7 +6,7 @@ import type { Component } from '../Component'; * * Serialized entity reference format. */ -export interface SerializedEntityRef { +export type SerializedEntityRef = { /** * 运行时 ID(向后兼容) * diff --git a/packages/core/src/ECS/Serialization/SerializationDecorators.ts b/packages/core/src/ECS/Serialization/SerializationDecorators.ts index f5e74163..e347cfe6 100644 --- a/packages/core/src/ECS/Serialization/SerializationDecorators.ts +++ b/packages/core/src/ECS/Serialization/SerializationDecorators.ts @@ -16,7 +16,7 @@ export const SERIALIZE_OPTIONS = Symbol('SerializeOptions'); /** * 可序列化配置选项 */ -export interface SerializableOptions { +export type SerializableOptions = { /** * 序列化版本号,用于数据迁移 */ @@ -31,7 +31,7 @@ export interface SerializableOptions { /** * 字段序列化配置 */ -export interface FieldSerializeOptions { +export type FieldSerializeOptions = { /** * 自定义序列化器 */ @@ -51,7 +51,7 @@ export interface FieldSerializeOptions { /** * 序列化元数据 */ -export interface SerializationMetadata { +export type SerializationMetadata = { options: SerializableOptions; fields: Map; ignoredFields: Set; diff --git a/packages/core/src/ECS/Systems/WorkerEntitySystem.ts b/packages/core/src/ECS/Systems/WorkerEntitySystem.ts index dd0f6293..be26cbd2 100644 --- a/packages/core/src/ECS/Systems/WorkerEntitySystem.ts +++ b/packages/core/src/ECS/Systems/WorkerEntitySystem.ts @@ -19,7 +19,7 @@ export type WorkerProcessFunction = any> = ( /** * Worker配置接口 */ -export interface WorkerSystemConfig { +export type WorkerSystemConfig = { /** 是否启用Worker并行处理 */ enableWorker?: boolean; /** Worker数量,默认为CPU核心数,自动限制在系统最大值内 */ diff --git a/packages/core/src/ECS/Utils/BigIntCompatibility.ts b/packages/core/src/ECS/Utils/BigIntCompatibility.ts index b68e88ef..ff1b2701 100644 --- a/packages/core/src/ECS/Utils/BigIntCompatibility.ts +++ b/packages/core/src/ECS/Utils/BigIntCompatibility.ts @@ -17,7 +17,7 @@ export type BitMask64Segment = [number,number] * 扩展模式(128+位):base[lo , hi] 作为第一段,segments 存储额外的 64 位段 * segments[0] 对应 bit 64-127,segments[1] 对应 bit 128-191,以此类推 */ -export interface BitMask64Data { +export type BitMask64Data = { base: BitMask64Segment; /** 扩展段数组,每个元素是一个 64 位段,用于超过 64 位的场景 */ segments?: BitMask64Segment[]; diff --git a/packages/core/src/ECS/Utils/Matcher.ts b/packages/core/src/ECS/Utils/Matcher.ts index ace58fb2..485a1b23 100644 --- a/packages/core/src/ECS/Utils/Matcher.ts +++ b/packages/core/src/ECS/Utils/Matcher.ts @@ -4,7 +4,7 @@ import { getComponentTypeName } from '../Decorators'; /** * 查询条件类型 */ -export interface QueryCondition { +export type QueryCondition = { all: ComponentType[]; any: ComponentType[]; none: ComponentType[]; diff --git a/packages/core/src/ECS/Utils/index.ts b/packages/core/src/ECS/Utils/index.ts index cf2feef7..683d407f 100644 --- a/packages/core/src/ECS/Utils/index.ts +++ b/packages/core/src/ECS/Utils/index.ts @@ -4,6 +4,7 @@ export { EntityProcessorList } from './EntityProcessorList'; export { IdentifierPool } from './IdentifierPool'; export { Matcher } from './Matcher'; export { Bits } from './Bits'; -export { BitMask64Utils, BitMask64Data } from './BigIntCompatibility'; +export { BitMask64Utils } from './BigIntCompatibility'; +export type { BitMask64Data } from './BigIntCompatibility'; export { SparseSet } from './SparseSet'; export { ComponentSparseSet } from './ComponentSparseSet'; diff --git a/packages/core/src/ECS/World.ts b/packages/core/src/ECS/World.ts index 407c3e5a..93df6ddc 100644 --- a/packages/core/src/ECS/World.ts +++ b/packages/core/src/ECS/World.ts @@ -10,7 +10,7 @@ const logger = createLogger('World'); * 全局系统接口 * 全局系统是在World级别运行的系统,不依赖特定Scene */ -export interface IGlobalSystem { +export type IGlobalSystem = { /** * 系统名称 */ @@ -40,7 +40,7 @@ export interface IGlobalSystem { /** * World配置接口 */ -export interface IWorldConfig { +export type IWorldConfig = { /** * World名称 */ diff --git a/packages/core/src/ECS/WorldManager.ts b/packages/core/src/ECS/WorldManager.ts index 78464f55..df8a97c8 100644 --- a/packages/core/src/ECS/WorldManager.ts +++ b/packages/core/src/ECS/WorldManager.ts @@ -7,7 +7,7 @@ const logger = createLogger('WorldManager'); /** * WorldManager配置接口 */ -export interface IWorldManagerConfig { +export type IWorldManagerConfig = { /** * 最大World数量 */ diff --git a/packages/core/src/ECS/index.ts b/packages/core/src/ECS/index.ts index 5e980d11..cb33418f 100644 --- a/packages/core/src/ECS/index.ts +++ b/packages/core/src/ECS/index.ts @@ -7,10 +7,12 @@ export * from './Utils'; export * from './Decorators'; export * from './Components'; export { Scene } from './Scene'; -export { IScene, ISceneFactory, ISceneConfig } from './IScene'; +export type { IScene, ISceneFactory, ISceneConfig } from './IScene'; export { SceneManager } from './SceneManager'; -export { World, IWorldConfig } from './World'; -export { WorldManager, IWorldManagerConfig } from './WorldManager'; +export { World } from './World'; +export type { IWorldConfig } from './World'; +export { WorldManager } from './WorldManager'; +export type { IWorldManagerConfig } from './WorldManager'; export * from './Core/Events'; export * from './Core/Query'; export * from './Core/Storage'; diff --git a/packages/core/src/Platform/IPlatformAdapter.ts b/packages/core/src/Platform/IPlatformAdapter.ts index 45a86b82..db5d1e73 100644 --- a/packages/core/src/Platform/IPlatformAdapter.ts +++ b/packages/core/src/Platform/IPlatformAdapter.ts @@ -2,7 +2,7 @@ * 平台适配器接口 * 用于适配不同的运行环境(浏览器、微信小游戏、字节跳动小游戏等) */ -export interface IPlatformAdapter { +export type IPlatformAdapter = { /** * 平台名称 */ @@ -60,7 +60,7 @@ export interface IPlatformAdapter { /** * Worker创建选项 */ -export interface WorkerCreationOptions { +export type WorkerCreationOptions = { /** * Worker类型 */ @@ -80,7 +80,7 @@ export interface WorkerCreationOptions { /** * 平台Worker接口 */ -export interface PlatformWorker { +export type PlatformWorker = { /** * 发送消息到Worker */ @@ -110,7 +110,7 @@ export interface PlatformWorker { /** * 平台配置 */ -export interface PlatformConfig { +export type PlatformConfig = { /** * 最大Worker数量限制 */ @@ -175,7 +175,7 @@ export interface PlatformConfig { /** * 平台检测结果 */ -export interface PlatformDetectionResult { +export type PlatformDetectionResult = { /** * 平台类型 */ diff --git a/packages/core/src/Plugins/DebugPlugin.ts b/packages/core/src/Plugins/DebugPlugin.ts index cc2a8763..e18b24fe 100644 --- a/packages/core/src/Plugins/DebugPlugin.ts +++ b/packages/core/src/Plugins/DebugPlugin.ts @@ -14,7 +14,7 @@ const logger = createLogger('DebugPlugin'); /** * ECS 调试插件统计信息 */ -export interface ECSDebugStats { +export type ECSDebugStats = { scenes: SceneDebugInfo[]; totalEntities: number; totalSystems: number; @@ -24,7 +24,7 @@ export interface ECSDebugStats { /** * 场景调试信息 */ -export interface SceneDebugInfo { +export type SceneDebugInfo = { name: string; entityCount: number; systems: SystemDebugInfo[]; @@ -34,7 +34,7 @@ export interface SceneDebugInfo { /** * 系统调试信息 */ -export interface SystemDebugInfo { +export type SystemDebugInfo = { name: string; enabled: boolean; updateOrder: number; @@ -49,7 +49,7 @@ export interface SystemDebugInfo { /** * 实体调试信息 */ -export interface EntityDebugInfo { +export type EntityDebugInfo = { id: number; name: string; enabled: boolean; @@ -61,7 +61,7 @@ export interface EntityDebugInfo { /** * 组件调试信息 */ -export interface ComponentDebugInfo { +export type ComponentDebugInfo = { type: string; data: any; } diff --git a/packages/core/src/Types/IUpdatable.ts b/packages/core/src/Types/IUpdatable.ts index e5c50a2b..b93768a6 100644 --- a/packages/core/src/Types/IUpdatable.ts +++ b/packages/core/src/Types/IUpdatable.ts @@ -3,7 +3,7 @@ * * 实现此接口的服务将在每帧被Core自动调用update方法 */ -export interface IUpdatable { +export type IUpdatable = { /** * 每帧更新方法 * diff --git a/packages/core/src/Types/TypeHelpers.ts b/packages/core/src/Types/TypeHelpers.ts index a08b09e2..d4ff31ab 100644 --- a/packages/core/src/Types/TypeHelpers.ts +++ b/packages/core/src/Types/TypeHelpers.ts @@ -48,7 +48,7 @@ export type ComponentTypeMap = { * 实体with组件的类型 * 表示一个实体确定拥有某些组件 */ -export interface EntityWithComponents { +export type EntityWithComponents = { readonly id: number; readonly name: string; @@ -163,7 +163,7 @@ export type TypedEventHandler = (data: T) => void | Promise; /** * 系统生命周期钩子类型 */ -export interface SystemLifecycleHooks { +export type SystemLifecycleHooks = { /** * 实体添加到系统时调用 */ @@ -188,7 +188,7 @@ export interface SystemLifecycleHooks /** * Fluent API构建器类型 */ -export interface TypeSafeBuilder { +export type TypeSafeBuilder = { /** * 完成构建 */ @@ -198,7 +198,7 @@ export interface TypeSafeBuilder { /** * 组件池类型 */ -export interface ComponentPool { +export type ComponentPool = { /** * 从池中获取组件实例 */ @@ -223,11 +223,11 @@ export interface ComponentPool { /** * 实体查询条件类型 */ -export interface TypedQueryCondition< +export type TypedQueryCondition< All extends readonly ComponentConstructor[] = [], Any extends readonly ComponentConstructor[] = [], None extends readonly ComponentConstructor[] = [] -> { +> = { all: All; any: Any; none: None; diff --git a/packages/core/src/Types/index.ts b/packages/core/src/Types/index.ts index bb4bd201..3d93d5aa 100644 --- a/packages/core/src/Types/index.ts +++ b/packages/core/src/Types/index.ts @@ -14,7 +14,7 @@ export * from './IUpdatable'; * 定义组件的基本契约。 * 在 ECS 架构中,组件应该是纯数据容器,不包含业务逻辑。 */ -export interface IComponent { +export type IComponent = { /** 组件唯一标识符 */ readonly id: number; /** 组件所属的实体ID */ @@ -49,7 +49,7 @@ export interface IComponent { * * 为现有的EntitySystem类提供类型定义 */ -export interface ISystemBase { +export type ISystemBase = { /** 系统名称 */ readonly systemName: string; /** 更新顺序/优先级 */ @@ -69,7 +69,7 @@ export interface ISystemBase { * 事件总线接口 * 提供类型安全的事件发布订阅机制 */ -export interface IEventBus { +export type IEventBus = { /** * 发射事件 * @param eventType 事件类型 @@ -145,7 +145,7 @@ export interface IEventBus { /** * 事件监听器配置接口 */ -export interface IEventListenerConfig { +export type IEventListenerConfig = { /** 是否只执行一次 */ once?: boolean; /** 优先级(数字越大优先级越高) */ @@ -159,7 +159,7 @@ export interface IEventListenerConfig { /** * 事件统计信息接口 */ -export interface IEventStats { +export type IEventStats = { /** 事件类型 */ eventType: string; /** 监听器数量 */ @@ -177,7 +177,7 @@ export interface IEventStats { /** * 事件数据基类接口 */ -export interface IEventData { +export type IEventData = { /** 事件时间戳 */ timestamp: number; /** 事件来源 */ @@ -245,7 +245,7 @@ export interface IPerformanceEventData extends IEventData { /** * ECS调试配置接口 */ -export interface IECSDebugConfig { +export type IECSDebugConfig = { /** 是否启用调试 */ enabled: boolean; /** WebSocket服务器URL */ @@ -269,7 +269,7 @@ export interface IECSDebugConfig { /** * Core配置接口 */ -export interface ICoreConfig { +export type ICoreConfig = { /** 是否启用调试模式 */ debug?: boolean; /** 调试配置 */ @@ -281,7 +281,7 @@ export interface ICoreConfig { /** * ECS调试数据接口 */ -export interface IECSDebugData { +export type IECSDebugData = { /** 时间戳 */ timestamp: number; /** 框架版本 */ @@ -307,7 +307,7 @@ export interface IECSDebugData { /** * 实体层次结构节点接口 */ -export interface IEntityHierarchyNode { +export type IEntityHierarchyNode = { id: number; name: string; active: boolean; @@ -325,7 +325,7 @@ export interface IEntityHierarchyNode { /** * 实体调试数据接口 */ -export interface IEntityDebugData { +export type IEntityDebugData = { /** 总实体数 */ totalEntities: number; /** 激活实体数 */ @@ -399,7 +399,7 @@ export interface IEntityDebugData { /** * 系统调试数据接口 */ -export interface ISystemDebugData { +export type ISystemDebugData = { /** 总系统数 */ totalSystems: number; /** 系统信息列表 */ @@ -422,7 +422,7 @@ export interface ISystemDebugData { /** * 性能调试数据接口 */ -export interface IPerformanceDebugData { +export type IPerformanceDebugData = { /** ECS框架执行时间(毫秒) */ frameTime: number; /** 引擎总帧时间(毫秒) */ @@ -472,7 +472,7 @@ export interface IPerformanceDebugData { /** * 组件调试数据接口 */ -export interface IComponentDebugData { +export type IComponentDebugData = { /** 组件类型数 */ componentTypes: number; /** 组件实例总数 */ @@ -492,7 +492,7 @@ export interface IComponentDebugData { /** * 场景调试数据接口 */ -export interface ISceneDebugData { +export type ISceneDebugData = { /** 当前场景名称 */ currentSceneName: string; /** 场景是否已初始化 */ diff --git a/packages/core/src/Utils/Debug/AdvancedProfilerCollector.ts b/packages/core/src/Utils/Debug/AdvancedProfilerCollector.ts index 2eea6430..3045f6ce 100644 --- a/packages/core/src/Utils/Debug/AdvancedProfilerCollector.ts +++ b/packages/core/src/Utils/Debug/AdvancedProfilerCollector.ts @@ -17,7 +17,7 @@ import { Time } from '../Time'; /** * 旧版 PerformanceMonitor 接口 (用于兼容) */ -export interface ILegacyPerformanceMonitor { +export type ILegacyPerformanceMonitor = { getAllSystemStats?: () => Map { +export type ITimer = { context: TContext; /** diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index c009c463..d137a364 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -48,7 +48,7 @@ export type { InjectableMetadata, UpdatableMetadata } from './Core/DI'; export { Emitter, FuncPack } from './Utils/Emitter'; export { GlobalManager } from './Utils/GlobalManager'; export { TimerManager } from './Utils/Timers/TimerManager'; -export { ITimer } from './Utils/Timers/ITimer'; +export type { ITimer } from './Utils/Timers/ITimer'; export { Timer } from './Utils/Timers/Timer'; // 日志系统 @@ -77,7 +77,8 @@ export * from './Utils'; export * from './Types'; // 显式导出ComponentPool类(解决与Types中ComponentPool接口的命名冲突) -export { ComponentPool, ComponentPoolManager } from './ECS/Core/Storage'; +export { ComponentPoolManager } from './ECS/Core/Storage'; +export type { ComponentPool } from './ECS/Core/Storage'; // 平台适配 export * from './Platform';