@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,820 +1,760 @@
1
- 'use strict';
2
-
3
- /**
4
- * @file NetworkingSystem.ts
5
- * @description Networking System for Nice2Dev Game Engine
6
- * PRO-1.11.6: Networking System
7
- *
8
- * Features:
9
- * - WebSocket multiplayer
10
- * - WebRTC peer-to-peer
11
- * - State synchronization
12
- * - Client-side prediction
13
- * - Lag compensation
14
- * - Matchmaking
15
- * - Lobby system
16
- */
17
- // ============================================================
18
- // Network Manager
19
- // ============================================================
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
20
3
  class NetworkManager {
21
- constructor(config) {
22
- this.connection = null;
23
- this.players = new Map();
24
- this.localPlayer = null;
25
- this.entities = new Map();
26
- this.snapshotBuffer = [];
27
- this.currentTick = 0;
28
- this.serverTimeOffset = 0;
29
- this.callbacks = {};
30
- this.messageHandlers = new Map();
31
- this.config = {
32
- maxPlayers: 16,
33
- tickRate: 60,
34
- interpolationDelay: 100,
35
- predictionEnabled: true,
36
- lagCompensationWindow: 200,
37
- reconciliationEnabled: true,
38
- snapshotBufferSize: 120,
39
- heartbeatInterval: 1000,
40
- timeoutDuration: 10000,
41
- compressionEnabled: true,
42
- encryptionEnabled: false,
43
- ...config,
44
- };
45
- }
46
- // ─── Connection ────────────────────────────────────────
47
- async connectToServer(url, playerName) {
48
- if (this.connection) {
49
- throw new Error('Already connected');
50
- }
51
- this.connection = new WebSocketConnection(url, this.config);
52
- await this.connection.connect();
53
- // Set up message handling
54
- this.connection.onMessage((msg) => this.handleMessage(msg));
55
- this.connection.onDisconnect((reason) => {
56
- this.callbacks.onDisconnected?.(reason);
57
- this.cleanup();
58
- });
59
- // Send join request
60
- this.sendMessage({
61
- type: 'join-request',
62
- channel: 'system',
63
- mode: 'reliable',
64
- data: { playerName },
65
- });
66
- // Wait for join response
67
- await this.waitForJoinResponse();
68
- this.callbacks.onConnected?.();
69
- }
70
- async waitForJoinResponse() {
71
- return new Promise((resolve, reject) => {
72
- const timeout = setTimeout(() => {
73
- reject(new Error('Join timeout'));
74
- }, this.config.timeoutDuration);
75
- this.messageHandlers.set('join-response', (msg) => {
76
- clearTimeout(timeout);
77
- const data = msg.data;
78
- this.localPlayer = {
79
- id: data.playerId,
80
- name: '',
81
- role: 'client',
82
- ping: 0,
83
- state: 'connected',
84
- inputSequence: 0,
85
- pendingInputs: [],
86
- };
87
- this.serverTimeOffset = data.serverTime - Date.now();
88
- for (const player of data.players) {
89
- this.players.set(player.id, player);
90
- }
91
- resolve();
92
- });
93
- });
94
- }
95
- async hostServer(port, playerName) {
96
- this.connection = new WebSocketServer(port, this.config);
97
- await this.connection.start();
4
+ constructor(config) {
5
+ this.connection = null;
6
+ this.players = /* @__PURE__ */ new Map();
7
+ this.localPlayer = null;
8
+ this.entities = /* @__PURE__ */ new Map();
9
+ this.snapshotBuffer = [];
10
+ this.currentTick = 0;
11
+ this.serverTimeOffset = 0;
12
+ this.callbacks = {};
13
+ this.messageHandlers = /* @__PURE__ */ new Map();
14
+ this.config = {
15
+ maxPlayers: 16,
16
+ tickRate: 60,
17
+ interpolationDelay: 100,
18
+ predictionEnabled: true,
19
+ lagCompensationWindow: 200,
20
+ reconciliationEnabled: true,
21
+ snapshotBufferSize: 120,
22
+ heartbeatInterval: 1e3,
23
+ timeoutDuration: 1e4,
24
+ compressionEnabled: true,
25
+ encryptionEnabled: false,
26
+ ...config
27
+ };
28
+ }
29
+ // ─── Connection ────────────────────────────────────────
30
+ async connectToServer(url, playerName) {
31
+ if (this.connection) {
32
+ throw new Error("Already connected");
33
+ }
34
+ this.connection = new WebSocketConnection(url, this.config);
35
+ await this.connection.connect();
36
+ this.connection.onMessage((msg) => this.handleMessage(msg));
37
+ this.connection.onDisconnect((reason) => {
38
+ this.callbacks.onDisconnected?.(reason);
39
+ this.cleanup();
40
+ });
41
+ this.sendMessage({
42
+ type: "join-request",
43
+ channel: "system",
44
+ mode: "reliable",
45
+ data: { playerName }
46
+ });
47
+ await this.waitForJoinResponse();
48
+ this.callbacks.onConnected?.();
49
+ }
50
+ async waitForJoinResponse() {
51
+ return new Promise((resolve, reject) => {
52
+ const timeout = setTimeout(() => {
53
+ reject(new Error("Join timeout"));
54
+ }, this.config.timeoutDuration);
55
+ this.messageHandlers.set("join-response", (msg) => {
56
+ clearTimeout(timeout);
57
+ const data = msg.data;
98
58
  this.localPlayer = {
99
- id: 'host',
100
- name: playerName,
101
- role: 'host',
102
- ping: 0,
103
- state: 'playing',
104
- inputSequence: 0,
105
- pendingInputs: [],
106
- };
107
- this.players.set('host', this.localPlayer);
108
- }
109
- disconnect() {
110
- if (this.connection) {
111
- this.sendMessage({
112
- type: 'leave',
113
- channel: 'system',
114
- mode: 'reliable',
115
- data: {},
116
- });
117
- this.connection.disconnect();
118
- this.cleanup();
119
- }
120
- }
121
- cleanup() {
122
- this.connection = null;
123
- this.players.clear();
124
- this.localPlayer = null;
125
- this.entities.clear();
126
- this.snapshotBuffer = [];
127
- this.currentTick = 0;
128
- }
129
- isConnected() {
130
- return this.connection?.getState() === 'connected';
131
- }
132
- getConnectionState() {
133
- return this.connection?.getState() ?? 'disconnected';
134
- }
135
- // ─── Players ───────────────────────────────────────────
136
- getLocalPlayer() {
137
- return this.localPlayer;
138
- }
139
- getPlayer(id) {
140
- return this.players.get(id);
141
- }
142
- getPlayers() {
143
- return Array.from(this.players.values());
144
- }
145
- getPlayerCount() {
146
- return this.players.size;
147
- }
148
- // ─── Entities ──────────────────────────────────────────
149
- registerEntity(entity) {
150
- this.entities.set(entity.networkId, entity);
151
- }
152
- unregisterEntity(entity) {
153
- this.entities.delete(entity.networkId);
154
- }
155
- getEntity(id) {
156
- return this.entities.get(id);
157
- }
158
- isEntityOwner(entity) {
159
- return entity.ownerId === this.localPlayer?.id;
160
- }
161
- // ─── Messages ──────────────────────────────────────────
162
- sendMessage(message) {
163
- if (!this.connection) {
164
- return;
165
- }
166
- const fullMessage = {
167
- ...message,
168
- timestamp: Date.now() + this.serverTimeOffset,
169
- senderId: this.localPlayer?.id ?? 'unknown',
170
- };
171
- this.connection.send(fullMessage);
172
- }
173
- sendToPlayer(playerId, message) {
174
- this.sendMessage({
175
- ...message,
176
- data: { ...message.data, targetPlayerId: playerId },
177
- });
178
- }
179
- broadcast(message, excludeSelf = false) {
180
- this.sendMessage({
181
- ...message,
182
- data: { ...message.data, broadcast: true, excludeSelf },
183
- });
184
- }
185
- handleMessage(message) {
186
- // Check for registered handler
187
- const handler = this.messageHandlers.get(message.type);
188
- if (handler) {
189
- handler(message);
190
- return;
191
- }
192
- switch (message.type) {
193
- case 'player-joined':
194
- this.handlePlayerJoined(message);
195
- break;
196
- case 'player-left':
197
- this.handlePlayerLeft(message);
198
- break;
199
- case 'state-sync':
200
- this.handleStateSync(message);
201
- break;
202
- case 'ping':
203
- this.handlePing(message);
204
- break;
205
- default:
206
- this.callbacks.onMessage?.(message);
207
- }
208
- }
209
- handlePlayerJoined(message) {
210
- const player = message.data;
211
- this.players.set(player.id, player);
212
- this.callbacks.onPlayerJoined?.(player);
213
- }
214
- handlePlayerLeft(message) {
215
- const { playerId } = message.data;
216
- const player = this.players.get(playerId);
217
- if (player) {
218
- this.players.delete(playerId);
219
- this.callbacks.onPlayerLeft?.(player);
220
- }
221
- }
222
- handleStateSync(message) {
223
- const snapshot = message.data;
224
- // Add to buffer
225
- this.snapshotBuffer.push(snapshot);
226
- if (this.snapshotBuffer.length > this.config.snapshotBufferSize) {
227
- this.snapshotBuffer.shift();
228
- }
229
- this.callbacks.onStateSync?.(snapshot);
230
- }
231
- handlePing(message) {
232
- const { sendTime } = message.data;
233
- const ping = Date.now() - sendTime;
234
- if (this.localPlayer) {
235
- this.localPlayer.ping = ping;
236
- }
237
- this.callbacks.onPingUpdate?.(ping);
238
- }
239
- // ─── Input ─────────────────────────────────────────────
240
- sendInput(input) {
241
- if (!this.localPlayer) {
242
- return;
243
- }
244
- const playerInput = {
245
- sequence: ++this.localPlayer.inputSequence,
246
- timestamp: Date.now() + this.serverTimeOffset,
247
- actions: input,
59
+ id: data.playerId,
60
+ name: "",
61
+ role: "client",
62
+ ping: 0,
63
+ state: "connected",
64
+ inputSequence: 0,
65
+ pendingInputs: []
248
66
  };
249
- // Store for reconciliation
67
+ this.serverTimeOffset = data.serverTime - Date.now();
68
+ for (const player of data.players) {
69
+ this.players.set(player.id, player);
70
+ }
71
+ resolve();
72
+ });
73
+ });
74
+ }
75
+ async hostServer(port, playerName) {
76
+ this.connection = new WebSocketServer(port, this.config);
77
+ await this.connection.start();
78
+ this.localPlayer = {
79
+ id: "host",
80
+ name: playerName,
81
+ role: "host",
82
+ ping: 0,
83
+ state: "playing",
84
+ inputSequence: 0,
85
+ pendingInputs: []
86
+ };
87
+ this.players.set("host", this.localPlayer);
88
+ }
89
+ disconnect() {
90
+ if (this.connection) {
91
+ this.sendMessage({
92
+ type: "leave",
93
+ channel: "system",
94
+ mode: "reliable",
95
+ data: {}
96
+ });
97
+ this.connection.disconnect();
98
+ this.cleanup();
99
+ }
100
+ }
101
+ cleanup() {
102
+ this.connection = null;
103
+ this.players.clear();
104
+ this.localPlayer = null;
105
+ this.entities.clear();
106
+ this.snapshotBuffer = [];
107
+ this.currentTick = 0;
108
+ }
109
+ isConnected() {
110
+ return this.connection?.getState() === "connected";
111
+ }
112
+ getConnectionState() {
113
+ return this.connection?.getState() ?? "disconnected";
114
+ }
115
+ // ─── Players ───────────────────────────────────────────
116
+ getLocalPlayer() {
117
+ return this.localPlayer;
118
+ }
119
+ getPlayer(id) {
120
+ return this.players.get(id);
121
+ }
122
+ getPlayers() {
123
+ return Array.from(this.players.values());
124
+ }
125
+ getPlayerCount() {
126
+ return this.players.size;
127
+ }
128
+ // ─── Entities ──────────────────────────────────────────
129
+ registerEntity(entity) {
130
+ this.entities.set(entity.networkId, entity);
131
+ }
132
+ unregisterEntity(entity) {
133
+ this.entities.delete(entity.networkId);
134
+ }
135
+ getEntity(id) {
136
+ return this.entities.get(id);
137
+ }
138
+ isEntityOwner(entity) {
139
+ return entity.ownerId === this.localPlayer?.id;
140
+ }
141
+ // ─── Messages ──────────────────────────────────────────
142
+ sendMessage(message) {
143
+ if (!this.connection) {
144
+ return;
145
+ }
146
+ const fullMessage = {
147
+ ...message,
148
+ timestamp: Date.now() + this.serverTimeOffset,
149
+ senderId: this.localPlayer?.id ?? "unknown"
150
+ };
151
+ this.connection.send(fullMessage);
152
+ }
153
+ sendToPlayer(playerId, message) {
154
+ this.sendMessage({
155
+ ...message,
156
+ data: { ...message.data, targetPlayerId: playerId }
157
+ });
158
+ }
159
+ broadcast(message, excludeSelf = false) {
160
+ this.sendMessage({
161
+ ...message,
162
+ data: { ...message.data, broadcast: true, excludeSelf }
163
+ });
164
+ }
165
+ handleMessage(message) {
166
+ const handler = this.messageHandlers.get(message.type);
167
+ if (handler) {
168
+ handler(message);
169
+ return;
170
+ }
171
+ switch (message.type) {
172
+ case "player-joined":
173
+ this.handlePlayerJoined(message);
174
+ break;
175
+ case "player-left":
176
+ this.handlePlayerLeft(message);
177
+ break;
178
+ case "state-sync":
179
+ this.handleStateSync(message);
180
+ break;
181
+ case "ping":
182
+ this.handlePing(message);
183
+ break;
184
+ default:
185
+ this.callbacks.onMessage?.(message);
186
+ }
187
+ }
188
+ handlePlayerJoined(message) {
189
+ const player = message.data;
190
+ this.players.set(player.id, player);
191
+ this.callbacks.onPlayerJoined?.(player);
192
+ }
193
+ handlePlayerLeft(message) {
194
+ const { playerId } = message.data;
195
+ const player = this.players.get(playerId);
196
+ if (player) {
197
+ this.players.delete(playerId);
198
+ this.callbacks.onPlayerLeft?.(player);
199
+ }
200
+ }
201
+ handleStateSync(message) {
202
+ const snapshot = message.data;
203
+ this.snapshotBuffer.push(snapshot);
204
+ if (this.snapshotBuffer.length > this.config.snapshotBufferSize) {
205
+ this.snapshotBuffer.shift();
206
+ }
207
+ this.callbacks.onStateSync?.(snapshot);
208
+ }
209
+ handlePing(message) {
210
+ const { sendTime } = message.data;
211
+ const ping = Date.now() - sendTime;
212
+ if (this.localPlayer) {
213
+ this.localPlayer.ping = ping;
214
+ }
215
+ this.callbacks.onPingUpdate?.(ping);
216
+ }
217
+ // ─── Input ─────────────────────────────────────────────
218
+ sendInput(input) {
219
+ if (!this.localPlayer) {
220
+ return;
221
+ }
222
+ const playerInput = {
223
+ sequence: ++this.localPlayer.inputSequence,
224
+ timestamp: Date.now() + this.serverTimeOffset,
225
+ actions: input
226
+ };
227
+ if (this.config.predictionEnabled) {
228
+ this.localPlayer.pendingInputs.push(playerInput);
229
+ }
230
+ this.sendMessage({
231
+ type: "player-input",
232
+ channel: "gameplay",
233
+ mode: "reliable-ordered",
234
+ data: playerInput
235
+ });
236
+ }
237
+ // ─── State Synchronization ─────────────────────────────
238
+ update(_deltaTime) {
239
+ if (!this.connection) {
240
+ return;
241
+ }
242
+ this.currentTick++;
243
+ if (this.currentTick % (this.config.tickRate * (this.config.heartbeatInterval / 1e3)) === 0) {
244
+ this.sendMessage({
245
+ type: "ping",
246
+ channel: "system",
247
+ mode: "unreliable",
248
+ data: { sendTime: Date.now() }
249
+ });
250
+ }
251
+ const renderTime = Date.now() - this.config.interpolationDelay + this.serverTimeOffset;
252
+ for (const entity of this.entities.values()) {
253
+ if (this.isEntityOwner(entity)) {
250
254
  if (this.config.predictionEnabled) {
251
- this.localPlayer.pendingInputs.push(playerInput);
252
- }
253
- this.sendMessage({
254
- type: 'player-input',
255
- channel: 'gameplay',
256
- mode: 'reliable-ordered',
257
- data: playerInput,
258
- });
259
- }
260
- // ─── State Synchronization ─────────────────────────────
261
- update(_deltaTime) {
262
- if (!this.connection) {
263
- return;
264
- }
265
- this.currentTick++;
266
- // Update ping
267
- if (this.currentTick % (this.config.tickRate * (this.config.heartbeatInterval / 1000)) === 0) {
268
- this.sendMessage({
269
- type: 'ping',
270
- channel: 'system',
271
- mode: 'unreliable',
272
- data: { sendTime: Date.now() },
273
- });
274
- }
275
- // Interpolation for remote entities
276
- const renderTime = Date.now() - this.config.interpolationDelay + this.serverTimeOffset;
277
- for (const entity of this.entities.values()) {
278
- if (this.isEntityOwner(entity)) {
279
- // Local entity - apply prediction
280
- if (this.config.predictionEnabled) {
281
- this.applyPrediction(entity);
282
- }
283
- }
284
- else {
285
- // Remote entity - interpolate
286
- this.interpolateEntity(entity, renderTime);
287
- }
288
- }
289
- }
290
- applyPrediction(_entity) {
291
- // Apply pending inputs to predict entity state
292
- if (!this.localPlayer) {
293
- return;
294
- }
295
- for (const _input of this.localPlayer.pendingInputs) {
296
- // Would apply input to entity simulation
297
- }
298
- }
299
- interpolateEntity(entity, renderTime) {
300
- // Find surrounding snapshots
301
- let before = null;
302
- let after = null;
303
- for (const snapshot of this.snapshotBuffer) {
304
- if (snapshot.timestamp <= renderTime) {
305
- before = snapshot;
306
- }
307
- else {
308
- after = snapshot;
309
- break;
310
- }
311
- }
312
- if (!before || !after) {
313
- // Extrapolate from latest
314
- if (this.snapshotBuffer.length > 0) {
315
- const latest = this.snapshotBuffer[this.snapshotBuffer.length - 1];
316
- const entityState = latest.entities.find((e) => e.id === entity.networkId);
317
- if (entityState) {
318
- entity.applyState(entityState);
319
- }
320
- }
321
- return;
322
- }
323
- // Interpolate between snapshots
324
- const t = (renderTime - before.timestamp) / (after.timestamp - before.timestamp);
325
- const beforeState = before.entities.find((e) => e.id === entity.networkId);
326
- const afterState = after.entities.find((e) => e.id === entity.networkId);
327
- if (beforeState && afterState) {
328
- const interpolated = {
329
- id: entity.networkId,
330
- ownerId: entity.ownerId,
331
- type: entity.type,
332
- position: this.lerpVec3(beforeState.position, afterState.position, t),
333
- rotation: this.slerpQuat(beforeState.rotation, afterState.rotation, t),
334
- velocity: beforeState.velocity && afterState.velocity
335
- ? this.lerpVec3(beforeState.velocity, afterState.velocity, t)
336
- : undefined,
337
- };
338
- entity.applyState(interpolated);
339
- }
340
- }
341
- lerpVec3(a, b, t) {
342
- return {
343
- x: a.x + (b.x - a.x) * t,
344
- y: a.y + (b.y - a.y) * t,
345
- z: a.z + (b.z - a.z) * t,
346
- };
347
- }
348
- slerpQuat(a, b, t) {
349
- // Simplified spherical linear interpolation
350
- let cosHalfTheta = a.w * b.w + a.x * b.x + a.y * b.y + a.z * b.z;
351
- if (Math.abs(cosHalfTheta) >= 1.0) {
352
- return a;
353
- }
354
- if (cosHalfTheta < 0) {
355
- b = { x: -b.x, y: -b.y, z: -b.z, w: -b.w };
356
- cosHalfTheta = -cosHalfTheta;
357
- }
358
- const halfTheta = Math.acos(cosHalfTheta);
359
- const sinHalfTheta = Math.sqrt(1.0 - cosHalfTheta * cosHalfTheta);
360
- if (Math.abs(sinHalfTheta) < 0.001) {
361
- return {
362
- x: a.x * 0.5 + b.x * 0.5,
363
- y: a.y * 0.5 + b.y * 0.5,
364
- z: a.z * 0.5 + b.z * 0.5,
365
- w: a.w * 0.5 + b.w * 0.5,
366
- };
367
- }
368
- const ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta;
369
- const ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
370
- return {
371
- x: a.x * ratioA + b.x * ratioB,
372
- y: a.y * ratioA + b.y * ratioB,
373
- z: a.z * ratioA + b.z * ratioB,
374
- w: a.w * ratioA + b.w * ratioB,
375
- };
376
- }
377
- // ─── Server Authority ──────────────────────────────────
378
- reconcileState(serverSequence, serverState) {
379
- if (!this.localPlayer || !this.config.reconciliationEnabled) {
380
- return;
381
- }
382
- // Remove acknowledged inputs
383
- this.localPlayer.pendingInputs = this.localPlayer.pendingInputs.filter((input) => input.sequence > serverSequence);
384
- // Get local entity
385
- const entity = this.entities.get(serverState.id);
386
- if (!entity || !this.isEntityOwner(entity)) {
387
- return;
388
- }
389
- // Apply server state
390
- entity.applyState(serverState);
391
- // Re-apply pending inputs
392
- for (const _input of this.localPlayer.pendingInputs) {
393
- // Would re-simulate with input
394
- }
395
- }
396
- // ─── Events ────────────────────────────────────────────
397
- on(event, callback) {
398
- this.callbacks[event] = callback;
399
- }
400
- off(event) {
401
- delete this.callbacks[event];
402
- }
403
- // ─── Custom Message Types ──────────────────────────────
404
- registerMessageHandler(type, handler) {
405
- this.messageHandlers.set(type, handler);
406
- }
407
- unregisterMessageHandler(type) {
408
- this.messageHandlers.delete(type);
409
- }
255
+ this.applyPrediction(entity);
256
+ }
257
+ } else {
258
+ this.interpolateEntity(entity, renderTime);
259
+ }
260
+ }
261
+ }
262
+ applyPrediction(_entity) {
263
+ if (!this.localPlayer) {
264
+ return;
265
+ }
266
+ for (const _input of this.localPlayer.pendingInputs) {
267
+ }
268
+ }
269
+ interpolateEntity(entity, renderTime) {
270
+ let before = null;
271
+ let after = null;
272
+ for (const snapshot of this.snapshotBuffer) {
273
+ if (snapshot.timestamp <= renderTime) {
274
+ before = snapshot;
275
+ } else {
276
+ after = snapshot;
277
+ break;
278
+ }
279
+ }
280
+ if (!before || !after) {
281
+ if (this.snapshotBuffer.length > 0) {
282
+ const latest = this.snapshotBuffer[this.snapshotBuffer.length - 1];
283
+ const entityState = latest.entities.find((e) => e.id === entity.networkId);
284
+ if (entityState) {
285
+ entity.applyState(entityState);
286
+ }
287
+ }
288
+ return;
289
+ }
290
+ const t = (renderTime - before.timestamp) / (after.timestamp - before.timestamp);
291
+ const beforeState = before.entities.find((e) => e.id === entity.networkId);
292
+ const afterState = after.entities.find((e) => e.id === entity.networkId);
293
+ if (beforeState && afterState) {
294
+ const interpolated = {
295
+ id: entity.networkId,
296
+ ownerId: entity.ownerId,
297
+ type: entity.type,
298
+ position: this.lerpVec3(beforeState.position, afterState.position, t),
299
+ rotation: this.slerpQuat(beforeState.rotation, afterState.rotation, t),
300
+ velocity: beforeState.velocity && afterState.velocity ? this.lerpVec3(beforeState.velocity, afterState.velocity, t) : void 0
301
+ };
302
+ entity.applyState(interpolated);
303
+ }
304
+ }
305
+ lerpVec3(a, b, t) {
306
+ return {
307
+ x: a.x + (b.x - a.x) * t,
308
+ y: a.y + (b.y - a.y) * t,
309
+ z: a.z + (b.z - a.z) * t
310
+ };
311
+ }
312
+ slerpQuat(a, b, t) {
313
+ let cosHalfTheta = a.w * b.w + a.x * b.x + a.y * b.y + a.z * b.z;
314
+ if (Math.abs(cosHalfTheta) >= 1) {
315
+ return a;
316
+ }
317
+ if (cosHalfTheta < 0) {
318
+ b = { x: -b.x, y: -b.y, z: -b.z, w: -b.w };
319
+ cosHalfTheta = -cosHalfTheta;
320
+ }
321
+ const halfTheta = Math.acos(cosHalfTheta);
322
+ const sinHalfTheta = Math.sqrt(1 - cosHalfTheta * cosHalfTheta);
323
+ if (Math.abs(sinHalfTheta) < 1e-3) {
324
+ return {
325
+ x: a.x * 0.5 + b.x * 0.5,
326
+ y: a.y * 0.5 + b.y * 0.5,
327
+ z: a.z * 0.5 + b.z * 0.5,
328
+ w: a.w * 0.5 + b.w * 0.5
329
+ };
330
+ }
331
+ const ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta;
332
+ const ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
333
+ return {
334
+ x: a.x * ratioA + b.x * ratioB,
335
+ y: a.y * ratioA + b.y * ratioB,
336
+ z: a.z * ratioA + b.z * ratioB,
337
+ w: a.w * ratioA + b.w * ratioB
338
+ };
339
+ }
340
+ // ─── Server Authority ──────────────────────────────────
341
+ reconcileState(serverSequence, serverState) {
342
+ if (!this.localPlayer || !this.config.reconciliationEnabled) {
343
+ return;
344
+ }
345
+ this.localPlayer.pendingInputs = this.localPlayer.pendingInputs.filter(
346
+ (input) => input.sequence > serverSequence
347
+ );
348
+ const entity = this.entities.get(serverState.id);
349
+ if (!entity || !this.isEntityOwner(entity)) {
350
+ return;
351
+ }
352
+ entity.applyState(serverState);
353
+ for (const _input of this.localPlayer.pendingInputs) {
354
+ }
355
+ }
356
+ // ─── Events ────────────────────────────────────────────
357
+ on(event, callback) {
358
+ this.callbacks[event] = callback;
359
+ }
360
+ off(event) {
361
+ delete this.callbacks[event];
362
+ }
363
+ // ─── Custom Message Types ──────────────────────────────
364
+ registerMessageHandler(type, handler) {
365
+ this.messageHandlers.set(type, handler);
366
+ }
367
+ unregisterMessageHandler(type) {
368
+ this.messageHandlers.delete(type);
369
+ }
410
370
  }
