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