@esengine/ecs-framework 2.2.2 → 2.2.3

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.2
2
+ * @esengine/ecs-framework v2.2.3
3
3
  * TypeScript definitions
4
4
  */
5
5
  /**
@@ -7417,6 +7417,184 @@ declare class ECSFluentAPI {
7417
7417
  */
7418
7418
  declare function createECSAPI(scene: IScene, querySystem: QuerySystem, eventSystem: TypeSafeEventSystem): ECSFluentAPI;
7419
7419
 
7420
+ /**
7421
+ * 单场景管理器
7422
+ *
7423
+ * 适用场景:
7424
+ * - 单人游戏
7425
+ * - 简单场景切换
7426
+ * - 不需要多World隔离的项目
7427
+ *
7428
+ * 特点:
7429
+ * - 轻量级,零额外开销
7430
+ * - 简单直观的API
7431
+ * - 支持延迟场景切换
7432
+ * - 自动管理ECS API
7433
+ *
7434
+ * @example
7435
+ * ```typescript
7436
+ * // 初始化Core
7437
+ * Core.create({ debug: true });
7438
+ *
7439
+ * // 创建场景管理器
7440
+ * const sceneManager = new SceneManager();
7441
+ *
7442
+ * // 设置场景
7443
+ * class GameScene extends Scene {
7444
+ * initialize() {
7445
+ * const player = this.createEntity('Player');
7446
+ * player.addComponent(new Transform(100, 100));
7447
+ * }
7448
+ * }
7449
+ *
7450
+ * sceneManager.setScene(new GameScene());
7451
+ *
7452
+ * // 游戏循环
7453
+ * function gameLoop(deltaTime: number) {
7454
+ * Core.update(deltaTime); // 更新全局服务
7455
+ * sceneManager.update(); // 更新场景
7456
+ * }
7457
+ *
7458
+ * // 延迟切换场景(下一帧生效)
7459
+ * sceneManager.loadScene(new MenuScene());
7460
+ * ```
7461
+ */
7462
+ declare class SceneManager implements IService {
7463
+ /**
7464
+ * 内部默认World
7465
+ */
7466
+ private _defaultWorld;
7467
+ /**
7468
+ * 待切换的下一个场景(延迟切换用)
7469
+ */
7470
+ private _nextScene;
7471
+ /**
7472
+ * ECS流式API
7473
+ */
7474
+ private _ecsAPI;
7475
+ /**
7476
+ * 日志器
7477
+ */
7478
+ private _logger;
7479
+ /**
7480
+ * 场景切换回调函数
7481
+ */
7482
+ private _onSceneChangedCallback?;
7483
+ /**
7484
+ * 默认场景ID
7485
+ */
7486
+ private static readonly DEFAULT_SCENE_ID;
7487
+ constructor();
7488
+ /**
7489
+ * 设置场景切换回调
7490
+ *
7491
+ * @param callback 场景切换时的回调函数
7492
+ * @internal
7493
+ */
7494
+ setSceneChangedCallback(callback: () => void): void;
7495
+ /**
7496
+ * 设置当前场景(立即切换)
7497
+ *
7498
+ * 会自动处理旧场景的结束和新场景的初始化。
7499
+ *
7500
+ * @param scene - 要设置的场景实例
7501
+ * @returns 返回设置的场景实例,便于链式调用
7502
+ *
7503
+ * @example
7504
+ * ```typescript
7505
+ * const gameScene = sceneManager.setScene(new GameScene());
7506
+ * console.log(gameScene.name); // 可以立即使用返回的场景
7507
+ * ```
7508
+ */
7509
+ setScene<T extends IScene>(scene: T): T;
7510
+ /**
7511
+ * 延迟加载场景(下一帧切换)
7512
+ *
7513
+ * 场景不会立即切换,而是在下一次调用 update() 时切换。
7514
+ * 这对于避免在当前帧的中途切换场景很有用。
7515
+ *
7516
+ * @param scene - 要加载的场景实例
7517
+ *
7518
+ * @example
7519
+ * ```typescript
7520
+ * // 在某个System中触发场景切换
7521
+ * class GameOverSystem extends EntitySystem {
7522
+ * process(entities: readonly Entity[]) {
7523
+ * if (playerHealth <= 0) {
7524
+ * sceneManager.loadScene(new GameOverScene());
7525
+ * // 当前帧继续执行,场景将在下一帧切换
7526
+ * }
7527
+ * }
7528
+ * }
7529
+ * ```
7530
+ */
7531
+ loadScene<T extends IScene>(scene: T): void;
7532
+ /**
7533
+ * 获取当前活跃的场景
7534
+ *
7535
+ * @returns 当前场景实例,如果没有场景则返回null
7536
+ */
7537
+ get currentScene(): IScene | null;
7538
+ /**
7539
+ * 获取ECS流式API
7540
+ *
7541
+ * 提供便捷的实体查询、事件发射等功能。
7542
+ *
7543
+ * @returns ECS API实例,如果当前没有场景则返回null
7544
+ *
7545
+ * @example
7546
+ * ```typescript
7547
+ * const api = sceneManager.api;
7548
+ * if (api) {
7549
+ * // 查询所有敌人
7550
+ * const enemies = api.find(Enemy, Transform);
7551
+ *
7552
+ * // 发射事件
7553
+ * api.emit('game:start', { level: 1 });
7554
+ * }
7555
+ * ```
7556
+ */
7557
+ get api(): ECSFluentAPI | null;
7558
+ /**
7559
+ * 更新场景
7560
+ *
7561
+ * 应该在每帧的游戏循环中调用。
7562
+ * 会自动处理延迟场景切换。
7563
+ *
7564
+ * @example
7565
+ * ```typescript
7566
+ * function gameLoop(deltaTime: number) {
7567
+ * Core.update(deltaTime);
7568
+ * sceneManager.update(); // 每帧调用
7569
+ * }
7570
+ * ```
7571
+ */
7572
+ update(): void;
7573
+ /**
7574
+ * 销毁场景管理器
7575
+ *
7576
+ * 会自动结束当前场景并清理所有资源。
7577
+ * 通常在应用程序关闭时调用。
7578
+ */
7579
+ destroy(): void;
7580
+ /**
7581
+ * 检查是否有活跃场景
7582
+ *
7583
+ * @returns 如果有活跃场景返回true,否则返回false
7584
+ */
7585
+ get hasScene(): boolean;
7586
+ /**
7587
+ * 检查是否有待切换的场景
7588
+ *
7589
+ * @returns 如果有待切换场景返回true,否则返回false
7590
+ */
7591
+ get hasPendingScene(): boolean;
7592
+ /**
7593
+ * 释放资源(IService接口)
7594
+ */
7595
+ dispose(): void;
7596
+ }
7597
+
7420
7598
  /**
7421
7599
  * 全局系统接口
7422
7600
  * 全局系统是在World级别运行的系统,不依赖特定Scene
@@ -7654,12 +7832,6 @@ interface IWorldManagerConfig {
7654
7832
  * 是否启用调试模式
7655
7833
  */
