@nice2dev/game-engine 1.3.15 → 1.3.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/CHANGELOG.md +9 -0
- package/dist/cjs/accessibility/Accessibility.js +152 -165
- package/dist/cjs/ai/AI.js +292 -294
- package/dist/cjs/ai/BehaviorTree.js +1029 -1113
- package/dist/cjs/ai/StateMachine.js +694 -756
- package/dist/cjs/animation/Animation.js +232 -241
- package/dist/cjs/audio/AudioAdvanced.js +221 -236
- package/dist/cjs/audio/AudioBridge.js +441 -435
- package/dist/cjs/audio/AudioManager.js +242 -259
- package/dist/cjs/build-cloud/BuildOrchestration.js +1059 -1098
- package/dist/cjs/build-cloud/GodotBuildCloud.js +641 -670
- package/dist/cjs/build-cloud/UnityBuildCloud.js +563 -610
- package/dist/cjs/build-cloud/UnrealBuildCloud.js +610 -635
- package/dist/cjs/core/EventBus.js +51 -56
- package/dist/cjs/core/GameClock.js +62 -66
- package/dist/cjs/core/GameConfig.js +72 -79
- package/dist/cjs/core/GameLoop.js +80 -89
- package/dist/cjs/core/ServiceLocator.js +61 -65
- package/dist/cjs/core/Validation.js +72 -82
- package/dist/cjs/core/math.js +108 -112
- package/dist/cjs/devtools/DevTools.js +542 -563
- package/dist/cjs/devtools/DeveloperExperience.js +521 -559
- package/dist/cjs/devtools/GameplayAnalytics.js +636 -646
- package/dist/cjs/dialogue/DialogueSystem.js +984 -986
- package/dist/cjs/docs/DocGenerator.js +339 -364
- package/dist/cjs/ecs/World.js +355 -371
- package/dist/cjs/editor/AchievementEditor.js +580 -636
- package/dist/cjs/editor/AdvancedEditor.js +184 -191
- package/dist/cjs/editor/AnimationRetargeting.js +696 -741
- package/dist/cjs/editor/AssetBrowser.js +1072 -1160
- package/dist/cjs/editor/AssetManager.js +187 -192
- package/dist/cjs/editor/ConsolePro.js +971 -1061
- package/dist/cjs/editor/CraftingEditor.js +680 -730
- package/dist/cjs/editor/DebugTools.js +187 -185
- package/dist/cjs/editor/DialogueSystem.js +844 -901
- package/dist/cjs/editor/LeaderboardSystem.js +429 -483
- package/dist/cjs/editor/NiceGameEditor.js +1903 -1201
- package/dist/cjs/editor/PrefabSystem.js +772 -838
- package/dist/cjs/editor/ProfilerPanel.js +649 -700
- package/dist/cjs/editor/QuestEditor.js +792 -839
- package/dist/cjs/editor/ReplaySystem.js +585 -634
- package/dist/cjs/editor/SceneEditor.js +176 -200
- package/dist/cjs/editor/ScreenshotMode.js +621 -688
- package/dist/cjs/editor/ShaderGraph.js +1556 -1582
- package/dist/cjs/editor/TimelineEditor.js +715 -778
- package/dist/cjs/editor/UndoRedoPro.js +830 -904
- package/dist/cjs/editor/VRARMode.js +582 -645
- package/dist/cjs/engine/NiceGameEngine.js +141 -164
- package/dist/cjs/engine/SaveSystem.js +441 -495
- package/dist/cjs/enterprise/Enterprise.js +254 -261
- package/dist/cjs/export/BevyExporter.js +927 -967
- package/dist/cjs/export/CocosExporter.js +644 -673
- package/dist/cjs/export/Construct3Exporter.js +783 -794
- package/dist/cjs/export/DefoldExporter.js +1028 -1069
- package/dist/cjs/export/GDevelopExporter.js +674 -708
- package/dist/cjs/export/GameMakerExporter.js +791 -805
- package/dist/cjs/export/GodotExporter.js +1003 -1045
- package/dist/cjs/export/MinecraftBedrockExporter.js +573 -578
- package/dist/cjs/export/MonoGameExporter.js +1265 -1293
- package/dist/cjs/export/Pico8Exporter.js +766 -812
- package/dist/cjs/export/PlatformExporter.js +188 -206
- package/dist/cjs/export/RPGMakerExporter.js +860 -879
- package/dist/cjs/export/RobloxExporter.js +883 -919
- package/dist/cjs/export/Solar2DExporter.js +1218 -1256
- package/dist/cjs/export/ThreeJSExporter.js +1006 -1073
- package/dist/cjs/export/Tic80Exporter.js +1210 -1267
- package/dist/cjs/export/UnityExporter.js +1116 -1131
- package/dist/cjs/export/UnrealExporter.js +889 -919
- package/dist/cjs/export/WebExporter.js +931 -970
- package/dist/cjs/export/index.js +42 -65
- package/dist/cjs/godot-integration/GodotAssetLibrary.js +659 -692
- package/dist/cjs/godot-integration/GodotImport.js +929 -1027
- package/dist/cjs/godot-integration/GodotLiveLink.js +915 -945
- package/dist/cjs/godot-integration/components/GodotProjectBrowser.js +911 -611
- package/dist/cjs/i18n/I18n.js +860 -900
- package/dist/cjs/i18n/useTranslation.js +84 -89
- package/dist/cjs/import/AsepriteImporter.js +658 -716
- package/dist/cjs/import/DragonBonesImporter.js +437 -461
- package/dist/cjs/import/GameMakerImporter.js +511 -521
- package/dist/cjs/import/GodotSceneImporter.js +788 -822
- package/dist/cjs/import/LDtkImporter.js +436 -454
- package/dist/cjs/import/Live2DImporter.js +497 -518
- package/dist/cjs/import/NdgFormat.js +424 -457
- package/dist/cjs/import/OgmoImporter.js +466 -493
- package/dist/cjs/import/RPGMakerImporter.js +451 -477
- package/dist/cjs/import/SceneImporter.js +378 -423
- package/dist/cjs/import/SpineImporter.js +511 -546
- package/dist/cjs/import/SpriterImporter.js +590 -613
- package/dist/cjs/import/TiledMapImporter.js +811 -846
- package/dist/cjs/import/UnitySceneImporter.js +687 -703
- package/dist/cjs/import/index.js +206 -251
- package/dist/cjs/index.js +275 -278
- package/dist/cjs/input/GamepadNavigation.js +185 -205
- package/dist/cjs/input/InputManager.js +397 -421
- package/dist/cjs/input/useGamepads.js +70 -81
- package/dist/cjs/integration/IconSprite.js +129 -256
- package/dist/cjs/inventory/InventorySystem.js +920 -995
- package/dist/cjs/kids/KidMode.js +997 -1022
- package/dist/cjs/kids/KidTools.js +570 -594
- package/dist/cjs/monetization/Monetization.js +170 -177
- package/dist/cjs/multiplayer/LocalMultiplayer.js +287 -287
- package/dist/cjs/multiplayer/MiniGameTypes.js +49 -59
- package/dist/cjs/native-engine/AnimationSystem.js +731 -806
- package/dist/cjs/native-engine/AssetPipeline.js +454 -515
- package/dist/cjs/native-engine/AudioEngine.js +763 -804
- package/dist/cjs/native-engine/InputSystem.js +1075 -1145
- package/dist/cjs/native-engine/NetworkingSystem.js +733 -793
- package/dist/cjs/native-engine/PhysicsEngine.js +583 -607
- package/dist/cjs/native-engine/RenderingEngine.js +302 -350
- package/dist/cjs/native-engine/SceneGraph.js +769 -808
- package/dist/cjs/network/MultiplayerTransport.js +97 -132
- package/dist/cjs/network/Networking.js +549 -564
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AbortController.js +21 -29
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +40 -48
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +35 -43
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +10 -15
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Errors.js +103 -135
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +131 -158
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +39 -53
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +5 -8
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +40 -48
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +494 -572
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +826 -953
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +125 -146
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +13 -23
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ILogger.js +11 -25
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ITransport.js +13 -24
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +108 -121
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Loggers.js +10 -14
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +150 -185
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +158 -196
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +90 -105
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Subject.js +30 -35
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +16 -21
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Utils.js +215 -248
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +135 -157
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +76 -85
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/index.js +24 -27
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +3 -4
- package/dist/cjs/pathfinding/Pathfinding.js +245 -263
- package/dist/cjs/performance/AssetStreaming.js +561 -635
- package/dist/cjs/performance/BenchmarkSuite.js +283 -311
- package/dist/cjs/performance/DeltaCompression.js +467 -526
- package/dist/cjs/performance/DeterministicPhysics.js +450 -498
- package/dist/cjs/performance/ECSOptimization.js +644 -695
- package/dist/cjs/performance/GameSaveSystem.js +509 -556
- package/dist/cjs/performance/HotReload.js +447 -500
- package/dist/cjs/performance/InputRecording.js +511 -561
- package/dist/cjs/performance/InterestManagement.js +453 -500
- package/dist/cjs/performance/LocalizationRuntime.js +376 -423
- package/dist/cjs/performance/MemoryManagement.js +410 -470
- package/dist/cjs/performance/ModSupport.js +445 -496
- package/dist/cjs/performance/MultiThreadedPhysics.js +400 -443
- package/dist/cjs/performance/NetworkPrediction.js +424 -482
- package/dist/cjs/performance/ObjectPooling.js +569 -617
- package/dist/cjs/performance/Performance.js +174 -190
- package/dist/cjs/performance/PerformanceAdvanced.js +614 -637
- package/dist/cjs/performance/WebGPURenderer.js +656 -683
- package/dist/cjs/physics/PhysicsAdvanced.js +345 -379
- package/dist/cjs/physics/PhysicsEngine2D.js +391 -427
- package/dist/cjs/plugins/PluginSDK.js +432 -466
- package/dist/cjs/plugins/PluginTestKit.js +307 -330
- package/dist/cjs/procedural/Procedural.js +243 -254
- package/dist/cjs/procedural/WorldBuilding.js +297 -314
- package/dist/cjs/quest/QuestSystem.js +975 -932
- package/dist/cjs/release/MobileExport.js +157 -163
- package/dist/cjs/release/Release.js +225 -238
- package/dist/cjs/rendering/Camera2D.js +121 -124
- package/dist/cjs/rendering/Renderer2D.js +321 -335
- package/dist/cjs/rendering/WebGPURenderPipeline.js +632 -651
- package/dist/cjs/runtime3d/Runtime3D.js +359 -378
- package/dist/cjs/runtime3d/SceneEditor3D.js +252 -263
- package/dist/cjs/scene/SceneManager.js +177 -193
- package/dist/cjs/scripting/GraphToAST.js +574 -547
- package/dist/cjs/scripting/LanguageExporter.js +254 -279
- package/dist/cjs/scripting/NodeGraph.js +546 -570
- package/dist/cjs/scripting/ScriptAST.js +31 -39
- package/dist/cjs/scripting/VisualScripting2.js +1016 -1065
- package/dist/cjs/scripting/exporters/CSharpExporter.js +464 -496
- package/dist/cjs/scripting/exporters/GDScriptExporter.js +390 -442
- package/dist/cjs/scripting/exporters/LuaExporter.js +406 -447
- package/dist/cjs/scripting/exporters/PythonExporter.js +484 -549
- package/dist/cjs/scripting/exporters/RustExporter.js +459 -512
- package/dist/cjs/scripting/exporters/TypeScriptExporter.js +505 -556
- package/dist/cjs/social/Social.js +72 -80
- package/dist/cjs/systems/LightingSystem.js +844 -931
- package/dist/cjs/systems/ParticleSystem2.js +1447 -1451
- package/dist/cjs/systems/PhysicsDebugSystem.js +1070 -1141
- package/dist/cjs/systems/TerrainSystem.js +985 -1098
- package/dist/cjs/templates/ActionTemplates.js +296 -309
- package/dist/cjs/templates/FightingTemplate.js +417 -463
- package/dist/cjs/templates/MetroidvaniaTemplate.js +353 -405
- package/dist/cjs/templates/PartyTemplates.js +190 -202
- package/dist/cjs/templates/PuzzleTemplates.js +245 -261
- package/dist/cjs/templates/RPGTemplates.js +160 -178
- package/dist/cjs/templates/SportsTemplates.js +237 -250
- package/dist/cjs/templates/StrategyTemplates.js +143 -153
- package/dist/cjs/templates/SurvivalTemplate.js +336 -380
- package/dist/cjs/templates/WaveDefense.js +499 -526
- package/dist/cjs/tilemap/Tilemap.js +207 -214
- package/dist/cjs/tutorials/TutorialBranching.js +396 -417
- package/dist/cjs/tutorials/TutorialEngine.js +888 -931
- package/dist/cjs/tutorials/TutorialOverlay.js +602 -640
- package/dist/cjs/tutorials/content/Tutorials_T05_T08.js +787 -809
- package/dist/cjs/tutorials/content/Tutorials_T09_T11.js +736 -756
- package/dist/cjs/tutorials/content/Tutorials_T12_T15.js +754 -778
- package/dist/cjs/ui/GameUI.js +295 -312
- package/dist/cjs/unity-integration/UnityAssetStore.js +700 -741
- package/dist/cjs/unity-integration/UnityImport.js +1066 -1176
- package/dist/cjs/unity-integration/UnityLiveLink.js +934 -981
- package/dist/cjs/unity-integration/components/UnityAssetStoreBrowser.js +1233 -757
- package/dist/cjs/unity-integration/components/UnityProjectBrowser.js +1240 -768
- package/dist/cjs/unreal-integration/UnrealImport.js +391 -412
- package/dist/cjs/unreal-integration/UnrealLiveLink.js +1102 -1137
- package/dist/cjs/unreal-integration/UnrealMarketplace.js +436 -473
- package/dist/cjs/unreal-integration/components/UnrealProjectBrowser.js +1150 -767
- package/dist/cjs/xr/ARVR.js +167 -175
- package/dist/esm/accessibility/Accessibility.js +160 -164
- package/dist/esm/ai/AI.js +310 -293
- package/dist/esm/ai/BehaviorTree.js +1057 -1112
- package/dist/esm/ai/StateMachine.js +709 -755
- package/dist/esm/animation/Animation.js +237 -240
- package/dist/esm/audio/AudioAdvanced.js +239 -235
- package/dist/esm/audio/AudioBridge.js +448 -434
- package/dist/esm/audio/AudioManager.js +243 -258
- package/dist/esm/build-cloud/BuildOrchestration.js +1071 -1097
- package/dist/esm/build-cloud/GodotBuildCloud.js +647 -669
- package/dist/esm/build-cloud/UnityBuildCloud.js +571 -609
- package/dist/esm/build-cloud/UnrealBuildCloud.js +615 -634
- package/dist/esm/core/EventBus.js +52 -55
- package/dist/esm/core/GameClock.js +63 -65
- package/dist/esm/core/GameConfig.js +77 -78
- package/dist/esm/core/GameLoop.js +81 -88
- package/dist/esm/core/ServiceLocator.js +63 -64
- package/dist/esm/core/Validation.js +82 -81
- package/dist/esm/core/math.js +109 -111
- package/dist/esm/devtools/DevTools.js +546 -562
- package/dist/esm/devtools/DeveloperExperience.js +535 -558
- package/dist/esm/devtools/GameplayAnalytics.js +647 -645
- package/dist/esm/dialogue/DialogueSystem.js +998 -985
- package/dist/esm/docs/DocGenerator.js +342 -363
- package/dist/esm/ecs/World.js +358 -370
- package/dist/esm/editor/AchievementEditor.js +584 -635
- package/dist/esm/editor/AdvancedEditor.js +191 -190
- package/dist/esm/editor/AnimationRetargeting.js +700 -740
- package/dist/esm/editor/AssetBrowser.js +1078 -1159
- package/dist/esm/editor/AssetManager.js +188 -191
- package/dist/esm/editor/ConsolePro.js +977 -1060
- package/dist/esm/editor/CraftingEditor.js +684 -729
- package/dist/esm/editor/DebugTools.js +194 -184
- package/dist/esm/editor/DialogueSystem.js +849 -900
- package/dist/esm/editor/LeaderboardSystem.js +433 -482
- package/dist/esm/editor/NiceGameEditor.js +1908 -1200
- package/dist/esm/editor/PrefabSystem.js +777 -837
- package/dist/esm/editor/ProfilerPanel.js +654 -699
- package/dist/esm/editor/QuestEditor.js +795 -838
- package/dist/esm/editor/ReplaySystem.js +591 -633
- package/dist/esm/editor/SceneEditor.js +189 -199
- package/dist/esm/editor/ScreenshotMode.js +628 -687
- package/dist/esm/editor/ShaderGraph.js +1565 -1581
- package/dist/esm/editor/TimelineEditor.js +733 -777
- package/dist/esm/editor/UndoRedoPro.js +835 -903
- package/dist/esm/editor/VRARMode.js +586 -644
- package/dist/esm/engine/NiceGameEngine.js +142 -163
- package/dist/esm/engine/SaveSystem.js +447 -494
- package/dist/esm/enterprise/Enterprise.js +265 -260
- package/dist/esm/export/BevyExporter.js +929 -966
- package/dist/esm/export/CocosExporter.js +646 -672
- package/dist/esm/export/Construct3Exporter.js +785 -793
- package/dist/esm/export/DefoldExporter.js +1030 -1068
- package/dist/esm/export/GDevelopExporter.js +676 -707
- package/dist/esm/export/GameMakerExporter.js +793 -804
- package/dist/esm/export/GodotExporter.js +1004 -1044
- package/dist/esm/export/MinecraftBedrockExporter.js +575 -577
- package/dist/esm/export/MonoGameExporter.js +1267 -1292
- package/dist/esm/export/Pico8Exporter.js +768 -811
- package/dist/esm/export/PlatformExporter.js +193 -205
- package/dist/esm/export/RPGMakerExporter.js +862 -878
- package/dist/esm/export/RobloxExporter.js +885 -918
- package/dist/esm/export/Solar2DExporter.js +1220 -1255
- package/dist/esm/export/ThreeJSExporter.js +1007 -1072
- package/dist/esm/export/Tic80Exporter.js +1212 -1266
- package/dist/esm/export/UnityExporter.js +1117 -1130
- package/dist/esm/export/UnrealExporter.js +891 -918
- package/dist/esm/export/WebExporter.js +933 -969
- package/dist/esm/export/index.js +86 -71
- package/dist/esm/godot-integration/GodotAssetLibrary.js +663 -691
- package/dist/esm/godot-integration/GodotImport.js +935 -1026
- package/dist/esm/godot-integration/GodotLiveLink.js +918 -944
- package/dist/esm/godot-integration/components/GodotProjectBrowser.js +912 -610
- package/dist/esm/i18n/I18n.js +871 -899
- package/dist/esm/i18n/useTranslation.js +88 -88
- package/dist/esm/import/AsepriteImporter.js +637 -715
- package/dist/esm/import/DragonBonesImporter.js +417 -460
- package/dist/esm/import/GameMakerImporter.js +491 -520
- package/dist/esm/import/GodotSceneImporter.js +767 -821
- package/dist/esm/import/LDtkImporter.js +415 -453
- package/dist/esm/import/Live2DImporter.js +477 -517
- package/dist/esm/import/NdgFormat.js +410 -456
- package/dist/esm/import/OgmoImporter.js +446 -492
- package/dist/esm/import/RPGMakerImporter.js +431 -476
- package/dist/esm/import/SceneImporter.js +385 -422
- package/dist/esm/import/SpineImporter.js +491 -545
- package/dist/esm/import/SpriterImporter.js +570 -612
- package/dist/esm/import/TiledMapImporter.js +790 -845
- package/dist/esm/import/UnitySceneImporter.js +666 -702
- package/dist/esm/import/index.js +247 -258
- package/dist/esm/index.js +1332 -188
- package/dist/esm/input/GamepadNavigation.js +187 -204
- package/dist/esm/input/InputManager.js +401 -420
- package/dist/esm/input/useGamepads.js +72 -80
- package/dist/esm/integration/IconSprite.js +143 -255
- package/dist/esm/inventory/InventorySystem.js +925 -994
- package/dist/esm/kids/KidMode.js +1003 -1021
- package/dist/esm/kids/KidTools.js +573 -593
- package/dist/esm/monetization/Monetization.js +180 -176
- package/dist/esm/multiplayer/LocalMultiplayer.js +290 -286
- package/dist/esm/multiplayer/MiniGameTypes.js +58 -58
- package/dist/esm/native-engine/AnimationSystem.js +735 -805
- package/dist/esm/native-engine/AssetPipeline.js +456 -514
- package/dist/esm/native-engine/AudioEngine.js +765 -803
- package/dist/esm/native-engine/InputSystem.js +1079 -1144
- package/dist/esm/native-engine/NetworkingSystem.js +740 -792
- package/dist/esm/native-engine/PhysicsEngine.js +585 -606
- package/dist/esm/native-engine/RenderingEngine.js +304 -349
- package/dist/esm/native-engine/SceneGraph.js +773 -807
- package/dist/esm/network/MultiplayerTransport.js +99 -131
- package/dist/esm/network/Networking.js +556 -563
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AbortController.js +22 -28
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +41 -47
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +36 -42
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +11 -14
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Errors.js +111 -134
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +132 -157
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +40 -52
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +6 -7
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +42 -47
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +496 -571
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +828 -952
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +126 -145
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +14 -23
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ILogger.js +12 -25
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ITransport.js +15 -24
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +109 -120
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Loggers.js +11 -13
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +151 -184
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +159 -195
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +91 -104
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Subject.js +31 -34
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +17 -20
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Utils.js +230 -248
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +136 -156
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +77 -84
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/index.js +31 -12
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +4 -3
- package/dist/esm/pathfinding/Pathfinding.js +249 -262
- package/dist/esm/performance/AssetStreaming.js +567 -634
- package/dist/esm/performance/BenchmarkSuite.js +285 -310
- package/dist/esm/performance/DeltaCompression.js +478 -525
- package/dist/esm/performance/DeterministicPhysics.js +479 -497
- package/dist/esm/performance/ECSOptimization.js +653 -694
- package/dist/esm/performance/GameSaveSystem.js +515 -555
- package/dist/esm/performance/HotReload.js +454 -499
- package/dist/esm/performance/InputRecording.js +520 -560
- package/dist/esm/performance/InterestManagement.js +460 -499
- package/dist/esm/performance/LocalizationRuntime.js +382 -422
- package/dist/esm/performance/MemoryManagement.js +415 -469
- package/dist/esm/performance/ModSupport.js +455 -495
- package/dist/esm/performance/MultiThreadedPhysics.js +408 -442
- package/dist/esm/performance/NetworkPrediction.js +436 -481
- package/dist/esm/performance/ObjectPooling.js +582 -616
- package/dist/esm/performance/Performance.js +182 -189
- package/dist/esm/performance/PerformanceAdvanced.js +621 -636
- package/dist/esm/performance/WebGPURenderer.js +660 -682
- package/dist/esm/physics/PhysicsAdvanced.js +359 -378
- package/dist/esm/physics/PhysicsEngine2D.js +393 -426
- package/dist/esm/plugins/PluginSDK.js +435 -465
- package/dist/esm/plugins/PluginTestKit.js +315 -329
- package/dist/esm/procedural/Procedural.js +248 -253
- package/dist/esm/procedural/WorldBuilding.js +316 -313
- package/dist/esm/quest/QuestSystem.js +982 -931
- package/dist/esm/release/MobileExport.js +163 -162
- package/dist/esm/release/Release.js +234 -237
- package/dist/esm/rendering/Camera2D.js +122 -123
- package/dist/esm/rendering/Renderer2D.js +323 -334
- package/dist/esm/rendering/WebGPURenderPipeline.js +647 -650
- package/dist/esm/runtime3d/Runtime3D.js +368 -377
- package/dist/esm/runtime3d/SceneEditor3D.js +268 -262
- package/dist/esm/scene/SceneManager.js +178 -192
- package/dist/esm/scripting/GraphToAST.js +576 -546
- package/dist/esm/scripting/LanguageExporter.js +263 -278
- package/dist/esm/scripting/NodeGraph.js +550 -569
- package/dist/esm/scripting/ScriptAST.js +45 -38
- package/dist/esm/scripting/VisualScripting2.js +1025 -1064
- package/dist/esm/scripting/exporters/CSharpExporter.js +465 -495
- package/dist/esm/scripting/exporters/GDScriptExporter.js +391 -441
- package/dist/esm/scripting/exporters/LuaExporter.js +407 -446
- package/dist/esm/scripting/exporters/PythonExporter.js +485 -548
- package/dist/esm/scripting/exporters/RustExporter.js +460 -511
- package/dist/esm/scripting/exporters/TypeScriptExporter.js +506 -555
- package/dist/esm/social/Social.js +77 -79
- package/dist/esm/systems/LightingSystem.js +855 -930
- package/dist/esm/systems/ParticleSystem2.js +1453 -1450
- package/dist/esm/systems/PhysicsDebugSystem.js +1078 -1140
- package/dist/esm/systems/TerrainSystem.js +996 -1097
- package/dist/esm/templates/ActionTemplates.js +307 -308
- package/dist/esm/templates/FightingTemplate.js +439 -462
- package/dist/esm/templates/MetroidvaniaTemplate.js +391 -404
- package/dist/esm/templates/PartyTemplates.js +206 -201
- package/dist/esm/templates/PuzzleTemplates.js +260 -260
- package/dist/esm/templates/RPGTemplates.js +172 -177
- package/dist/esm/templates/SportsTemplates.js +251 -249
- package/dist/esm/templates/StrategyTemplates.js +158 -152
- package/dist/esm/templates/SurvivalTemplate.js +367 -379
- package/dist/esm/templates/WaveDefense.js +501 -525
- package/dist/esm/tilemap/Tilemap.js +209 -213
- package/dist/esm/tutorials/TutorialBranching.js +399 -416
- package/dist/esm/tutorials/TutorialEngine.js +893 -930
- package/dist/esm/tutorials/TutorialOverlay.js +603 -639
- package/dist/esm/tutorials/content/Tutorials_T05_T08.js +792 -808
- package/dist/esm/tutorials/content/Tutorials_T09_T11.js +740 -755
- package/dist/esm/tutorials/content/Tutorials_T12_T15.js +759 -777
- package/dist/esm/ui/GameUI.js +296 -311
- package/dist/esm/unity-integration/UnityAssetStore.js +704 -740
- package/dist/esm/unity-integration/UnityImport.js +1071 -1175
- package/dist/esm/unity-integration/UnityLiveLink.js +938 -980
- package/dist/esm/unity-integration/components/UnityAssetStoreBrowser.js +1234 -756
- package/dist/esm/unity-integration/components/UnityProjectBrowser.js +1241 -767
- package/dist/esm/unreal-integration/UnrealImport.js +395 -411
- package/dist/esm/unreal-integration/UnrealLiveLink.js +1105 -1136
- package/dist/esm/unreal-integration/UnrealMarketplace.js +442 -472
- package/dist/esm/unreal-integration/components/UnrealProjectBrowser.js +1151 -766
- package/dist/esm/xr/ARVR.js +181 -174
- package/package.json +7 -12
|
@@ -1,1177 +1,1122 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file BehaviorTree.ts
|
|
3
|
-
* @description Behavior Tree System with Graphical Editor Support
|
|
4
|
-
* PRO-1.4: Professional Editor Features
|
|
5
|
-
*
|
|
6
|
-
* Features:
|
|
7
|
-
* - Full behavior tree implementation
|
|
8
|
-
* - Composite nodes (Selector, Sequence, Parallel)
|
|
9
|
-
* - Decorator nodes (Inverter, Repeater, Succeeder, etc.)
|
|
10
|
-
* - Leaf nodes (Actions, Conditions)
|
|
11
|
-
* - Real-time preview and debugging
|
|
12
|
-
* - Blackboard system for shared data
|
|
13
|
-
* - Subtree support
|
|
14
|
-
* - Serialization support
|
|
15
|
-
*/
|
|
16
|
-
/** Blackboard for sharing data between nodes */
|
|
17
1
|
class BTBlackboard {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
cb(value);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
/** Get a value from the blackboard */
|
|
42
|
-
get(key) {
|
|
43
|
-
const name = typeof key === 'string' ? key : key.name;
|
|
44
|
-
const value = this.data.get(name);
|
|
45
|
-
if (value === undefined && typeof key !== 'string' && key.defaultValue !== undefined) {
|
|
46
|
-
return key.defaultValue;
|
|
47
|
-
}
|
|
48
|
-
return value;
|
|
49
|
-
}
|
|
50
|
-
/** Check if key exists */
|
|
51
|
-
has(key) {
|
|
52
|
-
const name = typeof key === 'string' ? key : key.name;
|
|
53
|
-
return this.data.has(name);
|
|
54
|
-
}
|
|
55
|
-
/** Remove a key */
|
|
56
|
-
delete(key) {
|
|
57
|
-
const name = typeof key === 'string' ? key : key.name;
|
|
58
|
-
this.data.delete(name);
|
|
59
|
-
this.types.delete(name);
|
|
60
|
-
}
|
|
61
|
-
/** Clear all data */
|
|
62
|
-
clear() {
|
|
63
|
-
this.data.clear();
|
|
64
|
-
}
|
|
65
|
-
/** Subscribe to key changes */
|
|
66
|
-
subscribe(key, callback) {
|
|
67
|
-
const name = typeof key === 'string' ? key : key.name;
|
|
68
|
-
let callbacks = this.listeners.get(name);
|
|
69
|
-
if (!callbacks) {
|
|
70
|
-
callbacks = [];
|
|
71
|
-
this.listeners.set(name, callbacks);
|
|
72
|
-
}
|
|
73
|
-
callbacks.push(callback);
|
|
74
|
-
// Return unsubscribe function
|
|
75
|
-
return () => {
|
|
76
|
-
const idx = callbacks.indexOf(callback);
|
|
77
|
-
if (idx >= 0) {
|
|
78
|
-
callbacks.splice(idx, 1);
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
/** Get all keys */
|
|
83
|
-
keys() {
|
|
84
|
-
return Array.from(this.data.keys());
|
|
85
|
-
}
|
|
86
|
-
/** Clone the blackboard */
|
|
87
|
-
clone() {
|
|
88
|
-
const bb = new BTBlackboard();
|
|
89
|
-
for (const [key, value] of this.data) {
|
|
90
|
-
bb.data.set(key, value);
|
|
2
|
+
constructor() {
|
|
3
|
+
this.data = /* @__PURE__ */ new Map();
|
|
4
|
+
this.types = /* @__PURE__ */ new Map();
|
|
5
|
+
this.listeners = /* @__PURE__ */ new Map();
|
|
6
|
+
}
|
|
7
|
+
/** Set a value in the blackboard */
|
|
8
|
+
set(key, value) {
|
|
9
|
+
const name = typeof key === "string" ? key : key.name;
|
|
10
|
+
const oldValue = this.data.get(name);
|
|
11
|
+
this.data.set(name, value);
|
|
12
|
+
if (typeof key !== "string") {
|
|
13
|
+
this.types.set(name, key.type);
|
|
14
|
+
}
|
|
15
|
+
if (oldValue !== value) {
|
|
16
|
+
const callbacks = this.listeners.get(name);
|
|
17
|
+
if (callbacks) {
|
|
18
|
+
for (const cb of callbacks) {
|
|
19
|
+
cb(value);
|
|
91
20
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** Get a value from the blackboard */
|
|
25
|
+
get(key) {
|
|
26
|
+
const name = typeof key === "string" ? key : key.name;
|
|
27
|
+
const value = this.data.get(name);
|
|
28
|
+
if (value === void 0 && typeof key !== "string" && key.defaultValue !== void 0) {
|
|
29
|
+
return key.defaultValue;
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
/** Check if key exists */
|
|
34
|
+
has(key) {
|
|
35
|
+
const name = typeof key === "string" ? key : key.name;
|
|
36
|
+
return this.data.has(name);
|
|
37
|
+
}
|
|
38
|
+
/** Remove a key */
|
|
39
|
+
delete(key) {
|
|
40
|
+
const name = typeof key === "string" ? key : key.name;
|
|
41
|
+
this.data.delete(name);
|
|
42
|
+
this.types.delete(name);
|
|
43
|
+
}
|
|
44
|
+
/** Clear all data */
|
|
45
|
+
clear() {
|
|
46
|
+
this.data.clear();
|
|
47
|
+
}
|
|
48
|
+
/** Subscribe to key changes */
|
|
49
|
+
subscribe(key, callback) {
|
|
50
|
+
const name = typeof key === "string" ? key : key.name;
|
|
51
|
+
let callbacks = this.listeners.get(name);
|
|
52
|
+
if (!callbacks) {
|
|
53
|
+
callbacks = [];
|
|
54
|
+
this.listeners.set(name, callbacks);
|
|
55
|
+
}
|
|
56
|
+
callbacks.push(callback);
|
|
57
|
+
return () => {
|
|
58
|
+
const idx = callbacks.indexOf(callback);
|
|
59
|
+
if (idx >= 0) {
|
|
60
|
+
callbacks.splice(idx, 1);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** Get all keys */
|
|
65
|
+
keys() {
|
|
66
|
+
return Array.from(this.data.keys());
|
|
67
|
+
}
|
|
68
|
+
/** Clone the blackboard */
|
|
69
|
+
clone() {
|
|
70
|
+
const bb = new BTBlackboard();
|
|
71
|
+
for (const [key, value] of this.data) {
|
|
72
|
+
bb.data.set(key, value);
|
|
73
|
+
}
|
|
74
|
+
for (const [key, type] of this.types) {
|
|
75
|
+
bb.types.set(key, type);
|
|
76
|
+
}
|
|
77
|
+
return bb;
|
|
78
|
+
}
|
|
79
|
+
/** Export to JSON */
|
|
80
|
+
toJSON() {
|
|
81
|
+
const result = {};
|
|
82
|
+
for (const [key, value] of this.data) {
|
|
83
|
+
result[key] = value;
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
/** Import from JSON */
|
|
88
|
+
fromJSON(data) {
|
|
89
|
+
for (const [key, value] of Object.entries(data)) {
|
|
90
|
+
this.data.set(key, value);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
111
93
|
}
|
|
112
|
-
/** Base class for all behavior tree nodes */
|
|
113
94
|
class BTNode {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
comment: this.comment,
|
|
148
|
-
};
|
|
149
|
-
}
|
|
95
|
+
constructor(type, category, name) {
|
|
96
|
+
this.position = { x: 0, y: 0 };
|
|
97
|
+
this.properties = {};
|
|
98
|
+
this.lastStatus = "inactive";
|
|
99
|
+
this.lastExecutionTime = 0;
|
|
100
|
+
this.id = `bt_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
101
|
+
this.type = type;
|
|
102
|
+
this.category = category;
|
|
103
|
+
this.name = name;
|
|
104
|
+
}
|
|
105
|
+
/** Initialize the node */
|
|
106
|
+
initialize(_context) {
|
|
107
|
+
}
|
|
108
|
+
/** Reset the node state */
|
|
109
|
+
reset() {
|
|
110
|
+
this.lastStatus = "inactive";
|
|
111
|
+
}
|
|
112
|
+
/** Called when execution is aborted */
|
|
113
|
+
abort() {
|
|
114
|
+
this.lastStatus = "aborted";
|
|
115
|
+
}
|
|
116
|
+
/** Serialize to JSON */
|
|
117
|
+
toJSON() {
|
|
118
|
+
return {
|
|
119
|
+
id: this.id,
|
|
120
|
+
type: this.type,
|
|
121
|
+
category: this.category,
|
|
122
|
+
name: this.name,
|
|
123
|
+
position: this.position,
|
|
124
|
+
properties: this.properties,
|
|
125
|
+
comment: this.comment
|
|
126
|
+
};
|
|
127
|
+
}
|
|
150
128
|
}
|
|
151
|
-
// ============================================================
|
|
152
|
-
// Composite Nodes
|
|
153
|
-
// ============================================================
|
|
154
|
-
/** Base class for composite nodes (have children) */
|
|
155
129
|
class BTComposite extends BTNode {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
130
|
+
constructor(type, name) {
|
|
131
|
+
super(type, "composite", name);
|
|
132
|
+
this.children = [];
|
|
133
|
+
this.currentChild = 0;
|
|
134
|
+
}
|
|
135
|
+
addChild(child) {
|
|
136
|
+
this.children.push(child);
|
|
137
|
+
}
|
|
138
|
+
removeChild(child) {
|
|
139
|
+
const idx = this.children.indexOf(child);
|
|
140
|
+
if (idx >= 0) {
|
|
141
|
+
this.children.splice(idx, 1);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
reset() {
|
|
145
|
+
super.reset();
|
|
146
|
+
this.currentChild = 0;
|
|
147
|
+
for (const child of this.children) {
|
|
148
|
+
child.reset();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
abort() {
|
|
152
|
+
super.abort();
|
|
153
|
+
if (this.currentChild < this.children.length) {
|
|
154
|
+
this.children[this.currentChild].abort();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
toJSON() {
|
|
158
|
+
return {
|
|
159
|
+
...super.toJSON(),
|
|
160
|
+
children: this.children.map((c) => c.toJSON())
|
|
161
|
+
};
|
|
162
|
+
}
|
|
190
163
|
}
|
|
191
|
-
/** Sequence: Runs children in order until one fails */
|
|
192
164
|
class BTSequence extends BTComposite {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
this.currentChild = 0;
|
|
207
|
-
this.lastStatus = 'failure';
|
|
208
|
-
return 'failure';
|
|
209
|
-
}
|
|
210
|
-
this.currentChild++;
|
|
211
|
-
}
|
|
165
|
+
constructor(name = "Sequence") {
|
|
166
|
+
super("sequence", name);
|
|
167
|
+
}
|
|
168
|
+
tick(context) {
|
|
169
|
+
while (this.currentChild < this.children.length) {
|
|
170
|
+
const child = this.children[this.currentChild];
|
|
171
|
+
const status = child.tick(context);
|
|
172
|
+
child.lastStatus = status;
|
|
173
|
+
if (status === "running") {
|
|
174
|
+
this.lastStatus = "running";
|
|
175
|
+
return "running";
|
|
176
|
+
}
|
|
177
|
+
if (status === "failure") {
|
|
212
178
|
this.currentChild = 0;
|
|
213
|
-
this.lastStatus =
|
|
214
|
-
return
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
179
|
+
this.lastStatus = "failure";
|
|
180
|
+
return "failure";
|
|
181
|
+
}
|
|
182
|
+
this.currentChild++;
|
|
183
|
+
}
|
|
184
|
+
this.currentChild = 0;
|
|
185
|
+
this.lastStatus = "success";
|
|
186
|
+
return "success";
|
|
187
|
+
}
|
|
188
|
+
clone() {
|
|
189
|
+
const node = new BTSequence(this.name);
|
|
190
|
+
node.properties = { ...this.properties };
|
|
191
|
+
node.position = { ...this.position };
|
|
192
|
+
node.children = this.children.map((c) => c.clone());
|
|
193
|
+
return node;
|
|
194
|
+
}
|
|
223
195
|
}
|
|
224
|
-
/** Selector: Runs children until one succeeds */
|
|
225
196
|
class BTSelector extends BTComposite {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
this.currentChild = 0;
|
|
240
|
-
this.lastStatus = 'success';
|
|
241
|
-
return 'success';
|
|
242
|
-
}
|
|
243
|
-
this.currentChild++;
|
|
244
|
-
}
|
|
197
|
+
constructor(name = "Selector") {
|
|
198
|
+
super("selector", name);
|
|
199
|
+
}
|
|
200
|
+
tick(context) {
|
|
201
|
+
while (this.currentChild < this.children.length) {
|
|
202
|
+
const child = this.children[this.currentChild];
|
|
203
|
+
const status = child.tick(context);
|
|
204
|
+
child.lastStatus = status;
|
|
205
|
+
if (status === "running") {
|
|
206
|
+
this.lastStatus = "running";
|
|
207
|
+
return "running";
|
|
208
|
+
}
|
|
209
|
+
if (status === "success") {
|
|
245
210
|
this.currentChild = 0;
|
|
246
|
-
this.lastStatus =
|
|
247
|
-
return
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
211
|
+
this.lastStatus = "success";
|
|
212
|
+
return "success";
|
|
213
|
+
}
|
|
214
|
+
this.currentChild++;
|
|
215
|
+
}
|
|
216
|
+
this.currentChild = 0;
|
|
217
|
+
this.lastStatus = "failure";
|
|
218
|
+
return "failure";
|
|
219
|
+
}
|
|
220
|
+
clone() {
|
|
221
|
+
const node = new BTSelector(this.name);
|
|
222
|
+
node.properties = { ...this.properties };
|
|
223
|
+
node.position = { ...this.position };
|
|
224
|
+
node.children = this.children.map((c) => c.clone());
|
|
225
|
+
return node;
|
|
226
|
+
}
|
|
256
227
|
}
|
|
257
|
-
/** Parallel: Runs all children simultaneously */
|
|
258
228
|
class BTParallel extends BTComposite {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
successCount++;
|
|
279
|
-
}
|
|
280
|
-
else if (this.childStatuses[i] === 'failure') {
|
|
281
|
-
failureCount++;
|
|
282
|
-
}
|
|
283
|
-
continue;
|
|
284
|
-
}
|
|
285
|
-
const child = this.children[i];
|
|
286
|
-
const status = child.tick(context);
|
|
287
|
-
child.lastStatus = status;
|
|
288
|
-
this.childStatuses[i] = status;
|
|
289
|
-
if (status === 'success') {
|
|
290
|
-
successCount++;
|
|
291
|
-
}
|
|
292
|
-
else if (status === 'failure') {
|
|
293
|
-
failureCount++;
|
|
294
|
-
}
|
|
295
|
-
else {
|
|
296
|
-
runningCount++;
|
|
297
|
-
}
|
|
229
|
+
constructor(name = "Parallel") {
|
|
230
|
+
super("parallel", name);
|
|
231
|
+
this.successPolicy = "all";
|
|
232
|
+
this.failurePolicy = "one";
|
|
233
|
+
this.childStatuses = [];
|
|
234
|
+
}
|
|
235
|
+
initialize(_context) {
|
|
236
|
+
this.childStatuses = new Array(this.children.length).fill("running");
|
|
237
|
+
}
|
|
238
|
+
tick(context) {
|
|
239
|
+
let successCount = 0;
|
|
240
|
+
let failureCount = 0;
|
|
241
|
+
let runningCount = 0;
|
|
242
|
+
for (let i = 0; i < this.children.length; i++) {
|
|
243
|
+
if (this.childStatuses[i] !== "running") {
|
|
244
|
+
if (this.childStatuses[i] === "success") {
|
|
245
|
+
successCount++;
|
|
246
|
+
} else if (this.childStatuses[i] === "failure") {
|
|
247
|
+
failureCount++;
|
|
298
248
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
const child = this.children[i];
|
|
252
|
+
const status = child.tick(context);
|
|
253
|
+
child.lastStatus = status;
|
|
254
|
+
this.childStatuses[i] = status;
|
|
255
|
+
if (status === "success") {
|
|
256
|
+
successCount++;
|
|
257
|
+
} else if (status === "failure") {
|
|
258
|
+
failureCount++;
|
|
259
|
+
} else {
|
|
260
|
+
runningCount++;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (this.failurePolicy === "one" && failureCount > 0) {
|
|
264
|
+
this.reset();
|
|
265
|
+
this.lastStatus = "failure";
|
|
266
|
+
return "failure";
|
|
267
|
+
}
|
|
268
|
+
if (this.failurePolicy === "all" && failureCount === this.children.length) {
|
|
269
|
+
this.reset();
|
|
270
|
+
this.lastStatus = "failure";
|
|
271
|
+
return "failure";
|
|
272
|
+
}
|
|
273
|
+
if (this.successPolicy === "one" && successCount > 0) {
|
|
274
|
+
this.reset();
|
|
275
|
+
this.lastStatus = "success";
|
|
276
|
+
return "success";
|
|
277
|
+
}
|
|
278
|
+
if (this.successPolicy === "all" && successCount === this.children.length) {
|
|
279
|
+
this.reset();
|
|
280
|
+
this.lastStatus = "success";
|
|
281
|
+
return "success";
|
|
282
|
+
}
|
|
283
|
+
if (runningCount > 0) {
|
|
284
|
+
this.lastStatus = "running";
|
|
285
|
+
return "running";
|
|
286
|
+
}
|
|
287
|
+
this.reset();
|
|
288
|
+
this.lastStatus = "failure";
|
|
289
|
+
return "failure";
|
|
290
|
+
}
|
|
291
|
+
reset() {
|
|
292
|
+
super.reset();
|
|
293
|
+
this.childStatuses = [];
|
|
294
|
+
}
|
|
295
|
+
clone() {
|
|
296
|
+
const node = new BTParallel(this.name);
|
|
297
|
+
node.properties = { ...this.properties };
|
|
298
|
+
node.position = { ...this.position };
|
|
299
|
+
node.successPolicy = this.successPolicy;
|
|
300
|
+
node.failurePolicy = this.failurePolicy;
|
|
301
|
+
node.children = this.children.map((c) => c.clone());
|
|
302
|
+
return node;
|
|
303
|
+
}
|
|
344
304
|
}
|
|
345
|
-
/** Random Selector: Selects children in random order */
|
|
346
305
|
class BTRandomSelector extends BTComposite {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
this.currentChild = 0;
|
|
376
|
-
this.shuffle();
|
|
377
|
-
this.lastStatus = 'success';
|
|
378
|
-
return 'success';
|
|
379
|
-
}
|
|
380
|
-
this.currentChild++;
|
|
381
|
-
}
|
|
306
|
+
constructor(name = "Random Selector") {
|
|
307
|
+
super("randomSelector", name);
|
|
308
|
+
this.shuffledOrder = [];
|
|
309
|
+
}
|
|
310
|
+
initialize(_context) {
|
|
311
|
+
this.shuffle();
|
|
312
|
+
}
|
|
313
|
+
shuffle() {
|
|
314
|
+
this.shuffledOrder = this.children.map((_, i) => i);
|
|
315
|
+
for (let i = this.shuffledOrder.length - 1; i > 0; i--) {
|
|
316
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
317
|
+
[this.shuffledOrder[i], this.shuffledOrder[j]] = [
|
|
318
|
+
this.shuffledOrder[j],
|
|
319
|
+
this.shuffledOrder[i]
|
|
320
|
+
];
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
tick(context) {
|
|
324
|
+
while (this.currentChild < this.shuffledOrder.length) {
|
|
325
|
+
const childIdx = this.shuffledOrder[this.currentChild];
|
|
326
|
+
const child = this.children[childIdx];
|
|
327
|
+
const status = child.tick(context);
|
|
328
|
+
child.lastStatus = status;
|
|
329
|
+
if (status === "running") {
|
|
330
|
+
this.lastStatus = "running";
|
|
331
|
+
return "running";
|
|
332
|
+
}
|
|
333
|
+
if (status === "success") {
|
|
382
334
|
this.currentChild = 0;
|
|
383
335
|
this.shuffle();
|
|
384
|
-
this.lastStatus =
|
|
385
|
-
return
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
336
|
+
this.lastStatus = "success";
|
|
337
|
+
return "success";
|
|
338
|
+
}
|
|
339
|
+
this.currentChild++;
|
|
340
|
+
}
|
|
341
|
+
this.currentChild = 0;
|
|
342
|
+
this.shuffle();
|
|
343
|
+
this.lastStatus = "failure";
|
|
344
|
+
return "failure";
|
|
345
|
+
}
|
|
346
|
+
clone() {
|
|
347
|
+
const node = new BTRandomSelector(this.name);
|
|
348
|
+
node.properties = { ...this.properties };
|
|
349
|
+
node.position = { ...this.position };
|
|
350
|
+
node.children = this.children.map((c) => c.clone());
|
|
351
|
+
return node;
|
|
352
|
+
}
|
|
394
353
|
}
|
|
395
|
-
/** Random Sequence: Runs children in random order */
|
|
396
354
|
class BTRandomSequence extends BTComposite {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
this.currentChild = 0;
|
|
426
|
-
this.shuffle();
|
|
427
|
-
this.lastStatus = 'failure';
|
|
428
|
-
return 'failure';
|
|
429
|
-
}
|
|
430
|
-
this.currentChild++;
|
|
431
|
-
}
|
|
355
|
+
constructor(name = "Random Sequence") {
|
|
356
|
+
super("randomSequence", name);
|
|
357
|
+
this.shuffledOrder = [];
|
|
358
|
+
}
|
|
359
|
+
initialize(_context) {
|
|
360
|
+
this.shuffle();
|
|
361
|
+
}
|
|
362
|
+
shuffle() {
|
|
363
|
+
this.shuffledOrder = this.children.map((_, i) => i);
|
|
364
|
+
for (let i = this.shuffledOrder.length - 1; i > 0; i--) {
|
|
365
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
366
|
+
[this.shuffledOrder[i], this.shuffledOrder[j]] = [
|
|
367
|
+
this.shuffledOrder[j],
|
|
368
|
+
this.shuffledOrder[i]
|
|
369
|
+
];
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
tick(context) {
|
|
373
|
+
while (this.currentChild < this.shuffledOrder.length) {
|
|
374
|
+
const childIdx = this.shuffledOrder[this.currentChild];
|
|
375
|
+
const child = this.children[childIdx];
|
|
376
|
+
const status = child.tick(context);
|
|
377
|
+
child.lastStatus = status;
|
|
378
|
+
if (status === "running") {
|
|
379
|
+
this.lastStatus = "running";
|
|
380
|
+
return "running";
|
|
381
|
+
}
|
|
382
|
+
if (status === "failure") {
|
|
432
383
|
this.currentChild = 0;
|
|
433
384
|
this.shuffle();
|
|
434
|
-
this.lastStatus =
|
|
435
|
-
return
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
385
|
+
this.lastStatus = "failure";
|
|
386
|
+
return "failure";
|
|
387
|
+
}
|
|
388
|
+
this.currentChild++;
|
|
389
|
+
}
|
|
390
|
+
this.currentChild = 0;
|
|
391
|
+
this.shuffle();
|
|
392
|
+
this.lastStatus = "success";
|
|
393
|
+
return "success";
|
|
394
|
+
}
|
|
395
|
+
clone() {
|
|
396
|
+
const node = new BTRandomSequence(this.name);
|
|
397
|
+
node.properties = { ...this.properties };
|
|
398
|
+
node.position = { ...this.position };
|
|
399
|
+
node.children = this.children.map((c) => c.clone());
|
|
400
|
+
return node;
|
|
401
|
+
}
|
|
444
402
|
}
|
|
445
|
-
// ============================================================
|
|
446
|
-
// Decorator Nodes
|
|
447
|
-
// ============================================================
|
|
448
|
-
/** Base class for decorator nodes (single child) */
|
|
449
403
|
class BTDecorator extends BTNode {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
404
|
+
constructor(type, name) {
|
|
405
|
+
super(type, "decorator", name);
|
|
406
|
+
this.child = null;
|
|
407
|
+
}
|
|
408
|
+
setChild(child) {
|
|
409
|
+
this.child = child;
|
|
410
|
+
}
|
|
411
|
+
reset() {
|
|
412
|
+
super.reset();
|
|
413
|
+
this.child?.reset();
|
|
414
|
+
}
|
|
415
|
+
abort() {
|
|
416
|
+
super.abort();
|
|
417
|
+
this.child?.abort();
|
|
418
|
+
}
|
|
419
|
+
toJSON() {
|
|
420
|
+
return {
|
|
421
|
+
...super.toJSON(),
|
|
422
|
+
children: this.child ? [this.child.toJSON()] : []
|
|
423
|
+
};
|
|
424
|
+
}
|
|
471
425
|
}
|
|
472
|
-
/** Inverter: Inverts child's result */
|
|
473
426
|
class BTInverter extends BTDecorator {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
427
|
+
constructor(name = "Inverter") {
|
|
428
|
+
super("inverter", name);
|
|
429
|
+
}
|
|
430
|
+
tick(context) {
|
|
431
|
+
if (!this.child) {
|
|
432
|
+
this.lastStatus = "failure";
|
|
433
|
+
return "failure";
|
|
434
|
+
}
|
|
435
|
+
const status = this.child.tick(context);
|
|
436
|
+
this.child.lastStatus = status;
|
|
437
|
+
if (status === "running") {
|
|
438
|
+
this.lastStatus = "running";
|
|
439
|
+
return "running";
|
|
440
|
+
}
|
|
441
|
+
const inverted = status === "success" ? "failure" : "success";
|
|
442
|
+
this.lastStatus = inverted;
|
|
443
|
+
return inverted;
|
|
444
|
+
}
|
|
445
|
+
clone() {
|
|
446
|
+
const node = new BTInverter(this.name);
|
|
447
|
+
node.properties = { ...this.properties };
|
|
448
|
+
node.position = { ...this.position };
|
|
449
|
+
node.child = this.child?.clone() || null;
|
|
450
|
+
return node;
|
|
451
|
+
}
|
|
499
452
|
}
|
|
500
|
-
/** Succeeder: Always returns success */
|
|
501
453
|
class BTSucceeder extends BTDecorator {
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
454
|
+
constructor(name = "Succeeder") {
|
|
455
|
+
super("succeeder", name);
|
|
456
|
+
}
|
|
457
|
+
tick(context) {
|
|
458
|
+
if (!this.child) {
|
|
459
|
+
this.lastStatus = "success";
|
|
460
|
+
return "success";
|
|
461
|
+
}
|
|
462
|
+
const status = this.child.tick(context);
|
|
463
|
+
this.child.lastStatus = status;
|
|
464
|
+
if (status === "running") {
|
|
465
|
+
this.lastStatus = "running";
|
|
466
|
+
return "running";
|
|
467
|
+
}
|
|
468
|
+
this.lastStatus = "success";
|
|
469
|
+
return "success";
|
|
470
|
+
}
|
|
471
|
+
clone() {
|
|
472
|
+
const node = new BTSucceeder(this.name);
|
|
473
|
+
node.properties = { ...this.properties };
|
|
474
|
+
node.position = { ...this.position };
|
|
475
|
+
node.child = this.child?.clone() || null;
|
|
476
|
+
return node;
|
|
477
|
+
}
|
|
526
478
|
}
|
|
527
|
-
/** Failer: Always returns failure */
|
|
528
479
|
class BTFailer extends BTDecorator {
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
480
|
+
constructor(name = "Failer") {
|
|
481
|
+
super("failer", name);
|
|
482
|
+
}
|
|
483
|
+
tick(context) {
|
|
484
|
+
if (!this.child) {
|
|
485
|
+
this.lastStatus = "failure";
|
|
486
|
+
return "failure";
|
|
487
|
+
}
|
|
488
|
+
const status = this.child.tick(context);
|
|
489
|
+
this.child.lastStatus = status;
|
|
490
|
+
if (status === "running") {
|
|
491
|
+
this.lastStatus = "running";
|
|
492
|
+
return "running";
|
|
493
|
+
}
|
|
494
|
+
this.lastStatus = "failure";
|
|
495
|
+
return "failure";
|
|
496
|
+
}
|
|
497
|
+
clone() {
|
|
498
|
+
const node = new BTFailer(this.name);
|
|
499
|
+
node.properties = { ...this.properties };
|
|
500
|
+
node.position = { ...this.position };
|
|
501
|
+
node.child = this.child?.clone() || null;
|
|
502
|
+
return node;
|
|
503
|
+
}
|
|
553
504
|
}
|
|
554
|
-
/** Repeater: Repeats child N times */
|
|
555
505
|
class BTRepeater extends BTDecorator {
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
506
|
+
constructor(name = "Repeater", times = -1) {
|
|
507
|
+
super("repeater", name);
|
|
508
|
+
this.times = -1;
|
|
509
|
+
this.currentCount = 0;
|
|
510
|
+
this.times = times;
|
|
511
|
+
}
|
|
512
|
+
tick(context) {
|
|
513
|
+
if (!this.child) {
|
|
514
|
+
this.lastStatus = "failure";
|
|
515
|
+
return "failure";
|
|
516
|
+
}
|
|
517
|
+
while (this.times === -1 || this.currentCount < this.times) {
|
|
518
|
+
const status = this.child.tick(context);
|
|
519
|
+
this.child.lastStatus = status;
|
|
520
|
+
if (status === "running") {
|
|
521
|
+
this.lastStatus = "running";
|
|
522
|
+
return "running";
|
|
523
|
+
}
|
|
524
|
+
this.currentCount++;
|
|
525
|
+
this.child.reset();
|
|
526
|
+
}
|
|
527
|
+
this.currentCount = 0;
|
|
528
|
+
this.lastStatus = "success";
|
|
529
|
+
return "success";
|
|
530
|
+
}
|
|
531
|
+
reset() {
|
|
532
|
+
super.reset();
|
|
533
|
+
this.currentCount = 0;
|
|
534
|
+
}
|
|
535
|
+
clone() {
|
|
536
|
+
const node = new BTRepeater(this.name, this.times);
|
|
537
|
+
node.properties = { ...this.properties };
|
|
538
|
+
node.position = { ...this.position };
|
|
539
|
+
node.child = this.child?.clone() || null;
|
|
540
|
+
return node;
|
|
541
|
+
}
|
|
592
542
|
}
|
|
593
|
-
/** RepeatUntilFail: Repeats until child fails */
|
|
594
543
|
class BTRepeatUntilFail extends BTDecorator {
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
}
|
|
544
|
+
constructor(name = "Repeat Until Fail") {
|
|
545
|
+
super("repeatUntilFail", name);
|
|
546
|
+
}
|
|
547
|
+
tick(context) {
|
|
548
|
+
if (!this.child) {
|
|
549
|
+
this.lastStatus = "failure";
|
|
550
|
+
return "failure";
|
|
551
|
+
}
|
|
552
|
+
const status = this.child.tick(context);
|
|
553
|
+
this.child.lastStatus = status;
|
|
554
|
+
if (status === "failure") {
|
|
555
|
+
this.lastStatus = "success";
|
|
556
|
+
return "success";
|
|
557
|
+
}
|
|
558
|
+
if (status === "running") {
|
|
559
|
+
this.lastStatus = "running";
|
|
560
|
+
return "running";
|
|
561
|
+
}
|
|
562
|
+
this.child.reset();
|
|
563
|
+
this.lastStatus = "running";
|
|
564
|
+
return "running";
|
|
565
|
+
}
|
|
566
|
+
clone() {
|
|
567
|
+
const node = new BTRepeatUntilFail(this.name);
|
|
568
|
+
node.properties = { ...this.properties };
|
|
569
|
+
node.position = { ...this.position };
|
|
570
|
+
node.child = this.child?.clone() || null;
|
|
571
|
+
return node;
|
|
572
|
+
}
|
|
625
573
|
}
|
|
626
|
-
/** RepeatUntilSuccess: Repeats until child succeeds */
|
|
627
574
|
class BTRepeatUntilSuccess extends BTDecorator {
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
}
|
|
575
|
+
constructor(name = "Repeat Until Success") {
|
|
576
|
+
super("repeatUntilSuccess", name);
|
|
577
|
+
}
|
|
578
|
+
tick(context) {
|
|
579
|
+
if (!this.child) {
|
|
580
|
+
this.lastStatus = "failure";
|
|
581
|
+
return "failure";
|
|
582
|
+
}
|
|
583
|
+
const status = this.child.tick(context);
|
|
584
|
+
this.child.lastStatus = status;
|
|
585
|
+
if (status === "success") {
|
|
586
|
+
this.lastStatus = "success";
|
|
587
|
+
return "success";
|
|
588
|
+
}
|
|
589
|
+
if (status === "running") {
|
|
590
|
+
this.lastStatus = "running";
|
|
591
|
+
return "running";
|
|
592
|
+
}
|
|
593
|
+
this.child.reset();
|
|
594
|
+
this.lastStatus = "running";
|
|
595
|
+
return "running";
|
|
596
|
+
}
|
|
597
|
+
clone() {
|
|
598
|
+
const node = new BTRepeatUntilSuccess(this.name);
|
|
599
|
+
node.properties = { ...this.properties };
|
|
600
|
+
node.position = { ...this.position };
|
|
601
|
+
node.child = this.child?.clone() || null;
|
|
602
|
+
return node;
|
|
603
|
+
}
|
|
658
604
|
}
|
|
659
|
-
/** Timeout: Fails if child takes too long */
|
|
660
605
|
class BTTimeout extends BTDecorator {
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
606
|
+
constructor(name = "Timeout", seconds = 5) {
|
|
607
|
+
super("timeout", name);
|
|
608
|
+
this.elapsed = 0;
|
|
609
|
+
this.started = false;
|
|
610
|
+
this.timeoutSeconds = seconds;
|
|
611
|
+
}
|
|
612
|
+
tick(context) {
|
|
613
|
+
if (!this.child) {
|
|
614
|
+
this.lastStatus = "failure";
|
|
615
|
+
return "failure";
|
|
616
|
+
}
|
|
617
|
+
if (!this.started) {
|
|
618
|
+
this.elapsed = 0;
|
|
619
|
+
this.started = true;
|
|
620
|
+
}
|
|
621
|
+
this.elapsed += context.dt;
|
|
622
|
+
if (this.elapsed >= this.timeoutSeconds) {
|
|
623
|
+
this.child.abort();
|
|
624
|
+
this.started = false;
|
|
625
|
+
this.lastStatus = "failure";
|
|
626
|
+
return "failure";
|
|
627
|
+
}
|
|
628
|
+
const status = this.child.tick(context);
|
|
629
|
+
this.child.lastStatus = status;
|
|
630
|
+
if (status !== "running") {
|
|
631
|
+
this.started = false;
|
|
632
|
+
}
|
|
633
|
+
this.lastStatus = status;
|
|
634
|
+
return status;
|
|
635
|
+
}
|
|
636
|
+
reset() {
|
|
637
|
+
super.reset();
|
|
638
|
+
this.elapsed = 0;
|
|
639
|
+
this.started = false;
|
|
640
|
+
}
|
|
641
|
+
clone() {
|
|
642
|
+
const node = new BTTimeout(this.name, this.timeoutSeconds);
|
|
643
|
+
node.properties = { ...this.properties };
|
|
644
|
+
node.position = { ...this.position };
|
|
645
|
+
node.child = this.child?.clone() || null;
|
|
646
|
+
return node;
|
|
647
|
+
}
|
|
703
648
|
}
|
|
704
|
-
/** Cooldown: Rate limits child execution */
|
|
705
649
|
class BTCooldown extends BTDecorator {
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
}
|
|
650
|
+
constructor(name = "Cooldown", seconds = 1) {
|
|
651
|
+
super("cooldown", name);
|
|
652
|
+
this.lastExecution = -Infinity;
|
|
653
|
+
this.cooldownSeconds = seconds;
|
|
654
|
+
}
|
|
655
|
+
tick(context) {
|
|
656
|
+
if (!this.child) {
|
|
657
|
+
this.lastStatus = "failure";
|
|
658
|
+
return "failure";
|
|
659
|
+
}
|
|
660
|
+
const elapsed = context.time - this.lastExecution;
|
|
661
|
+
if (elapsed < this.cooldownSeconds) {
|
|
662
|
+
this.lastStatus = "failure";
|
|
663
|
+
return "failure";
|
|
664
|
+
}
|
|
665
|
+
const status = this.child.tick(context);
|
|
666
|
+
this.child.lastStatus = status;
|
|
667
|
+
if (status !== "running") {
|
|
668
|
+
this.lastExecution = context.time;
|
|
669
|
+
}
|
|
670
|
+
this.lastStatus = status;
|
|
671
|
+
return status;
|
|
672
|
+
}
|
|
673
|
+
reset() {
|
|
674
|
+
super.reset();
|
|
675
|
+
}
|
|
676
|
+
clone() {
|
|
677
|
+
const node = new BTCooldown(this.name, this.cooldownSeconds);
|
|
678
|
+
node.properties = { ...this.properties };
|
|
679
|
+
node.position = { ...this.position };
|
|
680
|
+
node.child = this.child?.clone() || null;
|
|
681
|
+
return node;
|
|
682
|
+
}
|
|
740
683
|
}
|
|
741
|
-
/** Condition Guard: Only runs child if condition is true */
|
|
742
684
|
class BTConditionGuard extends BTDecorator {
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
685
|
+
constructor(name = "Guard", condition = () => true) {
|
|
686
|
+
super("guard", name);
|
|
687
|
+
this.condition = condition;
|
|
688
|
+
}
|
|
689
|
+
tick(context) {
|
|
690
|
+
if (!this.child) {
|
|
691
|
+
this.lastStatus = "failure";
|
|
692
|
+
return "failure";
|
|
693
|
+
}
|
|
694
|
+
if (!this.condition(context)) {
|
|
695
|
+
this.lastStatus = "failure";
|
|
696
|
+
return "failure";
|
|
697
|
+
}
|
|
698
|
+
const status = this.child.tick(context);
|
|
699
|
+
this.child.lastStatus = status;
|
|
700
|
+
this.lastStatus = status;
|
|
701
|
+
return status;
|
|
702
|
+
}
|
|
703
|
+
clone() {
|
|
704
|
+
const node = new BTConditionGuard(this.name, this.condition);
|
|
705
|
+
node.properties = { ...this.properties };
|
|
706
|
+
node.position = { ...this.position };
|
|
707
|
+
node.child = this.child?.clone() || null;
|
|
708
|
+
return node;
|
|
709
|
+
}
|
|
768
710
|
}
|
|
769
|
-
/** Wait Action: Waits for a duration */
|
|
770
711
|
class BTWait extends BTNode {
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
712
|
+
constructor(name = "Wait", seconds = 1) {
|
|
713
|
+
super("wait", "action", name);
|
|
714
|
+
this.elapsed = 0;
|
|
715
|
+
this.started = false;
|
|
716
|
+
this.seconds = seconds;
|
|
717
|
+
}
|
|
718
|
+
tick(context) {
|
|
719
|
+
if (!this.started) {
|
|
720
|
+
this.elapsed = 0;
|
|
721
|
+
this.started = true;
|
|
722
|
+
}
|
|
723
|
+
this.elapsed += context.dt;
|
|
724
|
+
if (this.elapsed >= this.seconds) {
|
|
725
|
+
this.started = false;
|
|
726
|
+
this.lastStatus = "success";
|
|
727
|
+
return "success";
|
|
728
|
+
}
|
|
729
|
+
this.lastStatus = "running";
|
|
730
|
+
return "running";
|
|
731
|
+
}
|
|
732
|
+
reset() {
|
|
733
|
+
super.reset();
|
|
734
|
+
this.elapsed = 0;
|
|
735
|
+
this.started = false;
|
|
736
|
+
}
|
|
737
|
+
clone() {
|
|
738
|
+
const node = new BTWait(this.name, this.seconds);
|
|
739
|
+
node.properties = { ...this.properties };
|
|
740
|
+
node.position = { ...this.position };
|
|
741
|
+
return node;
|
|
742
|
+
}
|
|
802
743
|
}
|
|
803
|
-
/** Log Action: Logs a message */
|
|
804
744
|
class BTLog extends BTNode {
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
745
|
+
constructor(name = "Log", message = "", level = "info") {
|
|
746
|
+
super("log", "action", name);
|
|
747
|
+
this.message = message;
|
|
748
|
+
this.level = level;
|
|
749
|
+
}
|
|
750
|
+
tick(_context) {
|
|
751
|
+
console.log(`[BT ${this.level}] ${this.message}`);
|
|
752
|
+
this.lastStatus = "success";
|
|
753
|
+
return "success";
|
|
754
|
+
}
|
|
755
|
+
clone() {
|
|
756
|
+
const node = new BTLog(this.name, this.message, this.level);
|
|
757
|
+
node.properties = { ...this.properties };
|
|
758
|
+
node.position = { ...this.position };
|
|
759
|
+
return node;
|
|
760
|
+
}
|
|
821
761
|
}
|
|
822
|
-
// ============================================================
|
|
823
|
-
// Subtree Node
|
|
824
|
-
// ============================================================
|
|
825
762
|
class BTSubtree extends BTNode {
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
763
|
+
constructor(name, subtreeId) {
|
|
764
|
+
super("subtree", "subtree", name);
|
|
765
|
+
this.subtree = null;
|
|
766
|
+
this.subtreeId = subtreeId;
|
|
767
|
+
}
|
|
768
|
+
setSubtree(tree) {
|
|
769
|
+
this.subtree = tree;
|
|
770
|
+
}
|
|
771
|
+
tick(context) {
|
|
772
|
+
if (!this.subtree) {
|
|
773
|
+
this.lastStatus = "failure";
|
|
774
|
+
return "failure";
|
|
775
|
+
}
|
|
776
|
+
const status = this.subtree.tick(context);
|
|
777
|
+
this.lastStatus = status;
|
|
778
|
+
return status;
|
|
779
|
+
}
|
|
780
|
+
reset() {
|
|
781
|
+
super.reset();
|
|
782
|
+
this.subtree?.reset();
|
|
783
|
+
}
|
|
784
|
+
clone() {
|
|
785
|
+
const node = new BTSubtree(this.name, this.subtreeId);
|
|
786
|
+
node.properties = { ...this.properties };
|
|
787
|
+
node.position = { ...this.position };
|
|
788
|
+
node.subtree = this.subtree?.clone() || null;
|
|
789
|
+
return node;
|
|
790
|
+
}
|
|
854
791
|
}
|
|
855
|
-
// ============================================================
|
|
856
|
-
// Root Node
|
|
857
|
-
// ============================================================
|
|
858
792
|
class BTRoot extends BTNode {
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
793
|
+
constructor(name = "Root") {
|
|
794
|
+
super("root", "root", name);
|
|
795
|
+
this.child = null;
|
|
796
|
+
}
|
|
797
|
+
setChild(child) {
|
|
798
|
+
this.child = child;
|
|
799
|
+
}
|
|
800
|
+
tick(context) {
|
|
801
|
+
if (!this.child) {
|
|
802
|
+
this.lastStatus = "success";
|
|
803
|
+
return "success";
|
|
804
|
+
}
|
|
805
|
+
const status = this.child.tick(context);
|
|
806
|
+
this.child.lastStatus = status;
|
|
807
|
+
this.lastStatus = status;
|
|
808
|
+
return status;
|
|
809
|
+
}
|
|
810
|
+
reset() {
|
|
811
|
+
super.reset();
|
|
812
|
+
this.child?.reset();
|
|
813
|
+
}
|
|
814
|
+
toJSON() {
|
|
815
|
+
return {
|
|
816
|
+
...super.toJSON(),
|
|
817
|
+
children: this.child ? [this.child.toJSON()] : []
|
|
818
|
+
};
|
|
819
|
+
}
|
|
820
|
+
clone() {
|
|
821
|
+
const node = new BTRoot(this.name);
|
|
822
|
+
node.properties = { ...this.properties };
|
|
823
|
+
node.position = { ...this.position };
|
|
824
|
+
node.child = this.child?.clone() || null;
|
|
825
|
+
return node;
|
|
826
|
+
}
|
|
893
827
|
}
|
|
894
|
-
// ============================================================
|
|
895
|
-
// Behavior Tree
|
|
896
|
-
// ============================================================
|
|
897
828
|
class BehaviorTree {
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
return node;
|
|
971
|
-
}
|
|
972
|
-
if (node instanceof BTComposite) {
|
|
973
|
-
for (const child of node.children) {
|
|
974
|
-
const found = this.findNodeRecursive(child, nodeId);
|
|
975
|
-
if (found) {
|
|
976
|
-
return found;
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
|
-
}
|
|
980
|
-
else if (node instanceof BTDecorator && node.child) {
|
|
981
|
-
return this.findNodeRecursive(node.child, nodeId);
|
|
982
|
-
}
|
|
983
|
-
else if (node instanceof BTRoot && node.child) {
|
|
984
|
-
return this.findNodeRecursive(node.child, nodeId);
|
|
985
|
-
}
|
|
986
|
-
return null;
|
|
987
|
-
}
|
|
988
|
-
/** Get all nodes */
|
|
989
|
-
getAllNodes() {
|
|
990
|
-
const nodes = [];
|
|
991
|
-
this.collectNodes(this.root, nodes);
|
|
992
|
-
return nodes;
|
|
993
|
-
}
|
|
994
|
-
collectNodes(node, nodes) {
|
|
995
|
-
nodes.push(node);
|
|
996
|
-
if (node instanceof BTComposite) {
|
|
997
|
-
for (const child of node.children) {
|
|
998
|
-
this.collectNodes(child, nodes);
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
else if (node instanceof BTDecorator && node.child) {
|
|
1002
|
-
this.collectNodes(node.child, nodes);
|
|
1003
|
-
}
|
|
1004
|
-
else if (node instanceof BTRoot && node.child) {
|
|
1005
|
-
this.collectNodes(node.child, nodes);
|
|
829
|
+
constructor(name = "Behavior Tree") {
|
|
830
|
+
this.stats = {
|
|
831
|
+
tickCount: 0,
|
|
832
|
+
lastTickTime: 0,
|
|
833
|
+
averageTickTime: 0
|
|
834
|
+
};
|
|
835
|
+
this.debugMode = false;
|
|
836
|
+
this.breakpoints = /* @__PURE__ */ new Set();
|
|
837
|
+
this.isPaused = false;
|
|
838
|
+
this.id = `tree_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
839
|
+
this.name = name;
|
|
840
|
+
this.root = new BTRoot();
|
|
841
|
+
this.blackboard = new BTBlackboard();
|
|
842
|
+
}
|
|
843
|
+
/** Tick the tree */
|
|
844
|
+
tick(context) {
|
|
845
|
+
if (this.isPaused) {
|
|
846
|
+
return "running";
|
|
847
|
+
}
|
|
848
|
+
const mergedContext = {
|
|
849
|
+
...context,
|
|
850
|
+
blackboard: this.blackboard
|
|
851
|
+
};
|
|
852
|
+
const startTime = performance.now();
|
|
853
|
+
const status = this.root.tick(mergedContext);
|
|
854
|
+
const endTime = performance.now();
|
|
855
|
+
this.stats.tickCount++;
|
|
856
|
+
this.stats.lastTickTime = endTime - startTime;
|
|
857
|
+
this.stats.averageTickTime = (this.stats.averageTickTime * (this.stats.tickCount - 1) + this.stats.lastTickTime) / this.stats.tickCount;
|
|
858
|
+
return status;
|
|
859
|
+
}
|
|
860
|
+
/** Reset the tree */
|
|
861
|
+
reset() {
|
|
862
|
+
this.root.reset();
|
|
863
|
+
}
|
|
864
|
+
/** Pause execution */
|
|
865
|
+
pause() {
|
|
866
|
+
this.isPaused = true;
|
|
867
|
+
}
|
|
868
|
+
/** Resume execution */
|
|
869
|
+
resume() {
|
|
870
|
+
this.isPaused = false;
|
|
871
|
+
}
|
|
872
|
+
/** Add breakpoint */
|
|
873
|
+
addBreakpoint(nodeId) {
|
|
874
|
+
this.breakpoints.add(nodeId);
|
|
875
|
+
}
|
|
876
|
+
/** Remove breakpoint */
|
|
877
|
+
removeBreakpoint(nodeId) {
|
|
878
|
+
this.breakpoints.delete(nodeId);
|
|
879
|
+
}
|
|
880
|
+
/** Toggle breakpoint */
|
|
881
|
+
toggleBreakpoint(nodeId) {
|
|
882
|
+
if (this.breakpoints.has(nodeId)) {
|
|
883
|
+
this.breakpoints.delete(nodeId);
|
|
884
|
+
} else {
|
|
885
|
+
this.breakpoints.add(nodeId);
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
/** Find node by ID */
|
|
889
|
+
findNode(nodeId) {
|
|
890
|
+
return this.findNodeRecursive(this.root, nodeId);
|
|
891
|
+
}
|
|
892
|
+
findNodeRecursive(node, nodeId) {
|
|
893
|
+
if (node.id === nodeId) {
|
|
894
|
+
return node;
|
|
895
|
+
}
|
|
896
|
+
if (node instanceof BTComposite) {
|
|
897
|
+
for (const child of node.children) {
|
|
898
|
+
const found = this.findNodeRecursive(child, nodeId);
|
|
899
|
+
if (found) {
|
|
900
|
+
return found;
|
|
1006
901
|
}
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
902
|
+
}
|
|
903
|
+
} else if (node instanceof BTDecorator && node.child) {
|
|
904
|
+
return this.findNodeRecursive(node.child, nodeId);
|
|
905
|
+
} else if (node instanceof BTRoot && node.child) {
|
|
906
|
+
return this.findNodeRecursive(node.child, nodeId);
|
|
907
|
+
}
|
|
908
|
+
return null;
|
|
909
|
+
}
|
|
910
|
+
/** Get all nodes */
|
|
911
|
+
getAllNodes() {
|
|
912
|
+
const nodes = [];
|
|
913
|
+
this.collectNodes(this.root, nodes);
|
|
914
|
+
return nodes;
|
|
915
|
+
}
|
|
916
|
+
collectNodes(node, nodes) {
|
|
917
|
+
nodes.push(node);
|
|
918
|
+
if (node instanceof BTComposite) {
|
|
919
|
+
for (const child of node.children) {
|
|
920
|
+
this.collectNodes(child, nodes);
|
|
921
|
+
}
|
|
922
|
+
} else if (node instanceof BTDecorator && node.child) {
|
|
923
|
+
this.collectNodes(node.child, nodes);
|
|
924
|
+
} else if (node instanceof BTRoot && node.child) {
|
|
925
|
+
this.collectNodes(node.child, nodes);
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
/** Clone the tree */
|
|
929
|
+
clone() {
|
|
930
|
+
const tree = new BehaviorTree(this.name);
|
|
931
|
+
tree.root = this.root.clone();
|
|
932
|
+
tree.blackboard = this.blackboard.clone();
|
|
933
|
+
return tree;
|
|
934
|
+
}
|
|
935
|
+
/** Serialize to JSON */
|
|
936
|
+
toJSON() {
|
|
937
|
+
return {
|
|
938
|
+
id: this.id,
|
|
939
|
+
name: this.name,
|
|
940
|
+
root: this.root.toJSON(),
|
|
941
|
+
blackboard: this.blackboard.toJSON()
|
|
942
|
+
};
|
|
943
|
+
}
|
|
1024
944
|
}
|
|
1025
|
-
// ============================================================
|
|
1026
|
-
// Node Registry
|
|
1027
|
-
// ============================================================
|
|
1028
945
|
class BTNodeRegistry {
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
946
|
+
constructor() {
|
|
947
|
+
this.definitions = /* @__PURE__ */ new Map();
|
|
948
|
+
}
|
|
949
|
+
register(definition) {
|
|
950
|
+
this.definitions.set(definition.type, definition);
|
|
951
|
+
}
|
|
952
|
+
get(type) {
|
|
953
|
+
return this.definitions.get(type);
|
|
954
|
+
}
|
|
955
|
+
getAll() {
|
|
956
|
+
return Array.from(this.definitions.values());
|
|
957
|
+
}
|
|
958
|
+
getByCategory(category) {
|
|
959
|
+
return this.getAll().filter((d) => d.category === category);
|
|
960
|
+
}
|
|
961
|
+
createNode(type, properties) {
|
|
962
|
+
const def = this.definitions.get(type);
|
|
963
|
+
if (!def) {
|
|
964
|
+
return null;
|
|
965
|
+
}
|
|
966
|
+
return def.create(properties);
|
|
967
|
+
}
|
|
1051
968
|
}
|
|
1052
|
-
// ============================================================
|
|
1053
|
-
// Factory Functions
|
|
1054
|
-
// ============================================================
|
|
1055
969
|
function createBehaviorTree(name) {
|
|
1056
|
-
|
|
970
|
+
return new BehaviorTree(name);
|
|
1057
971
|
}
|
|
1058
972
|
function createBlackboard() {
|
|
1059
|
-
|
|
973
|
+
return new BTBlackboard();
|
|
1060
974
|
}
|
|
1061
975
|
function createNodeRegistry() {
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
976
|
+
const registry = new BTNodeRegistry();
|
|
977
|
+
registry.register({
|
|
978
|
+
type: "sequence",
|
|
979
|
+
category: "composite",
|
|
980
|
+
name: "Sequence",
|
|
981
|
+
description: "Executes children in order until one fails",
|
|
982
|
+
icon: "arrow-right",
|
|
983
|
+
color: "#3b82f6",
|
|
984
|
+
create: () => new BTSequence()
|
|
985
|
+
});
|
|
986
|
+
registry.register({
|
|
987
|
+
type: "selector",
|
|
988
|
+
category: "composite",
|
|
989
|
+
name: "Selector",
|
|
990
|
+
description: "Executes children until one succeeds",
|
|
991
|
+
icon: "git-branch",
|
|
992
|
+
color: "#22c55e",
|
|
993
|
+
create: () => new BTSelector()
|
|
994
|
+
});
|
|
995
|
+
registry.register({
|
|
996
|
+
type: "parallel",
|
|
997
|
+
category: "composite",
|
|
998
|
+
name: "Parallel",
|
|
999
|
+
description: "Executes all children simultaneously",
|
|
1000
|
+
icon: "layers",
|
|
1001
|
+
color: "#8b5cf6",
|
|
1002
|
+
properties: [
|
|
1003
|
+
{ name: "successPolicy", type: "enum", enumValues: ["all", "one"], default: "all" },
|
|
1004
|
+
{ name: "failurePolicy", type: "enum", enumValues: ["all", "one"], default: "one" }
|
|
1005
|
+
],
|
|
1006
|
+
create: (props) => {
|
|
1007
|
+
const node = new BTParallel();
|
|
1008
|
+
if (props?.successPolicy) {
|
|
1009
|
+
node.successPolicy = props.successPolicy;
|
|
1010
|
+
}
|
|
1011
|
+
if (props?.failurePolicy) {
|
|
1012
|
+
node.failurePolicy = props.failurePolicy;
|
|
1013
|
+
}
|
|
1014
|
+
return node;
|
|
1015
|
+
}
|
|
1016
|
+
});
|
|
1017
|
+
registry.register({
|
|
1018
|
+
type: "inverter",
|
|
1019
|
+
category: "decorator",
|
|
1020
|
+
name: "Inverter",
|
|
1021
|
+
description: "Inverts the result of its child",
|
|
1022
|
+
icon: "refresh-cw",
|
|
1023
|
+
color: "#f97316",
|
|
1024
|
+
create: () => new BTInverter()
|
|
1025
|
+
});
|
|
1026
|
+
registry.register({
|
|
1027
|
+
type: "repeater",
|
|
1028
|
+
category: "decorator",
|
|
1029
|
+
name: "Repeater",
|
|
1030
|
+
description: "Repeats child N times (-1 = infinite)",
|
|
1031
|
+
icon: "repeat",
|
|
1032
|
+
color: "#f97316",
|
|
1033
|
+
properties: [{ name: "times", type: "number", default: -1, min: -1 }],
|
|
1034
|
+
create: (props) => new BTRepeater("Repeater", props?.times ?? -1)
|
|
1035
|
+
});
|
|
1036
|
+
registry.register({
|
|
1037
|
+
type: "timeout",
|
|
1038
|
+
category: "decorator",
|
|
1039
|
+
name: "Timeout",
|
|
1040
|
+
description: "Fails if child takes too long",
|
|
1041
|
+
icon: "clock",
|
|
1042
|
+
color: "#f97316",
|
|
1043
|
+
properties: [{ name: "seconds", type: "number", default: 5, min: 0 }],
|
|
1044
|
+
create: (props) => new BTTimeout("Timeout", props?.seconds ?? 5)
|
|
1045
|
+
});
|
|
1046
|
+
registry.register({
|
|
1047
|
+
type: "wait",
|
|
1048
|
+
category: "action",
|
|
1049
|
+
name: "Wait",
|
|
1050
|
+
description: "Waits for a duration",
|
|
1051
|
+
icon: "pause",
|
|
1052
|
+
color: "#6b7280",
|
|
1053
|
+
properties: [{ name: "seconds", type: "number", default: 1, min: 0 }],
|
|
1054
|
+
create: (props) => new BTWait("Wait", props?.seconds ?? 1)
|
|
1055
|
+
});
|
|
1056
|
+
registry.register({
|
|
1057
|
+
type: "log",
|
|
1058
|
+
category: "action",
|
|
1059
|
+
name: "Log",
|
|
1060
|
+
description: "Logs a message",
|
|
1061
|
+
icon: "message-square",
|
|
1062
|
+
color: "#6b7280",
|
|
1063
|
+
properties: [
|
|
1064
|
+
{ name: "message", type: "string", default: "" },
|
|
1065
|
+
{ name: "level", type: "enum", enumValues: ["info", "warn", "error"], default: "info" }
|
|
1066
|
+
],
|
|
1067
|
+
create: (props) => new BTLog(
|
|
1068
|
+
"Log",
|
|
1069
|
+
props?.message ?? "",
|
|
1070
|
+
props?.level ?? "info"
|
|
1071
|
+
)
|
|
1072
|
+
});
|
|
1073
|
+
return registry;
|
|
1157
1074
|
}
|
|
1158
|
-
/** Create execution context */
|
|
1159
1075
|
function createBTContext(params) {
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
}
|
|
1076
|
+
let isAborted = false;
|
|
1077
|
+
return {
|
|
1078
|
+
entityId: params.entityId,
|
|
1079
|
+
blackboard: params.blackboard || new BTBlackboard(),
|
|
1080
|
+
dt: params.dt,
|
|
1081
|
+
time: params.time,
|
|
1082
|
+
world: params.world,
|
|
1083
|
+
emit: () => {
|
|
1084
|
+
},
|
|
1085
|
+
abort: () => {
|
|
1086
|
+
isAborted = true;
|
|
1087
|
+
},
|
|
1088
|
+
get isAborted() {
|
|
1089
|
+
return isAborted;
|
|
1090
|
+
}
|
|
1091
|
+
};
|
|
1175
1092
|
}
|
|
1176
|
-
|
|
1177
|
-
|
|
1093
|
+
export {
|
|
1094
|
+
BTBlackboard,
|
|
1095
|
+
BTComposite,
|
|
1096
|
+
BTConditionGuard,
|
|
1097
|
+
BTCooldown,
|
|
1098
|
+
BTDecorator,
|
|
1099
|
+
BTFailer,
|
|
1100
|
+
BTInverter,
|
|
1101
|
+
BTLog,
|
|
1102
|
+
BTNode,
|
|
1103
|
+
BTNodeRegistry,
|
|
1104
|
+
BTParallel,
|
|
1105
|
+
BTRandomSelector,
|
|
1106
|
+
BTRandomSequence,
|
|
1107
|
+
BTRepeatUntilFail,
|
|
1108
|
+
BTRepeatUntilSuccess,
|
|
1109
|
+
BTRepeater,
|
|
1110
|
+
BTRoot,
|
|
1111
|
+
BTSelector,
|
|
1112
|
+
BTSequence,
|
|
1113
|
+
BTSubtree,
|
|
1114
|
+
BTSucceeder,
|
|
1115
|
+
BTTimeout,
|
|
1116
|
+
BTWait,
|
|
1117
|
+
BehaviorTree,
|
|
1118
|
+
createBTContext,
|
|
1119
|
+
createBehaviorTree,
|
|
1120
|
+
createBlackboard,
|
|
1121
|
+
createNodeRegistry
|
|
1122
|
+
};
|