@nice2dev/game-engine 1.3.15 → 1.3.17

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,861 +1,795 @@
1
- 'use strict';
2
-
3
- /**
4
- * @file PrefabSystem.ts
5
- * @description Advanced Prefab System with nested prefabs, variants, override tracking
6
- * PRO-1.4: Professional Editor Features
7
- *
8
- * Features:
9
- * - Prefab definition and instantiation
10
- * - Nested prefabs (prefabs containing other prefabs)
11
- * - Prefab variants (inherited modifications)
12
- * - Override tracking (property-level changes)
13
- * - Apply/revert overrides
14
- * - Prefab linking (maintain connection to source)
15
- * - Unpack prefab (break connection)
16
- * - Auto-update instances when prefab changes
17
- * - Serialization/deserialization
18
- * - Prefab comparison (diff)
19
- */
20
- // ============================================================
21
- // Default Transform
22
- // ============================================================
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
23
3
  const DEFAULT_TRANSFORM = {
24
- position: { x: 0, y: 0, z: 0 },
25
- rotation: { x: 0, y: 0, z: 0, w: 1 },
26
- scale: { x: 1, y: 1, z: 1 },
4
+ position: { x: 0, y: 0, z: 0 },
5
+ rotation: { x: 0, y: 0, z: 0, w: 1 },
6
+ scale: { x: 1, y: 1, z: 1 }
27
7
  };