7656
7834
  debug?: boolean;
7657
- /**
7658
- * 是否创建默认World(默认true)
7659
- *
7660
- * 当通过Core使用时应该为true,直接使用WorldManager时可设为false
7661
- */
7662
- createDefaultWorld?: boolean;
7663
7835
  }
7664
7836
  /**
7665
7837
  * World管理器 - 管理所有World实例
@@ -7689,38 +7861,24 @@ interface IWorldManagerConfig {
7689
7861
  *
7690
7862
  * // 游戏循环
7691
7863
  * function gameLoop(deltaTime: number) {
7692
- * Core.update(deltaTime); // 自动更新所有@Updatable服务(包括WorldManager)
7864
+ * Core.update(deltaTime);
7865
+ * worldManager.updateAll(); // 更新所有活跃World
7693
7866
  * }
7694
7867
  * ```
7695
7868
  */
7696
- declare class WorldManager implements IService, IUpdatable {
7697
- /**
7698
- * 默认World的ID
7699
- */
7700
- static readonly DEFAULT_WORLD_ID = "__default__";
7869
+ declare class WorldManager implements IService {
7701
7870
  private readonly _config;
7702
7871
  private readonly _worlds;
7703
7872
  private readonly _activeWorlds;
7704
7873
  private _cleanupTimer;
7705
7874
  private _isRunning;
7706
7875
  constructor(config?: IWorldManagerConfig);
7707
- /**
7708
- * 获取默认World
7709
- *
7710
- * 默认World由WorldManager自动创建,供SceneManager使用。
7711
- * 此方法主要供SceneManager内部使用。
7712
- *
7713
- * @returns 默认World实例
7714
- */
7715
- getDefaultWorld(): World;
7716
7876
  /**
7717
7877
  * 创建新World
7718
7878
  */
7719
7879
  createWorld(worldId: string, config?: IWorldConfig): World;
7720
7880
  /**
7721
7881
  * 移除World
7722
- *
7723
- * 注意:默认World不能被删除
7724
7882
  */
7725
7883
  removeWorld(worldId: string): boolean;
7726
7884
  /**
@@ -7746,12 +7904,18 @@ declare class WorldManager implements IService, IUpdatable {
7746
7904
  /**
7747
7905
  * 更新所有活跃的World
7748
7906
  *
7749
- * 此方法由ServiceContainer自动调用(@Updatable装饰器)
7907
+ * 应该在每帧的游戏循环中调用。
7750
7908
  * 会自动更新所有活跃World的全局系统和场景。
7751
7909
  *
7752
- * @param deltaTime 帧时间间隔(未使用,保留用于接口兼容)
7910
+ * @example
7911
+ * ```typescript
7912
+ * function gameLoop(deltaTime: number) {
7913
+ * Core.update(deltaTime); // 更新全局服务
7914
+ * worldManager.updateAll(); // 更新所有World
7915
+ * }
7916
+ * ```
7753
7917
  */
7754
- update(deltaTime?: number): void;
7918
+ updateAll(): void;
7755
7919
  /**
7756
7920
  * 获取所有激活的World
7757
7921
  */
@@ -7800,12 +7964,6 @@ declare class WorldManager implements IService, IUpdatable {
7800
7964
  * 是否启用调试模式
7801
7965
  */
7802
7966
  debug?: boolean;
7803
- /**
7804
- * 是否创建默认World(默认true)
7805
- *
7806
- * 当通过Core使用时应该为true,直接使用WorldManager时可设为false
7807
- */
7808
- createDefaultWorld?: boolean;
7809
7967
  };
7810
7968
  worlds: any[];
7811
7969
  };
@@ -7860,12 +8018,6 @@ declare class WorldManager implements IService, IUpdatable {
7860
8018
  * 是否启用调试模式
7861
8019
  */
7862
8020
  debug?: boolean;
7863
- /**
7864
- * 是否创建默认World(默认true)
7865
- *
7866
- * 当通过Core使用时应该为true,直接使用WorldManager时可设为false
7867
- */
7868
- createDefaultWorld?: boolean;
7869
8021
  };
7870
8022
  };