411
- // ============================================================
412
- // Network Entity
413
- // ============================================================
414
371
  class NetworkEntity {
415
- constructor(networkId, ownerId, type) {
416
- this.position = { x: 0, y: 0, z: 0 };
417
- this.rotation = { x: 0, y: 0, z: 0, w: 1 };
418
- this.velocity = { x: 0, y: 0, z: 0 };
419
- this.customState = {};
420
- this.networkId = networkId;
421
- this.ownerId = ownerId;
422
- this.type = type;
423
- }
424
- getState() {
425
- return {
426
- id: this.networkId,
427
- ownerId: this.ownerId,
428
- type: this.type,
429
- position: { ...this.position },
430
- rotation: { ...this.rotation },
431
- velocity: { ...this.velocity },
432
- customState: { ...this.customState },
433
- };
434
- }
435
- applyState(state) {
436
- this.position = { ...state.position };
437
- this.rotation = { ...state.rotation };
438
- if (state.velocity) {
439
- this.velocity = { ...state.velocity };
440
- }
441
- if (state.customState) {
442
- this.customState = { ...state.customState };
443
- }
444
- }
372
+ constructor(networkId, ownerId, type) {
373
+ this.position = { x: 0, y: 0, z: 0 };
374
+ this.rotation = { x: 0, y: 0, z: 0, w: 1 };
375
+ this.velocity = { x: 0, y: 0, z: 0 };
376
+ this.customState = {};
377
+ this.networkId = networkId;
378
+ this.ownerId = ownerId;
379
+ this.type = type;
380
+ }
381
+ getState() {
382
+ return {
383
+ id: this.networkId,
384
+ ownerId: this.ownerId,
385
+ type: this.type,
386
+ position: { ...this.position },
387
+ rotation: { ...this.rotation },
388
+ velocity: { ...this.velocity },
389
+ customState: { ...this.customState }
390
+ };
391
+ }
392
+ applyState(state) {
393
+ this.position = { ...state.position };
394
+ this.rotation = { ...state.rotation };
395
+ if (state.velocity) {
396
+ this.velocity = { ...state.velocity };
397
+ }
398
+ if (state.customState) {
399
+ this.customState = { ...state.customState };
400
+ }
401
+ }
445
402
  }
