@esengine/ecs-framework 2.2.15 → 2.2.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @esengine/ecs-framework v2.2.15
2
+ * @esengine/ecs-framework v2.2.16
3
3
  * TypeScript definitions
4
4
  */
5
5
  /**
@@ -251,6 +251,8 @@ interface IComponent {
251
251
  onAddedToEntity(): void;
252
252
  /** 组件从实体移除时的回调 */
253
253
  onRemovedFromEntity(): void;
254
+ /** 组件反序列化后的回调 */
255
+ onDeserialized(): void | Promise<void>;
254
256
  }
255
257
  /**
256
258
  * 系统基础接口
@@ -771,6 +773,32 @@ declare abstract class Component implements IComponent {
771
773
  * 虽然保留此方法,但建议将复杂的清理逻辑放在 System 中处理。
772
774
  */
773
775
  onRemovedFromEntity(): void;
776
+ /**
777
+ * 组件反序列化后的回调
778
+ *
779
+ * 当组件从场景文件加载或快照恢复后调用,可以在此方法中恢复运行时数据。
780
+ *
781
+ * @remarks
782
+ * 这是一个生命周期钩子,用于恢复无法序列化的运行时数据。
783
+ * 例如:从图片路径重新加载图片尺寸信息,重建缓存等。
784
+ *
785
+ * @example
786
+ * ```typescript
787
+ * class TilemapComponent extends Component {
788
+ * public tilesetImage: string = '';
789
+ * private _tilesetData: TilesetData | undefined;
790
+ *
791
+ * public async onDeserialized(): Promise<void> {
792
+ * if (this.tilesetImage) {
793
+ * // 重新加载 tileset 图片并恢复运行时数据
794
+ * const img = await loadImage(this.tilesetImage);
795
+ * this.setTilesetInfo(img.width, img.height, ...);
796
+ * }
797
+ * }
798
+ * }
799
+ * ```
800
+ */
801
+ onDeserialized(): void | Promise<void>;
774
802
  }
775
803
 
776
804
  /**
@@ -1896,6 +1924,12 @@ interface IService {
1896
1924
  * 使用 any[] 以允许任意参数类型的构造函数
1897
1925
  */
1898
1926
  type ServiceType<T extends IService> = new (...args: any[]) => T;
1927
+ /**
1928
+ * 服务标识符
1929
+ *
1930
+ * 支持类构造函数或 Symbol 作为服务标识符
1931
+ */
1932
+ type ServiceIdentifier<T extends IService = IService> = ServiceType<T> | symbol;
1899
1933
  /**
1900
1934
  * 服务生命周期
1901
1935
  */