7871
8023
  /**
@@ -7911,188 +8063,6 @@ declare class WorldManager implements IService, IUpdatable {
7911
8063
  get config(): IWorldManagerConfig;
7912
8064
  }
7913
8065
 
7914
- /**
7915
- * 单场景管理器
7916
- *
7917
- * 适用场景:
7918
- * - 单人游戏
7919
- * - 简单场景切换
7920
- * - 不需要多World隔离的项目
7921
- *
7922
- * 特点:
7923
- * - 轻量级,零额外开销
7924
- * - 简单直观的API
7925
- * - 支持延迟场景切换
7926
- * - 自动管理ECS API
7927
- * - 通过依赖注入获取WorldManager的默认World
7928
- *
7929
- * @example
7930
- * ```typescript
7931
- * // 初始化Core
7932
- * Core.create({ debug: true });
7933
- *
7934
- * // 设置场景
7935
- * class GameScene extends Scene {
7936
- * initialize() {
7937
- * const player = this.createEntity('Player');
7938
- * player.addComponent(new Transform(100, 100));
7939
- * }
7940
- * }
7941
- *
7942
- * Core.setScene(new GameScene());
7943
- *
7944
- * // 游戏循环
7945
- * function gameLoop(deltaTime: number) {
7946
- * Core.update(deltaTime); // 自动更新所有服务(包括SceneManager)
7947
- * }
7948
- *
7949
- * // 延迟切换场景(下一帧生效)
7950
- * Core.loadScene(new MenuScene());
7951
- * ```
7952
- */
7953
- declare class SceneManager implements IService, IUpdatable {
7954
- /**
7955
- * 内部默认World(从WorldManager获取)
7956
- */
7957
- private _defaultWorld;
7958
- /**
7959
- * 待切换的下一个场景(延迟切换用)
7960
- */
7961
- private _nextScene;
7962
- /**
7963
- * ECS流式API
7964
- */
7965
- private _ecsAPI;
7966
- /**
7967
- * 日志器
7968
- */
7969
- private _logger;
7970
- /**
7971
- * 场景切换回调函数
7972
- */
7973
- private _onSceneChangedCallback?;
7974
- /**
7975
- * 默认场景ID
7976
- */
7977
- private static readonly DEFAULT_SCENE_ID;
7978
- /**
7979
- * 构造函数
7980
- *
7981
- * WorldManager通过依赖注入自动传入
7982
- *
7983
- * @param worldManager WorldManager实例,用于获取默认World
7984
- */
7985
- constructor(worldManager: WorldManager);
7986
- /**
7987
- * 设置场景切换回调
7988
- *
7989
- * @param callback 场景切换时的回调函数
7990
- * @internal
7991
- */
7992
- setSceneChangedCallback(callback: () => void): void;
7993
- /**
7994
- * 设置当前场景(立即切换)
7995
- *
7996
- * 会自动处理旧场景的结束和新场景的初始化。
7997
- *
7998
- * @param scene - 要设置的场景实例
7999
- * @returns 返回设置的场景实例,便于链式调用
8000
- *
8001
- * @example
8002
- * ```typescript
8003
- * const gameScene = sceneManager.setScene(new GameScene());
8004
- * console.log(gameScene.name); // 可以立即使用返回的场景
8005
- * ```
8006
- */
8007
- setScene<T extends IScene>(scene: T): T;
8008
- /**
8009
- * 延迟加载场景(下一帧切换)
8010
- *
8011
- * 场景不会立即切换,而是在下一次调用 update() 时切换。
8012
- * 这对于避免在当前帧的中途切换场景很有用。
8013
- *
8014
- * @param scene - 要加载的场景实例
8015
- *
8016
- * @example
8017
- * ```typescript
8018
- * // 在某个System中触发场景切换
8019
- * class GameOverSystem extends EntitySystem {
8020
- * process(entities: readonly Entity[]) {
8021
- * if (playerHealth <= 0) {
8022
- * sceneManager.loadScene(new GameOverScene());
8023
- * // 当前帧继续执行,场景将在下一帧切换
8024
- * }
8025
- * }
8026
- * }
8027
- * ```
8028
- */
8029
- loadScene<T extends IScene>(scene: T): void;
8030
- /**
8031
- * 获取当前活跃的场景
8032
- *
8033
- * @returns 当前场景实例,如果没有场景则返回null
8034
- */
8035
- get currentScene(): IScene | null;
8036
- /**
8037
- * 获取ECS流式API
8038
- *
8039
- * 提供便捷的实体查询、事件发射等功能。
8040
- *
8041
- * @returns ECS API实例,如果当前没有场景则返回null
8042
- *
8043
- * @example
8044
- * ```typescript
8045
- * const api = sceneManager.api;
8046
- * if (api) {
8047
- * // 查询所有敌人
8048
- * const enemies = api.find(Enemy, Transform);
8049
- *
8050
- * // 发射事件
8051
- * api.emit('game:start', { level: 1 });
8052
- * }
8053
- * ```
8054
- */
8055
- get api(): ECSFluentAPI | null;
8056
- /**
8057
- * 更新场景
8058
- *
8059
- * 应该在每帧的游戏循环中调用。
8060
- * 会自动处理延迟场景切换。
8061
- *
8062
- * @example
8063
- * ```typescript
8064
- * function gameLoop(deltaTime: number) {
8065
- * Core.update(deltaTime);
8066
- * sceneManager.update(); // 每帧调用
8067
- * }
8068
- * ```
8069
- */
8070
- update(): void;
8071
- /**
8072
- * 销毁场景管理器
8073
- *
8074
- * 会自动结束当前场景并清理所有资源。
8075
- * 通常在应用程序关闭时调用。
8076
- */
8077
- destroy(): void;
8078
- /**
8079
- * 检查是否有活跃场景
8080
- *
8081
- * @returns 如果有活跃场景返回true,否则返回false
8082
- */
8083
- get hasScene(): boolean;
8084
- /**
8085
- * 检查是否有待切换的场景
8086
- *
8087
- * @returns 如果有待切换场景返回true,否则返回false
8088
- */
8089
- get hasPendingScene(): boolean;
8090
- /**
8091
- * 释放资源(IService接口)
8092
- */
8093
- dispose(): void;
8094
- }
8095
-
8096
8066
  /**
8097
8067
  * 组件对象池,用于复用组件实例以减少内存分配
8098
8068
  */