446
- // ============================================================
447
- // Connection Implementations
448
- // ============================================================
449
403
  class NetworkConnection {
450
- constructor() {
451
- this.state = 'disconnected';
452
- this.messageCallback = null;
453
- this.disconnectCallback = null;
454
- }
455
- getState() {
456
- return this.state;
457
- }
458
- onMessage(callback) {
459
- this.messageCallback = callback;
460
- }
461
- onDisconnect(callback) {
462
- this.disconnectCallback = callback;
463
- }
404
+ constructor() {
405
+ this.state = "disconnected";
406
+ this.messageCallback = null;
407
+ this.disconnectCallback = null;
408
+ }
409
+ getState() {
410
+ return this.state;
411
+ }
412
+ onMessage(callback) {
413
+ this.messageCallback = callback;
414
+ }
415
+ onDisconnect(callback) {
416
+ this.disconnectCallback = callback;
417
+ }
464
418
  }
465
419
  class WebSocketConnection extends NetworkConnection {
466
- constructor(url, config) {
467
- super();
468
- this.socket = null;
420
+ constructor(url, config) {
421
+ super();
422
+ this.socket = null;
423
+ this.reconnectAttempts = 0;
424
+ this.maxReconnectAttempts = 5;
425
+ this.url = url;
426
+ this.config = config;
427
+ }
428
+ async connect() {
429
+ return new Promise((resolve, reject) => {
430
+ this.state = "connecting";
431
+ this.socket = new WebSocket(this.url);
432
+ this.socket.onopen = () => {
433
+ this.state = "connected";
469
434
  this.reconnectAttempts = 0;
470
- this.maxReconnectAttempts = 5;
471
- this.url = url;
472
- this.config = config;
473
- }
474
- async connect() {
475
- return new Promise((resolve, reject) => {
476
- this.state = 'connecting';
477
- this.socket = new WebSocket(this.url);
478
- this.socket.onopen = () => {
479
- this.state = 'connected';
480
- this.reconnectAttempts = 0;
481
- resolve();
482
- };
483
- this.socket.onmessage = (event) => {
484
- try {
485
- const message = JSON.parse(event.data);
486
- this.messageCallback?.(message);
487
- }
488
- catch (e) {
489
- console.error('Failed to parse message:', e);
490
- }
491
- };
492
- this.socket.onclose = (event) => {
493
- this.state = 'disconnected';
494
- this.disconnectCallback?.(event.reason || 'Connection closed');
495
- // Attempt reconnection
496
- if (this.reconnectAttempts < this.maxReconnectAttempts) {
497
- this.reconnectAttempts++;
498
- setTimeout(() => this.connect(), 1000 * this.reconnectAttempts);
499
- }
500
- };
501
- this.socket.onerror = () => {
502
- this.state = 'disconnected';
503
- reject(new Error('WebSocket connection failed'));
504
- };
505
- // Connection timeout
506
- setTimeout(() => {
507
- if (this.state === 'connecting') {
508
- this.socket?.close();
509
- reject(new Error('Connection timeout'));
510
- }
511
- }, this.config.timeoutDuration);
512
- });
513
- }
514
- disconnect() {
515
- this.state = 'disconnecting';
516
- this.socket?.close();
517
- this.socket = null;
518
- this.state = 'disconnected';
519
- }
520
- send(message) {
521
- if (this.socket && this.state === 'connected') {
522
- const data = this.config.compressionEnabled
523
- ? this.compress(JSON.stringify(message))
524
- : JSON.stringify(message);
525
- this.socket.send(data);
526
- }
527
- }
528
- async start() {
529
- // Client connection - use connect() instead
530
- throw new Error('Use connect() for client connections');
531
- }
532
- compress(data) {
533
- // Would implement compression
534
- return data;
535
- }
435
+ resolve();
436
+ };
437
+ this.socket.onmessage = (event) => {
438
+ try {
439
+ const message = JSON.parse(event.data);
440
+ this.messageCallback?.(message);
441
+ } catch (e) {
442
+ console.error("Failed to parse message:", e);
443
+ }
444
+ };
445
+ this.socket.onclose = (event) => {
446
+ this.state = "disconnected";
447
+ this.disconnectCallback?.(event.reason || "Connection closed");
448
+ if (this.reconnectAttempts < this.maxReconnectAttempts) {
449
+ this.reconnectAttempts++;
450
+ setTimeout(() => this.connect(), 1e3 * this.reconnectAttempts);
451
+ }
452
+ };
453
+ this.socket.onerror = () => {
454
+ this.state = "disconnected";
455
+ reject(new Error("WebSocket connection failed"));
456
+ };
457
+ setTimeout(() => {
458
+ if (this.state === "connecting") {
459
+ this.socket?.close();
460
+ reject(new Error("Connection timeout"));
461
+ }
462
+ }, this.config.timeoutDuration);
463
+ });
464
+ }
465
+ disconnect() {
466
+ this.state = "disconnecting";
467
+ this.socket?.close();
468
+ this.socket = null;
469
+ this.state = "disconnected";
470
+ }
471
+ send(message) {
472
+ if (this.socket && this.state === "connected") {
473
+ const data = this.config.compressionEnabled ? this.compress(JSON.stringify(message)) : JSON.stringify(message);
474
+ this.socket.send(data);
475
+ }
476
+ }
477
+ async start() {
478
+ throw new Error("Use connect() for client connections");
479
+ }
480
+ compress(data) {
481
+ return data;
482
+ }
536
483
  }