28
- // ============================================================
29
- // Utility Functions
30
- // ============================================================
31
8
  function generateId() {
32
- return `${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
9
+ return `${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
33
10
  }
34
11
  function deepClone(obj) {
35
- return JSON.parse(JSON.stringify(obj));
12
+ return JSON.parse(JSON.stringify(obj));
36
13
  }
37
14
  function getValueAtPath(obj, path) {
38
- const parts = path.split('.');
39
- let current = obj;
40
- for (const part of parts) {
41
- if (current === null || current === undefined) {
42
- return undefined;
43
- }
44
- if (typeof current !== 'object') {
45
- return undefined;
46
- }
47
- const index = parseInt(part, 10);
48
- if (!isNaN(index) && Array.isArray(current)) {
49
- current = current[index];
50
- }
51
- else {
52
- current = current[part];
53
- }
54
- }
55
- return current;
15
+ const parts = path.split(".");
16
+ let current = obj;
17
+ for (const part of parts) {
18
+ if (current === null || current === void 0) {
19
+ return void 0;
20
+ }
21
+ if (typeof current !== "object") {
22
+ return void 0;
23
+ }
24
+ const index = parseInt(part, 10);
25
+ if (!isNaN(index) && Array.isArray(current)) {
26
+ current = current[index];
27
+ } else {
28
+ current = current[part];
29
+ }
30
+ }
31
+ return current;
56
32
  }
57
33
  function setValueAtPath(obj, path, value) {
58
- const parts = path.split('.');
59
- let current = obj;
60
- for (let i = 0; i < parts.length - 1; i++) {
61
- const part = parts[i];
62
- if (current === null || current === undefined) {
63
- return;
64
- }
65
- if (typeof current !== 'object') {
66
- return;
67
- }
68
- const index = parseInt(part, 10);
69
- if (!isNaN(index) && Array.isArray(current)) {
70
- current = current[index];
71
- }
72
- else {
73
- current = current[part];
74
- }
75
- }
76
- if (current && typeof current === 'object') {
77
- const lastPart = parts[parts.length - 1];
78
- const index = parseInt(lastPart, 10);
79
- if (!isNaN(index) && Array.isArray(current)) {
80
- current[index] = value;
81
- }
82
- else {
83
- current[lastPart] = value;
84
- }
85
- }
34
+ const parts = path.split(".");
35
+ let current = obj;
36
+ for (let i = 0; i < parts.length - 1; i++) {
37
+ const part = parts[i];
38
+ if (current === null || current === void 0) {
39
+ return;
40
+ }
41
+ if (typeof current !== "object") {
42
+ return;
43
+ }
44
+ const index = parseInt(part, 10);
45
+ if (!isNaN(index) && Array.isArray(current)) {
46
+ current = current[index];
47
+ } else {
48
+ current = current[part];
49
+ }
50
+ }
51
+ if (current && typeof current === "object") {
52
+ const lastPart = parts[parts.length - 1];
53
+ const index = parseInt(lastPart, 10);
54
+ if (!isNaN(index) && Array.isArray(current)) {
55
+ current[index] = value;
56
+ } else {
57
+ current[lastPart] = value;
58
+ }
59
+ }
86
60
  }
87
61
  function compareValues(a, b) {
88
- return JSON.stringify(a) === JSON.stringify(b);
62
+ return JSON.stringify(a) === JSON.stringify(b);
89
63
  }
90
- // ============================================================
91
- // Prefab Manager
92
- // ============================================================
93
64
  class PrefabManager {
94
- constructor() {
95
- this.prefabs = new Map();
96
- this.instances = new Map();
97
- this.prefabVersions = new Map();
98
- }
99
- // ─── Prefab Creation ───────────────────────────────────
100
- createPrefab(name, rootEntity) {
101
- const id = `prefab_${generateId()}`;
102
- const now = Date.now();
103
- const root = {
104
- id: `entity_${generateId()}`,
105
- name: rootEntity?.name ?? name,
106
- parentId: null,
107
- transform: rootEntity?.transform ?? deepClone(DEFAULT_TRANSFORM),
108
- components: rootEntity?.components ?? [],
109
- children: rootEntity?.children ?? [],
110
- tags: rootEntity?.tags ?? [],
111
- layer: rootEntity?.layer ?? 'default',
112
- active: rootEntity?.active ?? true,
113
- };
114
- const prefab = {
115
- id,
116
- name,
117
- description: '',
118
- version: 1,
119
- createdAt: now,
120
- modifiedAt: now,
121
- author: '',
122
- rootEntity: root,
123
- entities: new Map([[root.id, root]]),
124
- nestedPrefabs: [],
125
- tags: [],
126
- category: 'General',
127
- };
128
- this.prefabs.set(id, prefab);
129
- this.prefabVersions.set(id, 1);
130
- return prefab;
131
- }
132
- createPrefabFromEntities(name, entities) {
133
- const prefab = this.createPrefab(name);
134
- // Find root (entity with no parent or parent not in list)
135
- const entityIds = new Set(entities.map((e) => e.id));
136
- const root = entities.find((e) => !e.parentId || !entityIds.has(e.parentId));
137
- if (root) {
138
- prefab.rootEntity = deepClone(root);
139
- prefab.entities.set(root.id, prefab.rootEntity);
140
- }
141
- // Add all entities
142
- for (const entity of entities) {
143
- if (entity.id !== prefab.rootEntity.id) {
144
- const clone = deepClone(entity);
145
- prefab.entities.set(clone.id, clone);
146
- }
147
- }
148
- this.updatePrefabVersion(prefab.id);
149
- return prefab;
150
- }
151
- // ─── Prefab Variants ───────────────────────────────────
152
- createVariant(basePrefabId, name) {
153
- const basePrefab = this.prefabs.get(basePrefabId);
154
- if (!basePrefab) {
155
- return null;
156
- }
157
- const variant = this.createPrefab(name);
158
- variant.variantOf = basePrefabId;
159
- variant.inheritedOverrides = [];
160
- // Copy base structure
161
- variant.rootEntity = deepClone(basePrefab.rootEntity);
162
- variant.rootEntity.id = `entity_${generateId()}`;
163
- variant.entities.clear();
164
- variant.entities.set(variant.rootEntity.id, variant.rootEntity);
165
- for (const [, entity] of basePrefab.entities) {
166
- if (entity.id !== basePrefab.rootEntity.id) {
167
- const clone = deepClone(entity);
168
- clone.id = `entity_${generateId()}`;
169
- variant.entities.set(clone.id, clone);
170
- }
171
- }
172
- variant.nestedPrefabs = deepClone(basePrefab.nestedPrefabs);
173
- return variant;
174
- }
175
- getBasePrefab(variantId) {
176
- const variant = this.prefabs.get(variantId);
177
- if (!variant?.variantOf) {
178
- return null;
179
- }
180
- return this.prefabs.get(variant.variantOf) ?? null;
181
- }
182
- applyVariantOverrides(variantId) {
183
- const variant = this.prefabs.get(variantId);
184
- if (!variant || !variant.variantOf) {
185
- return;
186
- }
187
- const base = this.prefabs.get(variant.variantOf);
188
- if (!base) {
189
- return;
190
- }
191
- // Apply inherited overrides from base to variant
192
- if (variant.inheritedOverrides) {
193
- for (const override of variant.inheritedOverrides) {
194
- const targetEntity = this.findEntityByPathRoot(variant, override.path);
195
- if (targetEntity) {
196
- setValueAtPath(targetEntity, override.path, override.overridenValue);
197
- }
198
- }
199
- }
200
- this.updatePrefabVersion(variantId);
201
- }
202
- // ─── Nested Prefabs ────────────────────────────────────
203
- addNestedPrefab(parentPrefabId, nestedPrefabId, parentEntityId, transform) {
204
- const parentPrefab = this.prefabs.get(parentPrefabId);
205
- const nestedPrefab = this.prefabs.get(nestedPrefabId);
206
- if (!parentPrefab || !nestedPrefab) {
207
- return null;
208
- }
209
- if (!parentPrefab.entities.has(parentEntityId)) {
210
- return null;
211
- }
212
- // Check for circular reference
213
- if (this.hasCircularReference(parentPrefabId, nestedPrefabId)) {
214
- console.error('Circular prefab reference detected');
215
- return null;
216
- }
217
- const reference = {
218
- instanceId: `nested_${generateId()}`,
219
- prefabId: nestedPrefabId,
220
- parentEntityId,
221
- overrides: [],
222
- transform: {
223
- ...deepClone(DEFAULT_TRANSFORM),
224
- ...transform,
225
- },
226
- };
227
- parentPrefab.nestedPrefabs.push(reference);
228
- this.updatePrefabVersion(parentPrefabId);
229
- return reference;
230
- }
231
- removeNestedPrefab(parentPrefabId, instanceId) {
232
- const parentPrefab = this.prefabs.get(parentPrefabId);
233
- if (!parentPrefab) {
234
- return false;
235
- }
236
- const index = parentPrefab.nestedPrefabs.findIndex((n) => n.instanceId === instanceId);
237
- if (index === -1) {
238
- return false;
239
- }
240
- parentPrefab.nestedPrefabs.splice(index, 1);
241
- this.updatePrefabVersion(parentPrefabId);
242
- return true;
243
- }
244
- hasCircularReference(parentId, childId, visited = new Set()) {
245
- if (parentId === childId) {
246
- return true;
247
- }
248
- if (visited.has(childId)) {
249
- return true;
250
- }
251
- visited.add(childId);
252
- const childPrefab = this.prefabs.get(childId);
253
- if (!childPrefab) {
254
- return false;
255
- }
256
- for (const nested of childPrefab.nestedPrefabs) {
257
- if (this.hasCircularReference(parentId, nested.prefabId, visited)) {
258
- return true;
259
- }
260
- }
261
- return false;
262
- }
263
- // ─── Instantiation ─────────────────────────────────────
264
- instantiate(prefabId, worldTransform) {
265
- const prefab = this.prefabs.get(prefabId);
266
- if (!prefab) {
267
- return null;
268
- }
269
- const instance = {
270
- id: `instance_${generateId()}`,
271
- prefabId,
272
- name: prefab.name,
273
- overrides: [],
274
- worldTransform: {
275
- ...deepClone(DEFAULT_TRANSFORM),
276
- ...worldTransform,
277
- },
278
- nestedInstances: new Map(),
279
- isLinked: true,
280
- createdAt: Date.now(),
281
- lastSyncedAt: Date.now(),
282
- };
283
- // Instantiate nested prefabs recursively
284
- for (const nestedRef of prefab.nestedPrefabs) {
285
- const nestedInstance = this.instantiate(nestedRef.prefabId, nestedRef.transform);
286
- if (nestedInstance) {
287
- // Apply nested prefab overrides
288
- nestedInstance.overrides = deepClone(nestedRef.overrides);
289
- instance.nestedInstances.set(nestedRef.instanceId, nestedInstance);
290
- }
291
- }
292
- this.instances.set(instance.id, instance);
293
- return instance;
294
- }
295
- destroyInstance(instanceId) {
296
- const instance = this.instances.get(instanceId);
297
- if (!instance) {
298
- return false;
299
- }
300
- // Destroy nested instances
301
- for (const [, nested] of instance.nestedInstances) {
302
- this.destroyInstance(nested.id);
303
- }
304
- this.instances.delete(instanceId);
305
- return true;
306
- }
307
- // ─── Override Management ───────────────────────────────
308
- setOverride(instanceId, path, value) {
309
- const instance = this.instances.get(instanceId);
310
- if (!instance) {
311
- return;
312
- }
313
- const prefab = this.prefabs.get(instance.prefabId);
314
- if (!prefab) {
315
- return;
316
- }
317
- const originalValue = this.getOriginalValue(prefab, path);
318
- // Check if value is same as original
319
- if (compareValues(originalValue, value)) {
320
- this.removeOverride(instanceId, path);
321
- return;
322
- }
323
- // Check if override already exists
324
- const existingIndex = instance.overrides.findIndex((o) => o.path === path);
325
- const override = {
326
- path,
327
- originalValue,
328
- overridenValue: value,
329
- overrideType: 'modify',
330
- timestamp: Date.now(),
331
- };
332
- if (existingIndex !== -1) {
333
- instance.overrides[existingIndex] = override;
334
- }
335
- else {
336
- instance.overrides.push(override);
337
- }
338
- this.onInstanceChanged?.(instanceId);
339
- }
340
- removeOverride(instanceId, path) {
341
- const instance = this.instances.get(instanceId);
342
- if (!instance) {
343
- return;
344
- }
345
- instance.overrides = instance.overrides.filter((o) => o.path !== path);
346
- this.onInstanceChanged?.(instanceId);
347
- }
348
- revertAllOverrides(instanceId) {
349
- const instance = this.instances.get(instanceId);
350
- if (!instance) {
351
- return;
352
- }
353
- instance.overrides = [];
354
- this.onInstanceChanged?.(instanceId);
355
- }
356
- applyOverridesToPrefab(instanceId) {
357
- const instance = this.instances.get(instanceId);
358
- if (!instance) {
359
- return;
360
- }
361
- const prefab = this.prefabs.get(instance.prefabId);
362
- if (!prefab) {
363
- return;
364
- }
365
- // Apply all overrides to the prefab
366
- for (const override of instance.overrides) {
367
- const entity = this.findEntityByPathRoot(prefab, override.path);
368
- if (entity) {
369
- setValueAtPath(entity, override.path, override.overridenValue);
370
- }
371
- }
372
- // Clear instance overrides
373
- instance.overrides = [];
374
- this.updatePrefabVersion(instance.prefabId);
375
- }
376
- hasOverrides(instanceId) {
377
- const instance = this.instances.get(instanceId);
378
- return instance ? instance.overrides.length > 0 : false;
379
- }
380
- getOverrides(instanceId) {
381
- const instance = this.instances.get(instanceId);
382
- return instance ? [...instance.overrides] : [];
383
- }
384
- getOriginalValue(prefab, path) {
385
- // Parse path to find the entity and property
386
- const entity = this.findEntityByPathRoot(prefab, path);
387
- if (!entity) {
388
- return undefined;
389
- }
390
- const relativePath = this.getRelativePropertyPath(path);
391
- return getValueAtPath(entity, relativePath);
392
- }
393
- findEntityByPathRoot(prefab, path) {
394
- const parts = path.split('.');
395
- // Check if path starts with entity reference
396
- if (parts[0].startsWith('entity_')) {
397
- return prefab.entities.get(parts[0]) ?? null;
398
- }
399
- // Default to root entity
400
- return prefab.rootEntity;
401
- }
402
- getRelativePropertyPath(path) {
403
- const parts = path.split('.');
404
- // Skip entity ID if present
405
- if (parts[0].startsWith('entity_')) {
406
- return parts.slice(1).join('.');
407
- }
408
- return path;
409
- }
410
- // ─── Linking ───────────────────────────────────────────
411
- unlinkInstance(instanceId) {
412
- const instance = this.instances.get(instanceId);
413
- if (!instance) {
414
- return;
415
- }
416
- instance.isLinked = false;
417
- instance.unpackedAt = Date.now();
418
- // Unlink nested instances
419
- for (const [, nested] of instance.nestedInstances) {
420
- this.unlinkInstance(nested.id);
421
- }
422
- this.onInstanceChanged?.(instanceId);
423
- }
424
- relinkInstance(instanceId) {
425
- const instance = this.instances.get(instanceId);
426
- if (!instance) {
427
- return false;
428
- }
429
- // Check if prefab still exists
430
- if (!this.prefabs.has(instance.prefabId)) {
431
- return false;
432
- }
433
- instance.isLinked = true;
434
- instance.unpackedAt = undefined;
435
- instance.lastSyncedAt = Date.now();
436
- this.onInstanceChanged?.(instanceId);
437
- return true;
438
- }
439
- // ─── Synchronization ───────────────────────────────────
440
- syncInstance(instanceId) {
441
- const instance = this.instances.get(instanceId);
442
- if (!instance || !instance.isLinked) {
443
- return;
444
- }
445
- const prefab = this.prefabs.get(instance.prefabId);
446
- if (!prefab) {
447
- return;
448
- }
449
- this.prefabVersions.get(instance.prefabId) ?? 0;
450
- // Instance is already synced
451
- if (instance.lastSyncedAt >= prefab.modifiedAt) {
452
- return;
453
- }
454
- // Re-apply overrides after sync
455
- // (In a real implementation, you'd merge changes intelligently)
456
- instance.lastSyncedAt = Date.now();
457
- // Sync nested instances
458
- for (const [, nested] of instance.nestedInstances) {
459
- this.syncInstance(nested.id);
460
- }
461
- this.onInstanceChanged?.(instanceId);
462
- }
463
- syncAllInstances(prefabId) {
464
- for (const [instanceId, instance] of this.instances) {
465
- if (instance.prefabId === prefabId && instance.isLinked) {
466
- this.syncInstance(instanceId);
467
- }
468
- }
469
- }
470
- updatePrefabVersion(prefabId) {
471
- const prefab = this.prefabs.get(prefabId);
472
- if (prefab) {
473
- prefab.version++;
474
- prefab.modifiedAt = Date.now();
475
- this.prefabVersions.set(prefabId, prefab.version);
476
- this.onPrefabChanged?.(prefabId);
477
- }
478
- }
479
- // ─── Entity Management ─────────────────────────────────
480
- addEntity(prefabId, entity, parentId) {
481
- const prefab = this.prefabs.get(prefabId);
482
- if (!prefab) {
483
- return null;
484
- }
485
- const newEntity = {
486
- id: `entity_${generateId()}`,
487
- name: entity.name ?? 'New Entity',
488
- parentId: parentId ?? prefab.rootEntity.id,
489
- transform: entity.transform ?? deepClone(DEFAULT_TRANSFORM),
490
- components: entity.components ?? [],
491
- children: entity.children ?? [],
492
- tags: entity.tags ?? [],
493
- layer: entity.layer ?? 'default',
494
- active: entity.active ?? true,
495
- };
496
- prefab.entities.set(newEntity.id, newEntity);
497
- // Update parent's children list
498
- const parent = prefab.entities.get(newEntity.parentId);
499
- if (parent) {
500
- parent.children.push(newEntity.id);
501
- }
502
- this.updatePrefabVersion(prefabId);
503
- return newEntity;
504
- }
505
- removeEntity(prefabId, entityId) {
506
- const prefab = this.prefabs.get(prefabId);
507
- if (!prefab) {
508
- return false;
509
- }
510
- if (entityId === prefab.rootEntity.id) {
511
- return false;
512
- } // Can't remove root
513
- const entity = prefab.entities.get(entityId);
514
- if (!entity) {
515
- return false;
516
- }
517
- // Remove from parent's children
518
- if (entity.parentId) {
519
- const parent = prefab.entities.get(entity.parentId);
520
- if (parent) {
521
- parent.children = parent.children.filter((id) => id !== entityId);
522
- }
523
- }
524
- // Remove children recursively
525
- for (const childId of entity.children) {
526
- this.removeEntity(prefabId, childId);
527
- }
528
- prefab.entities.delete(entityId);
529
- this.updatePrefabVersion(prefabId);
530
- return true;
531
- }
532
- // ─── Component Management ──────────────────────────────
533
- addComponent(prefabId, entityId, component) {
534
- const prefab = this.prefabs.get(prefabId);
535
- if (!prefab) {
536
- return null;
537
- }
538
- const entity = prefab.entities.get(entityId);
539
- if (!entity) {
540
- return null;
541
- }
542
- const newComponent = {
543
- id: `component_${generateId()}`,
544
- type: component.type ?? 'Unknown',
545
- properties: component.properties ?? {},
546
- enabled: component.enabled ?? true,
547
- };
548
- entity.components.push(newComponent);
549
- this.updatePrefabVersion(prefabId);
550
- return newComponent;
551
- }
552
- removeComponent(prefabId, entityId, componentId) {
553
- const prefab = this.prefabs.get(prefabId);
554
- if (!prefab) {
555
- return false;
556
- }
557
- const entity = prefab.entities.get(entityId);
558
- if (!entity) {
559
- return false;
560
- }
561
- const index = entity.components.findIndex((c) => c.id === componentId);
562
- if (index === -1) {
563
- return false;
564
- }
565
- entity.components.splice(index, 1);
566
- this.updatePrefabVersion(prefabId);
567
- return true;
568
- }
569
- // ─── Comparison ────────────────────────────────────────
570
- comparePrefabs(prefabIdA, prefabIdB) {
571
- const prefabA = this.prefabs.get(prefabIdA);
572
- const prefabB = this.prefabs.get(prefabIdB);
573
- if (!prefabA || !prefabB) {
574
- return null;
575
- }
576
- const diff = {
577
- added: [],
578
- removed: [],
579
- modified: [],
580
- componentAdded: [],
581
- componentRemoved: [],
582
- entityAdded: [],
583
- entityRemoved: [],
584
- };
585
- // Compare entities
586
- const entityIdsA = new Set(prefabA.entities.keys());
587
- const entityIdsB = new Set(prefabB.entities.keys());
588
- for (const id of entityIdsB) {
589
- if (!entityIdsA.has(id)) {
590
- diff.entityAdded.push(id);
591
- }
592
- }
593
- for (const id of entityIdsA) {
594
- if (!entityIdsB.has(id)) {
595
- diff.entityRemoved.push(id);
596
- }
597
- }
598
- // Compare matching entities
599
- for (const [id, entityA] of prefabA.entities) {
600
- const entityB = prefabB.entities.get(id);
601
- if (!entityB) {
602
- continue;
603
- }
604
- this.compareEntities(entityA, entityB, id, diff);
605
- }
606
- return diff;
607
- }
608
- compareInstanceToPrefab(instanceId) {
609
- const instance = this.instances.get(instanceId);
610
- if (!instance) {
611
- return null;
612
- }
613
- const prefab = this.prefabs.get(instance.prefabId);
614
- if (!prefab) {
615
- return null;
616
- }
617
- const diff = {
618
- added: [],
619
- removed: [],
620
- modified: [],
621
- componentAdded: [],
622
- componentRemoved: [],
623
- entityAdded: [],
624
- entityRemoved: [],
625
- };
626
- // List all overrides as modifications
627
- for (const override of instance.overrides) {
628
- diff.modified.push({
629
- path: override.path,
630
- oldValue: override.originalValue,
631
- newValue: override.overridenValue,
632
- });
633
- }
634
- return diff;
635
- }
636
- compareEntities(entityA, entityB, prefix, diff) {
637
- // Compare transform
638
- this.compareProperty(entityA.transform, entityB.transform, `${prefix}.transform`, diff);
639
- // Compare components
640
- const compIdsA = new Set(entityA.components.map((c) => c.id));
641
- const compIdsB = new Set(entityB.components.map((c) => c.id));
642
- for (const comp of entityB.components) {
643
- if (!compIdsA.has(comp.id)) {
644
- diff.componentAdded.push(`${prefix}.${comp.id}`);
645
- }
646
- }
647
- for (const comp of entityA.components) {
648
- if (!compIdsB.has(comp.id)) {
649
- diff.componentRemoved.push(`${prefix}.${comp.id}`);
650
- }
651
- }
652
- // Compare matching components
653
- for (const compA of entityA.components) {
654
- const compB = entityB.components.find((c) => c.id === compA.id);
655
- if (!compB) {
656
- continue;
657
- }
658
- this.compareProperty(compA.properties, compB.properties, `${prefix}.${compA.id}.properties`, diff);
659
- }
660
- }
661
- compareProperty(valueA, valueB, path, diff) {
662
- if (typeof valueA !== typeof valueB) {
663
- diff.modified.push({ path, oldValue: valueA, newValue: valueB });
664
- return;
665
- }
666
- if (valueA === null || valueB === null) {
667
- if (valueA !== valueB) {
668
- diff.modified.push({ path, oldValue: valueA, newValue: valueB });
669
- }
670
- return;
671
- }
672
- if (typeof valueA !== 'object') {
673
- if (valueA !== valueB) {
674
- diff.modified.push({ path, oldValue: valueA, newValue: valueB });
675
- }
676
- return;
677
- }
678
- if (Array.isArray(valueA) && Array.isArray(valueB)) {
679
- if (valueA.length !== valueB.length) {
680
- diff.modified.push({ path, oldValue: valueA, newValue: valueB });
681
- return;
682
- }
683
- for (let i = 0; i < valueA.length; i++) {
684
- this.compareProperty(valueA[i], valueB[i], `${path}.${i}`, diff);
685
- }
686
- return;
687
- }
688
- const objA = valueA;
689
- const objB = valueB;
690
- const keysA = new Set(Object.keys(objA));
691
- const keysB = new Set(Object.keys(objB));
692
- for (const key of keysB) {
693
- if (!keysA.has(key)) {
694
- diff.added.push(`${path}.${key}`);
695
- }
696
- }
697
- for (const key of keysA) {
698
- if (!keysB.has(key)) {
699
- diff.removed.push(`${path}.${key}`);
700
- }
701
- else {
702
- this.compareProperty(objA[key], objB[key], `${path}.${key}`, diff);
703
- }
704
- }
705
- }
706
- // ─── Serialization ─────────────────────────────────────
707
- serializePrefab(prefabId) {
708
- const prefab = this.prefabs.get(prefabId);
709
- if (!prefab) {
710
- return null;
711
- }
712
- const serialized = {
713
- ...prefab,
714
- entities: Object.fromEntries(prefab.entities),
715
- };
716
- return JSON.stringify(serialized, null, 2);
717
- }
718
- deserializePrefab(json) {
719
- try {
720
- const data = JSON.parse(json);
721
- const prefab = {
722
- ...data,
723
- entities: new Map(Object.entries(data.entities)),
724
- createdAt: data.createdAt ?? Date.now(),
725
- modifiedAt: data.modifiedAt ?? Date.now(),
726
- };
727
- this.prefabs.set(prefab.id, prefab);
728
- this.prefabVersions.set(prefab.id, prefab.version);
729
- return prefab;
730
- }
731
- catch (error) {
732
- console.error('Failed to deserialize prefab:', error);
733
- return null;
734
- }
735
- }
736
- serializeInstance(instanceId) {
737
- const instance = this.instances.get(instanceId);
738
- if (!instance) {
739
- return null;
740
- }
741
- const serialized = {
742
- ...instance,
743
- nestedInstances: Object.fromEntries(instance.nestedInstances),
744
- };
745
- return JSON.stringify(serialized, null, 2);
746
- }
747
- deserializeInstance(json) {
748
- try {
749
- const data = JSON.parse(json);
750
- const instance = {
751
- ...data,
752
- nestedInstances: new Map(Object.entries(data.nestedInstances)),
753
- };
754
- this.instances.set(instance.id, instance);
755
- return instance;
756
- }
757
- catch (error) {
758
- console.error('Failed to deserialize instance:', error);
759
- return null;
760
- }
761
- }
762
- // ─── Queries ───────────────────────────────────────────
763
- getPrefab(prefabId) {
764
- return this.prefabs.get(prefabId);
765
- }
766
- getInstance(instanceId) {
767
- return this.instances.get(instanceId);
768
- }
769
- getAllPrefabs() {
770
- return Array.from(this.prefabs.values());
771
- }
772
- getAllInstances() {
773
- return Array.from(this.instances.values());
774
- }
775
- getInstancesOfPrefab(prefabId) {
776
- return this.getAllInstances().filter((i) => i.prefabId === prefabId);
777
- }
778
- searchPrefabs(query) {
779
- const lowerQuery = query.toLowerCase();
780
- return this.getAllPrefabs().filter((p) => p.name.toLowerCase().includes(lowerQuery) ||
781
- p.description.toLowerCase().includes(lowerQuery) ||
782
- p.tags.some((t) => t.toLowerCase().includes(lowerQuery)));
783
- }
784
- getPrefabsByCategory(category) {
785
- return this.getAllPrefabs().filter((p) => p.category === category);
786
- }
787
- getCategories() {
788
- const categories = new Set();
789
- for (const prefab of this.prefabs.values()) {
790
- categories.add(prefab.category);
791
- }
792
- return Array.from(categories).sort();
793
- }
794
- // ─── Callbacks ─────────────────────────────────────────
795
- setOnPrefabChanged(callback) {
796
- this.onPrefabChanged = callback;
797
- }
798
- setOnInstanceChanged(callback) {
799
- this.onInstanceChanged = callback;
800
- }
801
- // ─── Cleanup ───────────────────────────────────────────
802
- deletePrefab(prefabId) {
803
- const prefab = this.prefabs.get(prefabId);
804
- if (!prefab) {
805
- return false;
806
- }
807
- // Delete all instances
808
- for (const instance of this.getInstancesOfPrefab(prefabId)) {
809
- this.destroyInstance(instance.id);
810
- }
811
- // Remove from variants
812
- for (const variant of this.prefabs.values()) {
813
- if (variant.variantOf === prefabId) {
814
- variant.variantOf = undefined;
815
- }
816
- }
817
- // Remove nested references
818
- for (const p of this.prefabs.values()) {
819
- p.nestedPrefabs = p.nestedPrefabs.filter((n) => n.prefabId !== prefabId);
820
- }
821
- this.prefabs.delete(prefabId);
822
- this.prefabVersions.delete(prefabId);
65
+ constructor() {
66
+ this.prefabs = /* @__PURE__ */ new Map();
67
+ this.instances = /* @__PURE__ */ new Map();
68
+ this.prefabVersions = /* @__PURE__ */ new Map();
69
+ }
70
+ // ─── Prefab Creation ───────────────────────────────────
71
+ createPrefab(name, rootEntity) {
72
+ const id = `prefab_${generateId()}`;
73
+ const now = Date.now();
74
+ const root = {
75
+ id: `entity_${generateId()}`,
76
+ name: rootEntity?.name ?? name,
77
+ parentId: null,
78
+ transform: rootEntity?.transform ?? deepClone(DEFAULT_TRANSFORM),
79
+ components: rootEntity?.components ?? [],
80
+ children: rootEntity?.children ?? [],
81
+ tags: rootEntity?.tags ?? [],
82
+ layer: rootEntity?.layer ?? "default",
83
+ active: rootEntity?.active ?? true
84
+ };
85
+ const prefab = {
86
+ id,
87
+ name,
88
+ description: "",
89
+ version: 1,
90
+ createdAt: now,
91
+ modifiedAt: now,
92
+ author: "",
93
+ rootEntity: root,
94
+ entities: /* @__PURE__ */ new Map([[root.id, root]]),
95
+ nestedPrefabs: [],
96
+ tags: [],
97
+ category: "General"
98
+ };
99
+ this.prefabs.set(id, prefab);
100
+ this.prefabVersions.set(id, 1);
101
+ return prefab;
102
+ }
103
+ createPrefabFromEntities(name, entities) {
104
+ const prefab = this.createPrefab(name);
105
+ const entityIds = new Set(entities.map((e) => e.id));
106
+ const root = entities.find((e) => !e.parentId || !entityIds.has(e.parentId));
107
+ if (root) {
108
+ prefab.rootEntity = deepClone(root);
109
+ prefab.entities.set(root.id, prefab.rootEntity);
110
+ }
111
+ for (const entity of entities) {
112
+ if (entity.id !== prefab.rootEntity.id) {
113
+ const clone = deepClone(entity);
114
+ prefab.entities.set(clone.id, clone);
115
+ }
116
+ }
117
+ this.updatePrefabVersion(prefab.id);
118
+ return prefab;
119
+ }
120
+ // ─── Prefab Variants ───────────────────────────────────
121
+ createVariant(basePrefabId, name) {
122
+ const basePrefab = this.prefabs.get(basePrefabId);
123
+ if (!basePrefab) {
124
+ return null;
125
+ }
126
+ const variant = this.createPrefab(name);
127
+ variant.variantOf = basePrefabId;
128
+ variant.inheritedOverrides = [];
129
+ variant.rootEntity = deepClone(basePrefab.rootEntity);
130
+ variant.rootEntity.id = `entity_${generateId()}`;
131
+ variant.entities.clear();
132
+ variant.entities.set(variant.rootEntity.id, variant.rootEntity);
133
+ for (const [, entity] of basePrefab.entities) {
134
+ if (entity.id !== basePrefab.rootEntity.id) {
135
+ const clone = deepClone(entity);
136
+ clone.id = `entity_${generateId()}`;
137
+ variant.entities.set(clone.id, clone);
138
+ }
139
+ }
140
+ variant.nestedPrefabs = deepClone(basePrefab.nestedPrefabs);
141
+ return variant;
142
+ }
143
+ getBasePrefab(variantId) {
144
+ const variant = this.prefabs.get(variantId);
145
+ if (!variant?.variantOf) {
146
+ return null;
147
+ }
148
+ return this.prefabs.get(variant.variantOf) ?? null;
149
+ }
150
+ applyVariantOverrides(variantId) {
151
+ const variant = this.prefabs.get(variantId);
152
+ if (!variant || !variant.variantOf) {
153
+ return;
154
+ }
155
+ const base = this.prefabs.get(variant.variantOf);
156
+ if (!base) {
157
+ return;
158
+ }
159
+ if (variant.inheritedOverrides) {
160
+ for (const override of variant.inheritedOverrides) {
161
+ const targetEntity = this.findEntityByPathRoot(variant, override.path);
162
+ if (targetEntity) {
163
+ setValueAtPath(targetEntity, override.path, override.overridenValue);
164
+ }
165
+ }
166
+ }
167
+ this.updatePrefabVersion(variantId);
168
+ }
169
+ // ─── Nested Prefabs ────────────────────────────────────
170
+ addNestedPrefab(parentPrefabId, nestedPrefabId, parentEntityId, transform) {
171
+ const parentPrefab = this.prefabs.get(parentPrefabId);
172
+ const nestedPrefab = this.prefabs.get(nestedPrefabId);
173
+ if (!parentPrefab || !nestedPrefab) {
174
+ return null;
175
+ }
176
+ if (!parentPrefab.entities.has(parentEntityId)) {
177
+ return null;
178
+ }
179
+ if (this.hasCircularReference(parentPrefabId, nestedPrefabId)) {
180
+ console.error("Circular prefab reference detected");
181
+ return null;
182
+ }
183
+ const reference = {
184
+ instanceId: `nested_${generateId()}`,
185
+ prefabId: nestedPrefabId,
186
+ parentEntityId,
187
+ overrides: [],
188
+ transform: {
189
+ ...deepClone(DEFAULT_TRANSFORM),
190
+ ...transform
191
+ }
192
+ };
193
+ parentPrefab.nestedPrefabs.push(reference);
194
+ this.updatePrefabVersion(parentPrefabId);
195
+ return reference;
196
+ }
197
+ removeNestedPrefab(parentPrefabId, instanceId) {
198
+ const parentPrefab = this.prefabs.get(parentPrefabId);
199
+ if (!parentPrefab) {
200
+ return false;
201
+ }
202
+ const index = parentPrefab.nestedPrefabs.findIndex((n) => n.instanceId === instanceId);
203
+ if (index === -1) {
204
+ return false;
205
+ }
206
+ parentPrefab.nestedPrefabs.splice(index, 1);
207
+ this.updatePrefabVersion(parentPrefabId);
208
+ return true;
209
+ }
210
+ hasCircularReference(parentId, childId, visited = /* @__PURE__ */ new Set()) {
211
+ if (parentId === childId) {
212
+ return true;
213
+ }
214
+ if (visited.has(childId)) {
215
+ return true;
216
+ }
217
+ visited.add(childId);
218
+ const childPrefab = this.prefabs.get(childId);
219
+ if (!childPrefab) {
220
+ return false;
221
+ }
222
+ for (const nested of childPrefab.nestedPrefabs) {
223
+ if (this.hasCircularReference(parentId, nested.prefabId, visited)) {
823
224
  return true;
824
- }
825
- clear() {
826
- this.prefabs.clear();
827
- this.instances.clear();
828
- this.prefabVersions.clear();
829
- }
225
+ }
226
+ }
227
+ return false;
228
+ }
229
+ // ─── Instantiation ─────────────────────────────────────
230
+ instantiate(prefabId, worldTransform) {
231
+ const prefab = this.prefabs.get(prefabId);
232
+ if (!prefab) {
233
+ return null;
234
+ }
235
+ const instance = {
236
+ id: `instance_${generateId()}`,
237
+ prefabId,
238
+ name: prefab.name,
239
+ overrides: [],
240
+ worldTransform: {
241
+ ...deepClone(DEFAULT_TRANSFORM),
242
+ ...worldTransform
243
+ },
244
+ nestedInstances: /* @__PURE__ */ new Map(),
245
+ isLinked: true,
246
+ createdAt: Date.now(),
247
+ lastSyncedAt: Date.now()
248
+ };
249
+ for (const nestedRef of prefab.nestedPrefabs) {
250
+ const nestedInstance = this.instantiate(nestedRef.prefabId, nestedRef.transform);
251
+ if (nestedInstance) {
252
+ nestedInstance.overrides = deepClone(nestedRef.overrides);
253
+ instance.nestedInstances.set(nestedRef.instanceId, nestedInstance);
254
+ }
255
+ }
256
+ this.instances.set(instance.id, instance);
257
+ return instance;
258
+ }
259
+ destroyInstance(instanceId) {
260
+ const instance = this.instances.get(instanceId);
261
+ if (!instance) {
262
+ return false;
263
+ }
264
+ for (const [, nested] of instance.nestedInstances) {
265
+ this.destroyInstance(nested.id);
266
+ }
267
+ this.instances.delete(instanceId);
268
+ return true;
269
+ }
270
+ // ─── Override Management ───────────────────────────────
271
+ setOverride(instanceId, path, value) {
272
+ const instance = this.instances.get(instanceId);
273
+ if (!instance) {
274
+ return;
275
+ }
276
+ const prefab = this.prefabs.get(instance.prefabId);
277
+ if (!prefab) {
278
+ return;
279
+ }
280
+ const originalValue = this.getOriginalValue(prefab, path);
281
+ if (compareValues(originalValue, value)) {
282
+ this.removeOverride(instanceId, path);
283
+ return;
284
+ }
285
+ const existingIndex = instance.overrides.findIndex((o) => o.path === path);
286
+ const override = {
287
+ path,
288
+ originalValue,
289
+ overridenValue: value,
290
+ overrideType: "modify",
291
+ timestamp: Date.now()
292
+ };
293
+ if (existingIndex !== -1) {
294
+ instance.overrides[existingIndex] = override;
295
+ } else {
296
+ instance.overrides.push(override);
297
+ }
298
+ this.onInstanceChanged?.(instanceId);
299
+ }
300
+ removeOverride(instanceId, path) {
301
+ const instance = this.instances.get(instanceId);
302
+ if (!instance) {
303
+ return;
304
+ }
305
+ instance.overrides = instance.overrides.filter((o) => o.path !== path);
306
+ this.onInstanceChanged?.(instanceId);
307
+ }
308
+ revertAllOverrides(instanceId) {
309
+ const instance = this.instances.get(instanceId);
310
+ if (!instance) {
311
+ return;
312
+ }
313
+ instance.overrides = [];
314
+ this.onInstanceChanged?.(instanceId);
315
+ }
316
+ applyOverridesToPrefab(instanceId) {
317
+ const instance = this.instances.get(instanceId);
318
+ if (!instance) {
319
+ return;
320
+ }
321
+ const prefab = this.prefabs.get(instance.prefabId);
322
+ if (!prefab) {
323
+ return;
324
+ }
325
+ for (const override of instance.overrides) {
326
+ const entity = this.findEntityByPathRoot(prefab, override.path);
327
+ if (entity) {
328
+ setValueAtPath(entity, override.path, override.overridenValue);
329
+ }
330
+ }
331
+ instance.overrides = [];
332
+ this.updatePrefabVersion(instance.prefabId);
333
+ }
334
+ hasOverrides(instanceId) {
335
+ const instance = this.instances.get(instanceId);
336
+ return instance ? instance.overrides.length > 0 : false;
337
+ }
338
+ getOverrides(instanceId) {
339
+ const instance = this.instances.get(instanceId);
340
+ return instance ? [...instance.overrides] : [];
341
+ }
342
+ getOriginalValue(prefab, path) {
343
+ const entity = this.findEntityByPathRoot(prefab, path);
344
+ if (!entity) {
345
+ return void 0;
346
+ }
347
+ const relativePath = this.getRelativePropertyPath(path);
348
+ return getValueAtPath(entity, relativePath);
349
+ }
350
+ findEntityByPathRoot(prefab, path) {
351
+ const parts = path.split(".");
352
+ if (parts[0].startsWith("entity_")) {
353
+ return prefab.entities.get(parts[0]) ?? null;
354
+ }
355
+ return prefab.rootEntity;
356
+ }
357
+ getRelativePropertyPath(path) {
358
+ const parts = path.split(".");
359
+ if (parts[0].startsWith("entity_")) {
360
+ return parts.slice(1).join(".");
361
+ }
362
+ return path;
363
+ }
364
+ // ─── Linking ───────────────────────────────────────────
365
+ unlinkInstance(instanceId) {
366
+ const instance = this.instances.get(instanceId);
367
+ if (!instance) {
368
+ return;
369
+ }
370
+ instance.isLinked = false;
371
+ instance.unpackedAt = Date.now();
372
+ for (const [, nested] of instance.nestedInstances) {
373
+ this.unlinkInstance(nested.id);
374
+ }
375
+ this.onInstanceChanged?.(instanceId);
376
+ }
377
+ relinkInstance(instanceId) {
378
+ const instance = this.instances.get(instanceId);
379
+ if (!instance) {
380
+ return false;
381
+ }
382
+ if (!this.prefabs.has(instance.prefabId)) {
383
+ return false;
384
+ }
385
+ instance.isLinked = true;
386
+ instance.unpackedAt = void 0;
387
+ instance.lastSyncedAt = Date.now();
388
+ this.onInstanceChanged?.(instanceId);
389
+ return true;
390
+ }
391
+ // ─── Synchronization ───────────────────────────────────
392
+ syncInstance(instanceId) {
393
+ const instance = this.instances.get(instanceId);
394
+ if (!instance || !instance.isLinked) {
395
+ return;
396
+ }
397
+ const prefab = this.prefabs.get(instance.prefabId);
398
+ if (!prefab) {
399
+ return;
400
+ }
401
+ this.prefabVersions.get(instance.prefabId) ?? 0;
402
+ if (instance.lastSyncedAt >= prefab.modifiedAt) {
403
+ return;
404
+ }
405
+ instance.lastSyncedAt = Date.now();
406
+ for (const [, nested] of instance.nestedInstances) {
407
+ this.syncInstance(nested.id);
408
+ }
409
+ this.onInstanceChanged?.(instanceId);
410
+ }
411
+ syncAllInstances(prefabId) {
412
+ for (const [instanceId, instance] of this.instances) {
413
+ if (instance.prefabId === prefabId && instance.isLinked) {
414
+ this.syncInstance(instanceId);
415
+ }
416
+ }
417
+ }
418
+ updatePrefabVersion(prefabId) {
419
+ const prefab = this.prefabs.get(prefabId);
420
+ if (prefab) {
421
+ prefab.version++;
422
+ prefab.modifiedAt = Date.now();
423
+ this.prefabVersions.set(prefabId, prefab.version);
424
+ this.onPrefabChanged?.(prefabId);
425
+ }
426
+ }
427
+ // ─── Entity Management ─────────────────────────────────
428
+ addEntity(prefabId, entity, parentId) {
429
+ const prefab = this.prefabs.get(prefabId);
430
+ if (!prefab) {
431
+ return null;
432
+ }
433
+ const newEntity = {
434
+ id: `entity_${generateId()}`,
435
+ name: entity.name ?? "New Entity",
436
+ parentId: parentId ?? prefab.rootEntity.id,
437
+ transform: entity.transform ?? deepClone(DEFAULT_TRANSFORM),
438
+ components: entity.components ?? [],
439
+ children: entity.children ?? [],
440
+ tags: entity.tags ?? [],
441
+ layer: entity.layer ?? "default",
442
+ active: entity.active ?? true
443
+ };
444
+ prefab.entities.set(newEntity.id, newEntity);
445
+ const parent = prefab.entities.get(newEntity.parentId);
446
+ if (parent) {
447
+ parent.children.push(newEntity.id);
448
+ }
449
+ this.updatePrefabVersion(prefabId);
450
+ return newEntity;
451
+ }
452
+ removeEntity(prefabId, entityId) {
453
+ const prefab = this.prefabs.get(prefabId);
454
+ if (!prefab) {
455
+ return false;
456
+ }
457
+ if (entityId === prefab.rootEntity.id) {
458
+ return false;
459
+ }
460
+ const entity = prefab.entities.get(entityId);
461
+ if (!entity) {
462
+ return false;
463
+ }
464
+ if (entity.parentId) {
465
+ const parent = prefab.entities.get(entity.parentId);
466
+ if (parent) {
467
+ parent.children = parent.children.filter((id) => id !== entityId);
468
+ }
469
+ }
470
+ for (const childId of entity.children) {
471
+ this.removeEntity(prefabId, childId);
472
+ }
473
+ prefab.entities.delete(entityId);
474
+ this.updatePrefabVersion(prefabId);
475
+ return true;
476
+ }
477
+ // ─── Component Management ──────────────────────────────
478
+ addComponent(prefabId, entityId, component) {
479
+ const prefab = this.prefabs.get(prefabId);
480
+ if (!prefab) {
481
+ return null;
482
+ }
483
+ const entity = prefab.entities.get(entityId);
484
+ if (!entity) {
485
+ return null;
486
+ }
487
+ const newComponent = {
488
+ id: `component_${generateId()}`,
489
+ type: component.type ?? "Unknown",
490
+ properties: component.properties ?? {},
491
+ enabled: component.enabled ?? true
492
+ };
493
+ entity.components.push(newComponent);
494
+ this.updatePrefabVersion(prefabId);
495
+ return newComponent;
496
+ }
497
+ removeComponent(prefabId, entityId, componentId) {
498
+ const prefab = this.prefabs.get(prefabId);
499
+ if (!prefab) {
500
+ return false;
501
+ }
502
+ const entity = prefab.entities.get(entityId);
503
+ if (!entity) {
504
+ return false;
505
+ }
506
+ const index = entity.components.findIndex((c) => c.id === componentId);
507
+ if (index === -1) {
508
+ return false;
509
+ }
510
+ entity.components.splice(index, 1);
511
+ this.updatePrefabVersion(prefabId);
512
+ return true;
513
+ }
514
+ // ─── Comparison ────────────────────────────────────────
515
+ comparePrefabs(prefabIdA, prefabIdB) {
516
+ const prefabA = this.prefabs.get(prefabIdA);
517
+ const prefabB = this.prefabs.get(prefabIdB);
518
+ if (!prefabA || !prefabB) {
519
+ return null;
520
+ }
521
+ const diff = {
522
+ added: [],
523
+ removed: [],
524
+ modified: [],
525
+ componentAdded: [],
526
+ componentRemoved: [],
527
+ entityAdded: [],
528
+ entityRemoved: []
529
+ };
530
+ const entityIdsA = new Set(prefabA.entities.keys());
531
+ const entityIdsB = new Set(prefabB.entities.keys());
532
+ for (const id of entityIdsB) {
533
+ if (!entityIdsA.has(id)) {
534
+ diff.entityAdded.push(id);
535
+ }
536
+ }
537
+ for (const id of entityIdsA) {
538
+ if (!entityIdsB.has(id)) {
539
+ diff.entityRemoved.push(id);
540
+ }
541
+ }
542
+ for (const [id, entityA] of prefabA.entities) {
543
+ const entityB = prefabB.entities.get(id);
544
+ if (!entityB) {
545
+ continue;
546
+ }
547
+ this.compareEntities(entityA, entityB, id, diff);
548
+ }
549
+ return diff;
550
+ }
551
+ compareInstanceToPrefab(instanceId) {
552
+ const instance = this.instances.get(instanceId);
553
+ if (!instance) {
554
+ return null;
555
+ }
556
+ const prefab = this.prefabs.get(instance.prefabId);
557
+ if (!prefab) {
558
+ return null;
559
+ }
560
+ const diff = {
561
+ added: [],
562
+ removed: [],
563
+ modified: [],
564
+ componentAdded: [],
565
+ componentRemoved: [],
566
+ entityAdded: [],
567
+ entityRemoved: []
568
+ };
569
+ for (const override of instance.overrides) {
570
+ diff.modified.push({
571
+ path: override.path,
572
+ oldValue: override.originalValue,
573
+ newValue: override.overridenValue
574
+ });
575
+ }
576
+ return diff;
577
+ }
578
+ compareEntities(entityA, entityB, prefix, diff) {
579
+ this.compareProperty(entityA.transform, entityB.transform, `${prefix}.transform`, diff);
580
+ const compIdsA = new Set(entityA.components.map((c) => c.id));
581
+ const compIdsB = new Set(entityB.components.map((c) => c.id));
582
+ for (const comp of entityB.components) {
583
+ if (!compIdsA.has(comp.id)) {
584
+ diff.componentAdded.push(`${prefix}.${comp.id}`);
585
+ }
586
+ }
587
+ for (const comp of entityA.components) {
588
+ if (!compIdsB.has(comp.id)) {
589
+ diff.componentRemoved.push(`${prefix}.${comp.id}`);
590
+ }
591
+ }
592
+ for (const compA of entityA.components) {
593
+ const compB = entityB.components.find((c) => c.id === compA.id);
594
+ if (!compB) {
595
+ continue;
596
+ }
597
+ this.compareProperty(
598
+ compA.properties,
599
+ compB.properties,
600
+ `${prefix}.${compA.id}.properties`,
601
+ diff
602
+ );
603
+ }
604
+ }
605
+ compareProperty(valueA, valueB, path, diff) {
606
+ if (typeof valueA !== typeof valueB) {
607
+ diff.modified.push({ path, oldValue: valueA, newValue: valueB });
608
+ return;
609
+ }
610
+ if (valueA === null || valueB === null) {
611
+ if (valueA !== valueB) {
612
+ diff.modified.push({ path, oldValue: valueA, newValue: valueB });
613
+ }
614
+ return;
615
+ }
616
+ if (typeof valueA !== "object") {
617
+ if (valueA !== valueB) {
618
+ diff.modified.push({ path, oldValue: valueA, newValue: valueB });
619
+ }
620
+ return;
621
+ }
622
+ if (Array.isArray(valueA) && Array.isArray(valueB)) {
623
+ if (valueA.length !== valueB.length) {
624
+ diff.modified.push({ path, oldValue: valueA, newValue: valueB });
625
+ return;
626
+ }
627
+ for (let i = 0; i < valueA.length; i++) {
628
+ this.compareProperty(valueA[i], valueB[i], `${path}.${i}`, diff);
629
+ }
630
+ return;
631
+ }
632
+ const objA = valueA;
633
+ const objB = valueB;
634
+ const keysA = new Set(Object.keys(objA));
635
+ const keysB = new Set(Object.keys(objB));
636
+ for (const key of keysB) {
637
+ if (!keysA.has(key)) {
638
+ diff.added.push(`${path}.${key}`);
639
+ }
640
+ }
641
+ for (const key of keysA) {
642
+ if (!keysB.has(key)) {
643
+ diff.removed.push(`${path}.${key}`);
644
+ } else {
645
+ this.compareProperty(objA[key], objB[key], `${path}.${key}`, diff);
646
+ }
647
+ }
648
+ }
649
+ // ─── Serialization ─────────────────────────────────────
650
+ serializePrefab(prefabId) {
651
+ const prefab = this.prefabs.get(prefabId);
652
+ if (!prefab) {
653
+ return null;
654
+ }
655
+ const serialized = {
656
+ ...prefab,
657
+ entities: Object.fromEntries(prefab.entities)
658
+ };
659
+ return JSON.stringify(serialized, null, 2);
660
+ }
661
+ deserializePrefab(json) {
662
+ try {
663
+ const data = JSON.parse(json);
664
+ const prefab = {
665
+ ...data,
666
+ entities: new Map(Object.entries(data.entities)),
667
+ createdAt: data.createdAt ?? Date.now(),
668
+ modifiedAt: data.modifiedAt ?? Date.now()
669
+ };
670
+ this.prefabs.set(prefab.id, prefab);
671
+ this.prefabVersions.set(prefab.id, prefab.version);
672
+ return prefab;
673
+ } catch (error) {
674
+ console.error("Failed to deserialize prefab:", error);
675
+ return null;
676
+ }
677
+ }
678
+ serializeInstance(instanceId) {
679
+ const instance = this.instances.get(instanceId);
680
+ if (!instance) {
681
+ return null;
682
+ }
683
+ const serialized = {
684
+ ...instance,
685
+ nestedInstances: Object.fromEntries(instance.nestedInstances)
686
+ };
687
+ return JSON.stringify(serialized, null, 2);
688
+ }
689
+ deserializeInstance(json) {
690
+ try {
691
+ const data = JSON.parse(json);
692
+ const instance = {
693
+ ...data,
694
+ nestedInstances: new Map(Object.entries(data.nestedInstances))
695
+ };
696
+ this.instances.set(instance.id, instance);
697
+ return instance;
698
+ } catch (error) {
699
+ console.error("Failed to deserialize instance:", error);
700
+ return null;
701
+ }
702
+ }
703
+ // ─── Queries ───────────────────────────────────────────
704
+ getPrefab(prefabId) {
705
+ return this.prefabs.get(prefabId);
706
+ }
707
+ getInstance(instanceId) {
708
+ return this.instances.get(instanceId);
709
+ }
710
+ getAllPrefabs() {
711
+ return Array.from(this.prefabs.values());
712
+ }
713
+ getAllInstances() {
714
+ return Array.from(this.instances.values());
715
+ }
716
+ getInstancesOfPrefab(prefabId) {
717
+ return this.getAllInstances().filter((i) => i.prefabId === prefabId);
718
+ }
719
+ searchPrefabs(query) {
720
+ const lowerQuery = query.toLowerCase();
721
+ return this.getAllPrefabs().filter(
722
+ (p) => p.name.toLowerCase().includes(lowerQuery) || p.description.toLowerCase().includes(lowerQuery) || p.tags.some((t) => t.toLowerCase().includes(lowerQuery))
723
+ );
724
+ }
725
+ getPrefabsByCategory(category) {
726
+ return this.getAllPrefabs().filter((p) => p.category === category);
727
+ }
728
+ getCategories() {
729
+ const categories = /* @__PURE__ */ new Set();
730
+ for (const prefab of this.prefabs.values()) {
731
+ categories.add(prefab.category);
732
+ }
733
+ return Array.from(categories).sort();
734
+ }
735
+ // ─── Callbacks ─────────────────────────────────────────
736
+ setOnPrefabChanged(callback) {
737
+ this.onPrefabChanged = callback;
738
+ }
739
+ setOnInstanceChanged(callback) {
740
+ this.onInstanceChanged = callback;
741
+ }
742
+ // ─── Cleanup ───────────────────────────────────────────
743
+ deletePrefab(prefabId) {
744
+ const prefab = this.prefabs.get(prefabId);
745
+ if (!prefab) {
746
+ return false;
747
+ }
748
+ for (const instance of this.getInstancesOfPrefab(prefabId)) {
749
+ this.destroyInstance(instance.id);
750
+ }
751
+ for (const variant of this.prefabs.values()) {
752
+ if (variant.variantOf === prefabId) {
753
+ variant.variantOf = void 0;
754
+ }
755
+ }
756
+ for (const p of this.prefabs.values()) {
757
+ p.nestedPrefabs = p.nestedPrefabs.filter((n) => n.prefabId !== prefabId);
758
+ }
759
+ this.prefabs.delete(prefabId);
760
+ this.prefabVersions.delete(prefabId);
761
+ return true;
762
+ }
763
+ clear() {
764
+ this.prefabs.clear();
765
+ this.instances.clear();
766
+ this.prefabVersions.clear();
767
+ }
830
768
  }
831
- // ============================================================
832
- // Factory Functions
833
- // ============================================================
834
769
  function createPrefabManager() {
835
- return new PrefabManager();
770
+ return new PrefabManager();
836
771
  }
837
- function createDefaultEntity(name = 'Entity') {
838
- return {
839
- id: `entity_${generateId()}`,
840
- name,
841
- parentId: null,
842
- transform: deepClone(DEFAULT_TRANSFORM),
843
- components: [],
844
- children: [],
845
- tags: [],
846
- layer: 'default',
847
- active: true,
848
- };
772
+ function createDefaultEntity(name = "Entity") {
773
+ return {
774
+ id: `entity_${generateId()}`,
775
+ name,
776
+ parentId: null,
777
+ transform: deepClone(DEFAULT_TRANSFORM),
778
+ components: [],
779
+ children: [],
780
+ tags: [],
781
+ layer: "default",
782
+ active: true
783
+ };
849
784
  }
850
785
  function createComponent(type, properties = {}) {
851
- return {
852
- id: `component_${generateId()}`,
853
- type,
854
- properties,
855
- enabled: true,
856
- };
786
+ return {
787
+ id: `component_${generateId()}`,
788
+ type,
789
+ properties,
790
+ enabled: true
791
+ };
857
792
  }
858
-
859
793
  exports.DEFAULT_TRANSFORM = DEFAULT_TRANSFORM;
860
794
  exports.PrefabManager = PrefabManager;
861
795
  exports.createComponent = createComponent;