@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.
Files changed (434) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/accessibility/Accessibility.js +152 -165
  3. package/dist/cjs/ai/AI.js +292 -294
  4. package/dist/cjs/ai/BehaviorTree.js +1029 -1113
  5. package/dist/cjs/ai/StateMachine.js +694 -756
  6. package/dist/cjs/animation/Animation.js +232 -241
  7. package/dist/cjs/audio/AudioAdvanced.js +221 -236
  8. package/dist/cjs/audio/AudioBridge.js +441 -435
  9. package/dist/cjs/audio/AudioManager.js +242 -259
  10. package/dist/cjs/build-cloud/BuildOrchestration.js +1059 -1098
  11. package/dist/cjs/build-cloud/GodotBuildCloud.js +641 -670
  12. package/dist/cjs/build-cloud/UnityBuildCloud.js +563 -610
  13. package/dist/cjs/build-cloud/UnrealBuildCloud.js +610 -635
  14. package/dist/cjs/core/EventBus.js +51 -56
  15. package/dist/cjs/core/GameClock.js +62 -66
  16. package/dist/cjs/core/GameConfig.js +72 -79
  17. package/dist/cjs/core/GameLoop.js +80 -89
  18. package/dist/cjs/core/ServiceLocator.js +61 -65
  19. package/dist/cjs/core/Validation.js +72 -82
  20. package/dist/cjs/core/math.js +108 -112
  21. package/dist/cjs/devtools/DevTools.js +542 -563
  22. package/dist/cjs/devtools/DeveloperExperience.js +521 -559
  23. package/dist/cjs/devtools/GameplayAnalytics.js +636 -646
  24. package/dist/cjs/dialogue/DialogueSystem.js +984 -986
  25. package/dist/cjs/docs/DocGenerator.js +339 -364
  26. package/dist/cjs/ecs/World.js +355 -371
  27. package/dist/cjs/editor/AchievementEditor.js +580 -636
  28. package/dist/cjs/editor/AdvancedEditor.js +184 -191
  29. package/dist/cjs/editor/AnimationRetargeting.js +696 -741
  30. package/dist/cjs/editor/AssetBrowser.js +1072 -1160
  31. package/dist/cjs/editor/AssetManager.js +187 -192
  32. package/dist/cjs/editor/ConsolePro.js +971 -1061
  33. package/dist/cjs/editor/CraftingEditor.js +680 -730
  34. package/dist/cjs/editor/DebugTools.js +187 -185
  35. package/dist/cjs/editor/DialogueSystem.js +844 -901
  36. package/dist/cjs/editor/LeaderboardSystem.js +429 -483
  37. package/dist/cjs/editor/NiceGameEditor.js +1903 -1201
  38. package/dist/cjs/editor/PrefabSystem.js +772 -838
  39. package/dist/cjs/editor/ProfilerPanel.js +649 -700
  40. package/dist/cjs/editor/QuestEditor.js +792 -839
  41. package/dist/cjs/editor/ReplaySystem.js +585 -634
  42. package/dist/cjs/editor/SceneEditor.js +176 -200
  43. package/dist/cjs/editor/ScreenshotMode.js +621 -688
  44. package/dist/cjs/editor/ShaderGraph.js +1556 -1582
  45. package/dist/cjs/editor/TimelineEditor.js +715 -778
  46. package/dist/cjs/editor/UndoRedoPro.js +830 -904
  47. package/dist/cjs/editor/VRARMode.js +582 -645
  48. package/dist/cjs/engine/NiceGameEngine.js +141 -164
  49. package/dist/cjs/engine/SaveSystem.js +441 -495
  50. package/dist/cjs/enterprise/Enterprise.js +254 -261
  51. package/dist/cjs/export/BevyExporter.js +927 -967
  52. package/dist/cjs/export/CocosExporter.js +644 -673
  53. package/dist/cjs/export/Construct3Exporter.js +783 -794
  54. package/dist/cjs/export/DefoldExporter.js +1028 -1069
  55. package/dist/cjs/export/GDevelopExporter.js +674 -708
  56. package/dist/cjs/export/GameMakerExporter.js +791 -805
  57. package/dist/cjs/export/GodotExporter.js +1003 -1045
  58. package/dist/cjs/export/MinecraftBedrockExporter.js +573 -578
  59. package/dist/cjs/export/MonoGameExporter.js +1265 -1293
  60. package/dist/cjs/export/Pico8Exporter.js +766 -812
  61. package/dist/cjs/export/PlatformExporter.js +188 -206
  62. package/dist/cjs/export/RPGMakerExporter.js +860 -879
  63. package/dist/cjs/export/RobloxExporter.js +883 -919
  64. package/dist/cjs/export/Solar2DExporter.js +1218 -1256
  65. package/dist/cjs/export/ThreeJSExporter.js +1006 -1073
  66. package/dist/cjs/export/Tic80Exporter.js +1210 -1267
  67. package/dist/cjs/export/UnityExporter.js +1116 -1131
  68. package/dist/cjs/export/UnrealExporter.js +889 -919
  69. package/dist/cjs/export/WebExporter.js +931 -970
  70. package/dist/cjs/export/index.js +42 -65
  71. package/dist/cjs/godot-integration/GodotAssetLibrary.js +659 -692
  72. package/dist/cjs/godot-integration/GodotImport.js +929 -1027
  73. package/dist/cjs/godot-integration/GodotLiveLink.js +915 -945
  74. package/dist/cjs/godot-integration/components/GodotProjectBrowser.js +911 -611
  75. package/dist/cjs/i18n/I18n.js +860 -900
  76. package/dist/cjs/i18n/useTranslation.js +84 -89
  77. package/dist/cjs/import/AsepriteImporter.js +658 -716
  78. package/dist/cjs/import/DragonBonesImporter.js +437 -461
  79. package/dist/cjs/import/GameMakerImporter.js +511 -521
  80. package/dist/cjs/import/GodotSceneImporter.js +788 -822
  81. package/dist/cjs/import/LDtkImporter.js +436 -454
  82. package/dist/cjs/import/Live2DImporter.js +497 -518
  83. package/dist/cjs/import/NdgFormat.js +424 -457
  84. package/dist/cjs/import/OgmoImporter.js +466 -493
  85. package/dist/cjs/import/RPGMakerImporter.js +451 -477
  86. package/dist/cjs/import/SceneImporter.js +378 -423
  87. package/dist/cjs/import/SpineImporter.js +511 -546
  88. package/dist/cjs/import/SpriterImporter.js +590 -613
  89. package/dist/cjs/import/TiledMapImporter.js +811 -846
  90. package/dist/cjs/import/UnitySceneImporter.js +687 -703
  91. package/dist/cjs/import/index.js +206 -251
  92. package/dist/cjs/index.js +275 -278
  93. package/dist/cjs/input/GamepadNavigation.js +185 -205
  94. package/dist/cjs/input/InputManager.js +397 -421
  95. package/dist/cjs/input/useGamepads.js +70 -81
  96. package/dist/cjs/integration/IconSprite.js +129 -256
  97. package/dist/cjs/inventory/InventorySystem.js +920 -995
  98. package/dist/cjs/kids/KidMode.js +997 -1022
  99. package/dist/cjs/kids/KidTools.js +570 -594
  100. package/dist/cjs/monetization/Monetization.js +170 -177
  101. package/dist/cjs/multiplayer/LocalMultiplayer.js +287 -287
  102. package/dist/cjs/multiplayer/MiniGameTypes.js +49 -59
  103. package/dist/cjs/native-engine/AnimationSystem.js +731 -806
  104. package/dist/cjs/native-engine/AssetPipeline.js +454 -515
  105. package/dist/cjs/native-engine/AudioEngine.js +763 -804
  106. package/dist/cjs/native-engine/InputSystem.js +1075 -1145
  107. package/dist/cjs/native-engine/NetworkingSystem.js +733 -793
  108. package/dist/cjs/native-engine/PhysicsEngine.js +583 -607
  109. package/dist/cjs/native-engine/RenderingEngine.js +302 -350
  110. package/dist/cjs/native-engine/SceneGraph.js +769 -808
  111. package/dist/cjs/network/MultiplayerTransport.js +97 -132
  112. package/dist/cjs/network/Networking.js +549 -564
  113. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AbortController.js +21 -29
  114. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +40 -48
  115. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +35 -43
  116. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +10 -15
  117. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Errors.js +103 -135
  118. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +131 -158
  119. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +39 -53
  120. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +5 -8
  121. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +40 -48
  122. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +494 -572
  123. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +826 -953
  124. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +125 -146
  125. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +13 -23
  126. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ILogger.js +11 -25
  127. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ITransport.js +13 -24
  128. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +108 -121
  129. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Loggers.js +10 -14
  130. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +150 -185
  131. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +158 -196
  132. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +90 -105
  133. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Subject.js +30 -35
  134. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +16 -21
  135. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Utils.js +215 -248
  136. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +135 -157
  137. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +76 -85
  138. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/index.js +24 -27
  139. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +3 -4
  140. package/dist/cjs/pathfinding/Pathfinding.js +245 -263
  141. package/dist/cjs/performance/AssetStreaming.js +561 -635
  142. package/dist/cjs/performance/BenchmarkSuite.js +283 -311
  143. package/dist/cjs/performance/DeltaCompression.js +467 -526
  144. package/dist/cjs/performance/DeterministicPhysics.js +450 -498
  145. package/dist/cjs/performance/ECSOptimization.js +644 -695
  146. package/dist/cjs/performance/GameSaveSystem.js +509 -556
  147. package/dist/cjs/performance/HotReload.js +447 -500
  148. package/dist/cjs/performance/InputRecording.js +511 -561
  149. package/dist/cjs/performance/InterestManagement.js +453 -500
  150. package/dist/cjs/performance/LocalizationRuntime.js +376 -423
  151. package/dist/cjs/performance/MemoryManagement.js +410 -470
  152. package/dist/cjs/performance/ModSupport.js +445 -496
  153. package/dist/cjs/performance/MultiThreadedPhysics.js +400 -443
  154. package/dist/cjs/performance/NetworkPrediction.js +424 -482
  155. package/dist/cjs/performance/ObjectPooling.js +569 -617
  156. package/dist/cjs/performance/Performance.js +174 -190
  157. package/dist/cjs/performance/PerformanceAdvanced.js +614 -637
  158. package/dist/cjs/performance/WebGPURenderer.js +656 -683
  159. package/dist/cjs/physics/PhysicsAdvanced.js +345 -379
  160. package/dist/cjs/physics/PhysicsEngine2D.js +391 -427
  161. package/dist/cjs/plugins/PluginSDK.js +432 -466
  162. package/dist/cjs/plugins/PluginTestKit.js +307 -330
  163. package/dist/cjs/procedural/Procedural.js +243 -254
  164. package/dist/cjs/procedural/WorldBuilding.js +297 -314
  165. package/dist/cjs/quest/QuestSystem.js +975 -932
  166. package/dist/cjs/release/MobileExport.js +157 -163
  167. package/dist/cjs/release/Release.js +225 -238
  168. package/dist/cjs/rendering/Camera2D.js +121 -124
  169. package/dist/cjs/rendering/Renderer2D.js +321 -335
  170. package/dist/cjs/rendering/WebGPURenderPipeline.js +632 -651
  171. package/dist/cjs/runtime3d/Runtime3D.js +359 -378
  172. package/dist/cjs/runtime3d/SceneEditor3D.js +252 -263
  173. package/dist/cjs/scene/SceneManager.js +177 -193
  174. package/dist/cjs/scripting/GraphToAST.js +574 -547
  175. package/dist/cjs/scripting/LanguageExporter.js +254 -279
  176. package/dist/cjs/scripting/NodeGraph.js +546 -570
  177. package/dist/cjs/scripting/ScriptAST.js +31 -39
  178. package/dist/cjs/scripting/VisualScripting2.js +1016 -1065
  179. package/dist/cjs/scripting/exporters/CSharpExporter.js +464 -496
  180. package/dist/cjs/scripting/exporters/GDScriptExporter.js +390 -442
  181. package/dist/cjs/scripting/exporters/LuaExporter.js +406 -447
  182. package/dist/cjs/scripting/exporters/PythonExporter.js +484 -549
  183. package/dist/cjs/scripting/exporters/RustExporter.js +459 -512
  184. package/dist/cjs/scripting/exporters/TypeScriptExporter.js +505 -556
  185. package/dist/cjs/social/Social.js +72 -80
  186. package/dist/cjs/systems/LightingSystem.js +844 -931
  187. package/dist/cjs/systems/ParticleSystem2.js +1447 -1451
  188. package/dist/cjs/systems/PhysicsDebugSystem.js +1070 -1141
  189. package/dist/cjs/systems/TerrainSystem.js +985 -1098
  190. package/dist/cjs/templates/ActionTemplates.js +296 -309
  191. package/dist/cjs/templates/FightingTemplate.js +417 -463
  192. package/dist/cjs/templates/MetroidvaniaTemplate.js +353 -405
  193. package/dist/cjs/templates/PartyTemplates.js +190 -202
  194. package/dist/cjs/templates/PuzzleTemplates.js +245 -261
  195. package/dist/cjs/templates/RPGTemplates.js +160 -178
  196. package/dist/cjs/templates/SportsTemplates.js +237 -250
  197. package/dist/cjs/templates/StrategyTemplates.js +143 -153
  198. package/dist/cjs/templates/SurvivalTemplate.js +336 -380
  199. package/dist/cjs/templates/WaveDefense.js +499 -526
  200. package/dist/cjs/tilemap/Tilemap.js +207 -214
  201. package/dist/cjs/tutorials/TutorialBranching.js +396 -417
  202. package/dist/cjs/tutorials/TutorialEngine.js +888 -931
  203. package/dist/cjs/tutorials/TutorialOverlay.js +602 -640
  204. package/dist/cjs/tutorials/content/Tutorials_T05_T08.js +787 -809
  205. package/dist/cjs/tutorials/content/Tutorials_T09_T11.js +736 -756
  206. package/dist/cjs/tutorials/content/Tutorials_T12_T15.js +754 -778
  207. package/dist/cjs/ui/GameUI.js +295 -312
  208. package/dist/cjs/unity-integration/UnityAssetStore.js +700 -741
  209. package/dist/cjs/unity-integration/UnityImport.js +1066 -1176
  210. package/dist/cjs/unity-integration/UnityLiveLink.js +934 -981
  211. package/dist/cjs/unity-integration/components/UnityAssetStoreBrowser.js +1233 -757
  212. package/dist/cjs/unity-integration/components/UnityProjectBrowser.js +1240 -768
  213. package/dist/cjs/unreal-integration/UnrealImport.js +391 -412
  214. package/dist/cjs/unreal-integration/UnrealLiveLink.js +1102 -1137
  215. package/dist/cjs/unreal-integration/UnrealMarketplace.js +436 -473
  216. package/dist/cjs/unreal-integration/components/UnrealProjectBrowser.js +1150 -767
  217. package/dist/cjs/xr/ARVR.js +167 -175
  218. package/dist/esm/accessibility/Accessibility.js +160 -164
  219. package/dist/esm/ai/AI.js +310 -293
  220. package/dist/esm/ai/BehaviorTree.js +1057 -1112
  221. package/dist/esm/ai/StateMachine.js +709 -755
  222. package/dist/esm/animation/Animation.js +237 -240
  223. package/dist/esm/audio/AudioAdvanced.js +239 -235
  224. package/dist/esm/audio/AudioBridge.js +448 -434
  225. package/dist/esm/audio/AudioManager.js +243 -258
  226. package/dist/esm/build-cloud/BuildOrchestration.js +1071 -1097
  227. package/dist/esm/build-cloud/GodotBuildCloud.js +647 -669
  228. package/dist/esm/build-cloud/UnityBuildCloud.js +571 -609
  229. package/dist/esm/build-cloud/UnrealBuildCloud.js +615 -634
  230. package/dist/esm/core/EventBus.js +52 -55
  231. package/dist/esm/core/GameClock.js +63 -65
  232. package/dist/esm/core/GameConfig.js +77 -78
  233. package/dist/esm/core/GameLoop.js +81 -88
  234. package/dist/esm/core/ServiceLocator.js +63 -64
  235. package/dist/esm/core/Validation.js +82 -81
  236. package/dist/esm/core/math.js +109 -111
  237. package/dist/esm/devtools/DevTools.js +546 -562
  238. package/dist/esm/devtools/DeveloperExperience.js +535 -558
  239. package/dist/esm/devtools/GameplayAnalytics.js +647 -645
  240. package/dist/esm/dialogue/DialogueSystem.js +998 -985
  241. package/dist/esm/docs/DocGenerator.js +342 -363
  242. package/dist/esm/ecs/World.js +358 -370
  243. package/dist/esm/editor/AchievementEditor.js +584 -635
  244. package/dist/esm/editor/AdvancedEditor.js +191 -190
  245. package/dist/esm/editor/AnimationRetargeting.js +700 -740
  246. package/dist/esm/editor/AssetBrowser.js +1078 -1159
  247. package/dist/esm/editor/AssetManager.js +188 -191
  248. package/dist/esm/editor/ConsolePro.js +977 -1060
  249. package/dist/esm/editor/CraftingEditor.js +684 -729
  250. package/dist/esm/editor/DebugTools.js +194 -184
  251. package/dist/esm/editor/DialogueSystem.js +849 -900
  252. package/dist/esm/editor/LeaderboardSystem.js +433 -482
  253. package/dist/esm/editor/NiceGameEditor.js +1908 -1200
  254. package/dist/esm/editor/PrefabSystem.js +777 -837
  255. package/dist/esm/editor/ProfilerPanel.js +654 -699
  256. package/dist/esm/editor/QuestEditor.js +795 -838
  257. package/dist/esm/editor/ReplaySystem.js +591 -633
  258. package/dist/esm/editor/SceneEditor.js +189 -199
  259. package/dist/esm/editor/ScreenshotMode.js +628 -687
  260. package/dist/esm/editor/ShaderGraph.js +1565 -1581
  261. package/dist/esm/editor/TimelineEditor.js +733 -777
  262. package/dist/esm/editor/UndoRedoPro.js +835 -903
  263. package/dist/esm/editor/VRARMode.js +586 -644
  264. package/dist/esm/engine/NiceGameEngine.js +142 -163
  265. package/dist/esm/engine/SaveSystem.js +447 -494
  266. package/dist/esm/enterprise/Enterprise.js +265 -260
  267. package/dist/esm/export/BevyExporter.js +929 -966
  268. package/dist/esm/export/CocosExporter.js +646 -672
  269. package/dist/esm/export/Construct3Exporter.js +785 -793
  270. package/dist/esm/export/DefoldExporter.js +1030 -1068
  271. package/dist/esm/export/GDevelopExporter.js +676 -707
  272. package/dist/esm/export/GameMakerExporter.js +793 -804
  273. package/dist/esm/export/GodotExporter.js +1004 -1044
  274. package/dist/esm/export/MinecraftBedrockExporter.js +575 -577
  275. package/dist/esm/export/MonoGameExporter.js +1267 -1292
  276. package/dist/esm/export/Pico8Exporter.js +768 -811
  277. package/dist/esm/export/PlatformExporter.js +193 -205
  278. package/dist/esm/export/RPGMakerExporter.js +862 -878
  279. package/dist/esm/export/RobloxExporter.js +885 -918
  280. package/dist/esm/export/Solar2DExporter.js +1220 -1255
  281. package/dist/esm/export/ThreeJSExporter.js +1007 -1072
  282. package/dist/esm/export/Tic80Exporter.js +1212 -1266
  283. package/dist/esm/export/UnityExporter.js +1117 -1130
  284. package/dist/esm/export/UnrealExporter.js +891 -918
  285. package/dist/esm/export/WebExporter.js +933 -969
  286. package/dist/esm/export/index.js +86 -71
  287. package/dist/esm/godot-integration/GodotAssetLibrary.js +663 -691
  288. package/dist/esm/godot-integration/GodotImport.js +935 -1026
  289. package/dist/esm/godot-integration/GodotLiveLink.js +918 -944
  290. package/dist/esm/godot-integration/components/GodotProjectBrowser.js +912 -610
  291. package/dist/esm/i18n/I18n.js +871 -899
  292. package/dist/esm/i18n/useTranslation.js +88 -88
  293. package/dist/esm/import/AsepriteImporter.js +637 -715
  294. package/dist/esm/import/DragonBonesImporter.js +417 -460
  295. package/dist/esm/import/GameMakerImporter.js +491 -520
  296. package/dist/esm/import/GodotSceneImporter.js +767 -821
  297. package/dist/esm/import/LDtkImporter.js +415 -453
  298. package/dist/esm/import/Live2DImporter.js +477 -517
  299. package/dist/esm/import/NdgFormat.js +410 -456
  300. package/dist/esm/import/OgmoImporter.js +446 -492
  301. package/dist/esm/import/RPGMakerImporter.js +431 -476
  302. package/dist/esm/import/SceneImporter.js +385 -422
  303. package/dist/esm/import/SpineImporter.js +491 -545
  304. package/dist/esm/import/SpriterImporter.js +570 -612
  305. package/dist/esm/import/TiledMapImporter.js +790 -845
  306. package/dist/esm/import/UnitySceneImporter.js +666 -702
  307. package/dist/esm/import/index.js +247 -258
  308. package/dist/esm/index.js +1332 -188
  309. package/dist/esm/input/GamepadNavigation.js +187 -204
  310. package/dist/esm/input/InputManager.js +401 -420
  311. package/dist/esm/input/useGamepads.js +72 -80
  312. package/dist/esm/integration/IconSprite.js +143 -255
  313. package/dist/esm/inventory/InventorySystem.js +925 -994
  314. package/dist/esm/kids/KidMode.js +1003 -1021
  315. package/dist/esm/kids/KidTools.js +573 -593
  316. package/dist/esm/monetization/Monetization.js +180 -176
  317. package/dist/esm/multiplayer/LocalMultiplayer.js +290 -286
  318. package/dist/esm/multiplayer/MiniGameTypes.js +58 -58
  319. package/dist/esm/native-engine/AnimationSystem.js +735 -805
  320. package/dist/esm/native-engine/AssetPipeline.js +456 -514
  321. package/dist/esm/native-engine/AudioEngine.js +765 -803
  322. package/dist/esm/native-engine/InputSystem.js +1079 -1144
  323. package/dist/esm/native-engine/NetworkingSystem.js +740 -792
  324. package/dist/esm/native-engine/PhysicsEngine.js +585 -606
  325. package/dist/esm/native-engine/RenderingEngine.js +304 -349
  326. package/dist/esm/native-engine/SceneGraph.js +773 -807
  327. package/dist/esm/network/MultiplayerTransport.js +99 -131
  328. package/dist/esm/network/Networking.js +556 -563
  329. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AbortController.js +22 -28
  330. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +41 -47
  331. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +36 -42
  332. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +11 -14
  333. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Errors.js +111 -134
  334. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +132 -157
  335. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +40 -52
  336. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +6 -7
  337. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +42 -47
  338. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +496 -571
  339. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +828 -952
  340. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +126 -145
  341. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +14 -23
  342. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ILogger.js +12 -25
  343. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ITransport.js +15 -24
  344. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +109 -120
  345. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Loggers.js +11 -13
  346. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +151 -184
  347. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +159 -195
  348. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +91 -104
  349. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Subject.js +31 -34
  350. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +17 -20
  351. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Utils.js +230 -248
  352. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +136 -156
  353. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +77 -84
  354. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/index.js +31 -12
  355. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +4 -3
  356. package/dist/esm/pathfinding/Pathfinding.js +249 -262
  357. package/dist/esm/performance/AssetStreaming.js +567 -634
  358. package/dist/esm/performance/BenchmarkSuite.js +285 -310
  359. package/dist/esm/performance/DeltaCompression.js +478 -525
  360. package/dist/esm/performance/DeterministicPhysics.js +479 -497
  361. package/dist/esm/performance/ECSOptimization.js +653 -694
  362. package/dist/esm/performance/GameSaveSystem.js +515 -555
  363. package/dist/esm/performance/HotReload.js +454 -499
  364. package/dist/esm/performance/InputRecording.js +520 -560
  365. package/dist/esm/performance/InterestManagement.js +460 -499
  366. package/dist/esm/performance/LocalizationRuntime.js +382 -422
  367. package/dist/esm/performance/MemoryManagement.js +415 -469
  368. package/dist/esm/performance/ModSupport.js +455 -495
  369. package/dist/esm/performance/MultiThreadedPhysics.js +408 -442
  370. package/dist/esm/performance/NetworkPrediction.js +436 -481
  371. package/dist/esm/performance/ObjectPooling.js +582 -616
  372. package/dist/esm/performance/Performance.js +182 -189
  373. package/dist/esm/performance/PerformanceAdvanced.js +621 -636
  374. package/dist/esm/performance/WebGPURenderer.js +660 -682
  375. package/dist/esm/physics/PhysicsAdvanced.js +359 -378
  376. package/dist/esm/physics/PhysicsEngine2D.js +393 -426
  377. package/dist/esm/plugins/PluginSDK.js +435 -465
  378. package/dist/esm/plugins/PluginTestKit.js +315 -329
  379. package/dist/esm/procedural/Procedural.js +248 -253
  380. package/dist/esm/procedural/WorldBuilding.js +316 -313
  381. package/dist/esm/quest/QuestSystem.js +982 -931
  382. package/dist/esm/release/MobileExport.js +163 -162
  383. package/dist/esm/release/Release.js +234 -237
  384. package/dist/esm/rendering/Camera2D.js +122 -123
  385. package/dist/esm/rendering/Renderer2D.js +323 -334
  386. package/dist/esm/rendering/WebGPURenderPipeline.js +647 -650
  387. package/dist/esm/runtime3d/Runtime3D.js +368 -377
  388. package/dist/esm/runtime3d/SceneEditor3D.js +268 -262
  389. package/dist/esm/scene/SceneManager.js +178 -192
  390. package/dist/esm/scripting/GraphToAST.js +576 -546
  391. package/dist/esm/scripting/LanguageExporter.js +263 -278
  392. package/dist/esm/scripting/NodeGraph.js +550 -569
  393. package/dist/esm/scripting/ScriptAST.js +45 -38
  394. package/dist/esm/scripting/VisualScripting2.js +1025 -1064
  395. package/dist/esm/scripting/exporters/CSharpExporter.js +465 -495
  396. package/dist/esm/scripting/exporters/GDScriptExporter.js +391 -441
  397. package/dist/esm/scripting/exporters/LuaExporter.js +407 -446
  398. package/dist/esm/scripting/exporters/PythonExporter.js +485 -548
  399. package/dist/esm/scripting/exporters/RustExporter.js +460 -511
  400. package/dist/esm/scripting/exporters/TypeScriptExporter.js +506 -555
  401. package/dist/esm/social/Social.js +77 -79
  402. package/dist/esm/systems/LightingSystem.js +855 -930
  403. package/dist/esm/systems/ParticleSystem2.js +1453 -1450
  404. package/dist/esm/systems/PhysicsDebugSystem.js +1078 -1140
  405. package/dist/esm/systems/TerrainSystem.js +996 -1097
  406. package/dist/esm/templates/ActionTemplates.js +307 -308
  407. package/dist/esm/templates/FightingTemplate.js +439 -462
  408. package/dist/esm/templates/MetroidvaniaTemplate.js +391 -404
  409. package/dist/esm/templates/PartyTemplates.js +206 -201
  410. package/dist/esm/templates/PuzzleTemplates.js +260 -260
  411. package/dist/esm/templates/RPGTemplates.js +172 -177
  412. package/dist/esm/templates/SportsTemplates.js +251 -249
  413. package/dist/esm/templates/StrategyTemplates.js +158 -152
  414. package/dist/esm/templates/SurvivalTemplate.js +367 -379
  415. package/dist/esm/templates/WaveDefense.js +501 -525
  416. package/dist/esm/tilemap/Tilemap.js +209 -213
  417. package/dist/esm/tutorials/TutorialBranching.js +399 -416
  418. package/dist/esm/tutorials/TutorialEngine.js +893 -930
  419. package/dist/esm/tutorials/TutorialOverlay.js +603 -639
  420. package/dist/esm/tutorials/content/Tutorials_T05_T08.js +792 -808
  421. package/dist/esm/tutorials/content/Tutorials_T09_T11.js +740 -755
  422. package/dist/esm/tutorials/content/Tutorials_T12_T15.js +759 -777
  423. package/dist/esm/ui/GameUI.js +296 -311
  424. package/dist/esm/unity-integration/UnityAssetStore.js +704 -740
  425. package/dist/esm/unity-integration/UnityImport.js +1071 -1175
  426. package/dist/esm/unity-integration/UnityLiveLink.js +938 -980
  427. package/dist/esm/unity-integration/components/UnityAssetStoreBrowser.js +1234 -756
  428. package/dist/esm/unity-integration/components/UnityProjectBrowser.js +1241 -767
  429. package/dist/esm/unreal-integration/UnrealImport.js +395 -411
  430. package/dist/esm/unreal-integration/UnrealLiveLink.js +1105 -1136
  431. package/dist/esm/unreal-integration/UnrealMarketplace.js +442 -472
  432. package/dist/esm/unreal-integration/components/UnrealProjectBrowser.js +1151 -766
  433. package/dist/esm/xr/ARVR.js +181 -174
  434. package/package.json +7 -12