537
484
  class WebSocketServer extends NetworkConnection {
538
- constructor(port, config) {
539
- super();
540
- this.clients = new Map();
541
- this.port = port;
542
- this.config = config;
543
- }
544
- async connect() {
545
- // Server doesn't connect - use start() instead
546
- throw new Error('Use start() for server');
547
- }
548
- async start() {
549
- // In browser environment, this would require a signaling server
550
- // For Node.js, would use ws package
551
- this.state = 'connected';
552
- console.log(`Server started on port ${this.port}`);
553
- }
554
- disconnect() {
555
- this.state = 'disconnecting';
556
- for (const client of this.clients.values()) {
557
- client.close();
558
- }
559
- this.clients.clear();
560
- this.state = 'disconnected';
561
- }
562
- send(message) {
563
- const data = JSON.stringify(message);
564
- for (const client of this.clients.values()) {
565
- if (client.readyState === WebSocket.OPEN) {
566
- client.send(data);
567
- }
568
- }
569
- }
570
- sendToClient(clientId, message) {
571
- const client = this.clients.get(clientId);
572
- if (client && client.readyState === WebSocket.OPEN) {
573
- client.send(JSON.stringify(message));
574
- }
575
- }
485
+ constructor(port, config) {
486
+ super();
487
+ this.clients = /* @__PURE__ */ new Map();
488
+ this.port = port;
489
+ this.config = config;
490
+ }
491
+ async connect() {
492
+ throw new Error("Use start() for server");
493
+ }
494
+ async start() {
495
+ this.state = "connected";
496
+ console.log(`Server started on port ${this.port}`);
497
+ }
498
+ disconnect() {
499
+ this.state = "disconnecting";
500
+ for (const client of this.clients.values()) {
501
+ client.close();
502
+ }
503
+ this.clients.clear();
504
+ this.state = "disconnected";
505
+ }
506
+ send(message) {
507
+ const data = JSON.stringify(message);
508
+ for (const client of this.clients.values()) {
509
+ if (client.readyState === WebSocket.OPEN) {
510
+ client.send(data);
511
+ }
512
+ }
513
+ }
514
+ sendToClient(clientId, message) {
515
+ const client = this.clients.get(clientId);
516
+ if (client && client.readyState === WebSocket.OPEN) {
517
+ client.send(JSON.stringify(message));
518
+ }
519
+ }
576
520
  }
