@esengine/behavior-tree 4.0.0 → 4.1.0

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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _esengine_ecs_framework from '@esengine/ecs-framework';
2
- import { Component, IService, Entity, EntitySystem, ServiceContainer } from '@esengine/ecs-framework';
2
+ import { Component, IService, Entity, EntitySystem, ServiceContainer, IPlugin, Core, IScene } from '@esengine/ecs-framework';
3
3
 
4
4
  /**
5
5
  * Behavior Tree Constants
@@ -2009,4 +2009,86 @@ declare const BlackboardTypes: Record<BlackboardValueType, BlackboardTypeDefinit
2009
2009
  */
2010
2010
  declare const BehaviorTreeSystemToken: _esengine_ecs_framework.ServiceToken<BehaviorTreeExecutionSystem>;
2011
2011
 
2012
- export { AbortType, AlwaysFailExecutor, AlwaysSucceedExecutor, type AssetMetadata, type AssetValidationResult, type BehaviorNodeConfigData, type BehaviorNodeData, type BehaviorTreeAsset, BehaviorTreeAssetManager, BehaviorTreeAssetSerializer, BehaviorTreeAssetType, BehaviorTreeAssetValidator, BehaviorTreeBuilder, type BehaviorTreeData, BehaviorTreeExecutionSystem, type BehaviorTreeNodeData, BehaviorTreeRuntimeComponent, type BehaviorTreeSerializationFormat, BehaviorTreeStarter, BehaviorTreeSystemToken, BindingHelper, BlackboardCompare, BlackboardExists, type BlackboardTypeDefinition, BlackboardTypes, BlackboardValueType$1 as BlackboardValueType, type BlackboardVariable, type BlackboardVariableDefinition, CompositeType, ConditionalExecutor, type ConfigFieldDefinition, CooldownExecutor, DecoratorType, type DeserializationOptions, type EditorConnection$1 as EditorConnection, type EditorFormat, EditorFormatConverter, type EditorNode$1 as EditorNode, type EditorNodeData, type EditorNodeTemplate, EditorToBehaviorTreeDataConverter, ExecuteAction, ExecuteCondition, type GlobalBlackboardConfig, GlobalBlackboardService, type IBTAssetManager, type IBehaviorTreeAssetContent, type INodeExecutor, type IServiceExecutor, InverterExecutor, LogAction, ModifyBlackboardValue, type NodeDataJSON, type NodeExecutionContext, NodeExecutorMetadata, NodeExecutorRegistry, type NodeMetadata, NodeMetadataRegistry, NodePropertyType, type NodeRuntimeState, type NodeTemplate, NodeTemplates, NodeType, ParallelExecutor, ParallelSelectorExecutor, type PropertyBinding, type PropertyDefinition, RandomProbability, RandomSelectorExecutor, RandomSequenceExecutor, RepeaterExecutor, RootExecutor, SelectorExecutor, SequenceExecutor, type SerializationOptions, ServiceDecorator, ServiceRegistry, SetBlackboardValue, SubTreeExecutor, TaskStatus, TimeoutExecutor, UntilFailExecutor, UntilSuccessExecutor, WaitAction, createDefaultRuntimeState };
2012
+ /**
2013
+ * @zh 行为树插件
2014
+ * @en Behavior Tree Plugin
2015
+ *
2016
+ * @zh 为 ECS 框架提供行为树支持的插件。
2017
+ * 可与任何基于 @esengine/ecs-framework 的引擎集成(Cocos、Laya、Node.js 等)。
2018
+ *
2019
+ * @en Plugin that provides behavior tree support for ECS framework.
2020
+ * Can be integrated with any engine based on @esengine/ecs-framework (Cocos, Laya, Node.js, etc.).
2021
+ *
2022
+ * @example
2023
+ * ```typescript
2024
+ * import { Core, Scene } from '@esengine/ecs-framework';
2025
+ * import { BehaviorTreePlugin, BehaviorTreeBuilder, BehaviorTreeStarter } from '@esengine/behavior-tree';
2026
+ *
2027
+ * // Initialize
2028
+ * Core.create();
2029
+ * const plugin = new BehaviorTreePlugin();
2030
+ * await Core.installPlugin(plugin);
2031
+ *
2032
+ * // Setup scene
2033
+ * const scene = new Scene();
2034
+ * plugin.setupScene(scene);
2035
+ * Core.setScene(scene);
2036
+ *
2037
+ * // Create and start behavior tree
2038
+ * const tree = BehaviorTreeBuilder.create('MyAI')
2039
+ * .selector('Root')
2040
+ * .log('Hello from behavior tree!')
2041
+ * .end()
2042
+ * .build();
2043
+ *
2044
+ * const entity = scene.createEntity('AIEntity');
2045
+ * BehaviorTreeStarter.start(entity, tree);
2046
+ * ```
2047
+ */
2048
+ declare class BehaviorTreePlugin implements IPlugin {
2049
+ /**
2050
+ * @zh 插件名称
2051
+ * @en Plugin name
2052
+ */
2053
+ readonly name = "@esengine/behavior-tree";
2054
+ /**
2055
+ * @zh 插件版本
2056
+ * @en Plugin version
2057
+ */
2058
+ readonly version = "1.0.0";
2059
+ /**
2060
+ * @zh 插件依赖
2061
+ * @en Plugin dependencies
2062
+ */
2063
+ readonly dependencies: readonly string[];
2064
+ private _services;
2065
+ /**
2066
+ * @zh 安装插件
2067
+ * @en Install plugin
2068
+ *
2069
+ * @param _core - Core 实例
2070
+ * @param services - 服务容器
2071
+ */
2072
+ install(_core: Core, services: ServiceContainer): void;
2073
+ /**
2074
+ * @zh 卸载插件
2075
+ * @en Uninstall plugin
2076
+ */
2077
+ uninstall(): void;
2078
+ /**
2079
+ * @zh 设置场景,添加行为树执行系统
2080
+ * @en Setup scene, add behavior tree execution system
2081
+ *
2082
+ * @param scene - 要设置的场景
2083
+ *
2084
+ * @example
2085
+ * ```typescript
2086
+ * const scene = new Scene();
2087
+ * plugin.setupScene(scene);
2088
+ * Core.setScene(scene);
2089
+ * ```
2090
+ */
2091
+ setupScene(scene: IScene): void;
2092
+ }
2093
+
2094
+ export { AbortType, AlwaysFailExecutor, AlwaysSucceedExecutor, type AssetMetadata, type AssetValidationResult, type BehaviorNodeConfigData, type BehaviorNodeData, type BehaviorTreeAsset, BehaviorTreeAssetManager, BehaviorTreeAssetSerializer, BehaviorTreeAssetType, BehaviorTreeAssetValidator, BehaviorTreeBuilder, type BehaviorTreeData, BehaviorTreeExecutionSystem, type BehaviorTreeNodeData, BehaviorTreePlugin, BehaviorTreeRuntimeComponent, type BehaviorTreeSerializationFormat, BehaviorTreeStarter, BehaviorTreeSystemToken, BindingHelper, BlackboardCompare, BlackboardExists, type BlackboardTypeDefinition, BlackboardTypes, BlackboardValueType$1 as BlackboardValueType, type BlackboardVariable, type BlackboardVariableDefinition, CompositeType, ConditionalExecutor, type ConfigFieldDefinition, CooldownExecutor, DecoratorType, type DeserializationOptions, type EditorConnection$1 as EditorConnection, type EditorFormat, EditorFormatConverter, type EditorNode$1 as EditorNode, type EditorNodeData, type EditorNodeTemplate, EditorToBehaviorTreeDataConverter, ExecuteAction, ExecuteCondition, type GlobalBlackboardConfig, GlobalBlackboardService, type IBTAssetManager, type IBehaviorTreeAssetContent, type INodeExecutor, type IServiceExecutor, InverterExecutor, LogAction, ModifyBlackboardValue, type NodeDataJSON, type NodeExecutionContext, NodeExecutorMetadata, NodeExecutorRegistry, type NodeMetadata, NodeMetadataRegistry, NodePropertyType, type NodeRuntimeState, type NodeTemplate, NodeTemplates, NodeType, ParallelExecutor, ParallelSelectorExecutor, type PropertyBinding, type PropertyDefinition, RandomProbability, RandomSelectorExecutor, RandomSequenceExecutor, RepeaterExecutor, RootExecutor, SelectorExecutor, SequenceExecutor, type SerializationOptions, ServiceDecorator, ServiceRegistry, SetBlackboardValue, SubTreeExecutor, TaskStatus, TimeoutExecutor, UntilFailExecutor, UntilSuccessExecutor, WaitAction, createDefaultRuntimeState };
package/dist/index.js CHANGED
@@ -4634,6 +4634,80 @@ var BlackboardTypes = {
4634
4634
  // src/tokens.ts
4635
4635
  import { createServiceToken } from "@esengine/ecs-framework";
4636
4636
  var BehaviorTreeSystemToken = createServiceToken("behaviorTreeSystem");
4637
+
4638
+ // src/BehaviorTreePlugin.ts
4639
+ var _BehaviorTreePlugin = class _BehaviorTreePlugin {
4640
+ constructor() {
4641
+ /**
4642
+ * @zh 插件名称
4643
+ * @en Plugin name
4644
+ */
4645
+ __publicField(this, "name", "@esengine/behavior-tree");
4646
+ /**
4647
+ * @zh 插件版本
4648
+ * @en Plugin version
4649
+ */
4650
+ __publicField(this, "version", "1.0.0");
4651
+ /**
4652
+ * @zh 插件依赖
4653
+ * @en Plugin dependencies
4654
+ */
4655
+ __publicField(this, "dependencies", []);
4656
+ __publicField(this, "_services", null);
4657
+ }
4658
+ /**
4659
+ * @zh 安装插件
4660
+ * @en Install plugin
4661
+ *
4662
+ * @param _core - Core 实例
4663
+ * @param services - 服务容器
4664
+ */
4665
+ install(_core, services) {
4666
+ this._services = services;
4667
+ if (!services.isRegistered(GlobalBlackboardService)) {
4668
+ services.registerSingleton(GlobalBlackboardService);
4669
+ }
4670
+ if (!services.isRegistered(BehaviorTreeAssetManager)) {
4671
+ services.registerSingleton(BehaviorTreeAssetManager);
4672
+ }
4673
+ }
4674
+ /**
4675
+ * @zh 卸载插件
4676
+ * @en Uninstall plugin
4677
+ */
4678
+ uninstall() {
4679
+ if (this._services) {
4680
+ const assetManager = this._services.tryResolve(BehaviorTreeAssetManager);
4681
+ if (assetManager) {
4682
+ assetManager.dispose();
4683
+ }
4684
+ const blackboardService = this._services.tryResolve(GlobalBlackboardService);
4685
+ if (blackboardService) {
4686
+ blackboardService.dispose();
4687
+ }
4688
+ }
4689
+ this._services = null;
4690
+ }
4691
+ /**
4692
+ * @zh 设置场景,添加行为树执行系统
4693
+ * @en Setup scene, add behavior tree execution system
4694
+ *
4695
+ * @param scene - 要设置的场景
4696
+ *
4697
+ * @example
4698
+ * ```typescript
4699
+ * const scene = new Scene();
4700
+ * plugin.setupScene(scene);
4701
+ * Core.setScene(scene);
4702
+ * ```
4703
+ */
4704
+ setupScene(scene) {
4705
+ const system = new BehaviorTreeExecutionSystem(this._services ?? void 0);
4706
+ scene.addSystem(system);
4707
+ }
4708
+ };
4709
+ __name(_BehaviorTreePlugin, "BehaviorTreePlugin");
4710
+ var BehaviorTreePlugin = _BehaviorTreePlugin;
4637
4711
  export {
4638
4712
  AbortType,
4639
4713
  AlwaysFailExecutor,
@@ -4644,6 +4718,7 @@ export {
4644
4718
  BehaviorTreeAssetValidator,
4645
4719
  BehaviorTreeBuilder,
4646
4720
  BehaviorTreeExecutionSystem,
4721
+ BehaviorTreePlugin,
4647
4722
  BehaviorTreeRuntimeComponent,
4648
4723
  BehaviorTreeStarter,
4649
4724
  BehaviorTreeSystemToken,