@@ -1,917 +1,866 @@
1
- /**
2
- * @file DialogueSystem.ts
3
- * @description Branching Dialogue System with localization support
4
- * PRO-1.4: Professional Editor Features
5
- *
6
- * Features:
7
- * - Dialogue nodes and connections
8
- * - Branching conversations
9
- * - Conditions for dialogue options
10
- * - Variables and state tracking
11
- * - Localization support (multiple languages)
12
- * - Character/speaker definitions
13
- * - Emotions/expressions
14
- * - Voice line references
15
- * - Custom commands/events
16
- * - Import/Export (JSON, Ink, Yarn)
17
- * - Dialogue preview/testing
18
- */
19
- // ============================================================
20
- // Dialogue Manager
21
- // ============================================================
22
1
  class DialogueManager {
23
- constructor() {
24
- this.trees = new Map();
25
- this.speakers = new Map();
26
- this.emotions = new Map();
27
- this.currentState = null;
28
- this.currentLanguage = 'en';
29
- }
30
- // ─── Tree Management ───────────────────────────────────
31
- createTree(name, defaultLanguage = 'en') {
32
- const startNode = {
33
- id: 'start',
34
- type: 'start',
35
- name: 'Start',
36
- position: { x: 100, y: 100 },
37
- };
38
- const tree = {
39
- id: `dialogue_${Date.now()}`,
40
- name,
41
- description: '',
42
- version: 1,
43
- nodes: new Map([['start', startNode]]),
44
- startNodeId: 'start',
45
- speakers: new Map(),
46
- variables: new Map(),
47
- flags: new Set(),
48
- defaultLanguage,
49
- supportedLanguages: [defaultLanguage],
50
- tags: [],
51
- createdAt: Date.now(),
52
- modifiedAt: Date.now(),
53
- };
54
- this.trees.set(tree.id, tree);
55
- return tree;
56
- }
57
- getTree(id) {
58
- return this.trees.get(id);
59
- }
60
- deleteTree(id) {
61
- return this.trees.delete(id);
62
- }
63
- // ─── Node Management ───────────────────────────────────
64
- addNode(treeId, node) {
65
- const tree = this.trees.get(treeId);
66
- if (!tree) {
67
- return null;
68
- }
69
- const fullNode = {
70
- id: `node_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
71
- type: node.type ?? 'dialogue',
72
- name: node.name ?? 'New Node',
73
- position: node.position ?? { x: 200, y: 200 },
74
- lines: node.lines,
75
- choices: node.choices,
76
- nextNodeId: node.nextNodeId,
77
- condition: node.condition,
78
- randomWeights: node.randomWeights,
79
- entryActions: node.entryActions,
80
- exitActions: node.exitActions,
81
- tags: node.tags,
82
- notes: node.notes,
83
- color: node.color,
84
- };
85
- tree.nodes.set(fullNode.id, fullNode);
86
- tree.modifiedAt = Date.now();
87
- return fullNode;
88
- }
89
- updateNode(treeId, nodeId, updates) {
90
- const tree = this.trees.get(treeId);
91
- if (!tree) {
92
- return false;
93
- }
94
- const node = tree.nodes.get(nodeId);
95
- if (!node) {
96
- return false;
97
- }
98
- Object.assign(node, updates);
99
- tree.modifiedAt = Date.now();
100
- return true;
101
- }
102
- deleteNode(treeId, nodeId) {
103
- const tree = this.trees.get(treeId);
104
- if (!tree || nodeId === tree.startNodeId) {
105
- return false;
106
- }
107
- // Remove references to this node
108
- for (const node of tree.nodes.values()) {
109
- if (node.nextNodeId === nodeId) {
110
- node.nextNodeId = undefined;
111
- }
112
- if (node.choices) {
113
- node.choices = node.choices.filter((c) => c.targetNodeId !== nodeId);
114
- }
115
- }
116
- tree.nodes.delete(nodeId);
117
- tree.modifiedAt = Date.now();
118
- return true;
119
- }
120
- connectNodes(treeId, fromNodeId, toNodeId, choiceId) {
121
- const tree = this.trees.get(treeId);
122
- if (!tree) {
123
- return false;
124
- }
125
- const fromNode = tree.nodes.get(fromNodeId);
126
- const toNode = tree.nodes.get(toNodeId);
127
- if (!fromNode || !toNode) {
128
- return false;
129
- }
130
- if (choiceId && fromNode.choices) {
131
- const choice = fromNode.choices.find((c) => c.id === choiceId);
132
- if (choice) {
133
- choice.targetNodeId = toNodeId;
134
- }
135
- }
136
- else {
137
- fromNode.nextNodeId = toNodeId;
138
- }
139
- tree.modifiedAt = Date.now();
140
- return true;
141
- }
142
- // ─── Dialogue Line Management ──────────────────────────
143
- addLine(treeId, nodeId, line) {
144
- const tree = this.trees.get(treeId);
145
- if (!tree) {
146
- return null;
147
- }
148
- const node = tree.nodes.get(nodeId);
149
- if (!node) {
150
- return null;
151
- }
152
- const fullLine = {
153
- speakerId: line.speakerId ?? '',
154
- text: line.text ?? this.createLocalizedText('', tree.defaultLanguage),
155
- emotion: line.emotion,
156
- voiceLine: line.voiceLine,
157
- duration: line.duration,
158
- animation: line.animation,
159
- effects: line.effects,
160
- };
161
- if (!node.lines) {
162
- node.lines = [];
163
- }
164
- node.lines.push(fullLine);
165
- tree.modifiedAt = Date.now();
166
- return fullLine;
167
- }
168
- addChoice(treeId, nodeId, choice) {
169
- const tree = this.trees.get(treeId);
170
- if (!tree) {
171
- return null;
172
- }
173
- const node = tree.nodes.get(nodeId);
174
- if (!node) {
175
- return null;
176
- }
177
- const fullChoice = {
178
- id: `choice_${Date.now()}`,
179
- text: choice.text ?? this.createLocalizedText('Choice', tree.defaultLanguage),
180
- targetNodeId: choice.targetNodeId ?? '',
181
- condition: choice.condition,
182
- actions: choice.actions,
183
- isDefault: choice.isDefault,
184
- isHidden: choice.isHidden,
185
- once: choice.once,
186
- priority: choice.priority,
187
- shortcut: choice.shortcut,
188
- };
189
- if (!node.choices) {
190
- node.choices = [];
191
- }
192
- node.choices.push(fullChoice);
193
- tree.modifiedAt = Date.now();
194
- return fullChoice;
195
- }
196
- // ─── Speaker Management ────────────────────────────────
197
- addSpeaker(treeId, speaker) {
198
- const tree = this.trees.get(treeId);
199
- if (!tree) {
200
- return null;
201
- }
202
- const fullSpeaker = {
203
- id: speaker.id ?? `speaker_${Date.now()}`,
204
- name: speaker.name ?? this.createLocalizedText('Speaker', tree.defaultLanguage),
205
- displayName: speaker.displayName,
206
- portrait: speaker.portrait,
207
- color: speaker.color,
208
- voiceId: speaker.voiceId,
209
- tags: speaker.tags,
210
- };
211
- tree.speakers.set(fullSpeaker.id, fullSpeaker);
212
- this.speakers.set(fullSpeaker.id, fullSpeaker);
213
- tree.modifiedAt = Date.now();
214
- return fullSpeaker;
215
- }
216
- getSpeaker(id) {
217
- return this.speakers.get(id);
218
- }
219
- addEmotion(emotion) {
220
- this.emotions.set(emotion.id, emotion);
221
- }
222
- getEmotion(id) {
223
- return this.emotions.get(id);
224
- }
225
- // ─── Variable Management ───────────────────────────────
226
- addVariable(treeId, variable) {
227
- const tree = this.trees.get(treeId);
228
- if (!tree) {
229
- return false;
230
- }
231
- tree.variables.set(variable.name, variable);
232
- tree.modifiedAt = Date.now();
233
- return true;
234
- }
235
- setFlag(treeId, flag, value = true) {
236
- const tree = this.trees.get(treeId);
237
- if (!tree) {
238
- return;
239
- }
240
- if (value) {
241
- tree.flags.add(flag);
242
- }
243
- else {
244
- tree.flags.delete(flag);
245
- }
246
- tree.modifiedAt = Date.now();
247
- }
248
- // ─── Localization ──────────────────────────────────────
249
- createLocalizedText(defaultText, language) {
250
- return {
251
- key: `text_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
252
- default: defaultText,
253
- translations: new Map([[language, defaultText]]),
254
- };
255
- }
256
- setTranslation(text, language, translation) {
257
- text.translations.set(language, translation);
258
- }
259
- getText(text, language) {
260
- const lang = language ?? this.currentLanguage;
261
- return text.translations.get(lang) ?? text.default;
262
- }
263
- setLanguage(language) {
264
- this.currentLanguage = language;
265
- }
266
- addLanguageSupport(treeId, language) {
267
- const tree = this.trees.get(treeId);
268
- if (!tree || tree.supportedLanguages.includes(language)) {
269
- return false;
270
- }
271
- tree.supportedLanguages.push(language);
272
- tree.modifiedAt = Date.now();
273
- return true;
274
- }
275
- // ─── Runtime Dialogue ──────────────────────────────────
276
- startDialogue(treeId) {
277
- const tree = this.trees.get(treeId);
278
- if (!tree) {
279
- return false;
280
- }
281
- // Initialize state
282
- this.currentState = {
283
- treeId,
284
- currentNodeId: tree.startNodeId,
285
- currentLineIndex: 0,
286
- variables: new Map(),
287
- flags: new Set(),
288
- visitedNodes: new Set(),
289
- selectedChoices: new Set(),
290
- history: [],
291
- };
292
- // Set default variable values
293
- for (const [name, variable] of tree.variables) {
294
- this.currentState.variables.set(name, variable.defaultValue);
295
- }
296
- // Copy flags
297
- for (const flag of tree.flags) {
298
- this.currentState.flags.add(flag);
299
- }
300
- this.onDialogueStart?.(tree);
301
- this.processCurrentNode();
302
- return true;
303
- }
304
- endDialogue() {
305
- if (!this.currentState) {
306
- return;
307
- }
308
- const tree = this.trees.get(this.currentState.treeId);
309
- this.currentState = null;
310
- if (tree) {
311
- this.onDialogueEnd?.(tree);
312
- }
313
- }
314
- processCurrentNode() {
315
- if (!this.currentState) {
316
- return;
317
- }
318
- const tree = this.trees.get(this.currentState.treeId);
319
- if (!tree) {
320
- return;
321
- }
322
- const node = tree.nodes.get(this.currentState.currentNodeId);
323
- if (!node) {
324
- return;
325
- }
326
- // Mark as visited
327
- this.currentState.visitedNodes.add(node.id);
328
- // Record history
329
- this.currentState.history.push({
330
- nodeId: node.id,
331
- timestamp: Date.now(),
332
- });
333
- // Execute entry actions
334
- if (node.entryActions) {
335
- for (const action of node.entryActions) {
336
- this.executeAction(action);
337
- }
338
- }
339
- this.onNodeEnter?.(node);
340
- // Handle node by type
341
- switch (node.type) {
342
- case 'start':
343
- this.advanceToNextNode(node);
344
- break;
345
- case 'dialogue':
346
- this.displayDialogueLine(node);
347
- break;
348
- case 'choice':
349
- this.displayChoices(node);
350
- break;
351
- case 'condition':
352
- this.evaluateConditionNode(node);
353
- break;
354
- case 'action':
355
- this.executeNodeActions(node);
356
- break;
357
- case 'random':
358
- this.selectRandomPath(node);
359
- break;
360
- case 'hub':
361
- this.displayChoices(node);
362
- break;
363
- case 'end':
364
- this.endDialogue();
365
- break;
366
- }
367
- }
368
- displayDialogueLine(node) {
369
- if (!this.currentState || !node.lines || node.lines.length === 0) {
370
- this.advanceToNextNode(node);
371
- return;
372
- }
373
- const line = node.lines[this.currentState.currentLineIndex];
374
- if (!line) {
375
- this.advanceToNextNode(node);
376
- return;
377
- }
378
- const speaker = this.speakers.get(line.speakerId);
379
- const emotion = line.emotion ? this.emotions.get(line.emotion) : undefined;
380
- const renderData = {
381
- speaker,
382
- emotion,
383
- text: this.getText(line.text),
384
- isEnd: false,
385
- autoAdvance: line.duration,
386
- };
387
- // Check if this is the last line and there are choices
388
- if (this.currentState.currentLineIndex === node.lines.length - 1 &&
389
- node.choices &&
390
- node.choices.length > 0) {
391
- renderData.choices = this.getAvailableChoices(node);
392
- }
393
- this.onLineDisplay?.(renderData);
394
- }
395
- displayChoices(node) {
396
- if (!node.choices || node.choices.length === 0) {
397
- this.advanceToNextNode(node);
398
- return;
399
- }
400
- const choices = this.getAvailableChoices(node);
401
- if (choices.length === 0) {
402
- // No available choices, try default or end
403
- const defaultChoice = node.choices.find((c) => c.isDefault);
404
- if (defaultChoice) {
405
- this.selectChoice(defaultChoice.id);
406
- }
407
- else {
408
- this.endDialogue();
409
- }
410
- return;
411
- }
412
- this.onChoicesDisplay?.(choices);
413
- }
414
- getAvailableChoices(node) {
415
- if (!node.choices || !this.currentState) {
416
- return [];
417
- }
418
- return node.choices
419
- .filter((choice) => {
420
- // Check if already selected (for once choices)
421
- if (choice.once && this.currentState.selectedChoices.has(choice.id)) {
422
- return false;
423
- }
424
- // Check if hidden
425
- if (choice.isHidden) {
426
- return false;
427
- }
428
- return true;
429
- })
430
- .map((choice) => ({
431
- id: choice.id,
432
- text: this.getText(choice.text),
433
- available: this.evaluateConditions(choice.condition),
434
- shortcut: choice.shortcut,
435
- }))
436
- .sort((a, b) => {
437
- const choiceA = node.choices.find((c) => c.id === a.id);
438
- const choiceB = node.choices.find((c) => c.id === b.id);
439
- return (choiceB?.priority ?? 0) - (choiceA?.priority ?? 0);
440
- });
441
- }
442
- advanceLine() {
443
- if (!this.currentState) {
444
- return;
445
- }
446
- const tree = this.trees.get(this.currentState.treeId);
447
- if (!tree) {
448
- return;
449
- }
450
- const node = tree.nodes.get(this.currentState.currentNodeId);
451
- if (!node || !node.lines) {
452
- return;
453
- }
454
- this.currentState.currentLineIndex++;
455
- if (this.currentState.currentLineIndex >= node.lines.length) {
456
- // All lines shown, check for choices or advance
457
- if (node.choices && node.choices.length > 0) {
458
- this.displayChoices(node);
459
- }
460
- else {
461
- this.advanceToNextNode(node);
462
- }
463
- }
464
- else {
465
- this.displayDialogueLine(node);
466
- }
467
- }
468
- selectChoice(choiceId) {
469
- if (!this.currentState) {
470
- return;
471
- }
472
- const tree = this.trees.get(this.currentState.treeId);
473
- if (!tree) {
474
- return;
475
- }
476
- const node = tree.nodes.get(this.currentState.currentNodeId);
477
- if (!node || !node.choices) {
478
- return;
479
- }
480
- const choice = node.choices.find((c) => c.id === choiceId);
481
- if (!choice) {
482
- return;
483
- }
484
- // Check if choice is available
485
- if (!this.evaluateConditions(choice.condition)) {
486
- return;
487
- }
488
- // Mark as selected
489
- this.currentState.selectedChoices.add(choiceId);
490
- // Record in history
491
- this.currentState.history.push({
492
- nodeId: node.id,
493
- choiceId,
494
- timestamp: Date.now(),
495
- });
496
- // Execute choice actions
497
- if (choice.actions) {
498
- for (const action of choice.actions) {
499
- this.executeAction(action);
500
- }
501
- }
502
- // Navigate to target
503
- if (choice.targetNodeId) {
504
- this.gotoNode(choice.targetNodeId);
505
- }
506
- }
507
- advanceToNextNode(node) {
508
- // Execute exit actions
509
- if (node.exitActions) {
510
- for (const action of node.exitActions) {
511
- this.executeAction(action);
512
- }
513
- }
514
- if (node.nextNodeId) {
515
- this.gotoNode(node.nextNodeId);
516
- }
517
- else {
518
- this.endDialogue();
519
- }
520
- }
521
- gotoNode(nodeId) {
522
- if (!this.currentState) {
523
- return;
524
- }
525
- this.currentState.currentNodeId = nodeId;
526
- this.currentState.currentLineIndex = 0;
527
- this.processCurrentNode();
528
- }
529
- evaluateConditionNode(node) {
530
- const result = this.evaluateConditions(node.condition);
531
- // For condition nodes, we need two outputs
532
- // We'll use choices with conditions for this
533
- if (node.choices && node.choices.length >= 2) {
534
- const targetChoice = result ? node.choices[0] : node.choices[1];
535
- if (targetChoice.targetNodeId) {
536
- this.gotoNode(targetChoice.targetNodeId);
537
- return;
538
- }
539
- }
540
- this.advanceToNextNode(node);
541
- }
542
- executeNodeActions(node) {
543
- // Entry actions already executed
2
+ constructor() {
3
+ this.trees = /* @__PURE__ */ new Map();
4
+ this.speakers = /* @__PURE__ */ new Map();
5
+ this.emotions = /* @__PURE__ */ new Map();
6
+ this.currentState = null;
7
+ this.currentLanguage = "en";
8
+ }
9
+ // ─── Tree Management ───────────────────────────────────
10
+ createTree(name, defaultLanguage = "en") {
11
+ const startNode = {
12
+ id: "start",
13
+ type: "start",
14
+ name: "Start",
15
+ position: { x: 100, y: 100 }
16
+ };
17
+ const tree = {
18
+ id: `dialogue_${Date.now()}`,
19
+ name,
20
+ description: "",
21
+ version: 1,
22
+ nodes: /* @__PURE__ */ new Map([["start", startNode]]),
23
+ startNodeId: "start",
24
+ speakers: /* @__PURE__ */ new Map(),
25
+ variables: /* @__PURE__ */ new Map(),
26
+ flags: /* @__PURE__ */ new Set(),
27
+ defaultLanguage,
28
+ supportedLanguages: [defaultLanguage],
29
+ tags: [],
30
+ createdAt: Date.now(),
31
+ modifiedAt: Date.now()
32
+ };
33
+ this.trees.set(tree.id, tree);
34
+ return tree;
35
+ }
36
+ getTree(id) {
37
+ return this.trees.get(id);
38
+ }
39
+ deleteTree(id) {
40
+ return this.trees.delete(id);
41
+ }
42
+ // ─── Node Management ───────────────────────────────────
43
+ addNode(treeId, node) {
44
+ const tree = this.trees.get(treeId);
45
+ if (!tree) {
46
+ return null;
47
+ }
48
+ const fullNode = {
49
+ id: `node_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
50
+ type: node.type ?? "dialogue",
51
+ name: node.name ?? "New Node",
52
+ position: node.position ?? { x: 200, y: 200 },
53
+ lines: node.lines,
54
+ choices: node.choices,
55
+ nextNodeId: node.nextNodeId,
56
+ condition: node.condition,
57
+ randomWeights: node.randomWeights,
58
+ entryActions: node.entryActions,
59
+ exitActions: node.exitActions,
60
+ tags: node.tags,
61
+ notes: node.notes,
62
+ color: node.color
63
+ };
64
+ tree.nodes.set(fullNode.id, fullNode);
65
+ tree.modifiedAt = Date.now();
66
+ return fullNode;
67
+ }
68
+ updateNode(treeId, nodeId, updates) {
69
+ const tree = this.trees.get(treeId);
70
+ if (!tree) {
71
+ return false;
72
+ }
73
+ const node = tree.nodes.get(nodeId);
74
+ if (!node) {
75
+ return false;
76
+ }
77
+ Object.assign(node, updates);
78
+ tree.modifiedAt = Date.now();
79
+ return true;
80
+ }
81
+ deleteNode(treeId, nodeId) {
82
+ const tree = this.trees.get(treeId);
83
+ if (!tree || nodeId === tree.startNodeId) {
84
+ return false;
85
+ }
86
+ for (const node of tree.nodes.values()) {
87
+ if (node.nextNodeId === nodeId) {
88
+ node.nextNodeId = void 0;
89
+ }
90
+ if (node.choices) {
91
+ node.choices = node.choices.filter((c) => c.targetNodeId !== nodeId);
92
+ }
93
+ }
94
+ tree.nodes.delete(nodeId);
95
+ tree.modifiedAt = Date.now();
96
+ return true;
97
+ }
98
+ connectNodes(treeId, fromNodeId, toNodeId, choiceId) {
99
+ const tree = this.trees.get(treeId);
100
+ if (!tree) {
101
+ return false;
102
+ }
103
+ const fromNode = tree.nodes.get(fromNodeId);
104
+ const toNode = tree.nodes.get(toNodeId);
105
+ if (!fromNode || !toNode) {
106
+ return false;
107
+ }
108
+ if (choiceId && fromNode.choices) {
109
+ const choice = fromNode.choices.find((c) => c.id === choiceId);
110
+ if (choice) {
111
+ choice.targetNodeId = toNodeId;
112
+ }
113
+ } else {
114
+ fromNode.nextNodeId = toNodeId;
115
+ }
116
+ tree.modifiedAt = Date.now();
117
+ return true;
118
+ }
119
+ // ─── Dialogue Line Management ──────────────────────────
120
+ addLine(treeId, nodeId, line) {
121
+ const tree = this.trees.get(treeId);
122
+ if (!tree) {
123
+ return null;
124
+ }
125
+ const node = tree.nodes.get(nodeId);
126
+ if (!node) {
127
+ return null;
128
+ }
129
+ const fullLine = {
130
+ speakerId: line.speakerId ?? "",
131
+ text: line.text ?? this.createLocalizedText("", tree.defaultLanguage),
132
+ emotion: line.emotion,
133
+ voiceLine: line.voiceLine,
134
+ duration: line.duration,
135
+ animation: line.animation,
136
+ effects: line.effects
137
+ };
138
+ if (!node.lines) {
139
+ node.lines = [];
140
+ }
141
+ node.lines.push(fullLine);
142
+ tree.modifiedAt = Date.now();
143
+ return fullLine;
144
+ }
145
+ addChoice(treeId, nodeId, choice) {
146
+ const tree = this.trees.get(treeId);
147
+ if (!tree) {
148
+ return null;
149
+ }
150
+ const node = tree.nodes.get(nodeId);
151
+ if (!node) {
152
+ return null;
153
+ }
154
+ const fullChoice = {
155
+ id: `choice_${Date.now()}`,
156
+ text: choice.text ?? this.createLocalizedText("Choice", tree.defaultLanguage),
157
+ targetNodeId: choice.targetNodeId ?? "",
158
+ condition: choice.condition,
159
+ actions: choice.actions,
160
+ isDefault: choice.isDefault,
161
+ isHidden: choice.isHidden,
162
+ once: choice.once,
163
+ priority: choice.priority,
164
+ shortcut: choice.shortcut
165
+ };
166
+ if (!node.choices) {
167
+ node.choices = [];
168
+ }
169
+ node.choices.push(fullChoice);
170
+ tree.modifiedAt = Date.now();
171
+ return fullChoice;
172
+ }
173
+ // ─── Speaker Management ────────────────────────────────
174
+ addSpeaker(treeId, speaker) {
175
+ const tree = this.trees.get(treeId);
176
+ if (!tree) {
177
+ return null;
178
+ }
179
+ const fullSpeaker = {
180
+ id: speaker.id ?? `speaker_${Date.now()}`,
181
+ name: speaker.name ?? this.createLocalizedText("Speaker", tree.defaultLanguage),
182
+ displayName: speaker.displayName,
183
+ portrait: speaker.portrait,
184
+ color: speaker.color,
185
+ voiceId: speaker.voiceId,
186
+ tags: speaker.tags
187
+ };
188
+ tree.speakers.set(fullSpeaker.id, fullSpeaker);
189
+ this.speakers.set(fullSpeaker.id, fullSpeaker);
190
+ tree.modifiedAt = Date.now();
191
+ return fullSpeaker;
192
+ }
193
+ getSpeaker(id) {
194
+ return this.speakers.get(id);
195
+ }
196
+ addEmotion(emotion) {
197
+ this.emotions.set(emotion.id, emotion);
198
+ }
199
+ getEmotion(id) {
200
+ return this.emotions.get(id);
201
+ }
202
+ // ─── Variable Management ───────────────────────────────
203
+ addVariable(treeId, variable) {
204
+ const tree = this.trees.get(treeId);
205
+ if (!tree) {
206
+ return false;
207
+ }
208
+ tree.variables.set(variable.name, variable);
209
+ tree.modifiedAt = Date.now();
210
+ return true;
211
+ }
212
+ setFlag(treeId, flag, value = true) {
213
+ const tree = this.trees.get(treeId);
214
+ if (!tree) {
215
+ return;
216
+ }
217
+ if (value) {
218
+ tree.flags.add(flag);
219
+ } else {
220
+ tree.flags.delete(flag);
221
+ }
222
+ tree.modifiedAt = Date.now();
223
+ }
224
+ // ─── Localization ──────────────────────────────────────
225
+ createLocalizedText(defaultText, language) {
226
+ return {
227
+ key: `text_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
228
+ default: defaultText,
229
+ translations: /* @__PURE__ */ new Map([[language, defaultText]])
230
+ };
231
+ }
232
+ setTranslation(text, language, translation) {
233
+ text.translations.set(language, translation);
234
+ }
235
+ getText(text, language) {
236
+ const lang = language ?? this.currentLanguage;
237
+ return text.translations.get(lang) ?? text.default;
238
+ }
239
+ setLanguage(language) {
240
+ this.currentLanguage = language;
241
+ }
242
+ addLanguageSupport(treeId, language) {
243
+ const tree = this.trees.get(treeId);
244
+ if (!tree || tree.supportedLanguages.includes(language)) {
245
+ return false;
246
+ }
247
+ tree.supportedLanguages.push(language);
248
+ tree.modifiedAt = Date.now();
249
+ return true;
250
+ }
251
+ // ─── Runtime Dialogue ──────────────────────────────────
252
+ startDialogue(treeId) {
253
+ const tree = this.trees.get(treeId);
254
+ if (!tree) {
255
+ return false;
256
+ }
257
+ this.currentState = {
258
+ treeId,
259
+ currentNodeId: tree.startNodeId,
260
+ currentLineIndex: 0,
261
+ variables: /* @__PURE__ */ new Map(),
262
+ flags: /* @__PURE__ */ new Set(),
263
+ visitedNodes: /* @__PURE__ */ new Set(),
264
+ selectedChoices: /* @__PURE__ */ new Set(),
265
+ history: []
266
+ };
267
+ for (const [name, variable] of tree.variables) {
268
+ this.currentState.variables.set(name, variable.defaultValue);
269
+ }
270
+ for (const flag of tree.flags) {
271
+ this.currentState.flags.add(flag);
272
+ }
273
+ this.onDialogueStart?.(tree);
274
+ this.processCurrentNode();
275
+ return true;
276
+ }
277
+ endDialogue() {
278
+ if (!this.currentState) {
279
+ return;
280
+ }
281
+ const tree = this.trees.get(this.currentState.treeId);
282
+ this.currentState = null;
283
+ if (tree) {
284
+ this.onDialogueEnd?.(tree);
285
+ }
286
+ }
287
+ processCurrentNode() {
288
+ if (!this.currentState) {
289
+ return;
290
+ }
291
+ const tree = this.trees.get(this.currentState.treeId);
292
+ if (!tree) {
293
+ return;
294
+ }
295
+ const node = tree.nodes.get(this.currentState.currentNodeId);
296
+ if (!node) {
297
+ return;
298
+ }
299
+ this.currentState.visitedNodes.add(node.id);
300
+ this.currentState.history.push({
301
+ nodeId: node.id,
302
+ timestamp: Date.now()
303
+ });
304
+ if (node.entryActions) {
305
+ for (const action of node.entryActions) {
306
+ this.executeAction(action);
307
+ }
308
+ }
309
+ this.onNodeEnter?.(node);
310
+ switch (node.type) {
311
+ case "start":
544
312
  this.advanceToNextNode(node);
545
- }
546
- selectRandomPath(node) {
547
- if (!node.choices || node.choices.length === 0) {
548
- this.advanceToNextNode(node);
549
- return;
550
- }
551
- const weights = node.randomWeights ?? node.choices.map(() => 1);
552
- const totalWeight = weights.reduce((sum, w) => sum + w, 0);
553
- let random = Math.random() * totalWeight;
554
- for (let i = 0; i < node.choices.length; i++) {
555
- random -= weights[i] ?? 1;
556
- if (random <= 0) {
557
- if (node.choices[i].targetNodeId) {
558
- this.gotoNode(node.choices[i].targetNodeId);
559
- return;
560
- }
561
- }
562
- }
313
+ break;
314
+ case "dialogue":
315
+ this.displayDialogueLine(node);
316
+ break;
317
+ case "choice":
318
+ this.displayChoices(node);
319
+ break;
320
+ case "condition":
321
+ this.evaluateConditionNode(node);
322
+ break;
323
+ case "action":
324
+ this.executeNodeActions(node);
325
+ break;
326
+ case "random":
327
+ this.selectRandomPath(node);
328
+ break;
329
+ case "hub":
330
+ this.displayChoices(node);
331
+ break;
332
+ case "end":
333
+ this.endDialogue();
334
+ break;
335
+ }
336
+ }
337
+ displayDialogueLine(node) {
338
+ if (!this.currentState || !node.lines || node.lines.length === 0) {
339
+ this.advanceToNextNode(node);
340
+ return;
341
+ }
342
+ const line = node.lines[this.currentState.currentLineIndex];
343
+ if (!line) {
344
+ this.advanceToNextNode(node);
345
+ return;
346
+ }
347
+ const speaker = this.speakers.get(line.speakerId);
348
+ const emotion = line.emotion ? this.emotions.get(line.emotion) : void 0;
349
+ const renderData = {
350
+ speaker,
351
+ emotion,
352
+ text: this.getText(line.text),
353
+ isEnd: false,
354
+ autoAdvance: line.duration
355
+ };
356
+ if (this.currentState.currentLineIndex === node.lines.length - 1 && node.choices && node.choices.length > 0) {
357
+ renderData.choices = this.getAvailableChoices(node);
358
+ }
359
+ this.onLineDisplay?.(renderData);
360
+ }
361
+ displayChoices(node) {
362
+ if (!node.choices || node.choices.length === 0) {
363
+ this.advanceToNextNode(node);
364
+ return;
365
+ }
366
+ const choices = this.getAvailableChoices(node);
367
+ if (choices.length === 0) {
368
+ const defaultChoice = node.choices.find((c) => c.isDefault);
369
+ if (defaultChoice) {
370
+ this.selectChoice(defaultChoice.id);
371
+ } else {
372
+ this.endDialogue();
373
+ }
374
+ return;
375
+ }
376
+ this.onChoicesDisplay?.(choices);
377
+ }
378
+ getAvailableChoices(node) {
379
+ if (!node.choices || !this.currentState) {
380
+ return [];
381
+ }
382
+ return node.choices.filter((choice) => {
383
+ if (choice.once && this.currentState.selectedChoices.has(choice.id)) {
384
+ return false;
385
+ }
386
+ if (choice.isHidden) {
387
+ return false;
388
+ }
389
+ return true;
390
+ }).map((choice) => ({
391
+ id: choice.id,
392
+ text: this.getText(choice.text),
393
+ available: this.evaluateConditions(choice.condition),
394
+ shortcut: choice.shortcut
395
+ })).sort((a, b) => {
396
+ const choiceA = node.choices.find((c) => c.id === a.id);
397
+ const choiceB = node.choices.find((c) => c.id === b.id);
398
+ return (choiceB?.priority ?? 0) - (choiceA?.priority ?? 0);
399
+ });
400
+ }
401
+ advanceLine() {
402
+ if (!this.currentState) {
403
+ return;
404
+ }
405
+ const tree = this.trees.get(this.currentState.treeId);
406
+ if (!tree) {
407
+ return;
408
+ }
409
+ const node = tree.nodes.get(this.currentState.currentNodeId);
410
+ if (!node || !node.lines) {
411
+ return;
412
+ }
413
+ this.currentState.currentLineIndex++;
414
+ if (this.currentState.currentLineIndex >= node.lines.length) {
415
+ if (node.choices && node.choices.length > 0) {
416
+ this.displayChoices(node);
417
+ } else {
563
418
  this.advanceToNextNode(node);
564
- }
565
- // ─── Condition Evaluation ──────────────────────────────
566
- evaluateConditions(group) {
567
- if (!group) {
568
- return true;
569
- }
570
- if (!this.currentState) {
571
- return false;
572
- }
573
- const results = group.conditions.map((item) => {
574
- if ('logic' in item) {
575
- return this.evaluateConditions(item);
576
- }
577
- return this.evaluateCondition(item);
578
- });
579
- switch (group.logic) {
580
- case 'and':
581
- return results.every(Boolean);
582
- case 'or':
583
- return results.some(Boolean);
584
- case 'not':
585
- return !results[0];
586
- default:
587
- return true;
588
- }
589
- }
590
- evaluateCondition(condition) {
591
- if (!this.currentState) {
592
- return false;
593
- }
594
- let value;
595
- switch (condition.type) {
596
- case 'variable':
597
- value = this.currentState.variables.get(condition.variable);
598
- break;
599
- case 'flag':
600
- value = this.currentState.flags.has(condition.variable);
601
- break;
602
- case 'custom':
603
- if (this.customConditionEvaluator) {
604
- return this.customConditionEvaluator(condition);
605
- }
606
- return false;
607
- default:
608
- return false;
609
- }
610
- let result;
611
- const target = condition.value;
612
- switch (condition.operator) {
613
- case 'eq':
614
- result = value === target;
615
- break;
616
- case 'ne':
617
- result = value !== target;
618
- break;
619
- case 'gt':
620
- result = value > target;
621
- break;
622
- case 'gte':
623
- result = value >= target;
624
- break;
625
- case 'lt':
626
- result = value < target;
627
- break;
628
- case 'lte':
629
- result = value <= target;
630
- break;
631
- case 'contains':
632
- result = String(value).includes(String(target));
633
- break;
634
- case 'startsWith':
635
- result = String(value).startsWith(String(target));
636
- break;
637
- case 'endsWith':
638
- result = String(value).endsWith(String(target));
639
- break;
640
- default:
641
- result = false;
642
- }
643
- return condition.negate ? !result : result;
644
- }
645
- // ─── Action Execution ──────────────────────────────────
646
- executeAction(action) {
647
- if (!this.currentState) {
648
- return;
649
- }
650
- switch (action.type) {
651
- case 'setVariable':
652
- this.currentState.variables.set(action.target, action.value);
653
- break;
654
- case 'setFlag':
655
- if (action.value) {
656
- this.currentState.flags.add(action.target);
657
- }
658
- else {
659
- this.currentState.flags.delete(action.target);
660
- }
661
- break;
662
- case 'addItem':
663
- case 'removeItem':
664
- case 'startQuest':
665
- case 'completeQuest':
666
- case 'playSound':
667
- case 'playAnimation':
668
- case 'custom':
669
- this.onAction?.(action);
670
- break;
671
- }
672
- }
673
- // ─── State Access ──────────────────────────────────────
674
- getVariable(name) {
675
- return this.currentState?.variables.get(name);
676
- }
677
- setVariable(name, value) {
678
- if (this.currentState) {
679
- this.currentState.variables.set(name, value);
680
- }
681
- }
682
- hasFlag(name) {
683
- return this.currentState?.flags.has(name) ?? false;
684
- }
685
- isNodeVisited(nodeId) {
686
- return this.currentState?.visitedNodes.has(nodeId) ?? false;
687
- }
688
- getCurrentState() {
689
- return this.currentState;
690
- }
691
- // ─── Callbacks ─────────────────────────────────────────
692
- setOnDialogueStart(callback) {
693
- this.onDialogueStart = callback;
694
- }
695
- setOnDialogueEnd(callback) {
696
- this.onDialogueEnd = callback;
697
- }
698
- setOnNodeEnter(callback) {
699
- this.onNodeEnter = callback;
700
- }
701
- setOnLineDisplay(callback) {
702
- this.onLineDisplay = callback;
703
- }
704
- setOnChoicesDisplay(callback) {
705
- this.onChoicesDisplay = callback;
706
- }
707
- setOnAction(callback) {
708
- this.onAction = callback;
709
- }
710
- setCustomConditionEvaluator(evaluator) {
711
- this.customConditionEvaluator = evaluator;
712
- }
713
- // ─── Import/Export ─────────────────────────────────────
714
- exportToJson(treeId) {
715
- const tree = this.trees.get(treeId);
716
- if (!tree) {
717
- return null;
718
- }
719
- const data = {
720
- ...tree,
721
- nodes: Object.fromEntries(tree.nodes),
722
- speakers: Object.fromEntries(tree.speakers),
723
- variables: Object.fromEntries(tree.variables),
724
- flags: Array.from(tree.flags),
725
- };
726
- // Convert LocalizedText.translations Maps to objects
727
- const convertLocalizedText = (lt) => ({
728
- ...lt,
729
- translations: Object.fromEntries(lt.translations),
730
- });
731
- for (const node of Object.values(data.nodes)) {
732
- if (node.lines) {
733
- for (const line of node.lines) {
734
- line.text = convertLocalizedText(line.text);
735
- }
736
- }
737
- if (node.choices) {
738
- for (const choice of node.choices) {
739
- choice.text = convertLocalizedText(choice.text);
740
- }
741
- }
742
- }
743
- for (const speaker of Object.values(data.speakers)) {
744
- speaker.name = convertLocalizedText(speaker.name);
745
- if (speaker.displayName) {
746
- speaker.displayName = convertLocalizedText(speaker.displayName);
747
- }
748
- }
749
- return JSON.stringify(data, null, 2);
750
- }
751
- importFromJson(json) {
752
- try {
753
- const data = JSON.parse(json);
754
- // Convert objects back to Maps
755
- const tree = {
756
- ...data,
757
- nodes: new Map(Object.entries(data.nodes)),
758
- speakers: new Map(Object.entries(data.speakers)),
759
- variables: new Map(Object.entries(data.variables)),
760
- flags: new Set(data.flags),
761
- };
762
- // Convert translation objects back to Maps
763
- const convertTranslations = (lt) => ({
764
- ...lt,
765
- translations: new Map(Object.entries(lt.translations)),
766
- });
767
- for (const node of tree.nodes.values()) {
768
- if (node.lines) {
769
- for (const line of node.lines) {
770
- line.text = convertTranslations(line.text);
771
- }
772
- }
773
- if (node.choices) {
774
- for (const choice of node.choices) {
775
- choice.text = convertTranslations(choice.text);
776
- }
777
- }
778
- }
779
- for (const speaker of tree.speakers.values()) {
780
- speaker.name = convertTranslations(speaker.name);
781
- if (speaker.displayName) {
782
- speaker.displayName = convertTranslations(speaker.displayName);
783
- }
784
- }
785
- this.trees.set(tree.id, tree);
786
- // Register speakers globally
787
- for (const [id, speaker] of tree.speakers) {
788
- this.speakers.set(id, speaker);
789
- }
790
- return tree;
791
- }
792
- catch (error) {
793
- console.error('Failed to import dialogue from JSON:', error);
794
- return null;
795
- }
796
- }
797
- exportStringsForLocalization(treeId) {
798
- const tree = this.trees.get(treeId);
799
- if (!tree) {
800
- return new Map();
801
- }
802
- const strings = new Map();
803
- for (const node of tree.nodes.values()) {
804
- if (node.lines) {
805
- for (const line of node.lines) {
806
- strings.set(line.text.key, line.text.default);
807
- }
808
- }
809
- if (node.choices) {
810
- for (const choice of node.choices) {
811
- strings.set(choice.text.key, choice.text.default);
812
- }
813
- }
814
- }
815
- for (const speaker of tree.speakers.values()) {
816
- strings.set(speaker.name.key, speaker.name.default);
817
- }
818
- return strings;
819
- }
820
- importTranslations(treeId, language, translations) {
821
- const tree = this.trees.get(treeId);
822
- if (!tree) {
823
- return false;
824
- }
825
- for (const node of tree.nodes.values()) {
826
- if (node.lines) {
827
- for (const line of node.lines) {
828
- const translation = translations.get(line.text.key);
829
- if (translation) {
830
- line.text.translations.set(language, translation);
831
- }
832
- }
833
- }
834
- if (node.choices) {
835
- for (const choice of node.choices) {
836
- const translation = translations.get(choice.text.key);
837
- if (translation) {
838
- choice.text.translations.set(language, translation);
839
- }
840
- }
841
- }
842
- }
843
- for (const speaker of tree.speakers.values()) {
844
- const translation = translations.get(speaker.name.key);
845
- if (translation) {
846
- speaker.name.translations.set(language, translation);
847
- }
848
- }
849
- if (!tree.supportedLanguages.includes(language)) {
850
- tree.supportedLanguages.push(language);
851
- }
852
- tree.modifiedAt = Date.now();
419
+ }
420
+ } else {
421
+ this.displayDialogueLine(node);
422
+ }
423
+ }
424
+ selectChoice(choiceId) {
425
+ if (!this.currentState) {
426
+ return;
427
+ }
428
+ const tree = this.trees.get(this.currentState.treeId);
429
+ if (!tree) {
430
+ return;
431
+ }
432
+ const node = tree.nodes.get(this.currentState.currentNodeId);
433
+ if (!node || !node.choices) {
434
+ return;
435
+ }
436
+ const choice = node.choices.find((c) => c.id === choiceId);
437
+ if (!choice) {
438
+ return;
439
+ }
440
+ if (!this.evaluateConditions(choice.condition)) {
441
+ return;
442
+ }
443
+ this.currentState.selectedChoices.add(choiceId);
444
+ this.currentState.history.push({
445
+ nodeId: node.id,
446
+ choiceId,
447
+ timestamp: Date.now()
448
+ });
449
+ if (choice.actions) {
450
+ for (const action of choice.actions) {
451
+ this.executeAction(action);
452
+ }
453
+ }
454
+ if (choice.targetNodeId) {
455
+ this.gotoNode(choice.targetNodeId);
456
+ }
457
+ }
458
+ advanceToNextNode(node) {
459
+ if (node.exitActions) {
460
+ for (const action of node.exitActions) {
461
+ this.executeAction(action);
462
+ }
463
+ }
464
+ if (node.nextNodeId) {
465
+ this.gotoNode(node.nextNodeId);
466
+ } else {
467
+ this.endDialogue();
468
+ }
469
+ }
470
+ gotoNode(nodeId) {
471
+ if (!this.currentState) {
472
+ return;
473
+ }
474
+ this.currentState.currentNodeId = nodeId;
475
+ this.currentState.currentLineIndex = 0;
476
+ this.processCurrentNode();
477
+ }
478
+ evaluateConditionNode(node) {
479
+ const result = this.evaluateConditions(node.condition);
480
+ if (node.choices && node.choices.length >= 2) {
481
+ const targetChoice = result ? node.choices[0] : node.choices[1];
482
+ if (targetChoice.targetNodeId) {
483
+ this.gotoNode(targetChoice.targetNodeId);
484
+ return;
485
+ }
486
+ }
487
+ this.advanceToNextNode(node);
488
+ }
489
+ executeNodeActions(node) {
490
+ this.advanceToNextNode(node);
491
+ }
492
+ selectRandomPath(node) {
493
+ if (!node.choices || node.choices.length === 0) {
494
+ this.advanceToNextNode(node);
495
+ return;
496
+ }
497
+ const weights = node.randomWeights ?? node.choices.map(() => 1);
498
+ const totalWeight = weights.reduce((sum, w) => sum + w, 0);
499
+ let random = Math.random() * totalWeight;
500
+ for (let i = 0; i < node.choices.length; i++) {
501
+ random -= weights[i] ?? 1;
502
+ if (random <= 0) {
503
+ if (node.choices[i].targetNodeId) {
504
+ this.gotoNode(node.choices[i].targetNodeId);
505
+ return;
506
+ }
507
+ }
508
+ }
509
+ this.advanceToNextNode(node);
510
+ }
511
+ // ─── Condition Evaluation ──────────────────────────────
512
+ evaluateConditions(group) {
513
+ if (!group) {
514
+ return true;
515
+ }
516
+ if (!this.currentState) {
517
+ return false;
518
+ }
519
+ const results = group.conditions.map((item) => {
520
+ if ("logic" in item) {
521
+ return this.evaluateConditions(item);
522
+ }
523
+ return this.evaluateCondition(item);
524
+ });
525
+ switch (group.logic) {
526
+ case "and":
527
+ return results.every(Boolean);
528
+ case "or":
529
+ return results.some(Boolean);
530
+ case "not":
531
+ return !results[0];
532
+ default:
853
533
  return true;
854
534
  }
855
- // ─── Graph Visualization ───────────────────────────────
856
- getGraphData(treeId) {
857
- const tree = this.trees.get(treeId);
858
- if (!tree) {
859
- return null;
860
- }
861
- const nodes = [];
862
- const edges = [];
863
- for (const node of tree.nodes.values()) {
864
- nodes.push({
865
- id: node.id,
866
- type: node.type,
867
- name: node.name,
868
- position: node.position,
869
- color: node.color,
870
- hasLines: (node.lines?.length ?? 0) > 0,
871
- hasChoices: (node.choices?.length ?? 0) > 0,
872
- hasCondition: !!node.condition,
535
+ }
536
+ evaluateCondition(condition) {
537
+ if (!this.currentState) {
538
+ return false;
539
+ }
540
+ let value;
541
+ switch (condition.type) {
542
+ case "variable":
543
+ value = this.currentState.variables.get(condition.variable);
544
+ break;
545
+ case "flag":
546
+ value = this.currentState.flags.has(condition.variable);
547
+ break;
548
+ case "custom":
549
+ if (this.customConditionEvaluator) {
550
+ return this.customConditionEvaluator(condition);
551
+ }
552
+ return false;
553
+ default:
554
+ return false;
555
+ }
556
+ let result;
557
+ const target = condition.value;
558
+ switch (condition.operator) {
559
+ case "eq":
560
+ result = value === target;
561
+ break;
562
+ case "ne":
563
+ result = value !== target;
564
+ break;
565
+ case "gt":
566
+ result = value > target;
567
+ break;
568
+ case "gte":
569
+ result = value >= target;
570
+ break;
571
+ case "lt":
572
+ result = value < target;
573
+ break;
574
+ case "lte":
575
+ result = value <= target;
576
+ break;
577
+ case "contains":
578
+ result = String(value).includes(String(target));
579
+ break;
580
+ case "startsWith":
581
+ result = String(value).startsWith(String(target));
582
+ break;
583
+ case "endsWith":
584
+ result = String(value).endsWith(String(target));
585
+ break;
586
+ default:
587
+ result = false;
588
+ }
589
+ return condition.negate ? !result : result;
590
+ }
591
+ // ─── Action Execution ──────────────────────────────────
592
+ executeAction(action) {
593
+ if (!this.currentState) {
594
+ return;
595
+ }
596
+ switch (action.type) {
597
+ case "setVariable":
598
+ this.currentState.variables.set(action.target, action.value);
599
+ break;
600
+ case "setFlag":
601
+ if (action.value) {
602
+ this.currentState.flags.add(action.target);
603
+ } else {
604
+ this.currentState.flags.delete(action.target);
605
+ }
606
+ break;
607
+ case "addItem":
608
+ case "removeItem":
609
+ case "startQuest":
610
+ case "completeQuest":
611
+ case "playSound":
612
+ case "playAnimation":
613
+ case "custom":
614
+ this.onAction?.(action);
615
+ break;
616
+ }
617
+ }
618
+ // ─── State Access ──────────────────────────────────────
619
+ getVariable(name) {
620
+ return this.currentState?.variables.get(name);
621
+ }
622
+ setVariable(name, value) {
623
+ if (this.currentState) {
624
+ this.currentState.variables.set(name, value);
625
+ }
626
+ }
627
+ hasFlag(name) {
628
+ return this.currentState?.flags.has(name) ?? false;
629
+ }
630
+ isNodeVisited(nodeId) {
631
+ return this.currentState?.visitedNodes.has(nodeId) ?? false;
632
+ }
633
+ getCurrentState() {
634
+ return this.currentState;
635
+ }
636
+ // ─── Callbacks ─────────────────────────────────────────
637
+ setOnDialogueStart(callback) {
638
+ this.onDialogueStart = callback;
639
+ }
640
+ setOnDialogueEnd(callback) {
641
+ this.onDialogueEnd = callback;
642
+ }
643
+ setOnNodeEnter(callback) {
644
+ this.onNodeEnter = callback;
645
+ }
646
+ setOnLineDisplay(callback) {
647
+ this.onLineDisplay = callback;
648
+ }
649
+ setOnChoicesDisplay(callback) {
650
+ this.onChoicesDisplay = callback;
651
+ }
652
+ setOnAction(callback) {
653
+ this.onAction = callback;
654
+ }
655
+ setCustomConditionEvaluator(evaluator) {
656
+ this.customConditionEvaluator = evaluator;
657
+ }
658
+ // ─── Import/Export ─────────────────────────────────────
659
+ exportToJson(treeId) {
660
+ const tree = this.trees.get(treeId);
661
+ if (!tree) {
662
+ return null;
663
+ }
664
+ const data = {
665
+ ...tree,
666
+ nodes: Object.fromEntries(tree.nodes),
667
+ speakers: Object.fromEntries(tree.speakers),
668
+ variables: Object.fromEntries(tree.variables),
669
+ flags: Array.from(tree.flags)
670
+ };
671
+ const convertLocalizedText = (lt) => ({
672
+ ...lt,
673
+ translations: Object.fromEntries(lt.translations)
674
+ });
675
+ for (const node of Object.values(data.nodes)) {
676
+ if (node.lines) {
677
+ for (const line of node.lines) {
678
+ line.text = convertLocalizedText(line.text);
679
+ }
680
+ }
681
+ if (node.choices) {
682
+ for (const choice of node.choices) {
683
+ choice.text = convertLocalizedText(choice.text);
684
+ }
685
+ }
686
+ }
687
+ for (const speaker of Object.values(data.speakers)) {
688
+ speaker.name = convertLocalizedText(speaker.name);
689
+ if (speaker.displayName) {
690
+ speaker.displayName = convertLocalizedText(speaker.displayName);
691
+ }
692
+ }
693
+ return JSON.stringify(data, null, 2);
694
+ }
695
+ importFromJson(json) {
696
+ try {
697
+ const data = JSON.parse(json);
698
+ const tree = {
699
+ ...data,
700
+ nodes: new Map(Object.entries(data.nodes)),
701
+ speakers: new Map(Object.entries(data.speakers)),
702
+ variables: new Map(Object.entries(data.variables)),
703
+ flags: new Set(data.flags)
704
+ };
705
+ const convertTranslations = (lt) => ({
706
+ ...lt,
707
+ translations: new Map(Object.entries(lt.translations))
708
+ });
709
+ for (const node of tree.nodes.values()) {
710
+ if (node.lines) {
711
+ for (const line of node.lines) {
712
+ line.text = convertTranslations(
713
+ line.text
714
+ );
715
+ }
716
+ }
717
+ if (node.choices) {
718
+ for (const choice of node.choices) {
719
+ choice.text = convertTranslations(
720
+ choice.text
721
+ );
722
+ }
723
+ }
724
+ }
725
+ for (const speaker of tree.speakers.values()) {
726
+ speaker.name = convertTranslations(
727
+ speaker.name
728
+ );
729
+ if (speaker.displayName) {
730
+ speaker.displayName = convertTranslations(
731
+ speaker.displayName
732
+ );
733
+ }
734
+ }
735
+ this.trees.set(tree.id, tree);
736
+ for (const [id, speaker] of tree.speakers) {
737
+ this.speakers.set(id, speaker);
738
+ }
739
+ return tree;
740
+ } catch (error) {
741
+ console.error("Failed to import dialogue from JSON:", error);
742
+ return null;
743
+ }
744
+ }
745
+ exportStringsForLocalization(treeId) {
746
+ const tree = this.trees.get(treeId);
747
+ if (!tree) {
748
+ return /* @__PURE__ */ new Map();
749
+ }
750
+ const strings = /* @__PURE__ */ new Map();
751
+ for (const node of tree.nodes.values()) {
752
+ if (node.lines) {
753
+ for (const line of node.lines) {
754
+ strings.set(line.text.key, line.text.default);
755
+ }
756
+ }
757
+ if (node.choices) {
758
+ for (const choice of node.choices) {
759
+ strings.set(choice.text.key, choice.text.default);
760
+ }
761
+ }
762
+ }
763
+ for (const speaker of tree.speakers.values()) {
764
+ strings.set(speaker.name.key, speaker.name.default);
765
+ }
766
+ return strings;
767
+ }
768
+ importTranslations(treeId, language, translations) {
769
+ const tree = this.trees.get(treeId);
770
+ if (!tree) {
771
+ return false;
772
+ }
773
+ for (const node of tree.nodes.values()) {
774
+ if (node.lines) {
775
+ for (const line of node.lines) {
776
+ const translation = translations.get(line.text.key);
777
+ if (translation) {
778
+ line.text.translations.set(language, translation);
779
+ }
780
+ }
781
+ }
782
+ if (node.choices) {
783
+ for (const choice of node.choices) {
784
+ const translation = translations.get(choice.text.key);
785
+ if (translation) {
786
+ choice.text.translations.set(language, translation);
787
+ }
788
+ }
789
+ }
790
+ }
791
+ for (const speaker of tree.speakers.values()) {
792
+ const translation = translations.get(speaker.name.key);
793
+ if (translation) {
794
+ speaker.name.translations.set(language, translation);
795
+ }
796
+ }
797
+ if (!tree.supportedLanguages.includes(language)) {
798
+ tree.supportedLanguages.push(language);
799
+ }
800
+ tree.modifiedAt = Date.now();
801
+ return true;
802
+ }
803
+ // ─── Graph Visualization ───────────────────────────────
804
+ getGraphData(treeId) {
805
+ const tree = this.trees.get(treeId);
806
+ if (!tree) {
807
+ return null;
808
+ }
809
+ const nodes = [];
810
+ const edges = [];
811
+ for (const node of tree.nodes.values()) {
812
+ nodes.push({
813
+ id: node.id,
814
+ type: node.type,
815
+ name: node.name,
816
+ position: node.position,
817
+ color: node.color,
818
+ hasLines: (node.lines?.length ?? 0) > 0,
819
+ hasChoices: (node.choices?.length ?? 0) > 0,
820
+ hasCondition: !!node.condition
821
+ });
822
+ if (node.nextNodeId) {
823
+ edges.push({
824
+ id: `edge_${node.id}_${node.nextNodeId}`,
825
+ from: node.id,
826
+ to: node.nextNodeId,
827
+ type: "default"
828
+ });
829
+ }
830
+ if (node.choices) {
831
+ for (const choice of node.choices) {
832
+ if (choice.targetNodeId) {
833
+ edges.push({
834
+ id: `edge_${node.id}_${choice.id}`,
835
+ from: node.id,
836
+ to: choice.targetNodeId,
837
+ type: "choice",
838
+ label: this.getText(choice.text).substring(0, 20),
839
+ hasCondition: !!choice.condition
873
840
  });
874
- // Create edges
875
- if (node.nextNodeId) {
876
- edges.push({
877
- id: `edge_${node.id}_${node.nextNodeId}`,
878
- from: node.id,
879
- to: node.nextNodeId,
880
- type: 'default',
881
- });
882
- }
883
- if (node.choices) {
884
- for (const choice of node.choices) {
885
- if (choice.targetNodeId) {
886
- edges.push({
887
- id: `edge_${node.id}_${choice.id}`,
888
- from: node.id,
889
- to: choice.targetNodeId,
890
- type: 'choice',
891
- label: this.getText(choice.text).substring(0, 20),
892
- hasCondition: !!choice.condition,
893
- });
894
- }
895
- }
896
- }
841
+ }
897
842
  }
898
- return { nodes, edges };
843
+ }
899
844
  }
845
+ return { nodes, edges };
846
+ }
900
847
  }
901
- // ============================================================
902
- // Factory Functions
903
- // ============================================================
904
848
  function createDialogueManager() {
905
- return new DialogueManager();
849
+ return new DialogueManager();
906
850
  }
907
851
  function createDialogueNode(type, name, position) {
908
- return { type, name, position };
852
+ return { type, name, position };
909
853
  }
910
854
  function createConditionGroup(logic, conditions) {
911
- return { logic, conditions };
855
+ return { logic, conditions };
912
856
  }
913
857
  function createCondition(type, variable, operator, value) {
914
- return { type, variable, operator, value };
858
+ return { type, variable, operator, value };
915
859
  }
916
-
917
- export { DialogueManager, createCondition, createConditionGroup, createDialogueManager, createDialogueNode };
860
+ export {
861
+ DialogueManager,
862
+ createCondition,
863
+ createConditionGroup,
864
+ createDialogueManager,
865
+ createDialogueNode
866
+ };