577
521
  class LobbyManager {
578
- constructor(network) {
579
- this.currentLobby = null;
580
- this.availableLobbies = [];
581
- this.callbacks = {};
582
- this.network = network;
583
- this.setupMessageHandlers();
584
- }
585
- setupMessageHandlers() {
586
- this.network.registerMessageHandler('lobby-created', (msg) => {
587
- const lobby = msg.data;
588
- this.currentLobby = lobby;
589
- this.callbacks.onLobbyCreated?.(lobby);
590
- });
591
- this.network.registerMessageHandler('lobby-joined', (msg) => {
592
- const lobby = msg.data;
593
- this.currentLobby = lobby;
594
- this.callbacks.onLobbyJoined?.(lobby);
595
- });
596
- this.network.registerMessageHandler('lobby-player-joined', (msg) => {
597
- const player = msg.data;
598
- if (this.currentLobby) {
599
- this.currentLobby.players.push(player);
600
- this.callbacks.onPlayerJoined?.(player);
601
- }
602
- });
603
- this.network.registerMessageHandler('lobby-player-left', (msg) => {
604
- const { playerId } = msg.data;
605
- if (this.currentLobby) {
606
- const idx = this.currentLobby.players.findIndex((p) => p.id === playerId);
607
- if (idx >= 0) {
608
- const player = this.currentLobby.players.splice(idx, 1)[0];
609
- this.callbacks.onPlayerLeft?.(player);
610
- }
611
- }
612
- });
613
- this.network.registerMessageHandler('lobby-list', (msg) => {
614
- this.availableLobbies = msg.data;
615
- });
616
- this.network.registerMessageHandler('game-starting', () => {
617
- if (this.currentLobby) {
618
- this.currentLobby.state = 'starting';
619
- this.callbacks.onGameStarted?.();
620
- }
621
- });
622
- }
623
- // ─── Lobby Management ──────────────────────────────────
624
- createLobby(config) {
625
- this.network.sendMessage({
626
- type: 'create-lobby',
627
- channel: 'system',
628
- mode: 'reliable',
629
- data: config,
630
- });
631
- }
632
- joinLobby(lobbyId, password) {
633
- this.network.sendMessage({
634
- type: 'join-lobby',
635
- channel: 'system',
636
- mode: 'reliable',
637
- data: { lobbyId, password },
638
- });
639
- }
640
- leaveLobby() {
641
- if (!this.currentLobby) {
642
- return;
643
- }
644
- this.network.sendMessage({
645
- type: 'leave-lobby',
646
- channel: 'system',
647
- mode: 'reliable',
648
- data: { lobbyId: this.currentLobby.id },
649
- });
650
- this.currentLobby = null;
651
- this.callbacks.onLobbyLeft?.();
652
- }
653
- refreshLobbyList() {
654
- this.network.sendMessage({
655
- type: 'list-lobbies',
656
- channel: 'system',
657
- mode: 'reliable',
658
- data: {},
659
- });
660
- }
661
- startGame() {
662
- if (!this.currentLobby) {
663
- return;
664
- }
665
- this.network.sendMessage({
666
- type: 'start-game',
667
- channel: 'system',
668
- mode: 'reliable',
669
- data: { lobbyId: this.currentLobby.id },
670
- });
671
- }
672
- // ─── Lobby Settings ────────────────────────────────────
673
- updateLobbySettings(settings) {
674
- if (!this.currentLobby) {
675
- return;
676
- }
677
- this.network.sendMessage({
678
- type: 'update-lobby',
679
- channel: 'system',
680
- mode: 'reliable',
681
- data: { lobbyId: this.currentLobby.id, settings },
682
- });
683
- }
684
- kickPlayer(playerId) {
685
- if (!this.currentLobby) {
686
- return;
687
- }
688
- this.network.sendMessage({
689
- type: 'kick-player',
690
- channel: 'system',
691
- mode: 'reliable',
692
- data: { lobbyId: this.currentLobby.id, playerId },
693
- });
694
- }
695
- // ─── Getters ───────────────────────────────────────────
696
- getCurrentLobby() {
697
- return this.currentLobby;
698
- }
699
- getAvailableLobbies() {
700
- return this.availableLobbies;
701
- }
702
- isInLobby() {
703
- return this.currentLobby !== null;
704
- }
705
- isHost() {
706
- const localPlayer = this.network.getLocalPlayer();
707
- return this.currentLobby?.host.id === localPlayer?.id;
708
- }
709
- // ─── Events ────────────────────────────────────────────
710
- on(event, callback) {
711
- this.callbacks[event] = callback;
712
- }
522
+ constructor(network) {
523
+ this.currentLobby = null;
524
+ this.availableLobbies = [];
525
+ this.callbacks = {};
526
+ this.network = network;
527
+ this.setupMessageHandlers();
528
+ }
529
+ setupMessageHandlers() {
530
+ this.network.registerMessageHandler("lobby-created", (msg) => {
531
+ const lobby = msg.data;
532
+ this.currentLobby = lobby;
533
+ this.callbacks.onLobbyCreated?.(lobby);
534
+ });
535
+ this.network.registerMessageHandler("lobby-joined", (msg) => {
536
+ const lobby = msg.data;
537
+ this.currentLobby = lobby;
538
+ this.callbacks.onLobbyJoined?.(lobby);
539
+ });
540
+ this.network.registerMessageHandler("lobby-player-joined", (msg) => {
541
+ const player = msg.data;
542
+ if (this.currentLobby) {
543
+ this.currentLobby.players.push(player);
544
+ this.callbacks.onPlayerJoined?.(player);
545
+ }
546
+ });
547
+ this.network.registerMessageHandler("lobby-player-left", (msg) => {
548
+ const { playerId } = msg.data;
549
+ if (this.currentLobby) {
550
+ const idx = this.currentLobby.players.findIndex((p) => p.id === playerId);
551
+ if (idx >= 0) {
552
+ const player = this.currentLobby.players.splice(idx, 1)[0];
553
+ this.callbacks.onPlayerLeft?.(player);
554
+ }
555
+ }
556
+ });
557
+ this.network.registerMessageHandler("lobby-list", (msg) => {
558
+ this.availableLobbies = msg.data;
559
+ });
560
+ this.network.registerMessageHandler("game-starting", () => {
561
+ if (this.currentLobby) {
562
+ this.currentLobby.state = "starting";
563
+ this.callbacks.onGameStarted?.();
564
+ }
565
+ });
566
+ }
567
+ // ─── Lobby Management ──────────────────────────────────
568
+ createLobby(config) {
569
+ this.network.sendMessage({
570
+ type: "create-lobby",
571
+ channel: "system",
572
+ mode: "reliable",
573
+ data: config
574
+ });
575
+ }
576
+ joinLobby(lobbyId, password) {
577
+ this.network.sendMessage({
578
+ type: "join-lobby",
579
+ channel: "system",
580
+ mode: "reliable",
581
+ data: { lobbyId, password }
582
+ });
583
+ }
584
+ leaveLobby() {
585
+ if (!this.currentLobby) {
586
+ return;
587
+ }
588
+ this.network.sendMessage({
589
+ type: "leave-lobby",
590
+ channel: "system",
591
+ mode: "reliable",
592
+ data: { lobbyId: this.currentLobby.id }
593
+ });
594
+ this.currentLobby = null;
595
+ this.callbacks.onLobbyLeft?.();
596
+ }
597
+ refreshLobbyList() {
598
+ this.network.sendMessage({
599
+ type: "list-lobbies",
600
+ channel: "system",
601
+ mode: "reliable",
602
+ data: {}
603
+ });
604
+ }
605
+ startGame() {
606
+ if (!this.currentLobby) {
607
+ return;
608
+ }
609
+ this.network.sendMessage({
610
+ type: "start-game",
611
+ channel: "system",
612
+ mode: "reliable",
613
+ data: { lobbyId: this.currentLobby.id }
614
+ });
615
+ }
616
+ // ─── Lobby Settings ────────────────────────────────────
617
+ updateLobbySettings(settings) {
618
+ if (!this.currentLobby) {
619
+ return;
620
+ }
621
+ this.network.sendMessage({
622
+ type: "update-lobby",
623
+ channel: "system",
624
+ mode: "reliable",
625
+ data: { lobbyId: this.currentLobby.id, settings }
626
+ });
627
+ }
628
+ kickPlayer(playerId) {
629
+ if (!this.currentLobby) {
630
+ return;
631
+ }
632
+ this.network.sendMessage({
633
+ type: "kick-player",
634
+ channel: "system",
635
+ mode: "reliable",
636
+ data: { lobbyId: this.currentLobby.id, playerId }
637
+ });
638
+ }
639
+ // ─── Getters ───────────────────────────────────────────
640
+ getCurrentLobby() {
641
+ return this.currentLobby;
642
+ }
643
+ getAvailableLobbies() {
644
+ return this.availableLobbies;
645
+ }
646
+ isInLobby() {
647
+ return this.currentLobby !== null;
648
+ }
649
+ isHost() {
650
+ const localPlayer = this.network.getLocalPlayer();
651
+ return this.currentLobby?.host.id === localPlayer?.id;
652
+ }
653
+ // ─── Events ────────────────────────────────────────────
654
+ on(event, callback) {
655
+ this.callbacks[event] = callback;
656
+ }
713
657
  }