@@ -1992,35 +2026,42 @@ declare class ServiceContainer {
1992
2026
  *
1993
2027
  * 直接注册已创建的实例,自动视为单例。
1994
2028
  *
1995
- * @param type - 服务类型(构造函数,仅用作标识)
2029
+ * @param identifier - 服务标识符(构造函数或 Symbol)
1996
2030
  * @param instance - 服务实例
1997
2031
  *
1998
2032
  * @example
1999
2033
  * ```typescript
2000
2034
  * const config = new Config();
2001
2035
  * container.registerInstance(Config, config);
2036
+ *
2037
+ * // 使用 Symbol 作为标识符(适用于接口)
2038
+ * const IFileSystem = Symbol('IFileSystem');
2039
+ * container.registerInstance(IFileSystem, new TauriFileSystem());
2002
2040
  * ```
2003
2041
  */
2004
- registerInstance<T extends IService>(type: ServiceType<T>, instance: T): void;
2042
+ registerInstance<T extends IService>(identifier: ServiceIdentifier<T>, instance: T): void;
2005
2043
  /**
2006
2044
  * 解析服务
2007
2045
  *
2008
- * @param type - 服务类型
2046
+ * @param identifier - 服务标识符(构造函数或 Symbol)
2009
2047
  * @returns 服务实例
2010
2048
  * @throws 如果服务未注册或存在循环依赖
2011
2049
  *
2012
2050
  * @example
2013
2051
  * ```typescript
2014
2052
  * const timer = container.resolve(TimerManager);
2053
+ *
2054
+ * // 使用 Symbol
2055
+ * const fileSystem = container.resolve(IFileSystem);
2015
2056
  * ```
2016
2057
  */
2017
- resolve<T extends IService>(type: ServiceType<T>): T;
2058
+ resolve<T extends IService>(identifier: ServiceIdentifier<T>): T;
2018
2059
  /**
2019
2060
  * 尝试解析服务
2020
2061
  *
2021
2062
  * 如果服务未注册,返回null而不是抛出异常。
2022
2063
  *
2023
- * @param type - 服务类型
2064
+ * @param identifier - 服务标识符(构造函数或 Symbol)
2024
2065
  * @returns 服务实例或null
2025
2066
  *
2026
2067
  * @example
@@ -2031,31 +2072,31 @@ declare class ServiceContainer {
2031
2072
  * }
2032
2073
  * ```
2033
2074
  */
2034
- tryResolve<T extends IService>(type: ServiceType<T>): T | null;
2075
+ tryResolve<T extends IService>(identifier: ServiceIdentifier<T>): T | null;
2035
2076
  /**
2036
2077
  * 检查服务是否已注册
2037
2078
  *
2038
- * @param type - 服务类型
2079
+ * @param identifier - 服务标识符(构造函数或 Symbol)
2039
2080
  * @returns 是否已注册
2040
2081
  */
2041
- isRegistered<T extends IService>(type: ServiceType<T>): boolean;
2082
+ isRegistered<T extends IService>(identifier: ServiceIdentifier<T>): boolean;
2042
2083
  /**
2043
2084
  * 注销服务
2044
2085
  *
2045
- * @param type - 服务类型
2086
+ * @param identifier - 服务标识符(构造函数或 Symbol)
2046
2087
  * @returns 是否成功注销
2047
2088
  */
2048
- unregister<T extends IService>(type: ServiceType<T>): boolean;
2089
+ unregister<T extends IService>(identifier: ServiceIdentifier<T>): boolean;
2049
2090
  /**
2050
2091
  * 清空所有服务
2051
2092
  */
2052
2093
  clear(): void;
2053
2094
  /**
2054
- * 获取所有已注册的服务类型
2095
+ * 获取所有已注册的服务标识符
2055
2096
  *
2056
- * @returns 服务类型数组
2097
+ * @returns 服务标识符数组
2057
2098
  */
2058
- getRegisteredServices(): ServiceType<IService>[];
2099
+ getRegisteredServices(): ServiceIdentifier[];
2059
2100
  /**
2060
2101
  * 更新所有使用@Updatable装饰器标记的服务
2061
2102
  *
@@ -2292,6 +2333,7 @@ interface QueryCondition$1 {
2292
2333
  tag?: number;
2293
2334
  name?: string;
2294
2335
  component?: ComponentType;
2336
+ matchNothing?: boolean;
2295
2337
  }
2296
2338
  /**
2297
2339
  * 实体匹配条件描述符
@@ -2349,6 +2391,29 @@ declare class Matcher {
2349
2391
  * 创建空匙配器
2350
2392
  */
2351
2393
  static empty(): Matcher;
2394
+ /**
2395
+ * 创建不匹配任何实体的匹配器
2396
+ * 用于只需要 onBegin/onEnd 生命周期方法但不需要处理实体的系统
2397
+ *
2398
+ * @example
2399
+ * ```typescript
2400
+ * // 创建一个只在帧开始时执行的系统
2401
+ * class FrameBeginSystem extends EntitySystem {
2402
+ * constructor() {
2403
+ * super(Matcher.nothing());
2404
+ * }
2405
+ *
2406
+ * protected onBegin(): void {
2407
+ * // 每帧开始时执行
2408
+ * }
2409
+ *
2410
+ * protected process(entities: readonly Entity[]): void {
2411
+ * // 永远不会被调用,因为没有实体匹配
2412
+ * }
2413
+ * }
2414
+ * ```
2415
+ */
2416
+ static nothing(): Matcher;
2352
2417
  /**
2353
2418
  * 必须包含所有指定组件
2354
2419
  * @param types 组件类型
@@ -2407,8 +2472,13 @@ declare class Matcher {
2407
2472
  getCondition(): Readonly<QueryCondition$1>;
2408
2473
  /**
2409
2474
  * 检查是否为空条件
2475
+ * 注意:matchNothing 不算空条件,因为它是明确的"不匹配任何实体"语义
2410
2476
  */
2411
2477
  isEmpty(): boolean;
2478
+ /**
2479
+ * 检查是否为"不匹配任何实体"的匹配器
2480
+ */
2481
+ isNothing(): boolean;
2412
2482
  /**
2413
2483
  * 重置所有条件
2414
2484
  */
@@ -4513,6 +4583,10 @@ declare class SceneSerializer {
4513
4583
  * @param options 反序列化选项
4514
4584
  */
4515
4585
  static deserialize(scene: IScene, saveData: string | Uint8Array, options?: SceneDeserializationOptions): void;
4586
+ /**
4587
+ * 递归调用实体及其子实体所有组件的 onDeserialized 方法
4588
+ */
4589
+ private static callOnDeserializedRecursively;
4516
4590
  /**
4517
4591
  * 递归添加实体的所有子实体到场景
4518
4592
  *
@@ -7856,6 +7930,19 @@ declare global {
7856
7930
  }
7857
7931
 
7858
7932
  type PropertyType = 'number' | 'integer' | 'string' | 'boolean' | 'color' | 'vector2' | 'vector3' | 'enum' | 'asset' | 'animationClips';
7933
+ /**
7934
+ * 资源类型
7935
+ * Asset type for asset properties
7936
+ */
7937
+ type AssetType = 'texture' | 'audio' | 'scene' | 'prefab' | 'animation' | 'any';
7938
+ /**
7939
+ * 枚举选项 - 支持简单字符串或带标签的对象
7940
+ * Enum option - supports simple string or labeled object
7941
+ */
7942
+ type EnumOption = string | {
7943
+ label: string;
7944
+ value: any;
7945
+ };
7859
7946
  /**
7860
7947
  * Action button configuration for property fields
7861
7948
  * 属性字段的操作按钮配置
@@ -7880,31 +7967,94 @@ interface PropertyControl {
7880
7967
  /** 被控制的属性名称 | Target property name */
7881
7968
  property: string;
7882
7969
  }
7883
- interface PropertyOptions {
7884
- /** 属性类型 */
7885
- type: PropertyType;
7886
- /** 显示标签 */
7970
+ /**
7971
+ * 属性基础选项
7972
+ * Base property options shared by all types
7973
+ */
7974
+ interface PropertyOptionsBase {
7975
+ /** 显示标签 | Display label */
7887
7976
  label?: string;
7888
- /** 最小值 (number/integer) */
7889
- min?: number;
7890
- /** 最大值 (number/integer) */
7891
- max?: number;
7892
- /** 步进值 (number/integer) */
7893
- step?: number;
7894
- /** 枚举选项 (enum) */
7895
- options?: Array<{
7896
- label: string;
7897
- value: any;
7898
- }>;
7899
- /** 是否只读 */
7977
+ /** 是否只读 | Read-only flag */
7900
7978
  readOnly?: boolean;
7901
- /** 资源文件扩展名 (asset) */
7902
- fileExtension?: string;
7903
- /** Action buttons for this property | 属性的操作按钮 */
7979
+ /** Action buttons | 操作按钮 */
7904
7980
  actions?: PropertyAction[];
7905
7981
  /** 此属性控制的其他组件属性 | Properties this field controls */
7906
7982
  controls?: PropertyControl[];
7907
7983
  }
7984
+ /**
7985
+ * 数值类型属性选项
7986
+ * Number property options
7987
+ */
7988
+ interface NumberPropertyOptions extends PropertyOptionsBase {
7989
+ type: 'number' | 'integer';
7990
+ min?: number;
7991
+ max?: number;
7992
+ step?: number;
7993
+ }
7994
+ /**
7995
+ * 字符串类型属性选项
7996
+ * String property options
7997
+ */
7998
+ interface StringPropertyOptions extends PropertyOptionsBase {
7999
+ type: 'string';
8000
+ /** 多行文本 | Multiline text */
8001
+ multiline?: boolean;
8002
+ }
8003
+ /**
8004
+ * 布尔类型属性选项
8005
+ * Boolean property options
8006
+ */
8007
+ interface BooleanPropertyOptions extends PropertyOptionsBase {
8008
+ type: 'boolean';
8009
+ }
8010
+ /**
8011
+ * 颜色类型属性选项
8012
+ * Color property options
8013
+ */
8014
+ interface ColorPropertyOptions extends PropertyOptionsBase {
8015
+ type: 'color';
8016
+ /** 是否包含透明度 | Include alpha channel */
8017
+ alpha?: boolean;
8018
+ }
8019
+ /**
8020
+ * 向量类型属性选项
8021
+ * Vector property options
8022
+ */
8023
+ interface VectorPropertyOptions extends PropertyOptionsBase {
8024
+ type: 'vector2' | 'vector3';
8025
+ }
8026
+ /**
8027
+ * 枚举类型属性选项
8028
+ * Enum property options
8029
+ */
8030
+ interface EnumPropertyOptions extends PropertyOptionsBase {
8031
+ type: 'enum';
8032
+ /** 枚举选项列表 | Enum options list */
8033
+ options: EnumOption[];
8034
+ }
8035
+ /**
8036
+ * 资源类型属性选项
8037
+ * Asset property options
8038
+ */
8039
+ interface AssetPropertyOptions extends PropertyOptionsBase {
8040
+ type: 'asset';
8041
+ /** 资源类型 | Asset type */
8042
+ assetType?: AssetType;
8043
+ /** 文件扩展名过滤 | File extension filter */
8044
+ extensions?: string[];
8045
+ }
8046
+ /**
8047
+ * 动画剪辑类型属性选项
8048
+ * Animation clips property options
8049
+ */
8050
+ interface AnimationClipsPropertyOptions extends PropertyOptionsBase {
8051
+ type: 'animationClips';
8052
+ }
8053
+ /**
8054
+ * 属性选项联合类型
8055
+ * Property options union type
8056
+ */
8057
+ type PropertyOptions = NumberPropertyOptions | StringPropertyOptions | BooleanPropertyOptions | ColorPropertyOptions | VectorPropertyOptions | EnumPropertyOptions | AssetPropertyOptions | AnimationClipsPropertyOptions;
7908
8058
  declare const PROPERTY_METADATA: unique symbol;
7909
8059
  /**
7910
8060
  * 属性装饰器 - 声明组件属性的编辑器元数据
@@ -11859,4 +12009,4 @@ declare function supportsFeature(feature: 'worker' | 'shared-array-buffer' | 'tr
11859
12009
  declare function hasAdapter(): boolean;
11860
12010
 
11861
12011
  export { BinarySerializer, BitMask64Utils, Bits, COMPONENT_DEPENDENCIES, COMPONENT_TYPE_NAME, ChangeOperation, Colors, Component, ComponentDataCollector, ComponentPool, ComponentPoolManager, ComponentRegistry, ComponentSerializer, ComponentSparseSet, ComponentStorage, ConsoleLogger, Core, DebugConfigService, DebugManager, DebugPlugin, DeepCopy, ECSComponent, ECSEventType, ECSFluentAPI, ECSSystem, ENTITY_REF_METADATA, EVENT_TYPES, Emitter, EnableSoA, Entity, EntityDataCollector, EntityList, EntityProcessorList, EntityRef, EntitySerializer, EntitySystem, EventBus, EventPriority, EventTypeValidator, Float32, Float64, FuncPack, GlobalEventBus, GlobalManager, IdentifierPool, IgnoreSerialization, IncrementalSerializer, InjectProperty, Injectable, Int16, Int32, Int8, IntervalSystem, LogLevel, Logger, LoggerManager, Matcher, MigrationBuilder, NumberExtension, PROPERTY_METADATA, PassiveSystem, PerformanceDataCollector, PerformanceMonitor, PerformanceWarningType, PlatformDetector, PlatformManager, PluginManager, PluginState, Pool, PoolManager, ProcessingSystem, Property, QuerySystem, ReactiveQuery, ReactiveQueryChangeType, ReferenceTracker, SERIALIZABLE_METADATA, SERIALIZE_FIELD, SERIALIZE_OPTIONS, SYSTEM_TYPE_NAME, Scene, SceneDataCollector, SceneManager, SceneSerializer, Serializable, Serialize, SerializeArray, SerializeAsMap, SerializeAsSet, SerializeMap, SerializeSet, ServiceContainer, ServiceLifetime, SoAStorage, SparseSet, SystemDataCollector, Time, Timer, TimerManager, TypeSafeEventSystem, TypeUtils, TypedEntityBuilder, TypedQueryBuilder, TypedQueryResult, Uint16, Uint32, Uint8, Uint8Clamped, Updatable, VersionMigrationManager, WebSocketManager, WorkerEntitySystem, World, WorldManager, addAndConfigure, buildEntity, createECSAPI, createInstance, createLogger, createQuery, getBasicWorkerConfig, getComponentDependencies, getComponentInstanceTypeName, getComponentTypeName, getComponents, getCurrentAdapter, getEntityRefMetadata, getFullPlatformConfig, getOrAddComponent, getPropertyInjectMetadata, getPropertyMetadata, getSceneByEntityId, getSerializationMetadata, getSystemInstanceTypeName, getSystemMetadata, getSystemTypeName, getUpdatableMetadata, hasAdapter, hasAnyComponent, hasComponents, hasEntityRef, hasPropertyMetadata, injectProperties, isComponentArray, isComponentType, isSerializable, isUpdatable, queryFor, queryForAll, registerInjectable, registerPlatformAdapter, requireComponent, resetLoggerColors, setGlobalLogLevel, setLoggerColors, setLoggerFactory, supportsFeature, tryGetComponent, updateComponent };
11862
- export type { AnyComponentConstructor, BitMask64Data, ComponentChange, ComponentConstructor, ComponentDebugInfo, ComponentInstance, ComponentMigrationFunction, ComponentOptions, ComponentType$1 as ComponentType, ComponentTypeMap, ComponentTypeName, ComponentTypeNames, DataOnly, DeepPartial, DeepReadonly, DeserializationStrategy, ECSDebugStats, EntityChange, EntityDebugInfo, EntityRefMetadata, EntityRefRecord, EntityWithComponents, EventListenerConfig, EventStats, ExtractComponents, FieldSerializeOptions, IComponent, IComponentDebugData, IComponentEventData, ICoreConfig, IECSDebugConfig, IECSDebugData, IEntityDebugData, IEntityEventData, IEntityHierarchyNode, IEventBus, IEventData, IEventListenerConfig, IEventStats, ILogger, IPerformanceDebugData, IPerformanceEventData, IPlatformAdapter, IPlugin, IPluginMetadata, IPoolable, IScene, ISceneConfig, ISceneDebugData, ISceneEventData, ISceneFactory, IService, ISystemBase, ISystemDebugData, ISystemEventData, ITimer, IUpdatable, IWorldConfig, IWorldManagerConfig, IncrementalSerializationFormat, IncrementalSerializationOptions, IncrementalSnapshot, InjectableMetadata, LoggerColorConfig, LoggerConfig, MigrationFunction, PartialComponent, PerformanceData, PerformanceStats, PerformanceThresholds, PerformanceWarning, PlatformConfig, PlatformDetectionResult, PlatformWorker, PoolStats, PropertyControl, PropertyOptions, PropertyType, QueryResult$1 as QueryResult, ReactiveQueryChange, ReactiveQueryConfig, ReactiveQueryListener, ReadonlyComponent, SceneDataChange, SceneDebugInfo, SceneDeserializationOptions, SceneMigrationFunction, SceneSerializationOptions, SerializableComponent, SerializableFields, SerializableOptions, SerializationFormat, SerializationMetadata, SerializedComponent, SerializedEntity, SerializedScene, ServiceType, SharedArrayBufferProcessFunction, SupportedTypedArray, SystemDebugInfo, SystemEntityType, SystemLifecycleHooks, SystemMetadata, TypeSafeBuilder, TypedEventHandler, TypedQueryCondition, UpdatableMetadata, ValidComponent, ValidComponentArray, WorkerCreationOptions, WorkerProcessFunction, WorkerSystemConfig };
12012
+ export type { AnyComponentConstructor, AssetType, BitMask64Data, ComponentChange, ComponentConstructor, ComponentDebugInfo, ComponentInstance, ComponentMigrationFunction, ComponentOptions, ComponentType$1 as ComponentType, ComponentTypeMap, ComponentTypeName, ComponentTypeNames, DataOnly, DeepPartial, DeepReadonly, DeserializationStrategy, ECSDebugStats, EntityChange, EntityDebugInfo, EntityRefMetadata, EntityRefRecord, EntityWithComponents, EnumOption, EventListenerConfig, EventStats, ExtractComponents, FieldSerializeOptions, IComponent, IComponentDebugData, IComponentEventData, ICoreConfig, IECSDebugConfig, IECSDebugData, IEntityDebugData, IEntityEventData, IEntityHierarchyNode, IEventBus, IEventData, IEventListenerConfig, IEventStats, ILogger, IPerformanceDebugData, IPerformanceEventData, IPlatformAdapter, IPlugin, IPluginMetadata, IPoolable, IScene, ISceneConfig, ISceneDebugData, ISceneEventData, ISceneFactory, IService, ISystemBase, ISystemDebugData, ISystemEventData, ITimer, IUpdatable, IWorldConfig, IWorldManagerConfig, IncrementalSerializationFormat, IncrementalSerializationOptions, IncrementalSnapshot, InjectableMetadata, LoggerColorConfig, LoggerConfig, MigrationFunction, PartialComponent, PerformanceData, PerformanceStats, PerformanceThresholds, PerformanceWarning, PlatformConfig, PlatformDetectionResult, PlatformWorker, PoolStats, PropertyAction, PropertyControl, PropertyOptions, PropertyType, QueryResult$1 as QueryResult, ReactiveQueryChange, ReactiveQueryConfig, ReactiveQueryListener, ReadonlyComponent, SceneDataChange, SceneDebugInfo, SceneDeserializationOptions, SceneMigrationFunction, SceneSerializationOptions, SerializableComponent, SerializableFields, SerializableOptions, SerializationFormat, SerializationMetadata, SerializedComponent, SerializedEntity, SerializedScene, ServiceIdentifier, ServiceType, SharedArrayBufferProcessFunction, SupportedTypedArray, SystemDebugInfo, SystemEntityType, SystemLifecycleHooks, SystemMetadata, TypeSafeBuilder, TypedEventHandler, TypedQueryCondition, UpdatableMetadata, ValidComponent, ValidComponentArray, WorkerCreationOptions, WorkerProcessFunction, WorkerSystemConfig };