@nice2dev/game-engine 1.3.14 → 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 +13 -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,748 +1,698 @@
1
- 'use strict';
2
-
3
- /**
4
- * @file CraftingEditor.ts
5
- * @description Visual Crafting Recipe Editor system
6
- * PRO-1.4: Professional Editor Features
7
- *
8
- * Features:
9
- * - Recipe definition with ingredients
10
- * - Crafting stations/workbenches
11
- * - Recipe categories and discovery
12
- * - Skill requirements
13
- * - Recipe variants and tiers
14
- * - Crafting time and progress
15
- * - By-products and waste
16
- * - Recipe chains
17
- * - Salvaging/recycling
18
- * - Quality system
19
- */
20
- // ============================================================
21
- // Crafting Editor
22
- // ============================================================
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
23
3
  class CraftingEditor {
24
- constructor() {
25
- this.recipes = new Map();
26
- this.stations = new Map();
27
- this.chains = new Map();
28
- this.salvageRules = new Map();
29
- // Runtime
30
- this.activeProgress = new Map();
31
- this.craftingQueues = new Map();
32
- // Player state
33
- this.playerSkills = new Map();
34
- this.playerInventory = new Map();
35
- this.discoveredRecipes = new Set();
36
- }
37
- // ─── Recipe Management ─────────────────────────────────
38
- createRecipe(name, category) {
39
- const recipe = {
40
- id: `recipe_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
41
- name,
42
- description: '',
43
- category,
44
- ingredients: [],
45
- outputs: [],
46
- requirements: [],
47
- skillRequired: 0,
48
- craftingTime: 5,
49
- experienceGained: 10,
50
- isStackable: true,
51
- maxBatch: 99,
52
- discoveryMethod: 'known',
53
- discoveredBy: new Set(),
54
- tier: 1,
55
- baseQuality: 'normal',
56
- qualityFactors: [],
57
- tags: [],
58
- isFavorite: false,
59
- createdAt: Date.now(),
60
- modifiedAt: Date.now(),
61
- version: 1,
4
+ constructor() {
5
+ this.recipes = /* @__PURE__ */ new Map();
6
+ this.stations = /* @__PURE__ */ new Map();
7
+ this.chains = /* @__PURE__ */ new Map();
8
+ this.salvageRules = /* @__PURE__ */ new Map();
9
+ this.activeProgress = /* @__PURE__ */ new Map();
10
+ this.craftingQueues = /* @__PURE__ */ new Map();
11
+ this.playerSkills = /* @__PURE__ */ new Map();
12
+ this.playerInventory = /* @__PURE__ */ new Map();
13
+ this.discoveredRecipes = /* @__PURE__ */ new Set();
14
+ }
15
+ // ─── Recipe Management ─────────────────────────────────
16
+ createRecipe(name, category) {
17
+ const recipe = {
18
+ id: `recipe_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
19
+ name,
20
+ description: "",
21
+ category,
22
+ ingredients: [],
23
+ outputs: [],
24
+ requirements: [],
25
+ skillRequired: 0,
26
+ craftingTime: 5,
27
+ experienceGained: 10,
28
+ isStackable: true,
29
+ maxBatch: 99,
30
+ discoveryMethod: "known",
31
+ discoveredBy: /* @__PURE__ */ new Set(),
32
+ tier: 1,
33
+ baseQuality: "normal",
34
+ qualityFactors: [],
35
+ tags: [],
36
+ isFavorite: false,
37
+ createdAt: Date.now(),
38
+ modifiedAt: Date.now(),
39
+ version: 1
40
+ };
41
+ this.recipes.set(recipe.id, recipe);
42
+ return recipe;
43
+ }
44
+ getRecipe(id) {
45
+ return this.recipes.get(id);
46
+ }
47
+ updateRecipe(id, updates) {
48
+ const recipe = this.recipes.get(id);
49
+ if (!recipe) {
50
+ return false;
51
+ }
52
+ Object.assign(recipe, updates, { modifiedAt: Date.now() });
53
+ return true;
54
+ }
55
+ deleteRecipe(id) {
56
+ return this.recipes.delete(id);
57
+ }
58
+ getAllRecipes() {
59
+ return Array.from(this.recipes.values());
60
+ }
61
+ getRecipesByCategory(category) {
62
+ return this.getAllRecipes().filter((r) => r.category === category);
63
+ }
64
+ // ─── Ingredient Management ─────────────────────────────
65
+ addIngredient(recipeId, itemId, amount, isConsumed = true) {
66
+ const recipe = this.recipes.get(recipeId);
67
+ if (!recipe) {
68
+ return false;
69
+ }
70
+ const ingredient = {
71
+ itemId,
72
+ amount,
73
+ isConsumed
74
+ };
75
+ recipe.ingredients.push(ingredient);
76
+ recipe.modifiedAt = Date.now();
77
+ return true;
78
+ }
79
+ removeIngredient(recipeId, index) {
80
+ const recipe = this.recipes.get(recipeId);
81
+ if (!recipe || index < 0 || index >= recipe.ingredients.length) {
82
+ return false;
83
+ }
84
+ recipe.ingredients.splice(index, 1);
85
+ recipe.modifiedAt = Date.now();
86
+ return true;
87
+ }
88
+ setIngredientAlternatives(recipeId, ingredientIndex, alternativeIds) {
89
+ const recipe = this.recipes.get(recipeId);
90
+ if (!recipe || !recipe.ingredients[ingredientIndex]) {
91
+ return false;
92
+ }
93
+ recipe.ingredients[ingredientIndex].alternativeIds = alternativeIds;
94
+ recipe.modifiedAt = Date.now();
95
+ return true;
96
+ }
97
+ // ─── Output Management ─────────────────────────────────
98
+ addOutput(recipeId, itemId, minAmount, maxAmount = minAmount, chance = 1) {
99
+ const recipe = this.recipes.get(recipeId);
100
+ if (!recipe) {
101
+ return false;
102
+ }
103
+ const output = {
104
+ itemId,
105
+ minAmount,
106
+ maxAmount,
107
+ chance
108
+ };
109
+ recipe.outputs.push(output);
110
+ recipe.modifiedAt = Date.now();
111
+ return true;
112
+ }
113
+ addByproduct(recipeId, itemId, chance, amount = 1) {
114
+ const recipe = this.recipes.get(recipeId);
115
+ if (!recipe) {
116
+ return false;
117
+ }
118
+ if (!recipe.byproducts) {
119
+ recipe.byproducts = [];
120
+ }
121
+ recipe.byproducts.push({
122
+ itemId,
123
+ minAmount: amount,
124
+ maxAmount: amount,
125
+ chance
126
+ });
127
+ recipe.modifiedAt = Date.now();
128
+ return true;
129
+ }
130
+ // ─── Requirement Management ────────────────────────────
131
+ addRequirement(recipeId, type, target, value, description) {
132
+ const recipe = this.recipes.get(recipeId);
133
+ if (!recipe) {
134
+ return false;
135
+ }
136
+ recipe.requirements.push({ type, target, value, description });
137
+ recipe.modifiedAt = Date.now();
138
+ return true;
139
+ }
140
+ // ─── Station Management ────────────────────────────────
141
+ createStation(name, categories) {
142
+ const station = {
143
+ id: `station_${Date.now()}`,
144
+ name,
145
+ description: "",
146
+ categories,
147
+ tier: 1
148
+ };
149
+ this.stations.set(station.id, station);
150
+ return station;
151
+ }
152
+ getStation(id) {
153
+ return this.stations.get(id);
154
+ }
155
+ getAllStations() {
156
+ return Array.from(this.stations.values());
157
+ }
158
+ getStationsForCategory(category) {
159
+ return this.getAllStations().filter((s) => s.categories.includes(category));
160
+ }
161
+ // ─── Recipe Chains ─────────────────────────────────────
162
+ createChain(name) {
163
+ const chain = {
164
+ id: `chain_${Date.now()}`,
165
+ name,
166
+ description: "",
167
+ recipeIds: [],
168
+ automatable: false
169
+ };
170
+ this.chains.set(chain.id, chain);
171
+ return chain;
172
+ }
173
+ addRecipeToChain(chainId, recipeId) {
174
+ const chain = this.chains.get(chainId);
175
+ if (!chain) {
176
+ return false;
177
+ }
178
+ chain.recipeIds.push(recipeId);
179
+ return true;
180
+ }
181
+ // ─── Salvage Rules ─────────────────────────────────────
182
+ createSalvageRule(sourceItemId) {
183
+ const rule = {
184
+ sourceItemId,
185
+ outputs: [],
186
+ preserveEnchantments: false
187
+ };
188
+ this.salvageRules.set(sourceItemId, rule);
189
+ return rule;
190
+ }
191
+ addSalvageOutput(sourceItemId, outputItemId, chance, amount = 1) {
192
+ const rule = this.salvageRules.get(sourceItemId);
193
+ if (!rule) {
194
+ return false;
195
+ }
196
+ rule.outputs.push({
197
+ itemId: outputItemId,
198
+ minAmount: amount,
199
+ maxAmount: amount,
200
+ chance
201
+ });
202
+ return true;
203
+ }
204
+ // ─── Runtime: Availability ─────────────────────────────
205
+ getAvailableRecipes(playerId, stationId) {
206
+ return this.getAllRecipes().filter((recipe) => {
207
+ if (recipe.discoveryMethod !== "known" && !this.discoveredRecipes.has(recipe.id)) {
208
+ return false;
209
+ }
210
+ if (stationId && recipe.stationId && recipe.stationId !== stationId) {
211
+ return false;
212
+ }
213
+ for (const req of recipe.requirements) {
214
+ if (!this.checkRequirement(req, playerId)) {
215
+ return false;
216
+ }
217
+ }
218
+ return true;
219
+ });
220
+ }
221
+ canCraft(recipeId, playerId, quantity = 1) {
222
+ const recipe = this.recipes.get(recipeId);
223
+ if (!recipe) {
224
+ return { canCraft: false, reason: "Recipe not found" };
225
+ }
226
+ if (recipe.discoveryMethod !== "known" && !this.discoveredRecipes.has(recipeId)) {
227
+ return { canCraft: false, reason: "Recipe not discovered" };
228
+ }
229
+ if (recipe.skillId) {
230
+ const skill = this.playerSkills.get(recipe.skillId) ?? 0;
231
+ if (skill < recipe.skillRequired) {
232
+ return {
233
+ canCraft: false,
234
+ reason: `Requires ${recipe.skillId} skill ${recipe.skillRequired}`
62
235
  };
63
- this.recipes.set(recipe.id, recipe);
64
- return recipe;
236
+ }
65
237
  }
66
- getRecipe(id) {
67
- return this.recipes.get(id);
68
- }
69
- updateRecipe(id, updates) {
70
- const recipe = this.recipes.get(id);
71
- if (!recipe) {
72
- return false;
73
- }
74
- Object.assign(recipe, updates, { modifiedAt: Date.now() });
75
- return true;
76
- }
77
- deleteRecipe(id) {
78
- return this.recipes.delete(id);
79
- }
80
- getAllRecipes() {
81
- return Array.from(this.recipes.values());
82
- }
83
- getRecipesByCategory(category) {
84
- return this.getAllRecipes().filter((r) => r.category === category);
85
- }
86
- // ─── Ingredient Management ─────────────────────────────
87
- addIngredient(recipeId, itemId, amount, isConsumed = true) {
88
- const recipe = this.recipes.get(recipeId);
89
- if (!recipe) {
90
- return false;
91
- }
92
- const ingredient = {
93
- itemId,
94
- amount,
95
- isConsumed,
96
- };
97
- recipe.ingredients.push(ingredient);
98
- recipe.modifiedAt = Date.now();
99
- return true;
100
- }
101
- removeIngredient(recipeId, index) {
102
- const recipe = this.recipes.get(recipeId);
103
- if (!recipe || index < 0 || index >= recipe.ingredients.length) {
104
- return false;
105
- }
106
- recipe.ingredients.splice(index, 1);
107
- recipe.modifiedAt = Date.now();
108
- return true;
109
- }
110
- setIngredientAlternatives(recipeId, ingredientIndex, alternativeIds) {
111
- const recipe = this.recipes.get(recipeId);
112
- if (!recipe || !recipe.ingredients[ingredientIndex]) {
113
- return false;
114
- }
115
- recipe.ingredients[ingredientIndex].alternativeIds = alternativeIds;
116
- recipe.modifiedAt = Date.now();
117
- return true;
118
- }
119
- // ─── Output Management ─────────────────────────────────
120
- addOutput(recipeId, itemId, minAmount, maxAmount = minAmount, chance = 1) {
121
- const recipe = this.recipes.get(recipeId);
122
- if (!recipe) {
123
- return false;
124
- }
125
- const output = {
126
- itemId,
127
- minAmount,
128
- maxAmount,
129
- chance,
130
- };
131
- recipe.outputs.push(output);
132
- recipe.modifiedAt = Date.now();
133
- return true;
134
- }
135
- addByproduct(recipeId, itemId, chance, amount = 1) {
136
- const recipe = this.recipes.get(recipeId);
137
- if (!recipe) {
138
- return false;
139
- }
140
- if (!recipe.byproducts) {
141
- recipe.byproducts = [];
142
- }
143
- recipe.byproducts.push({
144
- itemId,
145
- minAmount: amount,
146
- maxAmount: amount,
147
- chance,
148
- });
149
- recipe.modifiedAt = Date.now();
150
- return true;
151
- }
152
- // ─── Requirement Management ────────────────────────────
153
- addRequirement(recipeId, type, target, value, description) {
154
- const recipe = this.recipes.get(recipeId);
155
- if (!recipe) {
156
- return false;
157
- }
158
- recipe.requirements.push({ type, target, value, description });
159
- recipe.modifiedAt = Date.now();
160
- return true;
161
- }
162
- // ─── Station Management ────────────────────────────────
163
- createStation(name, categories) {
164
- const station = {
165
- id: `station_${Date.now()}`,
166
- name,
167
- description: '',
168
- categories,
169
- tier: 1,
170
- };
171
- this.stations.set(station.id, station);
172
- return station;
173
- }
174
- getStation(id) {
175
- return this.stations.get(id);
176
- }
177
- getAllStations() {
178
- return Array.from(this.stations.values());
179
- }
180
- getStationsForCategory(category) {
181
- return this.getAllStations().filter((s) => s.categories.includes(category));
182
- }
183
- // ─── Recipe Chains ─────────────────────────────────────
184
- createChain(name) {
185
- const chain = {
186
- id: `chain_${Date.now()}`,
187
- name,
188
- description: '',
189
- recipeIds: [],
190
- automatable: false,
191
- };
192
- this.chains.set(chain.id, chain);
193
- return chain;
194
- }
195
- addRecipeToChain(chainId, recipeId) {
196
- const chain = this.chains.get(chainId);
197
- if (!chain) {
198
- return false;
199
- }
200
- chain.recipeIds.push(recipeId);
201
- return true;
202
- }
203
- // ─── Salvage Rules ─────────────────────────────────────
204
- createSalvageRule(sourceItemId) {
205
- const rule = {
206
- sourceItemId,
207
- outputs: [],
208
- preserveEnchantments: false,
209
- };
210
- this.salvageRules.set(sourceItemId, rule);
211
- return rule;
212
- }
213
- addSalvageOutput(sourceItemId, outputItemId, chance, amount = 1) {
214
- const rule = this.salvageRules.get(sourceItemId);
215
- if (!rule) {
216
- return false;
217
- }
218
- rule.outputs.push({
219
- itemId: outputItemId,
220
- minAmount: amount,
221
- maxAmount: amount,
222
- chance,
223
- });
224
- return true;
225
- }
226
- // ─── Runtime: Availability ─────────────────────────────
227
- getAvailableRecipes(playerId, stationId) {
228
- return this.getAllRecipes().filter((recipe) => {
229
- // Check discovery
230
- if (recipe.discoveryMethod !== 'known' && !this.discoveredRecipes.has(recipe.id)) {
231
- return false;
232
- }
233
- // Check station
234
- if (stationId && recipe.stationId && recipe.stationId !== stationId) {
235
- return false;
236
- }
237
- // Check requirements
238
- for (const req of recipe.requirements) {
239
- if (!this.checkRequirement(req, playerId)) {
240
- return false;
241
- }
242
- }
243
- return true;
244
- });
245
- }
246
- canCraft(recipeId, playerId, quantity = 1) {
247
- const recipe = this.recipes.get(recipeId);
248
- if (!recipe) {
249
- return { canCraft: false, reason: 'Recipe not found' };
250
- }
251
- // Check discovery
252
- if (recipe.discoveryMethod !== 'known' && !this.discoveredRecipes.has(recipeId)) {
253
- return { canCraft: false, reason: 'Recipe not discovered' };
254
- }
255
- // Check skill requirement
256
- if (recipe.skillId) {
257
- const skill = this.playerSkills.get(recipe.skillId) ?? 0;
258
- if (skill < recipe.skillRequired) {
259
- return {
260
- canCraft: false,
261
- reason: `Requires ${recipe.skillId} skill ${recipe.skillRequired}`,
262
- };
263
- }
264
- }
265
- // Check ingredients
266
- for (const ingredient of recipe.ingredients) {
267
- const required = ingredient.amount * quantity;
268
- let hasIngredient = false;
269
- // Check main item or alternatives
270
- const itemIds = [ingredient.itemId, ...(ingredient.alternativeIds ?? [])];
271
- for (const itemId of itemIds) {
272
- const available = this.playerInventory.get(itemId) ?? 0;
273
- if (available >= required) {
274
- hasIngredient = true;
275
- break;
276
- }
277
- }
278
- if (!hasIngredient) {
279
- return { canCraft: false, reason: `Insufficient ${ingredient.itemId}` };
280
- }
281
- }
282
- // Check requirements
283
- for (const req of recipe.requirements) {
284
- if (!this.checkRequirement(req, playerId)) {
285
- return { canCraft: false, reason: req.description ?? `Requirement not met: ${req.type}` };
286
- }
287
- }
288
- return { canCraft: true };
289
- }
290
- checkRequirement(req, _playerId) {
291
- switch (req.type) {
292
- case 'skill': {
293
- const skill = this.playerSkills.get(req.target) ?? 0;
294
- return skill >= req.value;
295
- }
296
- case 'level':
297
- // Would integrate with player level system
298
- return true;
299
- default:
300
- return true;
301
- }
302
- }
303
- // ─── Runtime: Crafting ─────────────────────────────────
304
- startCrafting(recipeId, playerId, quantity = 1) {
305
- const recipe = this.recipes.get(recipeId);
306
- if (!recipe) {
307
- return null;
308
- }
309
- const check = this.canCraft(recipeId, playerId, quantity);
310
- if (!check.canCraft) {
311
- return null;
312
- }
313
- // Consume ingredients
314
- for (const ingredient of recipe.ingredients) {
315
- if (!ingredient.isConsumed) {
316
- continue;
317
- }
318
- const required = ingredient.amount * quantity;
319
- const itemIds = [ingredient.itemId, ...(ingredient.alternativeIds ?? [])];
320
- for (const itemId of itemIds) {
321
- const available = this.playerInventory.get(itemId) ?? 0;
322
- if (available >= required) {
323
- this.playerInventory.set(itemId, available - required);
324
- break;
325
- }
326
- }
327
- }
328
- const now = Date.now();
329
- const craftingTime = recipe.craftingTime * 1000 * quantity;
330
- const progress = {
331
- id: `progress_${Date.now()}`,
332
- recipeId,
333
- playerId,
334
- startedAt: now,
335
- completesAt: now + craftingTime,
336
- quantity,
337
- isPaused: false,
338
- accumulatedTime: 0,
339
- cancelled: false,
340
- };
341
- this.activeProgress.set(progress.id, progress);
342
- this.onCraftingStarted?.(progress);
343
- // Instant crafting
344
- if (recipe.craftingTime === 0) {
345
- this.completeCrafting(progress.id);
346
- }
347
- return progress;
348
- }
349
- updateCraftingProgress(_deltaTime) {
350
- const now = Date.now();
351
- for (const [progressId, progress] of this.activeProgress) {
352
- if (progress.isPaused || progress.cancelled) {
353
- continue;
354
- }
355
- const recipe = this.recipes.get(progress.recipeId);
356
- if (!recipe) {
357
- continue;
358
- }
359
- // Check if complete
360
- if (now >= progress.completesAt) {
361
- this.completeCrafting(progressId);
362
- }
363
- else {
364
- // Report progress
365
- const totalTime = progress.completesAt - progress.startedAt;
366
- const elapsed = now - progress.startedAt + progress.accumulatedTime;
367
- const percent = Math.min(1, elapsed / totalTime);
368
- this.onCraftingProgress?.(progress, percent);
369
- }
370
- }
371
- }
372
- completeCrafting(progressId) {
373
- const progress = this.activeProgress.get(progressId);
374
- if (!progress) {
375
- return;
376
- }
377
- const recipe = this.recipes.get(progress.recipeId);
378
- if (!recipe) {
379
- return;
380
- }
381
- // Determine quality
382
- const quality = this.determineQuality(recipe, progress.playerId);
383
- this.onQualityDetermined?.(recipe, quality, []);
384
- // Generate outputs
385
- const outputs = [];
386
- for (const output of recipe.outputs) {
387
- if (Math.random() <= output.chance) {
388
- const baseAmount = Math.floor(Math.random() * (output.maxAmount - output.minAmount + 1) + output.minAmount) *
389
- progress.quantity;
390
- // Apply skill bonus
391
- let finalAmount = baseAmount;
392
- if (output.bonusFromSkill && recipe.skillId) {
393
- const skill = this.playerSkills.get(recipe.skillId) ?? 0;
394
- finalAmount += Math.floor(skill * output.bonusFromSkill);
395
- }
396
- // Add to inventory
397
- const current = this.playerInventory.get(output.itemId) ?? 0;
398
- this.playerInventory.set(output.itemId, current + finalAmount);
399
- outputs.push({ ...output, minAmount: finalAmount, maxAmount: finalAmount });
400
- }
401
- }
402
- // Generate byproducts
403
- if (recipe.byproducts) {
404
- for (const byproduct of recipe.byproducts) {
405
- if (Math.random() <= byproduct.chance) {
406
- const amount = Math.floor(Math.random() * (byproduct.maxAmount - byproduct.minAmount + 1) + byproduct.minAmount) * progress.quantity;
407
- const current = this.playerInventory.get(byproduct.itemId) ?? 0;
408
- this.playerInventory.set(byproduct.itemId, current + amount);
409
- }
410
- }
411
- }
412
- // Award experience
413
- if (recipe.skillId && recipe.experienceGained > 0) {
414
- const totalXp = recipe.experienceGained * progress.quantity;
415
- this.onExperienceGained?.(recipe.skillId, totalXp);
416
- }
417
- this.activeProgress.delete(progressId);
418
- this.onCraftingCompleted?.(recipe, outputs, quality);
419
- }
420
- determineQuality(recipe, _playerId) {
421
- const qualities = [
422
- 'poor',
423
- 'normal',
424
- 'fine',
425
- 'superior',
426
- 'masterwork',
427
- 'legendary',
428
- ];
429
- const baseIndex = qualities.indexOf(recipe.baseQuality);
430
- let qualityScore = baseIndex;
431
- for (const factor of recipe.qualityFactors) {
432
- switch (factor.type) {
433
- case 'skill':
434
- if (recipe.skillId) {
435
- const skill = this.playerSkills.get(recipe.skillId) ?? 0;
436
- qualityScore += (skill / 100) * factor.weight;
437
- }
438
- break;
439
- case 'random':
440
- qualityScore += (Math.random() - 0.5) * factor.weight;
441
- break;
442
- }
443
- }
444
- const finalIndex = Math.max(0, Math.min(qualities.length - 1, Math.round(qualityScore)));
445
- return qualities[finalIndex];
446
- }
447
- pauseCrafting(progressId) {
448
- const progress = this.activeProgress.get(progressId);
449
- if (!progress || progress.isPaused) {
450
- return false;
451
- }
452
- progress.isPaused = true;
453
- progress.pausedAt = Date.now();
454
- progress.accumulatedTime += progress.pausedAt - progress.startedAt;
455
- return true;
456
- }
457
- resumeCrafting(progressId) {
458
- const progress = this.activeProgress.get(progressId);
459
- if (!progress || !progress.isPaused) {
460
- return false;
461
- }
462
- const now = Date.now();
463
- const remainingTime = progress.completesAt - progress.startedAt - progress.accumulatedTime;
464
- progress.isPaused = false;
465
- progress.startedAt = now;
466
- progress.completesAt = now + remainingTime;
467
- progress.pausedAt = undefined;
468
- return true;
469
- }
470
- cancelCrafting(progressId, refundIngredients = false) {
471
- const progress = this.activeProgress.get(progressId);
472
- if (!progress) {
473
- return false;
474
- }
475
- progress.cancelled = true;
476
- if (refundIngredients) {
477
- const recipe = this.recipes.get(progress.recipeId);
478
- if (recipe) {
479
- for (const ingredient of recipe.ingredients) {
480
- if (!ingredient.isConsumed) {
481
- continue;
482
- }
483
- const amount = ingredient.amount * progress.quantity;
484
- const current = this.playerInventory.get(ingredient.itemId) ?? 0;
485
- this.playerInventory.set(ingredient.itemId, current + amount);
486
- }
487
- }
488
- }
489
- this.activeProgress.delete(progressId);
490
- return true;
491
- }
492
- // ─── Crafting Queue ────────────────────────────────────
493
- addToQueue(playerId, recipeId, quantity, priority = 0) {
494
- if (!this.craftingQueues.has(playerId)) {
495
- this.craftingQueues.set(playerId, []);
496
- }
497
- const queue = this.craftingQueues.get(playerId);
498
- queue.push({ recipeId, quantity, priority });
499
- queue.sort((a, b) => b.priority - a.priority);
238
+ for (const ingredient of recipe.ingredients) {
239
+ const required = ingredient.amount * quantity;
240
+ let hasIngredient = false;
241
+ const itemIds = [ingredient.itemId, ...ingredient.alternativeIds ?? []];
242
+ for (const itemId of itemIds) {
243
+ const available = this.playerInventory.get(itemId) ?? 0;
244
+ if (available >= required) {
245
+ hasIngredient = true;
246
+ break;
247
+ }
248
+ }
249
+ if (!hasIngredient) {
250
+ return { canCraft: false, reason: `Insufficient ${ingredient.itemId}` };
251
+ }
252
+ }
253
+ for (const req of recipe.requirements) {
254
+ if (!this.checkRequirement(req, playerId)) {
255
+ return { canCraft: false, reason: req.description ?? `Requirement not met: ${req.type}` };
256
+ }
257
+ }
258
+ return { canCraft: true };
259
+ }
260
+ checkRequirement(req, _playerId) {
261
+ switch (req.type) {
262
+ case "skill": {
263
+ const skill = this.playerSkills.get(req.target) ?? 0;
264
+ return skill >= req.value;
265
+ }
266
+ case "level":
500
267
  return true;
501
- }
502
- getQueue(playerId) {
503
- return this.craftingQueues.get(playerId) ?? [];
504
- }
505
- processQueueItem(playerId) {
506
- const queue = this.craftingQueues.get(playerId);
507
- if (!queue || queue.length === 0) {
508
- return null;
509
- }
510
- const item = queue.shift();
511
- return this.startCrafting(item.recipeId, playerId, item.quantity);
512
- }
513
- // ─── Discovery ─────────────────────────────────────────
514
- discoverRecipe(recipeId, playerId) {
515
- const recipe = this.recipes.get(recipeId);
516
- if (!recipe) {
517
- return false;
518
- }
519
- if (this.discoveredRecipes.has(recipeId)) {
520
- return false;
521
- }
522
- this.discoveredRecipes.add(recipeId);
523
- recipe.discoveredBy.add(playerId);
524
- this.onRecipeDiscovered?.(recipe, playerId);
268
+ default:
525
269
  return true;
526
270
  }
527
- isRecipeDiscovered(recipeId) {
528
- const recipe = this.recipes.get(recipeId);
529
- if (!recipe) {
530
- return false;
531
- }
532
- if (recipe.discoveryMethod === 'known') {
533
- return true;
534
- }
535
- return this.discoveredRecipes.has(recipeId);
536
- }
537
- // ─── Salvage ───────────────────────────────────────────
538
- canSalvage(itemId, _playerId) {
539
- const rule = this.salvageRules.get(itemId);
540
- if (!rule) {
541
- return false;
542
- }
543
- if (rule.skillRequired) {
544
- const skill = this.playerSkills.get('salvaging') ?? 0;
545
- if (skill < rule.skillRequired) {
546
- return false;
547
- }
548
- }
549
- return true;
550
- }
551
- salvageItem(itemId, _playerId, quantity = 1) {
552
- const rule = this.salvageRules.get(itemId);
553
- if (!rule) {
554
- return null;
555
- }
556
- // Consume items
271
+ }
272
+ // ─── Runtime: Crafting ─────────────────────────────────
273
+ startCrafting(recipeId, playerId, quantity = 1) {
274
+ const recipe = this.recipes.get(recipeId);
275
+ if (!recipe) {
276
+ return null;
277
+ }
278
+ const check = this.canCraft(recipeId, playerId, quantity);
279
+ if (!check.canCraft) {
280
+ return null;
281
+ }
282
+ for (const ingredient of recipe.ingredients) {
283
+ if (!ingredient.isConsumed) {
284
+ continue;
285
+ }
286
+ const required = ingredient.amount * quantity;
287
+ const itemIds = [ingredient.itemId, ...ingredient.alternativeIds ?? []];
288
+ for (const itemId of itemIds) {
557
289
  const available = this.playerInventory.get(itemId) ?? 0;
558
- if (available < quantity) {
559
- return null;
560
- }
561
- this.playerInventory.set(itemId, available - quantity);
562
- // Generate outputs
563
- const outputs = [];
564
- for (const output of rule.outputs) {
565
- for (let i = 0; i < quantity; i++) {
566
- if (Math.random() <= output.chance) {
567
- const amount = Math.floor(Math.random() * (output.maxAmount - output.minAmount + 1) + output.minAmount);
568
- const current = this.playerInventory.get(output.itemId) ?? 0;
569
- this.playerInventory.set(output.itemId, current + amount);
570
- outputs.push({ ...output, minAmount: amount, maxAmount: amount });
571
- }
572
- }
573
- }
574
- return outputs;
575
- }
576
- // ─── Player State ──────────────────────────────────────
577
- setPlayerSkill(skillId, level) {
578
- this.playerSkills.set(skillId, level);
579
- }
580
- setPlayerItem(itemId, count) {
581
- this.playerInventory.set(itemId, count);
582
- }
583
- getPlayerInventory() {
584
- return new Map(this.playerInventory);
585
- }
586
- // ─── Callbacks ─────────────────────────────────────────
587
- setOnRecipeDiscovered(callback) {
588
- this.onRecipeDiscovered = callback;
589
- }
590
- setOnCraftingStarted(callback) {
591
- this.onCraftingStarted = callback;
592
- }
593
- setOnCraftingProgress(callback) {
594
- this.onCraftingProgress = callback;
595
- }
596
- setOnCraftingCompleted(callback) {
597
- this.onCraftingCompleted = callback;
598
- }
599
- setOnCraftingFailed(callback) {
600
- this.onCraftingFailed = callback;
601
- }
602
- setOnQualityDetermined(callback) {
603
- this.onQualityDetermined = callback;
604
- }
605
- setOnExperienceGained(callback) {
606
- this.onExperienceGained = callback;
607
- }
608
- // ─── Queries ───────────────────────────────────────────
609
- getActiveProgress() {
610
- return Array.from(this.activeProgress.values());
611
- }
612
- getProgressForPlayer(playerId) {
613
- return this.getActiveProgress().filter((p) => p.playerId === playerId);
614
- }
615
- searchRecipes(query) {
616
- const lowerQuery = query.toLowerCase();
617
- return this.getAllRecipes().filter((r) => r.name.toLowerCase().includes(lowerQuery) ||
618
- r.description.toLowerCase().includes(lowerQuery) ||
619
- r.tags.some((t) => t.toLowerCase().includes(lowerQuery)));
620
- }
621
- getRecipesByTags(tags) {
622
- return this.getAllRecipes().filter((r) => tags.some((t) => r.tags.includes(t)));
623
- }
624
- // ─── Serialization ─────────────────────────────────────
625
- exportRecipes() {
626
- const data = {
627
- recipes: Array.from(this.recipes.entries()).map(([_id, recipe]) => ({
628
- ...recipe,
629
- discoveredBy: Array.from(recipe.discoveredBy),
630
- })),
631
- stations: Array.from(this.stations.entries()),
632
- chains: Array.from(this.chains.entries()),
633
- salvageRules: Array.from(this.salvageRules.entries()),
634
- };
635
- return JSON.stringify(data, null, 2);
636
- }
637
- importRecipes(json) {
638
- try {
639
- const data = JSON.parse(json);
640
- this.recipes = new Map(data.recipes.map((r) => [
641
- r.id,
642
- { ...r, discoveredBy: new Set(r.discoveredBy) },
643
- ]));
644
- this.stations = new Map(data.stations);
645
- this.chains = new Map(data.chains);
646
- this.salvageRules = new Map(data.salvageRules);
647
- return true;
648
- }
649
- catch {
650
- return false;
651
- }
652
- }
653
- exportProgress() {
654
- const data = {
655
- activeProgress: Array.from(this.activeProgress.entries()),
656
- craftingQueues: Array.from(this.craftingQueues.entries()),
657
- discoveredRecipes: Array.from(this.discoveredRecipes),
658
- };
659
- return JSON.stringify(data);
660
- }
661
- importProgress(json) {
662
- try {
663
- const data = JSON.parse(json);
664
- this.activeProgress = new Map(data.activeProgress);
665
- this.craftingQueues = new Map(data.craftingQueues);
666
- this.discoveredRecipes = new Set(data.discoveredRecipes);
667
- return true;
668
- }
669
- catch {
670
- return false;
671
- }
672
- }
673
- // ─── Graph Visualization ───────────────────────────────
674
- getRecipeGraph(recipeId) {
675
- const recipe = this.recipes.get(recipeId);
676
- if (!recipe) {
677
- return null;
678
- }
679
- const nodes = [];
680
- const edges = [];
681
- // Recipe node
682
- nodes.push({
683
- id: recipe.id,
684
- type: 'recipe',
685
- name: recipe.name,
686
- x: 300,
687
- y: 150,
688
- });
689
- // Ingredient nodes
690
- let y = 50;
290
+ if (available >= required) {
291
+ this.playerInventory.set(itemId, available - required);
292
+ break;
293
+ }
294
+ }
295
+ }
296
+ const now = Date.now();
297
+ const craftingTime = recipe.craftingTime * 1e3 * quantity;
298
+ const progress = {
299
+ id: `progress_${Date.now()}`,
300
+ recipeId,
301
+ playerId,
302
+ startedAt: now,
303
+ completesAt: now + craftingTime,
304
+ quantity,
305
+ isPaused: false,
306
+ accumulatedTime: 0,
307
+ cancelled: false
308
+ };
309
+ this.activeProgress.set(progress.id, progress);
310
+ this.onCraftingStarted?.(progress);
311
+ if (recipe.craftingTime === 0) {
312
+ this.completeCrafting(progress.id);
313
+ }
314
+ return progress;
315
+ }
316
+ updateCraftingProgress(_deltaTime) {
317
+ const now = Date.now();
318
+ for (const [progressId, progress] of this.activeProgress) {
319
+ if (progress.isPaused || progress.cancelled) {
320
+ continue;
321
+ }
322
+ const recipe = this.recipes.get(progress.recipeId);
323
+ if (!recipe) {
324
+ continue;
325
+ }
326
+ if (now >= progress.completesAt) {
327
+ this.completeCrafting(progressId);
328
+ } else {
329
+ const totalTime = progress.completesAt - progress.startedAt;
330
+ const elapsed = now - progress.startedAt + progress.accumulatedTime;
331
+ const percent = Math.min(1, elapsed / totalTime);
332
+ this.onCraftingProgress?.(progress, percent);
333
+ }
334
+ }
335
+ }
336
+ completeCrafting(progressId) {
337
+ const progress = this.activeProgress.get(progressId);
338
+ if (!progress) {
339
+ return;
340
+ }
341
+ const recipe = this.recipes.get(progress.recipeId);
342
+ if (!recipe) {
343
+ return;
344
+ }
345
+ const quality = this.determineQuality(recipe, progress.playerId);
346
+ this.onQualityDetermined?.(recipe, quality, []);
347
+ const outputs = [];
348
+ for (const output of recipe.outputs) {
349
+ if (Math.random() <= output.chance) {
350
+ const baseAmount = Math.floor(Math.random() * (output.maxAmount - output.minAmount + 1) + output.minAmount) * progress.quantity;
351
+ let finalAmount = baseAmount;
352
+ if (output.bonusFromSkill && recipe.skillId) {
353
+ const skill = this.playerSkills.get(recipe.skillId) ?? 0;
354
+ finalAmount += Math.floor(skill * output.bonusFromSkill);
355
+ }
356
+ const current = this.playerInventory.get(output.itemId) ?? 0;
357
+ this.playerInventory.set(output.itemId, current + finalAmount);
358
+ outputs.push({ ...output, minAmount: finalAmount, maxAmount: finalAmount });
359
+ }
360
+ }
361
+ if (recipe.byproducts) {
362
+ for (const byproduct of recipe.byproducts) {
363
+ if (Math.random() <= byproduct.chance) {
364
+ const amount = Math.floor(
365
+ Math.random() * (byproduct.maxAmount - byproduct.minAmount + 1) + byproduct.minAmount
366
+ ) * progress.quantity;
367
+ const current = this.playerInventory.get(byproduct.itemId) ?? 0;
368
+ this.playerInventory.set(byproduct.itemId, current + amount);
369
+ }
370
+ }
371
+ }
372
+ if (recipe.skillId && recipe.experienceGained > 0) {
373
+ const totalXp = recipe.experienceGained * progress.quantity;
374
+ this.onExperienceGained?.(recipe.skillId, totalXp);
375
+ }
376
+ this.activeProgress.delete(progressId);
377
+ this.onCraftingCompleted?.(recipe, outputs, quality);
378
+ }
379
+ determineQuality(recipe, _playerId) {
380
+ const qualities = [
381
+ "poor",
382
+ "normal",
383
+ "fine",
384
+ "superior",
385
+ "masterwork",
386
+ "legendary"
387
+ ];
388
+ const baseIndex = qualities.indexOf(recipe.baseQuality);
389
+ let qualityScore = baseIndex;
390
+ for (const factor of recipe.qualityFactors) {
391
+ switch (factor.type) {
392
+ case "skill":
393
+ if (recipe.skillId) {
394
+ const skill = this.playerSkills.get(recipe.skillId) ?? 0;
395
+ qualityScore += skill / 100 * factor.weight;
396
+ }
397
+ break;
398
+ case "random":
399
+ qualityScore += (Math.random() - 0.5) * factor.weight;
400
+ break;
401
+ }
402
+ }
403
+ const finalIndex = Math.max(0, Math.min(qualities.length - 1, Math.round(qualityScore)));
404
+ return qualities[finalIndex];
405
+ }
406
+ pauseCrafting(progressId) {
407
+ const progress = this.activeProgress.get(progressId);
408
+ if (!progress || progress.isPaused) {
409
+ return false;
410
+ }
411
+ progress.isPaused = true;
412
+ progress.pausedAt = Date.now();
413
+ progress.accumulatedTime += progress.pausedAt - progress.startedAt;
414
+ return true;
415
+ }
416
+ resumeCrafting(progressId) {
417
+ const progress = this.activeProgress.get(progressId);
418
+ if (!progress || !progress.isPaused) {
419
+ return false;
420
+ }
421
+ const now = Date.now();
422
+ const remainingTime = progress.completesAt - progress.startedAt - progress.accumulatedTime;
423
+ progress.isPaused = false;
424
+ progress.startedAt = now;
425
+ progress.completesAt = now + remainingTime;
426
+ progress.pausedAt = void 0;
427
+ return true;
428
+ }
429
+ cancelCrafting(progressId, refundIngredients = false) {
430
+ const progress = this.activeProgress.get(progressId);
431
+ if (!progress) {
432
+ return false;
433
+ }
434
+ progress.cancelled = true;
435
+ if (refundIngredients) {
436
+ const recipe = this.recipes.get(progress.recipeId);
437
+ if (recipe) {
691
438
  for (const ingredient of recipe.ingredients) {
692
- nodes.push({
693
- id: `ing_${ingredient.itemId}`,
694
- type: 'ingredient',
695
- name: ingredient.itemId,
696
- amount: ingredient.amount,
697
- x: 100,
698
- y,
699
- });
700
- edges.push({
701
- id: `edge_${ingredient.itemId}_${recipe.id}`,
702
- from: `ing_${ingredient.itemId}`,
703
- to: recipe.id,
704
- type: ingredient.isConsumed ? 'consumed' : 'catalyst',
705
- });
706
- y += 60;
707
- }
708
- // Output nodes
709
- y = 50;
710
- for (const output of recipe.outputs) {
711
- nodes.push({
712
- id: `out_${output.itemId}`,
713
- type: 'output',
714
- name: output.itemId,
715
- amount: output.minAmount === output.maxAmount
716
- ? output.minAmount
717
- : `${output.minAmount}-${output.maxAmount}`,
718
- x: 500,
719
- y,
720
- });
721
- edges.push({
722
- id: `edge_${recipe.id}_${output.itemId}`,
723
- from: recipe.id,
724
- to: `out_${output.itemId}`,
725
- type: 'produces',
726
- chance: output.chance,
727
- });
728
- y += 60;
729
- }
730
- return { nodes, edges };
731
- }
439
+ if (!ingredient.isConsumed) {
440
+ continue;
441
+ }
442
+ const amount = ingredient.amount * progress.quantity;
443
+ const current = this.playerInventory.get(ingredient.itemId) ?? 0;
444
+ this.playerInventory.set(ingredient.itemId, current + amount);
445
+ }
446
+ }
447
+ }
448
+ this.activeProgress.delete(progressId);
449
+ return true;
450
+ }
451
+ // ─── Crafting Queue ────────────────────────────────────
452
+ addToQueue(playerId, recipeId, quantity, priority = 0) {
453
+ if (!this.craftingQueues.has(playerId)) {
454
+ this.craftingQueues.set(playerId, []);
455
+ }
456
+ const queue = this.craftingQueues.get(playerId);
457
+ queue.push({ recipeId, quantity, priority });
458
+ queue.sort((a, b) => b.priority - a.priority);
459
+ return true;
460
+ }
461
+ getQueue(playerId) {
462
+ return this.craftingQueues.get(playerId) ?? [];
463
+ }
464
+ processQueueItem(playerId) {
465
+ const queue = this.craftingQueues.get(playerId);
466
+ if (!queue || queue.length === 0) {
467
+ return null;
468
+ }
469
+ const item = queue.shift();
470
+ return this.startCrafting(item.recipeId, playerId, item.quantity);
471
+ }
472
+ // ─── Discovery ─────────────────────────────────────────
473
+ discoverRecipe(recipeId, playerId) {
474
+ const recipe = this.recipes.get(recipeId);
475
+ if (!recipe) {
476
+ return false;
477
+ }
478
+ if (this.discoveredRecipes.has(recipeId)) {
479
+ return false;
480
+ }
481
+ this.discoveredRecipes.add(recipeId);
482
+ recipe.discoveredBy.add(playerId);
483
+ this.onRecipeDiscovered?.(recipe, playerId);
484
+ return true;
485
+ }
486
+ isRecipeDiscovered(recipeId) {
487
+ const recipe = this.recipes.get(recipeId);
488
+ if (!recipe) {
489
+ return false;
490
+ }
491
+ if (recipe.discoveryMethod === "known") {
492
+ return true;
493
+ }
494
+ return this.discoveredRecipes.has(recipeId);
495
+ }
496
+ // ─── Salvage ───────────────────────────────────────────
497
+ canSalvage(itemId, _playerId) {
498
+ const rule = this.salvageRules.get(itemId);
499
+ if (!rule) {
500
+ return false;
501
+ }
502
+ if (rule.skillRequired) {
503
+ const skill = this.playerSkills.get("salvaging") ?? 0;
504
+ if (skill < rule.skillRequired) {
505
+ return false;
506
+ }
507
+ }
508
+ return true;
509
+ }
510
+ salvageItem(itemId, _playerId, quantity = 1) {
511
+ const rule = this.salvageRules.get(itemId);
512
+ if (!rule) {
513
+ return null;
514
+ }
515
+ const available = this.playerInventory.get(itemId) ?? 0;
516
+ if (available < quantity) {
517
+ return null;
518
+ }
519
+ this.playerInventory.set(itemId, available - quantity);
520
+ const outputs = [];
521
+ for (const output of rule.outputs) {
522
+ for (let i = 0; i < quantity; i++) {
523
+ if (Math.random() <= output.chance) {
524
+ const amount = Math.floor(
525
+ Math.random() * (output.maxAmount - output.minAmount + 1) + output.minAmount
526
+ );
527
+ const current = this.playerInventory.get(output.itemId) ?? 0;
528
+ this.playerInventory.set(output.itemId, current + amount);
529
+ outputs.push({ ...output, minAmount: amount, maxAmount: amount });
530
+ }
531
+ }
532
+ }
533
+ return outputs;
534
+ }
535
+ // ─── Player State ──────────────────────────────────────
536
+ setPlayerSkill(skillId, level) {
537
+ this.playerSkills.set(skillId, level);
538
+ }
539
+ setPlayerItem(itemId, count) {
540
+ this.playerInventory.set(itemId, count);
541
+ }
542
+ getPlayerInventory() {
543
+ return new Map(this.playerInventory);
544
+ }
545
+ // ─── Callbacks ─────────────────────────────────────────
546
+ setOnRecipeDiscovered(callback) {
547
+ this.onRecipeDiscovered = callback;
548
+ }
549
+ setOnCraftingStarted(callback) {
550
+ this.onCraftingStarted = callback;
551
+ }
552
+ setOnCraftingProgress(callback) {
553
+ this.onCraftingProgress = callback;
554
+ }
555
+ setOnCraftingCompleted(callback) {
556
+ this.onCraftingCompleted = callback;
557
+ }
558
+ setOnCraftingFailed(callback) {
559
+ this.onCraftingFailed = callback;
560
+ }
561
+ setOnQualityDetermined(callback) {
562
+ this.onQualityDetermined = callback;
563
+ }
564
+ setOnExperienceGained(callback) {
565
+ this.onExperienceGained = callback;
566
+ }
567
+ // ─── Queries ───────────────────────────────────────────
568
+ getActiveProgress() {
569
+ return Array.from(this.activeProgress.values());
570
+ }
571
+ getProgressForPlayer(playerId) {
572
+ return this.getActiveProgress().filter((p) => p.playerId === playerId);
573
+ }
574
+ searchRecipes(query) {
575
+ const lowerQuery = query.toLowerCase();
576
+ return this.getAllRecipes().filter(
577
+ (r) => r.name.toLowerCase().includes(lowerQuery) || r.description.toLowerCase().includes(lowerQuery) || r.tags.some((t) => t.toLowerCase().includes(lowerQuery))
578
+ );
579
+ }
580
+ getRecipesByTags(tags) {
581
+ return this.getAllRecipes().filter((r) => tags.some((t) => r.tags.includes(t)));
582
+ }
583
+ // ─── Serialization ─────────────────────────────────────
584
+ exportRecipes() {
585
+ const data = {
586
+ recipes: Array.from(this.recipes.entries()).map(([_id, recipe]) => ({
587
+ ...recipe,
588
+ discoveredBy: Array.from(recipe.discoveredBy)
589
+ })),
590
+ stations: Array.from(this.stations.entries()),
591
+ chains: Array.from(this.chains.entries()),
592
+ salvageRules: Array.from(this.salvageRules.entries())
593
+ };
594
+ return JSON.stringify(data, null, 2);
595
+ }
596
+ importRecipes(json) {
597
+ try {
598
+ const data = JSON.parse(json);
599
+ this.recipes = new Map(
600
+ data.recipes.map((r) => [
601
+ r.id,
602
+ { ...r, discoveredBy: new Set(r.discoveredBy) }
603
+ ])
604
+ );
605
+ this.stations = new Map(data.stations);
606
+ this.chains = new Map(data.chains);
607
+ this.salvageRules = new Map(data.salvageRules);
608
+ return true;
609
+ } catch {
610
+ return false;
611
+ }
612
+ }
613
+ exportProgress() {
614
+ const data = {
615
+ activeProgress: Array.from(this.activeProgress.entries()),
616
+ craftingQueues: Array.from(this.craftingQueues.entries()),
617
+ discoveredRecipes: Array.from(this.discoveredRecipes)
618
+ };
619
+ return JSON.stringify(data);
620
+ }
621
+ importProgress(json) {
622
+ try {
623
+ const data = JSON.parse(json);
624
+ this.activeProgress = new Map(data.activeProgress);
625
+ this.craftingQueues = new Map(data.craftingQueues);
626
+ this.discoveredRecipes = new Set(data.discoveredRecipes);
627
+ return true;
628
+ } catch {
629
+ return false;
630
+ }
631
+ }
632
+ // ─── Graph Visualization ───────────────────────────────
633
+ getRecipeGraph(recipeId) {
634
+ const recipe = this.recipes.get(recipeId);
635
+ if (!recipe) {
636
+ return null;
637
+ }
638
+ const nodes = [];
639
+ const edges = [];
640
+ nodes.push({
641
+ id: recipe.id,
642
+ type: "recipe",
643
+ name: recipe.name,
644
+ x: 300,
645
+ y: 150
646
+ });
647
+ let y = 50;
648
+ for (const ingredient of recipe.ingredients) {
649
+ nodes.push({
650
+ id: `ing_${ingredient.itemId}`,
651
+ type: "ingredient",
652
+ name: ingredient.itemId,
653
+ amount: ingredient.amount,
654
+ x: 100,
655
+ y
656
+ });
657
+ edges.push({
658
+ id: `edge_${ingredient.itemId}_${recipe.id}`,
659
+ from: `ing_${ingredient.itemId}`,
660
+ to: recipe.id,
661
+ type: ingredient.isConsumed ? "consumed" : "catalyst"
662
+ });
663
+ y += 60;
664
+ }
665
+ y = 50;
666
+ for (const output of recipe.outputs) {
667
+ nodes.push({
668
+ id: `out_${output.itemId}`,
669
+ type: "output",
670
+ name: output.itemId,
671
+ amount: output.minAmount === output.maxAmount ? output.minAmount : `${output.minAmount}-${output.maxAmount}`,
672
+ x: 500,
673
+ y
674
+ });
675
+ edges.push({
676
+ id: `edge_${recipe.id}_${output.itemId}`,
677
+ from: recipe.id,
678
+ to: `out_${output.itemId}`,
679
+ type: "produces",
680
+ chance: output.chance
681
+ });
682
+ y += 60;
683
+ }
684
+ return { nodes, edges };
685
+ }
732
686
  }
733
- // ============================================================
734
- // Factory Functions
735
- // ============================================================
736
687
  function createCraftingEditor() {
737
- return new CraftingEditor();
688
+ return new CraftingEditor();
738
689
  }
739
690
  function createIngredient(itemId, amount, isConsumed = true) {
740
- return { itemId, amount, isConsumed };
691
+ return { itemId, amount, isConsumed };
741
692
  }
742
693
  function createOutput(itemId, amount, chance = 1) {
743
- return { itemId, minAmount: amount, maxAmount: amount, chance };
694
+ return { itemId, minAmount: amount, maxAmount: amount, chance };
744
695
  }
745
-
746
696
  exports.CraftingEditor = CraftingEditor;
747
697
  exports.createCraftingEditor = createCraftingEditor;
748
698
  exports.createIngredient = createIngredient;