714
658
  class MatchmakingManager {
715
- constructor(network) {
716
- this.status = {
717
- state: 'idle',
718
- playersFound: 0,
719
- playersRequired: 0,
720
- estimatedWait: 0,
721
- };
722
- this.callbacks = {};
723
- this.network = network;
724
- this.setupMessageHandlers();
725
- }
726
- setupMessageHandlers() {
727
- this.network.registerMessageHandler('matchmaking-status', (msg) => {
728
- this.status = msg.data;
729
- this.callbacks.onStatusUpdate?.(this.status);
730
- });
731
- this.network.registerMessageHandler('match-found', (msg) => {
732
- const { matchId } = msg.data;
733
- this.status.state = 'found';
734
- this.status.matchId = matchId;
735
- this.callbacks.onMatchFound?.(matchId);
736
- });
737
- this.network.registerMessageHandler('match-failed', (msg) => {
738
- const { reason } = msg.data;
739
- this.status.state = 'failed';
740
- this.callbacks.onMatchFailed?.(reason);
741
- });
742
- }
743
- startMatchmaking(criteria) {
744
- this.status = {
745
- state: 'searching',
746
- playersFound: 1,
747
- playersRequired: criteria.teamSize ?? 2,
748
- estimatedWait: 30,
749
- };
750
- this.network.sendMessage({
751
- type: 'start-matchmaking',
752
- channel: 'system',
753
- mode: 'reliable',
754
- data: criteria,
755
- });
756
- this.callbacks.onStatusUpdate?.(this.status);
757
- }
758
- cancelMatchmaking() {
759
- this.network.sendMessage({
760
- type: 'cancel-matchmaking',
761
- channel: 'system',
762
- mode: 'reliable',
763
- data: {},
764
- });
765
- this.status.state = 'idle';
766
- this.callbacks.onStatusUpdate?.(this.status);
767
- }
768
- acceptMatch() {
769
- if (!this.status.matchId) {
770
- return;
771
- }
772
- this.status.state = 'joining';
773
- this.network.sendMessage({
774
- type: 'accept-match',
775
- channel: 'system',
776
- mode: 'reliable',
777
- data: { matchId: this.status.matchId },
778
- });
779
- this.callbacks.onStatusUpdate?.(this.status);
780
- }
781
- declineMatch() {
782
- if (!this.status.matchId) {
783
- return;
784
- }
785
- this.network.sendMessage({
786
- type: 'decline-match',
787
- channel: 'system',
788
- mode: 'reliable',
789
- data: { matchId: this.status.matchId },
790
- });
791
- this.status.state = 'searching';
792
- delete this.status.matchId;
793
- this.callbacks.onStatusUpdate?.(this.status);
794
- }
795
- getStatus() {
796
- return { ...this.status };
797
- }
798
- isSearching() {
799
- return this.status.state === 'searching';
800
- }
801
- on(event, callback) {
802
- this.callbacks[event] = callback;
803
- }
659
+ constructor(network) {
660
+ this.status = {
661
+ state: "idle",
662
+ playersFound: 0,
663
+ playersRequired: 0,
664
+ estimatedWait: 0
665
+ };
666
+ this.callbacks = {};
667
+ this.network = network;
668
+ this.setupMessageHandlers();
669
+ }
670
+ setupMessageHandlers() {
671
+ this.network.registerMessageHandler("matchmaking-status", (msg) => {
672
+ this.status = msg.data;
673
+ this.callbacks.onStatusUpdate?.(this.status);
674
+ });
675
+ this.network.registerMessageHandler("match-found", (msg) => {
676
+ const { matchId } = msg.data;
677
+ this.status.state = "found";
678
+ this.status.matchId = matchId;
679
+ this.callbacks.onMatchFound?.(matchId);
680
+ });
681
+ this.network.registerMessageHandler("match-failed", (msg) => {
682
+ const { reason } = msg.data;
683
+ this.status.state = "failed";
684
+ this.callbacks.onMatchFailed?.(reason);
685
+ });
686
+ }
687
+ startMatchmaking(criteria) {
688
+ this.status = {
689
+ state: "searching",
690
+ playersFound: 1,
691
+ playersRequired: criteria.teamSize ?? 2,
692
+ estimatedWait: 30
693
+ };
694
+ this.network.sendMessage({
695
+ type: "start-matchmaking",
696
+ channel: "system",
697
+ mode: "reliable",
698
+ data: criteria
699
+ });
700
+ this.callbacks.onStatusUpdate?.(this.status);
701
+ }
702
+ cancelMatchmaking() {
703
+ this.network.sendMessage({
704
+ type: "cancel-matchmaking",
705
+ channel: "system",
706
+ mode: "reliable",
707
+ data: {}
708
+ });
709
+ this.status.state = "idle";
710
+ this.callbacks.onStatusUpdate?.(this.status);
711
+ }
712
+ acceptMatch() {
713
+ if (!this.status.matchId) {
714
+ return;
715
+ }
716
+ this.status.state = "joining";
717
+ this.network.sendMessage({
718
+ type: "accept-match",
719
+ channel: "system",
720
+ mode: "reliable",
721
+ data: { matchId: this.status.matchId }
722
+ });
723
+ this.callbacks.onStatusUpdate?.(this.status);
724
+ }
725
+ declineMatch() {
726
+ if (!this.status.matchId) {
727
+ return;
728
+ }
729
+ this.network.sendMessage({
730
+ type: "decline-match",
731
+ channel: "system",
732
+ mode: "reliable",
733
+ data: { matchId: this.status.matchId }
734
+ });
735
+ this.status.state = "searching";
736
+ delete this.status.matchId;
737
+ this.callbacks.onStatusUpdate?.(this.status);
738
+ }
739
+ getStatus() {
740
+ return { ...this.status };
741
+ }
742
+ isSearching() {
743
+ return this.status.state === "searching";
744
+ }
745
+ on(event, callback) {
746
+ this.callbacks[event] = callback;
747
+ }
804
748
  }
805
- // ============================================================
806
- // Factory Functions
807
- // ============================================================
808
749
  function createNetworkManager(config) {
809
- return new NetworkManager(config);
750
+ return new NetworkManager(config);
810
751
  }
811
752
  function createLobbyManager(network) {
812
- return new LobbyManager(network);
753
+ return new LobbyManager(network);
813
754
  }
814
755
  function createMatchmakingManager(network) {
815
- return new MatchmakingManager(network);
756
+ return new MatchmakingManager(network);
816
757
  }
817
-
818
758
  exports.LobbyManager = LobbyManager;
819
759
  exports.MatchmakingManager = MatchmakingManager;
820
760
  exports.NetworkEntity = NetworkEntity;