@nice2dev/game-engine 1.3.15 → 1.3.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (434) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/accessibility/Accessibility.js +152 -165
  3. package/dist/cjs/ai/AI.js +292 -294
  4. package/dist/cjs/ai/BehaviorTree.js +1029 -1113
  5. package/dist/cjs/ai/StateMachine.js +694 -756
  6. package/dist/cjs/animation/Animation.js +232 -241
  7. package/dist/cjs/audio/AudioAdvanced.js +221 -236
  8. package/dist/cjs/audio/AudioBridge.js +441 -435
  9. package/dist/cjs/audio/AudioManager.js +242 -259
  10. package/dist/cjs/build-cloud/BuildOrchestration.js +1059 -1098
  11. package/dist/cjs/build-cloud/GodotBuildCloud.js +641 -670
  12. package/dist/cjs/build-cloud/UnityBuildCloud.js +563 -610
  13. package/dist/cjs/build-cloud/UnrealBuildCloud.js +610 -635
  14. package/dist/cjs/core/EventBus.js +51 -56
  15. package/dist/cjs/core/GameClock.js +62 -66
  16. package/dist/cjs/core/GameConfig.js +72 -79
  17. package/dist/cjs/core/GameLoop.js +80 -89
  18. package/dist/cjs/core/ServiceLocator.js +61 -65
  19. package/dist/cjs/core/Validation.js +72 -82
  20. package/dist/cjs/core/math.js +108 -112
  21. package/dist/cjs/devtools/DevTools.js +542 -563
  22. package/dist/cjs/devtools/DeveloperExperience.js +521 -559
  23. package/dist/cjs/devtools/GameplayAnalytics.js +636 -646
  24. package/dist/cjs/dialogue/DialogueSystem.js +984 -986
  25. package/dist/cjs/docs/DocGenerator.js +339 -364
  26. package/dist/cjs/ecs/World.js +355 -371
  27. package/dist/cjs/editor/AchievementEditor.js +580 -636
  28. package/dist/cjs/editor/AdvancedEditor.js +184 -191
  29. package/dist/cjs/editor/AnimationRetargeting.js +696 -741
  30. package/dist/cjs/editor/AssetBrowser.js +1072 -1160
  31. package/dist/cjs/editor/AssetManager.js +187 -192
  32. package/dist/cjs/editor/ConsolePro.js +971 -1061
  33. package/dist/cjs/editor/CraftingEditor.js +680 -730
  34. package/dist/cjs/editor/DebugTools.js +187 -185
  35. package/dist/cjs/editor/DialogueSystem.js +844 -901
  36. package/dist/cjs/editor/LeaderboardSystem.js +429 -483
  37. package/dist/cjs/editor/NiceGameEditor.js +1903 -1201
  38. package/dist/cjs/editor/PrefabSystem.js +772 -838
  39. package/dist/cjs/editor/ProfilerPanel.js +649 -700
  40. package/dist/cjs/editor/QuestEditor.js +792 -839
  41. package/dist/cjs/editor/ReplaySystem.js +585 -634
  42. package/dist/cjs/editor/SceneEditor.js +176 -200
  43. package/dist/cjs/editor/ScreenshotMode.js +621 -688
  44. package/dist/cjs/editor/ShaderGraph.js +1556 -1582
  45. package/dist/cjs/editor/TimelineEditor.js +715 -778
  46. package/dist/cjs/editor/UndoRedoPro.js +830 -904
  47. package/dist/cjs/editor/VRARMode.js +582 -645
  48. package/dist/cjs/engine/NiceGameEngine.js +141 -164
  49. package/dist/cjs/engine/SaveSystem.js +441 -495
  50. package/dist/cjs/enterprise/Enterprise.js +254 -261
  51. package/dist/cjs/export/BevyExporter.js +927 -967
  52. package/dist/cjs/export/CocosExporter.js +644 -673
  53. package/dist/cjs/export/Construct3Exporter.js +783 -794
  54. package/dist/cjs/export/DefoldExporter.js +1028 -1069
  55. package/dist/cjs/export/GDevelopExporter.js +674 -708
  56. package/dist/cjs/export/GameMakerExporter.js +791 -805
  57. package/dist/cjs/export/GodotExporter.js +1003 -1045
  58. package/dist/cjs/export/MinecraftBedrockExporter.js +573 -578
  59. package/dist/cjs/export/MonoGameExporter.js +1265 -1293
  60. package/dist/cjs/export/Pico8Exporter.js +766 -812
  61. package/dist/cjs/export/PlatformExporter.js +188 -206
  62. package/dist/cjs/export/RPGMakerExporter.js +860 -879
  63. package/dist/cjs/export/RobloxExporter.js +883 -919
  64. package/dist/cjs/export/Solar2DExporter.js +1218 -1256
  65. package/dist/cjs/export/ThreeJSExporter.js +1006 -1073
  66. package/dist/cjs/export/Tic80Exporter.js +1210 -1267
  67. package/dist/cjs/export/UnityExporter.js +1116 -1131
  68. package/dist/cjs/export/UnrealExporter.js +889 -919
  69. package/dist/cjs/export/WebExporter.js +931 -970
  70. package/dist/cjs/export/index.js +42 -65
  71. package/dist/cjs/godot-integration/GodotAssetLibrary.js +659 -692
  72. package/dist/cjs/godot-integration/GodotImport.js +929 -1027
  73. package/dist/cjs/godot-integration/GodotLiveLink.js +915 -945
  74. package/dist/cjs/godot-integration/components/GodotProjectBrowser.js +911 -611
  75. package/dist/cjs/i18n/I18n.js +860 -900
  76. package/dist/cjs/i18n/useTranslation.js +84 -89
  77. package/dist/cjs/import/AsepriteImporter.js +658 -716
  78. package/dist/cjs/import/DragonBonesImporter.js +437 -461
  79. package/dist/cjs/import/GameMakerImporter.js +511 -521
  80. package/dist/cjs/import/GodotSceneImporter.js +788 -822
  81. package/dist/cjs/import/LDtkImporter.js +436 -454
  82. package/dist/cjs/import/Live2DImporter.js +497 -518
  83. package/dist/cjs/import/NdgFormat.js +424 -457
  84. package/dist/cjs/import/OgmoImporter.js +466 -493
  85. package/dist/cjs/import/RPGMakerImporter.js +451 -477
  86. package/dist/cjs/import/SceneImporter.js +378 -423
  87. package/dist/cjs/import/SpineImporter.js +511 -546
  88. package/dist/cjs/import/SpriterImporter.js +590 -613
  89. package/dist/cjs/import/TiledMapImporter.js +811 -846
  90. package/dist/cjs/import/UnitySceneImporter.js +687 -703
  91. package/dist/cjs/import/index.js +206 -251
  92. package/dist/cjs/index.js +275 -278
  93. package/dist/cjs/input/GamepadNavigation.js +185 -205
  94. package/dist/cjs/input/InputManager.js +397 -421
  95. package/dist/cjs/input/useGamepads.js +70 -81
  96. package/dist/cjs/integration/IconSprite.js +129 -256
  97. package/dist/cjs/inventory/InventorySystem.js +920 -995
  98. package/dist/cjs/kids/KidMode.js +997 -1022
  99. package/dist/cjs/kids/KidTools.js +570 -594
  100. package/dist/cjs/monetization/Monetization.js +170 -177
  101. package/dist/cjs/multiplayer/LocalMultiplayer.js +287 -287
  102. package/dist/cjs/multiplayer/MiniGameTypes.js +49 -59
  103. package/dist/cjs/native-engine/AnimationSystem.js +731 -806
  104. package/dist/cjs/native-engine/AssetPipeline.js +454 -515
  105. package/dist/cjs/native-engine/AudioEngine.js +763 -804
  106. package/dist/cjs/native-engine/InputSystem.js +1075 -1145
  107. package/dist/cjs/native-engine/NetworkingSystem.js +733 -793
  108. package/dist/cjs/native-engine/PhysicsEngine.js +583 -607
  109. package/dist/cjs/native-engine/RenderingEngine.js +302 -350
  110. package/dist/cjs/native-engine/SceneGraph.js +769 -808
  111. package/dist/cjs/network/MultiplayerTransport.js +97 -132
  112. package/dist/cjs/network/Networking.js +549 -564
  113. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AbortController.js +21 -29
  114. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +40 -48
  115. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +35 -43
  116. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +10 -15
  117. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Errors.js +103 -135
  118. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +131 -158
  119. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +39 -53
  120. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +5 -8
  121. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +40 -48
  122. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +494 -572
  123. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +826 -953
  124. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +125 -146
  125. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +13 -23
  126. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ILogger.js +11 -25
  127. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ITransport.js +13 -24
  128. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +108 -121
  129. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Loggers.js +10 -14
  130. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +150 -185
  131. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +158 -196
  132. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +90 -105
  133. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Subject.js +30 -35
  134. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +16 -21
  135. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Utils.js +215 -248
  136. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +135 -157
  137. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +76 -85
  138. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/index.js +24 -27
  139. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +3 -4
  140. package/dist/cjs/pathfinding/Pathfinding.js +245 -263
  141. package/dist/cjs/performance/AssetStreaming.js +561 -635
  142. package/dist/cjs/performance/BenchmarkSuite.js +283 -311
  143. package/dist/cjs/performance/DeltaCompression.js +467 -526
  144. package/dist/cjs/performance/DeterministicPhysics.js +450 -498
  145. package/dist/cjs/performance/ECSOptimization.js +644 -695
  146. package/dist/cjs/performance/GameSaveSystem.js +509 -556
  147. package/dist/cjs/performance/HotReload.js +447 -500
  148. package/dist/cjs/performance/InputRecording.js +511 -561
  149. package/dist/cjs/performance/InterestManagement.js +453 -500
  150. package/dist/cjs/performance/LocalizationRuntime.js +376 -423
  151. package/dist/cjs/performance/MemoryManagement.js +410 -470
  152. package/dist/cjs/performance/ModSupport.js +445 -496
  153. package/dist/cjs/performance/MultiThreadedPhysics.js +400 -443
  154. package/dist/cjs/performance/NetworkPrediction.js +424 -482
  155. package/dist/cjs/performance/ObjectPooling.js +569 -617
  156. package/dist/cjs/performance/Performance.js +174 -190
  157. package/dist/cjs/performance/PerformanceAdvanced.js +614 -637
  158. package/dist/cjs/performance/WebGPURenderer.js +656 -683
  159. package/dist/cjs/physics/PhysicsAdvanced.js +345 -379
  160. package/dist/cjs/physics/PhysicsEngine2D.js +391 -427
  161. package/dist/cjs/plugins/PluginSDK.js +432 -466
  162. package/dist/cjs/plugins/PluginTestKit.js +307 -330
  163. package/dist/cjs/procedural/Procedural.js +243 -254
  164. package/dist/cjs/procedural/WorldBuilding.js +297 -314
  165. package/dist/cjs/quest/QuestSystem.js +975 -932
  166. package/dist/cjs/release/MobileExport.js +157 -163
  167. package/dist/cjs/release/Release.js +225 -238
  168. package/dist/cjs/rendering/Camera2D.js +121 -124
  169. package/dist/cjs/rendering/Renderer2D.js +321 -335
  170. package/dist/cjs/rendering/WebGPURenderPipeline.js +632 -651
  171. package/dist/cjs/runtime3d/Runtime3D.js +359 -378
  172. package/dist/cjs/runtime3d/SceneEditor3D.js +252 -263
  173. package/dist/cjs/scene/SceneManager.js +177 -193
  174. package/dist/cjs/scripting/GraphToAST.js +574 -547
  175. package/dist/cjs/scripting/LanguageExporter.js +254 -279
  176. package/dist/cjs/scripting/NodeGraph.js +546 -570
  177. package/dist/cjs/scripting/ScriptAST.js +31 -39
  178. package/dist/cjs/scripting/VisualScripting2.js +1016 -1065
  179. package/dist/cjs/scripting/exporters/CSharpExporter.js +464 -496
  180. package/dist/cjs/scripting/exporters/GDScriptExporter.js +390 -442
  181. package/dist/cjs/scripting/exporters/LuaExporter.js +406 -447
  182. package/dist/cjs/scripting/exporters/PythonExporter.js +484 -549
  183. package/dist/cjs/scripting/exporters/RustExporter.js +459 -512
  184. package/dist/cjs/scripting/exporters/TypeScriptExporter.js +505 -556
  185. package/dist/cjs/social/Social.js +72 -80
  186. package/dist/cjs/systems/LightingSystem.js +844 -931
  187. package/dist/cjs/systems/ParticleSystem2.js +1447 -1451
  188. package/dist/cjs/systems/PhysicsDebugSystem.js +1070 -1141
  189. package/dist/cjs/systems/TerrainSystem.js +985 -1098
  190. package/dist/cjs/templates/ActionTemplates.js +296 -309
  191. package/dist/cjs/templates/FightingTemplate.js +417 -463
  192. package/dist/cjs/templates/MetroidvaniaTemplate.js +353 -405
  193. package/dist/cjs/templates/PartyTemplates.js +190 -202
  194. package/dist/cjs/templates/PuzzleTemplates.js +245 -261
  195. package/dist/cjs/templates/RPGTemplates.js +160 -178
  196. package/dist/cjs/templates/SportsTemplates.js +237 -250
  197. package/dist/cjs/templates/StrategyTemplates.js +143 -153
  198. package/dist/cjs/templates/SurvivalTemplate.js +336 -380
  199. package/dist/cjs/templates/WaveDefense.js +499 -526
  200. package/dist/cjs/tilemap/Tilemap.js +207 -214
  201. package/dist/cjs/tutorials/TutorialBranching.js +396 -417
  202. package/dist/cjs/tutorials/TutorialEngine.js +888 -931
  203. package/dist/cjs/tutorials/TutorialOverlay.js +602 -640
  204. package/dist/cjs/tutorials/content/Tutorials_T05_T08.js +787 -809
  205. package/dist/cjs/tutorials/content/Tutorials_T09_T11.js +736 -756
  206. package/dist/cjs/tutorials/content/Tutorials_T12_T15.js +754 -778
  207. package/dist/cjs/ui/GameUI.js +295 -312
  208. package/dist/cjs/unity-integration/UnityAssetStore.js +700 -741
  209. package/dist/cjs/unity-integration/UnityImport.js +1066 -1176
  210. package/dist/cjs/unity-integration/UnityLiveLink.js +934 -981
  211. package/dist/cjs/unity-integration/components/UnityAssetStoreBrowser.js +1233 -757
  212. package/dist/cjs/unity-integration/components/UnityProjectBrowser.js +1240 -768
  213. package/dist/cjs/unreal-integration/UnrealImport.js +391 -412
  214. package/dist/cjs/unreal-integration/UnrealLiveLink.js +1102 -1137
  215. package/dist/cjs/unreal-integration/UnrealMarketplace.js +436 -473
  216. package/dist/cjs/unreal-integration/components/UnrealProjectBrowser.js +1150 -767
  217. package/dist/cjs/xr/ARVR.js +167 -175
  218. package/dist/esm/accessibility/Accessibility.js +160 -164
  219. package/dist/esm/ai/AI.js +310 -293
  220. package/dist/esm/ai/BehaviorTree.js +1057 -1112
  221. package/dist/esm/ai/StateMachine.js +709 -755
  222. package/dist/esm/animation/Animation.js +237 -240
  223. package/dist/esm/audio/AudioAdvanced.js +239 -235
  224. package/dist/esm/audio/AudioBridge.js +448 -434
  225. package/dist/esm/audio/AudioManager.js +243 -258
  226. package/dist/esm/build-cloud/BuildOrchestration.js +1071 -1097
  227. package/dist/esm/build-cloud/GodotBuildCloud.js +647 -669
  228. package/dist/esm/build-cloud/UnityBuildCloud.js +571 -609
  229. package/dist/esm/build-cloud/UnrealBuildCloud.js +615 -634
  230. package/dist/esm/core/EventBus.js +52 -55
  231. package/dist/esm/core/GameClock.js +63 -65
  232. package/dist/esm/core/GameConfig.js +77 -78
  233. package/dist/esm/core/GameLoop.js +81 -88
  234. package/dist/esm/core/ServiceLocator.js +63 -64
  235. package/dist/esm/core/Validation.js +82 -81
  236. package/dist/esm/core/math.js +109 -111
  237. package/dist/esm/devtools/DevTools.js +546 -562
  238. package/dist/esm/devtools/DeveloperExperience.js +535 -558
  239. package/dist/esm/devtools/GameplayAnalytics.js +647 -645
  240. package/dist/esm/dialogue/DialogueSystem.js +998 -985
  241. package/dist/esm/docs/DocGenerator.js +342 -363
  242. package/dist/esm/ecs/World.js +358 -370
  243. package/dist/esm/editor/AchievementEditor.js +584 -635
  244. package/dist/esm/editor/AdvancedEditor.js +191 -190
  245. package/dist/esm/editor/AnimationRetargeting.js +700 -740
  246. package/dist/esm/editor/AssetBrowser.js +1078 -1159
  247. package/dist/esm/editor/AssetManager.js +188 -191
  248. package/dist/esm/editor/ConsolePro.js +977 -1060
  249. package/dist/esm/editor/CraftingEditor.js +684 -729
  250. package/dist/esm/editor/DebugTools.js +194 -184
  251. package/dist/esm/editor/DialogueSystem.js +849 -900
  252. package/dist/esm/editor/LeaderboardSystem.js +433 -482
  253. package/dist/esm/editor/NiceGameEditor.js +1908 -1200
  254. package/dist/esm/editor/PrefabSystem.js +777 -837
  255. package/dist/esm/editor/ProfilerPanel.js +654 -699
  256. package/dist/esm/editor/QuestEditor.js +795 -838
  257. package/dist/esm/editor/ReplaySystem.js +591 -633
  258. package/dist/esm/editor/SceneEditor.js +189 -199
  259. package/dist/esm/editor/ScreenshotMode.js +628 -687
  260. package/dist/esm/editor/ShaderGraph.js +1565 -1581
  261. package/dist/esm/editor/TimelineEditor.js +733 -777
  262. package/dist/esm/editor/UndoRedoPro.js +835 -903
  263. package/dist/esm/editor/VRARMode.js +586 -644
  264. package/dist/esm/engine/NiceGameEngine.js +142 -163
  265. package/dist/esm/engine/SaveSystem.js +447 -494
  266. package/dist/esm/enterprise/Enterprise.js +265 -260
  267. package/dist/esm/export/BevyExporter.js +929 -966
  268. package/dist/esm/export/CocosExporter.js +646 -672
  269. package/dist/esm/export/Construct3Exporter.js +785 -793
  270. package/dist/esm/export/DefoldExporter.js +1030 -1068
  271. package/dist/esm/export/GDevelopExporter.js +676 -707
  272. package/dist/esm/export/GameMakerExporter.js +793 -804
  273. package/dist/esm/export/GodotExporter.js +1004 -1044
  274. package/dist/esm/export/MinecraftBedrockExporter.js +575 -577
  275. package/dist/esm/export/MonoGameExporter.js +1267 -1292
  276. package/dist/esm/export/Pico8Exporter.js +768 -811
  277. package/dist/esm/export/PlatformExporter.js +193 -205
  278. package/dist/esm/export/RPGMakerExporter.js +862 -878
  279. package/dist/esm/export/RobloxExporter.js +885 -918
  280. package/dist/esm/export/Solar2DExporter.js +1220 -1255
  281. package/dist/esm/export/ThreeJSExporter.js +1007 -1072
  282. package/dist/esm/export/Tic80Exporter.js +1212 -1266
  283. package/dist/esm/export/UnityExporter.js +1117 -1130
  284. package/dist/esm/export/UnrealExporter.js +891 -918
  285. package/dist/esm/export/WebExporter.js +933 -969
  286. package/dist/esm/export/index.js +86 -71
  287. package/dist/esm/godot-integration/GodotAssetLibrary.js +663 -691
  288. package/dist/esm/godot-integration/GodotImport.js +935 -1026
  289. package/dist/esm/godot-integration/GodotLiveLink.js +918 -944
  290. package/dist/esm/godot-integration/components/GodotProjectBrowser.js +912 -610
  291. package/dist/esm/i18n/I18n.js +871 -899
  292. package/dist/esm/i18n/useTranslation.js +88 -88
  293. package/dist/esm/import/AsepriteImporter.js +637 -715
  294. package/dist/esm/import/DragonBonesImporter.js +417 -460
  295. package/dist/esm/import/GameMakerImporter.js +491 -520
  296. package/dist/esm/import/GodotSceneImporter.js +767 -821
  297. package/dist/esm/import/LDtkImporter.js +415 -453
  298. package/dist/esm/import/Live2DImporter.js +477 -517
  299. package/dist/esm/import/NdgFormat.js +410 -456
  300. package/dist/esm/import/OgmoImporter.js +446 -492
  301. package/dist/esm/import/RPGMakerImporter.js +431 -476
  302. package/dist/esm/import/SceneImporter.js +385 -422
  303. package/dist/esm/import/SpineImporter.js +491 -545
  304. package/dist/esm/import/SpriterImporter.js +570 -612
  305. package/dist/esm/import/TiledMapImporter.js +790 -845
  306. package/dist/esm/import/UnitySceneImporter.js +666 -702
  307. package/dist/esm/import/index.js +247 -258
  308. package/dist/esm/index.js +1332 -188
  309. package/dist/esm/input/GamepadNavigation.js +187 -204
  310. package/dist/esm/input/InputManager.js +401 -420
  311. package/dist/esm/input/useGamepads.js +72 -80
  312. package/dist/esm/integration/IconSprite.js +143 -255
  313. package/dist/esm/inventory/InventorySystem.js +925 -994
  314. package/dist/esm/kids/KidMode.js +1003 -1021
  315. package/dist/esm/kids/KidTools.js +573 -593
  316. package/dist/esm/monetization/Monetization.js +180 -176
  317. package/dist/esm/multiplayer/LocalMultiplayer.js +290 -286
  318. package/dist/esm/multiplayer/MiniGameTypes.js +58 -58
  319. package/dist/esm/native-engine/AnimationSystem.js +735 -805
  320. package/dist/esm/native-engine/AssetPipeline.js +456 -514
  321. package/dist/esm/native-engine/AudioEngine.js +765 -803
  322. package/dist/esm/native-engine/InputSystem.js +1079 -1144
  323. package/dist/esm/native-engine/NetworkingSystem.js +740 -792
  324. package/dist/esm/native-engine/PhysicsEngine.js +585 -606
  325. package/dist/esm/native-engine/RenderingEngine.js +304 -349
  326. package/dist/esm/native-engine/SceneGraph.js +773 -807
  327. package/dist/esm/network/MultiplayerTransport.js +99 -131
  328. package/dist/esm/network/Networking.js +556 -563
  329. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AbortController.js +22 -28
  330. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +41 -47
  331. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +36 -42
  332. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +11 -14
  333. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Errors.js +111 -134
  334. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +132 -157
  335. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +40 -52
  336. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +6 -7
  337. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +42 -47
  338. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +496 -571
  339. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +828 -952
  340. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +126 -145
  341. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +14 -23
  342. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ILogger.js +12 -25
  343. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ITransport.js +15 -24
  344. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +109 -120
  345. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Loggers.js +11 -13
  346. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +151 -184
  347. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +159 -195
  348. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +91 -104
  349. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Subject.js +31 -34
  350. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +17 -20
  351. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Utils.js +230 -248
  352. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +136 -156
  353. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +77 -84
  354. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/index.js +31 -12
  355. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +4 -3
  356. package/dist/esm/pathfinding/Pathfinding.js +249 -262
  357. package/dist/esm/performance/AssetStreaming.js +567 -634
  358. package/dist/esm/performance/BenchmarkSuite.js +285 -310
  359. package/dist/esm/performance/DeltaCompression.js +478 -525
  360. package/dist/esm/performance/DeterministicPhysics.js +479 -497
  361. package/dist/esm/performance/ECSOptimization.js +653 -694
  362. package/dist/esm/performance/GameSaveSystem.js +515 -555
  363. package/dist/esm/performance/HotReload.js +454 -499
  364. package/dist/esm/performance/InputRecording.js +520 -560
  365. package/dist/esm/performance/InterestManagement.js +460 -499
  366. package/dist/esm/performance/LocalizationRuntime.js +382 -422
  367. package/dist/esm/performance/MemoryManagement.js +415 -469
  368. package/dist/esm/performance/ModSupport.js +455 -495
  369. package/dist/esm/performance/MultiThreadedPhysics.js +408 -442
  370. package/dist/esm/performance/NetworkPrediction.js +436 -481
  371. package/dist/esm/performance/ObjectPooling.js +582 -616
  372. package/dist/esm/performance/Performance.js +182 -189
  373. package/dist/esm/performance/PerformanceAdvanced.js +621 -636
  374. package/dist/esm/performance/WebGPURenderer.js +660 -682
  375. package/dist/esm/physics/PhysicsAdvanced.js +359 -378
  376. package/dist/esm/physics/PhysicsEngine2D.js +393 -426
  377. package/dist/esm/plugins/PluginSDK.js +435 -465
  378. package/dist/esm/plugins/PluginTestKit.js +315 -329
  379. package/dist/esm/procedural/Procedural.js +248 -253
  380. package/dist/esm/procedural/WorldBuilding.js +316 -313
  381. package/dist/esm/quest/QuestSystem.js +982 -931
  382. package/dist/esm/release/MobileExport.js +163 -162
  383. package/dist/esm/release/Release.js +234 -237
  384. package/dist/esm/rendering/Camera2D.js +122 -123
  385. package/dist/esm/rendering/Renderer2D.js +323 -334
  386. package/dist/esm/rendering/WebGPURenderPipeline.js +647 -650
  387. package/dist/esm/runtime3d/Runtime3D.js +368 -377
  388. package/dist/esm/runtime3d/SceneEditor3D.js +268 -262
  389. package/dist/esm/scene/SceneManager.js +178 -192
  390. package/dist/esm/scripting/GraphToAST.js +576 -546
  391. package/dist/esm/scripting/LanguageExporter.js +263 -278
  392. package/dist/esm/scripting/NodeGraph.js +550 -569
  393. package/dist/esm/scripting/ScriptAST.js +45 -38
  394. package/dist/esm/scripting/VisualScripting2.js +1025 -1064
  395. package/dist/esm/scripting/exporters/CSharpExporter.js +465 -495
  396. package/dist/esm/scripting/exporters/GDScriptExporter.js +391 -441
  397. package/dist/esm/scripting/exporters/LuaExporter.js +407 -446
  398. package/dist/esm/scripting/exporters/PythonExporter.js +485 -548
  399. package/dist/esm/scripting/exporters/RustExporter.js +460 -511
  400. package/dist/esm/scripting/exporters/TypeScriptExporter.js +506 -555
  401. package/dist/esm/social/Social.js +77 -79
  402. package/dist/esm/systems/LightingSystem.js +855 -930
  403. package/dist/esm/systems/ParticleSystem2.js +1453 -1450
  404. package/dist/esm/systems/PhysicsDebugSystem.js +1078 -1140
  405. package/dist/esm/systems/TerrainSystem.js +996 -1097
  406. package/dist/esm/templates/ActionTemplates.js +307 -308
  407. package/dist/esm/templates/FightingTemplate.js +439 -462
  408. package/dist/esm/templates/MetroidvaniaTemplate.js +391 -404
  409. package/dist/esm/templates/PartyTemplates.js +206 -201
  410. package/dist/esm/templates/PuzzleTemplates.js +260 -260
  411. package/dist/esm/templates/RPGTemplates.js +172 -177
  412. package/dist/esm/templates/SportsTemplates.js +251 -249
  413. package/dist/esm/templates/StrategyTemplates.js +158 -152
  414. package/dist/esm/templates/SurvivalTemplate.js +367 -379
  415. package/dist/esm/templates/WaveDefense.js +501 -525
  416. package/dist/esm/tilemap/Tilemap.js +209 -213
  417. package/dist/esm/tutorials/TutorialBranching.js +399 -416
  418. package/dist/esm/tutorials/TutorialEngine.js +893 -930
  419. package/dist/esm/tutorials/TutorialOverlay.js +603 -639
  420. package/dist/esm/tutorials/content/Tutorials_T05_T08.js +792 -808
  421. package/dist/esm/tutorials/content/Tutorials_T09_T11.js +740 -755
  422. package/dist/esm/tutorials/content/Tutorials_T12_T15.js +759 -777
  423. package/dist/esm/ui/GameUI.js +296 -311
  424. package/dist/esm/unity-integration/UnityAssetStore.js +704 -740
  425. package/dist/esm/unity-integration/UnityImport.js +1071 -1175
  426. package/dist/esm/unity-integration/UnityLiveLink.js +938 -980
  427. package/dist/esm/unity-integration/components/UnityAssetStoreBrowser.js +1234 -756
  428. package/dist/esm/unity-integration/components/UnityProjectBrowser.js +1241 -767
  429. package/dist/esm/unreal-integration/UnrealImport.js +395 -411
  430. package/dist/esm/unreal-integration/UnrealLiveLink.js +1105 -1136
  431. package/dist/esm/unreal-integration/UnrealMarketplace.js +442 -472
  432. package/dist/esm/unreal-integration/components/UnrealProjectBrowser.js +1151 -766
  433. package/dist/esm/xr/ARVR.js +181 -174
  434. package/package.json +7 -12
@@ -1,1176 +1,1111 @@
1
- /**
2
- * @file InputSystem.ts
3
- * @description Input & UI System for Nice2Dev Game Engine
4
- * PRO-1.11.5: Input & UI System
5
- *
6
- * Features:
7
- * - Keyboard, Mouse, Gamepad, Touch input
8
- * - Input mapping and actions
9
- * - Input rebinding
10
- * - In-game UI system
11
- * - Immediate mode GUI (IMGUI-style)
12
- */
13
- // ============================================================
14
- // Input System
15
- // ============================================================
16
1
  class InputSystem {
17
- constructor() {
18
- this.canvas = null;
19
- this.inputMaps = new Map();
20
- this.activeInputMaps = new Set();
21
- this.gamepads = new Map();
22
- this.actionCallbacks = new Map();
23
- this.keyboard = new KeyboardStateImpl();
24
- this.mouse = new MouseStateImpl();
25
- this.touch = new TouchStateImpl();
26
- }
27
- // ─── Initialization ────────────────────────────────────
28
- initialize(canvas) {
29
- this.canvas = canvas;
30
- // Keyboard events
31
- window.addEventListener('keydown', this.handleKeyDown.bind(this));
32
- window.addEventListener('keyup', this.handleKeyUp.bind(this));
33
- // Mouse events
34
- canvas.addEventListener('mousemove', this.handleMouseMove.bind(this));
35
- canvas.addEventListener('mousedown', this.handleMouseDown.bind(this));
36
- canvas.addEventListener('mouseup', this.handleMouseUp.bind(this));
37
- canvas.addEventListener('wheel', this.handleWheel.bind(this));
38
- canvas.addEventListener('contextmenu', (e) => e.preventDefault());
39
- // Pointer lock
40
- document.addEventListener('pointerlockchange', this.handlePointerLockChange.bind(this));
41
- // Gamepad events
42
- window.addEventListener('gamepadconnected', this.handleGamepadConnected.bind(this));
43
- window.addEventListener('gamepaddisconnected', this.handleGamepadDisconnected.bind(this));
44
- // Touch events
45
- canvas.addEventListener('touchstart', this.handleTouchStart.bind(this));
46
- canvas.addEventListener('touchmove', this.handleTouchMove.bind(this));
47
- canvas.addEventListener('touchend', this.handleTouchEnd.bind(this));
48
- canvas.addEventListener('touchcancel', this.handleTouchCancel.bind(this));
49
- }
50
- dispose() {
51
- // Remove all event listeners
52
- if (this.canvas) ;
53
- }
54
- // ─── Input Maps ────────────────────────────────────────
55
- createInputMap(name, actions) {
56
- const map = new InputMapImpl(name, actions);
57
- this.inputMaps.set(name, map);
58
- return map;
59
- }
60
- getInputMap(name) {
61
- return this.inputMaps.get(name);
62
- }
63
- enableInputMap(name) {
64
- const map = this.inputMaps.get(name);
65
- if (map) {
66
- map.enabled = true;
67
- this.activeInputMaps.add(name);
2
+ constructor() {
3
+ this.canvas = null;
4
+ this.inputMaps = /* @__PURE__ */ new Map();
5
+ this.activeInputMaps = /* @__PURE__ */ new Set();
6
+ this.gamepads = /* @__PURE__ */ new Map();
7
+ this.actionCallbacks = /* @__PURE__ */ new Map();
8
+ this.keyboard = new KeyboardStateImpl();
9
+ this.mouse = new MouseStateImpl();
10
+ this.touch = new TouchStateImpl();
11
+ }
12
+ // ─── Initialization ────────────────────────────────────
13
+ initialize(canvas) {
14
+ this.canvas = canvas;
15
+ window.addEventListener("keydown", this.handleKeyDown.bind(this));
16
+ window.addEventListener("keyup", this.handleKeyUp.bind(this));
17
+ canvas.addEventListener("mousemove", this.handleMouseMove.bind(this));
18
+ canvas.addEventListener("mousedown", this.handleMouseDown.bind(this));
19
+ canvas.addEventListener("mouseup", this.handleMouseUp.bind(this));
20
+ canvas.addEventListener("wheel", this.handleWheel.bind(this));
21
+ canvas.addEventListener("contextmenu", (e) => e.preventDefault());
22
+ document.addEventListener("pointerlockchange", this.handlePointerLockChange.bind(this));
23
+ window.addEventListener("gamepadconnected", this.handleGamepadConnected.bind(this));
24
+ window.addEventListener("gamepaddisconnected", this.handleGamepadDisconnected.bind(this));
25
+ canvas.addEventListener("touchstart", this.handleTouchStart.bind(this));
26
+ canvas.addEventListener("touchmove", this.handleTouchMove.bind(this));
27
+ canvas.addEventListener("touchend", this.handleTouchEnd.bind(this));
28
+ canvas.addEventListener("touchcancel", this.handleTouchCancel.bind(this));
29
+ }
30
+ dispose() {
31
+ if (this.canvas) ;
32
+ }
33
+ // ─── Input Maps ────────────────────────────────────────
34
+ createInputMap(name, actions) {
35
+ const map = new InputMapImpl(name, actions);
36
+ this.inputMaps.set(name, map);
37
+ return map;
38
+ }
39
+ getInputMap(name) {
40
+ return this.inputMaps.get(name);
41
+ }
42
+ enableInputMap(name) {
43
+ const map = this.inputMaps.get(name);
44
+ if (map) {
45
+ map.enabled = true;
46
+ this.activeInputMaps.add(name);
47
+ }
48
+ }
49
+ disableInputMap(name) {
50
+ const map = this.inputMaps.get(name);
51
+ if (map) {
52
+ map.enabled = false;
53
+ this.activeInputMaps.delete(name);
54
+ }
55
+ }
56
+ // ─── Action Values ─────────────────────────────────────
57
+ getActionValue(actionName) {
58
+ let value = 0;
59
+ for (const mapName of this.activeInputMaps) {
60
+ const map = this.inputMaps.get(mapName);
61
+ if (!map?.enabled) {
62
+ continue;
63
+ }
64
+ const action = map.actions.find((a) => a.name === actionName);
65
+ if (!action) {
66
+ continue;
67
+ }
68
+ value = Math.max(value, this.evaluateAction(action));
69
+ }
70
+ return value;
71
+ }
72
+ getActionVector2(actionName) {
73
+ let x = 0;
74
+ let y = 0;
75
+ for (const mapName of this.activeInputMaps) {
76
+ const map = this.inputMaps.get(mapName);
77
+ if (!map?.enabled) {
78
+ continue;
79
+ }
80
+ const action = map.actions.find((a) => a.name === actionName);
81
+ if (!action) {
82
+ continue;
83
+ }
84
+ const vec = this.evaluateActionVector2(action);
85
+ x += vec.x;
86
+ y += vec.y;
87
+ }
88
+ const mag = Math.sqrt(x * x + y * y);
89
+ if (mag > 1) {
90
+ x /= mag;
91
+ y /= mag;
92
+ }
93
+ return { x, y };
94
+ }
95
+ isActionPressed(actionName) {
96
+ return this.getActionValue(actionName) > 0.5;
97
+ }
98
+ wasActionJustPressed(actionName) {
99
+ for (const mapName of this.activeInputMaps) {
100
+ const map = this.inputMaps.get(mapName);
101
+ if (!map?.enabled) {
102
+ continue;
103
+ }
104
+ const action = map.actions.find((a) => a.name === actionName);
105
+ if (!action) {
106
+ continue;
107
+ }
108
+ for (const binding of action.bindings) {
109
+ if (this.wasBindingJustPressed(binding)) {
110
+ return true;
68
111
  }
69
- }
70
- disableInputMap(name) {
71
- const map = this.inputMaps.get(name);
72
- if (map) {
73
- map.enabled = false;
74
- this.activeInputMaps.delete(name);
112
+ }
113
+ }
114
+ return false;
115
+ }
116
+ wasActionJustReleased(actionName) {
117
+ for (const mapName of this.activeInputMaps) {
118
+ const map = this.inputMaps.get(mapName);
119
+ if (!map?.enabled) {
120
+ continue;
121
+ }
122
+ const action = map.actions.find((a) => a.name === actionName);
123
+ if (!action) {
124
+ continue;
125
+ }
126
+ for (const binding of action.bindings) {
127
+ if (this.wasBindingJustReleased(binding)) {
128
+ return true;
75
129
  }
76
- }
77
- // ─── Action Values ─────────────────────────────────────
78
- getActionValue(actionName) {
79
- let value = 0;
80
- for (const mapName of this.activeInputMaps) {
81
- const map = this.inputMaps.get(mapName);
82
- if (!map?.enabled) {
83
- continue;
84
- }
85
- const action = map.actions.find((a) => a.name === actionName);
86
- if (!action) {
87
- continue;
88
- }
89
- value = Math.max(value, this.evaluateAction(action));
130
+ }
131
+ }
132
+ return false;
133
+ }
134
+ evaluateAction(action) {
135
+ let maxValue = 0;
136
+ for (const binding of action.bindings) {
137
+ const value = this.evaluateBinding(binding);
138
+ maxValue = Math.max(maxValue, Math.abs(value));
139
+ }
140
+ return maxValue;
141
+ }
142
+ evaluateActionVector2(action) {
143
+ let x = 0;
144
+ const y = 0;
145
+ for (const binding of action.bindings) {
146
+ const value = this.evaluateBinding(binding);
147
+ x += value;
148
+ }
149
+ return { x, y };
150
+ }
151
+ evaluateBinding(binding) {
152
+ const scale = binding.scale ?? 1;
153
+ const deadzone = binding.deadzone ?? 0.1;
154
+ let value = 0;
155
+ switch (binding.type) {
156
+ case "keyboard":
157
+ if (binding.key && this.keyboard.isKeyDown(binding.key)) {
158
+ if (this.checkModifiers(binding.modifiers)) {
159
+ value = 1;
160
+ }
90
161
  }
91
- return value;
92
- }
93
- getActionVector2(actionName) {
94
- let x = 0;
95
- let y = 0;
96
- for (const mapName of this.activeInputMaps) {
97
- const map = this.inputMaps.get(mapName);
98
- if (!map?.enabled) {
99
- continue;
100
- }
101
- const action = map.actions.find((a) => a.name === actionName);
102
- if (!action) {
103
- continue;
162
+ break;
163
+ case "mouse":
164
+ if (binding.button) {
165
+ value = this.mouse.isButtonDown(binding.button) ? 1 : 0;
166
+ }
167
+ break;
168
+ case "gamepad":
169
+ for (const [, gamepad] of this.gamepads) {
170
+ if (!gamepad.connected) {
171
+ continue;
172
+ }
173
+ if (binding.button) {
174
+ value = Math.max(value, gamepad.getButton(binding.button));
175
+ }
176
+ if (binding.axis) {
177
+ const axisValue = gamepad.getAxis(binding.axis);
178
+ if (Math.abs(axisValue) > deadzone) {
179
+ value = Math.max(value, Math.abs(axisValue));
104
180
  }
105
- const vec = this.evaluateActionVector2(action);
106
- x += vec.x;
107
- y += vec.y;
181
+ }
108
182
  }
109
- // Normalize if magnitude > 1
110
- const mag = Math.sqrt(x * x + y * y);
111
- if (mag > 1) {
112
- x /= mag;
113
- y /= mag;
183
+ break;
184
+ case "touch":
185
+ if (this.touch.activeTouches > 0) {
186
+ value = 1;
114
187
  }
115
- return { x, y };
116
- }
117
- isActionPressed(actionName) {
118
- return this.getActionValue(actionName) > 0.5;
119
- }
120
- wasActionJustPressed(actionName) {
121
- for (const mapName of this.activeInputMaps) {
122
- const map = this.inputMaps.get(mapName);
123
- if (!map?.enabled) {
124
- continue;
125
- }
126
- const action = map.actions.find((a) => a.name === actionName);
127
- if (!action) {
128
- continue;
129
- }
130
- for (const binding of action.bindings) {
131
- if (this.wasBindingJustPressed(binding)) {
132
- return true;
133
- }
134
- }
188
+ break;
189
+ }
190
+ if (binding.invert) {
191
+ value = -value;
192
+ }
193
+ return value * scale;
194
+ }
195
+ wasBindingJustPressed(binding) {
196
+ switch (binding.type) {
197
+ case "keyboard":
198
+ return binding.key ? this.keyboard.wasKeyPressed(binding.key) : false;
199
+ case "mouse":
200
+ return binding.button ? this.mouse.wasButtonPressed(binding.button) : false;
201
+ case "gamepad":
202
+ for (const [, gamepad] of this.gamepads) {
203
+ if (binding.button && gamepad.wasButtonPressed(binding.button)) {
204
+ return true;
205
+ }
135
206
  }
136
207
  return false;
137
- }
138
- wasActionJustReleased(actionName) {
139
- for (const mapName of this.activeInputMaps) {
140
- const map = this.inputMaps.get(mapName);
141
- if (!map?.enabled) {
142
- continue;
143
- }
144
- const action = map.actions.find((a) => a.name === actionName);
145
- if (!action) {
146
- continue;
147
- }
148
- for (const binding of action.bindings) {
149
- if (this.wasBindingJustReleased(binding)) {
150
- return true;
151
- }
152
- }
153
- }
208
+ default:
154
209
  return false;
155
210
  }
156
- evaluateAction(action) {
157
- let maxValue = 0;
158
- for (const binding of action.bindings) {
159
- const value = this.evaluateBinding(binding);
160
- maxValue = Math.max(maxValue, Math.abs(value));
161
- }
162
- return maxValue;
163
- }
164
- evaluateActionVector2(action) {
165
- let x = 0;
166
- const y = 0;
167
- for (const binding of action.bindings) {
168
- const value = this.evaluateBinding(binding);
169
- // Bindings should specify which component they affect
170
- // This is simplified
171
- x += value;
172
- }
173
- return { x, y };
174
- }
175
- evaluateBinding(binding) {
176
- const scale = binding.scale ?? 1;
177
- const deadzone = binding.deadzone ?? 0.1;
178
- let value = 0;
179
- switch (binding.type) {
180
- case 'keyboard':
181
- if (binding.key && this.keyboard.isKeyDown(binding.key)) {
182
- // Check modifiers
183
- if (this.checkModifiers(binding.modifiers)) {
184
- value = 1;
185
- }
186
- }
187
- break;
188
- case 'mouse':
189
- if (binding.button) {
190
- value = this.mouse.isButtonDown(binding.button) ? 1 : 0;
191
- }
192
- break;
193
- case 'gamepad':
194
- for (const [, gamepad] of this.gamepads) {
195
- if (!gamepad.connected) {
196
- continue;
197
- }
198
- if (binding.button) {
199
- value = Math.max(value, gamepad.getButton(binding.button));
200
- }
201
- if (binding.axis) {
202
- const axisValue = gamepad.getAxis(binding.axis);
203
- if (Math.abs(axisValue) > deadzone) {
204
- value = Math.max(value, Math.abs(axisValue));
205
- }
206
- }
207
- }
208
- break;
209
- case 'touch':
210
- if (this.touch.activeTouches > 0) {
211
- value = 1;
212
- }
213
- break;
214
- }
215
- if (binding.invert) {
216
- value = -value;
217
- }
218
- return value * scale;
219
- }
220
- wasBindingJustPressed(binding) {
221
- switch (binding.type) {
222
- case 'keyboard':
223
- return binding.key ? this.keyboard.wasKeyPressed(binding.key) : false;
224
- case 'mouse':
225
- return binding.button ? this.mouse.wasButtonPressed(binding.button) : false;
226
- case 'gamepad':
227
- for (const [, gamepad] of this.gamepads) {
228
- if (binding.button && gamepad.wasButtonPressed(binding.button)) {
229
- return true;
230
- }
231
- }
232
- return false;
233
- default:
234
- return false;
235
- }
236
- }
237
- wasBindingJustReleased(binding) {
238
- switch (binding.type) {
239
- case 'keyboard':
240
- return binding.key ? this.keyboard.wasKeyReleased(binding.key) : false;
241
- case 'mouse':
242
- return binding.button ? this.mouse.wasButtonReleased(binding.button) : false;
243
- case 'gamepad':
244
- for (const [, gamepad] of this.gamepads) {
245
- if (binding.button && gamepad.wasButtonReleased(binding.button)) {
246
- return true;
247
- }
248
- }
249
- return false;
250
- default:
251
- return false;
252
- }
253
- }
254
- checkModifiers(modifiers) {
255
- if (!modifiers || modifiers.length === 0) {
211
+ }
212
+ wasBindingJustReleased(binding) {
213
+ switch (binding.type) {
214
+ case "keyboard":
215
+ return binding.key ? this.keyboard.wasKeyReleased(binding.key) : false;
216
+ case "mouse":
217
+ return binding.button ? this.mouse.wasButtonReleased(binding.button) : false;
218
+ case "gamepad":
219
+ for (const [, gamepad] of this.gamepads) {
220
+ if (binding.button && gamepad.wasButtonReleased(binding.button)) {
256
221
  return true;
222
+ }
257
223
  }
258
- for (const mod of modifiers) {
259
- if (!this.keyboard.isKeyDown(mod)) {
260
- return false;
261
- }
262
- }
263
- return true;
264
- }
265
- // ─── Action Callbacks ──────────────────────────────────
266
- onAction(actionName, callback) {
267
- if (!this.actionCallbacks.has(actionName)) {
268
- this.actionCallbacks.set(actionName, []);
269
- }
270
- this.actionCallbacks.get(actionName).push(callback);
271
- }
272
- offAction(actionName, callback) {
273
- const callbacks = this.actionCallbacks.get(actionName);
274
- if (callbacks) {
275
- const idx = callbacks.indexOf(callback);
276
- if (idx >= 0) {
277
- callbacks.splice(idx, 1);
278
- }
279
- }
280
- }
281
- // ─── Direct State Access ───────────────────────────────
282
- getKeyboard() {
283
- return this.keyboard;
284
- }
285
- getMouse() {
286
- return this.mouse;
287
- }
288
- getGamepad(index) {
289
- return this.gamepads.get(index);
290
- }
291
- getGamepads() {
292
- return Array.from(this.gamepads.values());
293
- }
294
- getTouch() {
295
- return this.touch;
296
- }
297
- // ─── Mouse Lock ────────────────────────────────────────
298
- lockMouse() {
299
- this.canvas?.requestPointerLock();
300
- }
301
- unlockMouse() {
302
- document.exitPointerLock();
303
- }
304
- isMouseLocked() {
305
- return document.pointerLockElement === this.canvas;
306
- }
307
- // ─── Update ────────────────────────────────────────────
308
- update() {
309
- // Update gamepads (they need polling)
310
- this.pollGamepads();
311
- // Fire action callbacks
312
- for (const [actionName, callbacks] of this.actionCallbacks) {
313
- const value = this.getActionValue(actionName);
314
- if (value > 0) {
315
- for (const cb of callbacks) {
316
- cb(value);
317
- }
318
- }
319
- }
320
- }
321
- endFrame() {
322
- // Clear per-frame state
323
- this.keyboard.endFrame();
324
- this.mouse.endFrame();
325
- for (const gamepad of this.gamepads.values()) {
326
- gamepad.endFrame();
327
- }
328
- this.touch.endFrame();
329
- }
330
- // ─── Event Handlers ────────────────────────────────────
331
- handleKeyDown(event) {
332
- this.keyboard.handleKeyDown(event.code);
333
- }
334
- handleKeyUp(event) {
335
- this.keyboard.handleKeyUp(event.code);
336
- }
337
- handleMouseMove(event) {
338
- this.mouse.handleMouseMove(event);
339
- }
340
- handleMouseDown(event) {
341
- this.mouse.handleMouseDown(event);
342
- }
343
- handleMouseUp(event) {
344
- this.mouse.handleMouseUp(event);
345
- }
346
- handleWheel(event) {
347
- event.preventDefault();
348
- this.mouse.handleWheel(event);
349
- }
350
- handlePointerLockChange() {
351
- this.mouse.setLocked(document.pointerLockElement === this.canvas);
224
+ return false;
225
+ default:
226
+ return false;
352
227
  }
353
- handleGamepadConnected(event) {
354
- const gamepad = new GamepadStateImpl(event.gamepad);
355
- this.gamepads.set(event.gamepad.index, gamepad);
228
+ }
229
+ checkModifiers(modifiers) {
230
+ if (!modifiers || modifiers.length === 0) {
231
+ return true;
356
232
  }
357
- handleGamepadDisconnected(event) {
358
- const gamepad = this.gamepads.get(event.gamepad.index);
359
- if (gamepad) {
360
- gamepad.connected = false;
361
- }
362
- }
363
- pollGamepads() {
364
- const gamepads = navigator.getGamepads();
365
- for (const gp of gamepads) {
366
- if (!gp) {
367
- continue;
368
- }
369
- let state = this.gamepads.get(gp.index);
370
- if (!state) {
371
- state = new GamepadStateImpl(gp);
372
- this.gamepads.set(gp.index, state);
373
- }
374
- state.update(gp);
233
+ for (const mod of modifiers) {
234
+ if (!this.keyboard.isKeyDown(mod)) {
235
+ return false;
236
+ }
237
+ }
238
+ return true;
239
+ }
240
+ // ─── Action Callbacks ──────────────────────────────────
241
+ onAction(actionName, callback) {
242
+ if (!this.actionCallbacks.has(actionName)) {
243
+ this.actionCallbacks.set(actionName, []);
244
+ }
245
+ this.actionCallbacks.get(actionName).push(callback);
246
+ }
247
+ offAction(actionName, callback) {
248
+ const callbacks = this.actionCallbacks.get(actionName);
249
+ if (callbacks) {
250
+ const idx = callbacks.indexOf(callback);
251
+ if (idx >= 0) {
252
+ callbacks.splice(idx, 1);
253
+ }
254
+ }
255
+ }
256
+ // ─── Direct State Access ───────────────────────────────
257
+ getKeyboard() {
258
+ return this.keyboard;
259
+ }
260
+ getMouse() {
261
+ return this.mouse;
262
+ }
263
+ getGamepad(index) {
264
+ return this.gamepads.get(index);
265
+ }
266
+ getGamepads() {
267
+ return Array.from(this.gamepads.values());
268
+ }
269
+ getTouch() {
270
+ return this.touch;
271
+ }
272
+ // ─── Mouse Lock ────────────────────────────────────────
273
+ lockMouse() {
274
+ this.canvas?.requestPointerLock();
275
+ }
276
+ unlockMouse() {
277
+ document.exitPointerLock();
278
+ }
279
+ isMouseLocked() {
280
+ return document.pointerLockElement === this.canvas;
281
+ }
282
+ // ─── Update ────────────────────────────────────────────
283
+ update() {
284
+ this.pollGamepads();
285
+ for (const [actionName, callbacks] of this.actionCallbacks) {
286
+ const value = this.getActionValue(actionName);
287
+ if (value > 0) {
288
+ for (const cb of callbacks) {
289
+ cb(value);
375
290
  }
376
- }
377
- handleTouchStart(event) {
378
- event.preventDefault();
379
- this.touch.handleTouchStart(event);
380
- }
381
- handleTouchMove(event) {
382
- event.preventDefault();
383
- this.touch.handleTouchMove(event);
384
- }
385
- handleTouchEnd(event) {
386
- event.preventDefault();
387
- this.touch.handleTouchEnd(event);
388
- }
389
- handleTouchCancel(event) {
390
- event.preventDefault();
391
- this.touch.handleTouchCancel(event);
392
- }
291
+ }
292
+ }
293
+ }
294
+ endFrame() {
295
+ this.keyboard.endFrame();
296
+ this.mouse.endFrame();
297
+ for (const gamepad of this.gamepads.values()) {
298
+ gamepad.endFrame();
299
+ }
300
+ this.touch.endFrame();
301
+ }
302
+ // ─── Event Handlers ────────────────────────────────────
303
+ handleKeyDown(event) {
304
+ this.keyboard.handleKeyDown(event.code);
305
+ }
306
+ handleKeyUp(event) {
307
+ this.keyboard.handleKeyUp(event.code);
308
+ }
309
+ handleMouseMove(event) {
310
+ this.mouse.handleMouseMove(event);
311
+ }
312
+ handleMouseDown(event) {
313
+ this.mouse.handleMouseDown(event);
314
+ }
315
+ handleMouseUp(event) {
316
+ this.mouse.handleMouseUp(event);
317
+ }
318
+ handleWheel(event) {
319
+ event.preventDefault();
320
+ this.mouse.handleWheel(event);
321
+ }
322
+ handlePointerLockChange() {
323
+ this.mouse.setLocked(document.pointerLockElement === this.canvas);
324
+ }
325
+ handleGamepadConnected(event) {
326
+ const gamepad = new GamepadStateImpl(event.gamepad);
327
+ this.gamepads.set(event.gamepad.index, gamepad);
328
+ }
329
+ handleGamepadDisconnected(event) {
330
+ const gamepad = this.gamepads.get(event.gamepad.index);
331
+ if (gamepad) {
332
+ gamepad.connected = false;
333
+ }
334
+ }
335
+ pollGamepads() {
336
+ const gamepads = navigator.getGamepads();
337
+ for (const gp of gamepads) {
338
+ if (!gp) {
339
+ continue;
340
+ }
341
+ let state = this.gamepads.get(gp.index);
342
+ if (!state) {
343
+ state = new GamepadStateImpl(gp);
344
+ this.gamepads.set(gp.index, state);
345
+ }
346
+ state.update(gp);
347
+ }
348
+ }
349
+ handleTouchStart(event) {
350
+ event.preventDefault();
351
+ this.touch.handleTouchStart(event);
352
+ }
353
+ handleTouchMove(event) {
354
+ event.preventDefault();
355
+ this.touch.handleTouchMove(event);
356
+ }
357
+ handleTouchEnd(event) {
358
+ event.preventDefault();
359
+ this.touch.handleTouchEnd(event);
360
+ }
361
+ handleTouchCancel(event) {
362
+ event.preventDefault();
363
+ this.touch.handleTouchCancel(event);
364
+ }
393
365
  }
394
- // ============================================================
395
- // Internal Implementations
396
- // ============================================================
397
366
  class KeyboardStateImpl {
398
- constructor() {
399
- this.keysDown = new Set();
400
- this.keysPressed = new Set();
401
- this.keysReleased = new Set();
402
- }
403
- isKeyDown(key) {
404
- return this.keysDown.has(key);
405
- }
406
- isKeyUp(key) {
407
- return !this.keysDown.has(key);
408
- }
409
- wasKeyPressed(key) {
410
- return this.keysPressed.has(key);
411
- }
412
- wasKeyReleased(key) {
413
- return this.keysReleased.has(key);
414
- }
415
- getKeysDown() {
416
- return Array.from(this.keysDown);
417
- }
418
- handleKeyDown(code) {
419
- if (!this.keysDown.has(code)) {
420
- this.keysPressed.add(code);
421
- }
422
- this.keysDown.add(code);
423
- }
424
- handleKeyUp(code) {
425
- this.keysDown.delete(code);
426
- this.keysReleased.add(code);
427
- }
428
- endFrame() {
429
- this.keysPressed.clear();
430
- this.keysReleased.clear();
431
- }
367
+ constructor() {
368
+ this.keysDown = /* @__PURE__ */ new Set();
369
+ this.keysPressed = /* @__PURE__ */ new Set();
370
+ this.keysReleased = /* @__PURE__ */ new Set();
371
+ }
372
+ isKeyDown(key) {
373
+ return this.keysDown.has(key);
374
+ }
375
+ isKeyUp(key) {
376
+ return !this.keysDown.has(key);
377
+ }
378
+ wasKeyPressed(key) {
379
+ return this.keysPressed.has(key);
380
+ }
381
+ wasKeyReleased(key) {
382
+ return this.keysReleased.has(key);
383
+ }
384
+ getKeysDown() {
385
+ return Array.from(this.keysDown);
386
+ }
387
+ handleKeyDown(code) {
388
+ if (!this.keysDown.has(code)) {
389
+ this.keysPressed.add(code);
390
+ }
391
+ this.keysDown.add(code);
392
+ }
393
+ handleKeyUp(code) {
394
+ this.keysDown.delete(code);
395
+ this.keysReleased.add(code);
396
+ }
397
+ endFrame() {
398
+ this.keysPressed.clear();
399
+ this.keysReleased.clear();
400
+ }
432
401
  }
433
402
  class MouseStateImpl {
434
- constructor() {
435
- this.position = { x: 0, y: 0 };
436
- this.delta = { x: 0, y: 0 };
437
- this.scroll = { x: 0, y: 0 };
438
- this.buttonsDown = new Set();
439
- this.buttonsPressed = new Set();
440
- this.buttonsReleased = new Set();
441
- this.locked = false;
442
- }
443
- isButtonDown(button) {
444
- return this.buttonsDown.has(button);
445
- }
446
- isButtonUp(button) {
447
- return !this.buttonsDown.has(button);
448
- }
449
- wasButtonPressed(button) {
450
- return this.buttonsPressed.has(button);
451
- }
452
- wasButtonReleased(button) {
453
- return this.buttonsReleased.has(button);
454
- }
455
- isLocked() {
456
- return this.locked;
457
- }
458
- setLocked(locked) {
459
- this.locked = locked;
460
- }
461
- handleMouseMove(event) {
462
- if (this.locked) {
463
- this.delta.x += event.movementX;
464
- this.delta.y += event.movementY;
465
- }
466
- else {
467
- this.delta.x = event.clientX - this.position.x;
468
- this.delta.y = event.clientY - this.position.y;
469
- this.position.x = event.clientX;
470
- this.position.y = event.clientY;
471
- }
472
- }
473
- handleMouseDown(event) {
474
- const button = this.mapButton(event.button);
475
- if (!this.buttonsDown.has(button)) {
476
- this.buttonsPressed.add(button);
477
- }
478
- this.buttonsDown.add(button);
479
- }
480
- handleMouseUp(event) {
481
- const button = this.mapButton(event.button);
482
- this.buttonsDown.delete(button);
483
- this.buttonsReleased.add(button);
484
- }
485
- handleWheel(event) {
486
- this.scroll.x += event.deltaX;
487
- this.scroll.y += event.deltaY;
488
- }
489
- mapButton(button) {
490
- switch (button) {
491
- case 0:
492
- return 'left';
493
- case 1:
494
- return 'middle';
495
- case 2:
496
- return 'right';
497
- case 3:
498
- return 'back';
499
- case 4:
500
- return 'forward';
501
- default:
502
- return 'left';
503
- }
504
- }
505
- endFrame() {
506
- this.delta.x = 0;
507
- this.delta.y = 0;
508
- this.scroll.x = 0;
509
- this.scroll.y = 0;
510
- this.buttonsPressed.clear();
511
- this.buttonsReleased.clear();
512
- }
513
- }
514
- class GamepadStateImpl {
515
- constructor(gamepad) {
516
- this.connected = true;
517
- this.buttons = new Map();
518
- this.axes = new Map();
519
- this.prevButtons = new Map();
520
- this.prevAxes = new Map();
521
- this.index = gamepad.index;
522
- this.id = gamepad.id;
523
- this.update(gamepad);
524
- }
525
- update(gamepad) {
526
- // Store previous state
527
- this.prevButtons = new Map(this.buttons);
528
- this.prevAxes = new Map(this.axes);
529
- // Update buttons
530
- for (let i = 0; i < gamepad.buttons.length && i < GamepadStateImpl.BUTTON_MAP.length; i++) {
531
- this.buttons.set(GamepadStateImpl.BUTTON_MAP[i], gamepad.buttons[i].value);
532
- }
533
- // Update axes
534
- for (let i = 0; i < gamepad.axes.length && i < GamepadStateImpl.AXIS_MAP.length; i++) {
535
- this.axes.set(GamepadStateImpl.AXIS_MAP[i], gamepad.axes[i]);
536
- }
537
- }
538
- getButton(button) {
539
- return this.buttons.get(button) ?? 0;
540
- }
541
- isButtonDown(button, threshold = 0.5) {
542
- return (this.buttons.get(button) ?? 0) > threshold;
543
- }
544
- wasButtonPressed(button, threshold = 0.5) {
545
- const current = this.buttons.get(button) ?? 0;
546
- const previous = this.prevButtons.get(button) ?? 0;
547
- return current > threshold && previous <= threshold;
548
- }
549
- wasButtonReleased(button, threshold = 0.5) {
550
- const current = this.buttons.get(button) ?? 0;
551
- const previous = this.prevButtons.get(button) ?? 0;
552
- return current <= threshold && previous > threshold;
553
- }
554
- getAxis(axis) {
555
- return this.axes.get(axis) ?? 0;
556
- }
557
- getLeftStick() {
558
- return {
559
- x: this.axes.get('left-x') ?? 0,
560
- y: this.axes.get('left-y') ?? 0,
561
- };
562
- }
563
- getRightStick() {
564
- return {
565
- x: this.axes.get('right-x') ?? 0,
566
- y: this.axes.get('right-y') ?? 0,
567
- };
568
- }
569
- setVibration(lowFrequency, highFrequency, duration) {
570
- const gamepads = navigator.getGamepads();
571
- const gamepad = gamepads[this.index];
572
- if (gamepad?.vibrationActuator) {
573
- gamepad.vibrationActuator.playEffect('dual-rumble', {
574
- duration,
575
- strongMagnitude: lowFrequency,
576
- weakMagnitude: highFrequency,
577
- });
578
- }
579
- }
580
- endFrame() {
581
- // Nothing to clear for gamepad
582
- }
403
+ constructor() {
404
+ this.position = { x: 0, y: 0 };
405
+ this.delta = { x: 0, y: 0 };
406
+ this.scroll = { x: 0, y: 0 };
407
+ this.buttonsDown = /* @__PURE__ */ new Set();
408
+ this.buttonsPressed = /* @__PURE__ */ new Set();
409
+ this.buttonsReleased = /* @__PURE__ */ new Set();
410
+ this.locked = false;
411
+ }
412
+ isButtonDown(button) {
413
+ return this.buttonsDown.has(button);
414
+ }
415
+ isButtonUp(button) {
416
+ return !this.buttonsDown.has(button);
417
+ }
418
+ wasButtonPressed(button) {
419
+ return this.buttonsPressed.has(button);
420
+ }
421
+ wasButtonReleased(button) {
422
+ return this.buttonsReleased.has(button);
423
+ }
424
+ isLocked() {
425
+ return this.locked;
426
+ }
427
+ setLocked(locked) {
428
+ this.locked = locked;
429
+ }
430
+ handleMouseMove(event) {
431
+ if (this.locked) {
432
+ this.delta.x += event.movementX;
433
+ this.delta.y += event.movementY;
434
+ } else {
435
+ this.delta.x = event.clientX - this.position.x;
436
+ this.delta.y = event.clientY - this.position.y;
437
+ this.position.x = event.clientX;
438
+ this.position.y = event.clientY;
439
+ }
440
+ }
441
+ handleMouseDown(event) {
442
+ const button = this.mapButton(event.button);
443
+ if (!this.buttonsDown.has(button)) {
444
+ this.buttonsPressed.add(button);
445
+ }
446
+ this.buttonsDown.add(button);
447
+ }
448
+ handleMouseUp(event) {
449
+ const button = this.mapButton(event.button);
450
+ this.buttonsDown.delete(button);
451
+ this.buttonsReleased.add(button);
452
+ }
453
+ handleWheel(event) {
454
+ this.scroll.x += event.deltaX;
455
+ this.scroll.y += event.deltaY;
456
+ }
457
+ mapButton(button) {
458
+ switch (button) {
459
+ case 0:
460
+ return "left";
461
+ case 1:
462
+ return "middle";
463
+ case 2:
464
+ return "right";
465
+ case 3:
466
+ return "back";
467
+ case 4:
468
+ return "forward";
469
+ default:
470
+ return "left";
471
+ }
472
+ }
473
+ endFrame() {
474
+ this.delta.x = 0;
475
+ this.delta.y = 0;
476
+ this.scroll.x = 0;
477
+ this.scroll.y = 0;
478
+ this.buttonsPressed.clear();
479
+ this.buttonsReleased.clear();
480
+ }
583
481
  }
584
- GamepadStateImpl.BUTTON_MAP = [
585
- 'a',
586
- 'b',
587
- 'x',
588
- 'y',
589
- 'lb',
590
- 'rb',
591
- 'lt',
592
- 'rt',
593
- 'back',
594
- 'start',
595
- 'ls',
596
- 'rs',
597
- 'dpad-up',
598
- 'dpad-down',
599
- 'dpad-left',
600
- 'dpad-right',
482
+ const _GamepadStateImpl = class _GamepadStateImpl {
483
+ constructor(gamepad) {
484
+ this.connected = true;
485
+ this.buttons = /* @__PURE__ */ new Map();
486
+ this.axes = /* @__PURE__ */ new Map();
487
+ this.prevButtons = /* @__PURE__ */ new Map();
488
+ this.prevAxes = /* @__PURE__ */ new Map();
489
+ this.index = gamepad.index;
490
+ this.id = gamepad.id;
491
+ this.update(gamepad);
492
+ }
493
+ update(gamepad) {
494
+ this.prevButtons = new Map(this.buttons);
495
+ this.prevAxes = new Map(this.axes);
496
+ for (let i = 0; i < gamepad.buttons.length && i < _GamepadStateImpl.BUTTON_MAP.length; i++) {
497
+ this.buttons.set(_GamepadStateImpl.BUTTON_MAP[i], gamepad.buttons[i].value);
498
+ }
499
+ for (let i = 0; i < gamepad.axes.length && i < _GamepadStateImpl.AXIS_MAP.length; i++) {
500
+ this.axes.set(_GamepadStateImpl.AXIS_MAP[i], gamepad.axes[i]);
501
+ }
502
+ }
503
+ getButton(button) {
504
+ return this.buttons.get(button) ?? 0;
505
+ }
506
+ isButtonDown(button, threshold = 0.5) {
507
+ return (this.buttons.get(button) ?? 0) > threshold;
508
+ }
509
+ wasButtonPressed(button, threshold = 0.5) {
510
+ const current = this.buttons.get(button) ?? 0;
511
+ const previous = this.prevButtons.get(button) ?? 0;
512
+ return current > threshold && previous <= threshold;
513
+ }
514
+ wasButtonReleased(button, threshold = 0.5) {
515
+ const current = this.buttons.get(button) ?? 0;
516
+ const previous = this.prevButtons.get(button) ?? 0;
517
+ return current <= threshold && previous > threshold;
518
+ }
519
+ getAxis(axis) {
520
+ return this.axes.get(axis) ?? 0;
521
+ }
522
+ getLeftStick() {
523
+ return {
524
+ x: this.axes.get("left-x") ?? 0,
525
+ y: this.axes.get("left-y") ?? 0
526
+ };
527
+ }
528
+ getRightStick() {
529
+ return {
530
+ x: this.axes.get("right-x") ?? 0,
531
+ y: this.axes.get("right-y") ?? 0
532
+ };
533
+ }
534
+ setVibration(lowFrequency, highFrequency, duration) {
535
+ const gamepads = navigator.getGamepads();
536
+ const gamepad = gamepads[this.index];
537
+ if (gamepad?.vibrationActuator) {
538
+ gamepad.vibrationActuator.playEffect("dual-rumble", {
539
+ duration,
540
+ strongMagnitude: lowFrequency,
541
+ weakMagnitude: highFrequency
542
+ });
543
+ }
544
+ }
545
+ endFrame() {
546
+ }
547
+ };
548
+ _GamepadStateImpl.BUTTON_MAP = [
549
+ "a",
550
+ "b",
551
+ "x",
552
+ "y",
553
+ "lb",
554
+ "rb",
555
+ "lt",
556
+ "rt",
557
+ "back",
558
+ "start",
559
+ "ls",
560
+ "rs",
561
+ "dpad-up",
562
+ "dpad-down",
563
+ "dpad-left",
564
+ "dpad-right"
601
565
  ];
602
- GamepadStateImpl.AXIS_MAP = ['left-x', 'left-y', 'right-x', 'right-y'];
566
+ _GamepadStateImpl.AXIS_MAP = ["left-x", "left-y", "right-x", "right-y"];
567
+ let GamepadStateImpl = _GamepadStateImpl;
603
568
  class TouchStateImpl {
604
- constructor() {
605
- this.touches = [];
606
- this.activeTouches = 0;
607
- this.touchMap = new Map();
608
- }
609
- handleTouchStart(event) {
610
- for (let i = 0; i < event.changedTouches.length; i++) {
611
- const t = event.changedTouches[i];
612
- const touch = {
613
- id: t.identifier,
614
- position: { x: t.clientX, y: t.clientY },
615
- startPosition: { x: t.clientX, y: t.clientY },
616
- delta: { x: 0, y: 0 },
617
- pressure: t.force,
618
- phase: 'began',
619
- };
620
- this.touchMap.set(t.identifier, touch);
621
- }
622
- this.updateTouchList();
623
- }
624
- handleTouchMove(event) {
625
- for (let i = 0; i < event.changedTouches.length; i++) {
626
- const t = event.changedTouches[i];
627
- const touch = this.touchMap.get(t.identifier);
628
- if (touch) {
629
- touch.delta.x = t.clientX - touch.position.x;
630
- touch.delta.y = t.clientY - touch.position.y;
631
- touch.position.x = t.clientX;
632
- touch.position.y = t.clientY;
633
- touch.pressure = t.force;
634
- touch.phase = 'moved';
635
- }
636
- }
637
- }
638
- handleTouchEnd(event) {
639
- for (let i = 0; i < event.changedTouches.length; i++) {
640
- const t = event.changedTouches[i];
641
- const touch = this.touchMap.get(t.identifier);
642
- if (touch) {
643
- touch.phase = 'ended';
644
- this.touchMap.delete(t.identifier);
645
- }
646
- }
647
- this.updateTouchList();
648
- }
649
- handleTouchCancel(event) {
650
- for (let i = 0; i < event.changedTouches.length; i++) {
651
- const t = event.changedTouches[i];
652
- const touch = this.touchMap.get(t.identifier);
653
- if (touch) {
654
- touch.phase = 'cancelled';
655
- this.touchMap.delete(t.identifier);
656
- }
657
- }
658
- this.updateTouchList();
659
- }
660
- updateTouchList() {
661
- this.touches = Array.from(this.touchMap.values());
662
- this.activeTouches = this.touches.length;
663
- }
664
- endFrame() {
665
- // Mark moved touches as stationary
666
- for (const touch of this.touchMap.values()) {
667
- if (touch.phase === 'moved' || touch.phase === 'began') {
668
- touch.phase = 'stationary';
669
- }
670
- touch.delta.x = 0;
671
- touch.delta.y = 0;
672
- }
673
- }
569
+ constructor() {
570
+ this.touches = [];
571
+ this.activeTouches = 0;
572
+ this.touchMap = /* @__PURE__ */ new Map();
573
+ }
574
+ handleTouchStart(event) {
575
+ for (let i = 0; i < event.changedTouches.length; i++) {
576
+ const t = event.changedTouches[i];
577
+ const touch = {
578
+ id: t.identifier,
579
+ position: { x: t.clientX, y: t.clientY },
580
+ startPosition: { x: t.clientX, y: t.clientY },
581
+ delta: { x: 0, y: 0 },
582
+ pressure: t.force,
583
+ phase: "began"
584
+ };
585
+ this.touchMap.set(t.identifier, touch);
586
+ }
587
+ this.updateTouchList();
588
+ }
589
+ handleTouchMove(event) {
590
+ for (let i = 0; i < event.changedTouches.length; i++) {
591
+ const t = event.changedTouches[i];
592
+ const touch = this.touchMap.get(t.identifier);
593
+ if (touch) {
594
+ touch.delta.x = t.clientX - touch.position.x;
595
+ touch.delta.y = t.clientY - touch.position.y;
596
+ touch.position.x = t.clientX;
597
+ touch.position.y = t.clientY;
598
+ touch.pressure = t.force;
599
+ touch.phase = "moved";
600
+ }
601
+ }
602
+ }
603
+ handleTouchEnd(event) {
604
+ for (let i = 0; i < event.changedTouches.length; i++) {
605
+ const t = event.changedTouches[i];
606
+ const touch = this.touchMap.get(t.identifier);
607
+ if (touch) {
608
+ touch.phase = "ended";
609
+ this.touchMap.delete(t.identifier);
610
+ }
611
+ }
612
+ this.updateTouchList();
613
+ }
614
+ handleTouchCancel(event) {
615
+ for (let i = 0; i < event.changedTouches.length; i++) {
616
+ const t = event.changedTouches[i];
617
+ const touch = this.touchMap.get(t.identifier);
618
+ if (touch) {
619
+ touch.phase = "cancelled";
620
+ this.touchMap.delete(t.identifier);
621
+ }
622
+ }
623
+ this.updateTouchList();
624
+ }
625
+ updateTouchList() {
626
+ this.touches = Array.from(this.touchMap.values());
627
+ this.activeTouches = this.touches.length;
628
+ }
629
+ endFrame() {
630
+ for (const touch of this.touchMap.values()) {
631
+ if (touch.phase === "moved" || touch.phase === "began") {
632
+ touch.phase = "stationary";
633
+ }
634
+ touch.delta.x = 0;
635
+ touch.delta.y = 0;
636
+ }
637
+ }
674
638
  }
675
639
  class InputMapImpl {
676
- constructor(name, actions) {
677
- this.name = name;
678
- this.actions = actions;
679
- this.enabled = false;
680
- }
640
+ constructor(name, actions) {
641
+ this.name = name;
642
+ this.actions = actions;
643
+ this.enabled = false;
644
+ }
681
645
  }
682
646
  class UISystem {
683
- constructor(canvas) {
684
- this.stateStack = [];
685
- this.hotWidget = null;
686
- this.activeWidget = null;
687
- this.mousePos = { x: 0, y: 0 };
688
- this.mouseDown = false;
689
- this.mouseClicked = false;
690
- this.keyboardInput = '';
691
- this._isHovered = false;
692
- this.style = {
693
- windowBg: 'rgba(30, 30, 30, 0.95)',
694
- windowBorder: 'rgba(60, 60, 60, 1)',
695
- panelBg: 'rgba(40, 40, 40, 0.8)',
696
- buttonBg: 'rgba(60, 60, 60, 1)',
697
- buttonHover: 'rgba(80, 80, 80, 1)',
698
- buttonActive: 'rgba(100, 100, 100, 1)',
699
- inputBg: 'rgba(20, 20, 20, 1)',
700
- inputBorder: 'rgba(80, 80, 80, 1)',
701
- sliderBg: 'rgba(40, 40, 40, 1)',
702
- sliderFill: 'rgba(70, 130, 180, 1)',
703
- textColor: 'rgba(220, 220, 220, 1)',
704
- textDim: 'rgba(150, 150, 150, 1)',
705
- accentColor: 'rgba(70, 130, 180, 1)',
706
- fontSize: 14,
707
- fontFamily: 'Arial, sans-serif',
708
- padding: 8,
709
- borderRadius: 4,
710
- itemSpacing: 4,
711
- };
712
- this.canvas = canvas;
713
- this.ctx = canvas.getContext('2d');
714
- this.currentState = this.createState();
715
- // Input handling
716
- canvas.addEventListener('mousemove', (e) => {
717
- const rect = canvas.getBoundingClientRect();
718
- this.mousePos.x = e.clientX - rect.left;
719
- this.mousePos.y = e.clientY - rect.top;
720
- });
721
- canvas.addEventListener('mousedown', () => {
722
- this.mouseDown = true;
723
- this.mouseClicked = true;
724
- });
725
- canvas.addEventListener('mouseup', () => {
726
- this.mouseDown = false;
727
- });
728
- window.addEventListener('keypress', (e) => {
729
- this.keyboardInput += e.key;
730
- });
731
- }
732
- createState() {
733
- return {
734
- cursorX: 0,
735
- cursorY: 0,
736
- windowX: 0,
737
- windowY: 0,
738
- windowWidth: 0,
739
- windowHeight: 0,
740
- indentLevel: 0,
741
- sameLine: false,
742
- maxWidgetWidth: 0,
743
- lastWidgetHeight: 0,
744
- };
745
- }
746
- beginFrame() {
747
- this._isHovered = false;
748
- this.keyboardInput = '';
749
- }
750
- endFrame() {
751
- this.mouseClicked = false;
752
- this.hotWidget = null;
753
- }
754
- // ─── Window ────────────────────────────────────────────
755
- beginWindow(title, x, y, width, height) {
756
- this.stateStack.push({ ...this.currentState });
757
- this.currentState.windowX = x;
758
- this.currentState.windowY = y;
759
- this.currentState.windowWidth = width;
760
- this.currentState.windowHeight = height;
761
- this.currentState.cursorX = x + this.style.padding;
762
- this.currentState.cursorY = y + this.style.padding + 20; // Title bar height
763
- // Draw window background
764
- this.ctx.fillStyle = this.style.windowBg;
765
- this.roundRect(x, y, width, height, this.style.borderRadius);
766
- this.ctx.fill();
767
- // Draw border
768
- this.ctx.strokeStyle = this.style.windowBorder;
769
- this.ctx.lineWidth = 1;
770
- this.roundRect(x, y, width, height, this.style.borderRadius);
771
- this.ctx.stroke();
772
- // Draw title
773
- this.ctx.fillStyle = this.style.textColor;
774
- this.ctx.font = `bold ${this.style.fontSize}px ${this.style.fontFamily}`;
775
- this.ctx.fillText(title, x + this.style.padding, y + this.style.fontSize + 4);
776
- // Separator
777
- this.ctx.strokeStyle = this.style.windowBorder;
778
- this.ctx.beginPath();
779
- this.ctx.moveTo(x, y + 24);
780
- this.ctx.lineTo(x + width, y + 24);
781
- this.ctx.stroke();
782
- return true;
783
- }
784
- endWindow() {
785
- if (this.stateStack.length > 0) {
786
- this.currentState = this.stateStack.pop();
787
- }
788
- }
789
- beginPanel(_id) {
790
- this.stateStack.push({ ...this.currentState });
791
- const x = this.currentState.cursorX;
792
- const y = this.currentState.cursorY;
793
- const width = this.currentState.windowWidth - this.style.padding * 2;
794
- this.ctx.fillStyle = this.style.panelBg;
795
- this.roundRect(x, y, width, 100, this.style.borderRadius); // Height will be adjusted
796
- this.ctx.fill();
797
- this.currentState.cursorX += this.style.padding;
798
- this.currentState.cursorY += this.style.padding;
799
- }
800
- endPanel() {
801
- if (this.stateStack.length > 0) {
802
- const prevState = this.stateStack.pop();
803
- this.currentState.cursorX = prevState.cursorX;
804
- this.currentState.cursorY += this.style.padding;
805
- }
806
- }
807
- // ─── Elements ──────────────────────────────────────────
808
- text(content) {
809
- const x = this.getX();
810
- const y = this.getY();
811
- this.ctx.fillStyle = this.style.textColor;
812
- this.ctx.font = `${this.style.fontSize}px ${this.style.fontFamily}`;
813
- this.ctx.fillText(content, x, y + this.style.fontSize);
814
- this.advanceCursor(this.ctx.measureText(content).width, this.style.fontSize + this.style.itemSpacing);
815
- }
816
- button(label) {
817
- const id = `button_${label}`;
818
- const x = this.getX();
819
- const y = this.getY();
820
- const width = Math.max(100, this.ctx.measureText(label).width + this.style.padding * 2);
821
- const height = this.style.fontSize + this.style.padding * 2;
822
- const hovered = this.isInRect(x, y, width, height);
823
- const clicked = hovered && this.mouseClicked;
824
- // Background
825
- if (this.mouseDown && hovered) {
826
- this.ctx.fillStyle = this.style.buttonActive;
827
- }
828
- else if (hovered) {
829
- this.ctx.fillStyle = this.style.buttonHover;
830
- this.hotWidget = id;
831
- }
832
- else {
833
- this.ctx.fillStyle = this.style.buttonBg;
834
- }
835
- this.roundRect(x, y, width, height, this.style.borderRadius);
836
- this.ctx.fill();
837
- // Label
838
- this.ctx.fillStyle = this.style.textColor;
839
- this.ctx.font = `${this.style.fontSize}px ${this.style.fontFamily}`;
840
- const textWidth = this.ctx.measureText(label).width;
841
- this.ctx.fillText(label, x + (width - textWidth) / 2, y + height / 2 + this.style.fontSize / 3);
842
- this.advanceCursor(width, height + this.style.itemSpacing);
843
- if (hovered) {
844
- this._isHovered = true;
845
- }
846
- return clicked;
847
- }
848
- checkbox(label, checked) {
849
- const id = `checkbox_${label}`;
850
- const x = this.getX();
851
- const y = this.getY();
852
- const boxSize = this.style.fontSize + 4;
853
- const hovered = this.isInRect(x, y, boxSize, boxSize);
854
- const clicked = hovered && this.mouseClicked;
855
- // Box
856
- this.ctx.fillStyle = this.style.inputBg;
857
- this.roundRect(x, y, boxSize, boxSize, 2);
858
- this.ctx.fill();
859
- this.ctx.strokeStyle = hovered ? this.style.accentColor : this.style.inputBorder;
860
- this.ctx.lineWidth = 1;
861
- this.roundRect(x, y, boxSize, boxSize, 2);
862
- this.ctx.stroke();
863
- // Checkmark
864
- if (checked) {
865
- this.ctx.fillStyle = this.style.accentColor;
866
- this.roundRect(x + 3, y + 3, boxSize - 6, boxSize - 6, 2);
867
- this.ctx.fill();
868
- }
869
- // Label
870
- this.ctx.fillStyle = this.style.textColor;
871
- this.ctx.font = `${this.style.fontSize}px ${this.style.fontFamily}`;
872
- this.ctx.fillText(label, x + boxSize + this.style.itemSpacing, y + boxSize / 2 + this.style.fontSize / 3);
873
- const width = boxSize + this.style.itemSpacing + this.ctx.measureText(label).width;
874
- this.advanceCursor(width, boxSize + this.style.itemSpacing);
875
- if (hovered) {
876
- this._isHovered = true;
877
- this.hotWidget = id;
878
- }
879
- return clicked ? !checked : checked;
880
- }
881
- slider(label, value, min, max) {
882
- const id = `slider_${label}`;
883
- const x = this.getX();
884
- const y = this.getY();
885
- const width = 200;
886
- const height = this.style.fontSize + this.style.padding;
887
- const trackHeight = 6;
888
- // Label
889
- this.ctx.fillStyle = this.style.textColor;
890
- this.ctx.font = `${this.style.fontSize}px ${this.style.fontFamily}`;
891
- this.ctx.fillText(label, x, y + this.style.fontSize);
892
- const trackY = y + this.style.fontSize + this.style.itemSpacing;
893
- const hovered = this.isInRect(x, trackY, width, trackHeight);
894
- // Track
895
- this.ctx.fillStyle = this.style.sliderBg;
896
- this.roundRect(x, trackY, width, trackHeight, 3);
897
- this.ctx.fill();
898
- // Fill
899
- const normalizedValue = (value - min) / (max - min);
900
- const fillWidth = width * normalizedValue;
901
- this.ctx.fillStyle = this.style.sliderFill;
902
- this.roundRect(x, trackY, fillWidth, trackHeight, 3);
903
- this.ctx.fill();
904
- // Handle
905
- const handleX = x + fillWidth - 6;
906
- this.ctx.fillStyle = this.style.textColor;
907
- this.ctx.beginPath();
908
- this.ctx.arc(handleX + 6, trackY + trackHeight / 2, 8, 0, Math.PI * 2);
909
- this.ctx.fill();
910
- // Value text
911
- const valueText = value.toFixed(2);
912
- this.ctx.fillStyle = this.style.textDim;
913
- this.ctx.fillText(valueText, x + width + this.style.itemSpacing, trackY + this.style.fontSize / 2);
914
- // Handle drag
915
- let newValue = value;
916
- if (hovered && this.mouseDown) {
917
- const localX = this.mousePos.x - x;
918
- const t = Math.max(0, Math.min(1, localX / width));
919
- newValue = min + t * (max - min);
920
- this.activeWidget = id;
921
- }
922
- this.advanceCursor(width + 50, height + trackHeight + this.style.itemSpacing);
923
- if (hovered) {
924
- this._isHovered = true;
925
- this.hotWidget = id;
926
- }
927
- return newValue;
928
- }
929
- textInput(label, value) {
930
- const id = `input_${label}`;
931
- const x = this.getX();
932
- const y = this.getY();
933
- const width = 200;
934
- const height = this.style.fontSize + this.style.padding * 2;
935
- // Label
936
- this.ctx.fillStyle = this.style.textColor;
937
- this.ctx.font = `${this.style.fontSize}px ${this.style.fontFamily}`;
938
- this.ctx.fillText(label, x, y + this.style.fontSize);
939
- const inputY = y + this.style.fontSize + this.style.itemSpacing;
940
- const hovered = this.isInRect(x, inputY, width, height);
941
- const isActive = this.activeWidget === id;
942
- // Background
943
- this.ctx.fillStyle = this.style.inputBg;
944
- this.roundRect(x, inputY, width, height, this.style.borderRadius);
945
- this.ctx.fill();
946
- // Border
947
- this.ctx.strokeStyle = isActive
948
- ? this.style.accentColor
949
- : hovered
950
- ? this.style.textDim
951
- : this.style.inputBorder;
952
- this.ctx.lineWidth = 1;
953
- this.roundRect(x, inputY, width, height, this.style.borderRadius);
954
- this.ctx.stroke();
955
- // Value text
956
- this.ctx.fillStyle = this.style.textColor;
957
- this.ctx.fillText(value, x + this.style.padding, inputY + height / 2 + this.style.fontSize / 3);
958
- // Cursor
959
- if (isActive) {
960
- const cursorX = x + this.style.padding + this.ctx.measureText(value).width;
961
- this.ctx.fillStyle = this.style.textColor;
962
- this.ctx.fillRect(cursorX + 2, inputY + 4, 2, height - 8);
963
- }
964
- // Focus
965
- if (hovered && this.mouseClicked) {
966
- this.activeWidget = id;
967
- }
968
- // Input
969
- let newValue = value;
970
- if (isActive && this.keyboardInput) {
971
- newValue = value + this.keyboardInput;
972
- }
973
- this.advanceCursor(width, height + this.style.fontSize + this.style.itemSpacing);
974
- if (hovered) {
975
- this._isHovered = true;
976
- this.hotWidget = id;
977
- }
978
- return newValue;
979
- }
980
- dropdown(label, selected, options) {
981
- const x = this.getX();
982
- const y = this.getY();
983
- const width = 200;
984
- const height = this.style.fontSize + this.style.padding * 2;
985
- // Label
986
- this.ctx.fillStyle = this.style.textColor;
987
- this.ctx.font = `${this.style.fontSize}px ${this.style.fontFamily}`;
988
- this.ctx.fillText(label, x, y + this.style.fontSize);
989
- const dropdownY = y + this.style.fontSize + this.style.itemSpacing;
990
- const hovered = this.isInRect(x, dropdownY, width, height);
991
- // Background
992
- this.ctx.fillStyle = this.style.inputBg;
993
- this.roundRect(x, dropdownY, width, height, this.style.borderRadius);
994
- this.ctx.fill();
995
- // Border
996
- this.ctx.strokeStyle = hovered ? this.style.accentColor : this.style.inputBorder;
997
- this.ctx.lineWidth = 1;
998
- this.roundRect(x, dropdownY, width, height, this.style.borderRadius);
999
- this.ctx.stroke();
1000
- // Selected value
1001
- this.ctx.fillStyle = this.style.textColor;
1002
- this.ctx.fillText(options[selected] ?? '', x + this.style.padding, dropdownY + height / 2 + this.style.fontSize / 3);
1003
- // Arrow (drawn, not a font glyph)
1004
- const arrowX = x + width - 16;
1005
- const arrowY = dropdownY + height / 2;
1006
- this.ctx.beginPath();
1007
- this.ctx.moveTo(arrowX - 5, arrowY - 3);
1008
- this.ctx.lineTo(arrowX + 5, arrowY - 3);
1009
- this.ctx.lineTo(arrowX, arrowY + 3);
1010
- this.ctx.closePath();
1011
- this.ctx.fill();
1012
- // Handle click - simplified, just cycle through options
1013
- let newSelected = selected;
1014
- if (hovered && this.mouseClicked) {
1015
- newSelected = (selected + 1) % options.length;
1016
- }
1017
- this.advanceCursor(width, height + this.style.fontSize + this.style.itemSpacing);
1018
- if (hovered) {
1019
- this._isHovered = true;
1020
- }
1021
- return newSelected;
1022
- }
1023
- colorPicker(label, color) {
1024
- const x = this.getX();
1025
- const y = this.getY();
1026
- const size = 24;
1027
- // Label
1028
- this.ctx.fillStyle = this.style.textColor;
1029
- this.ctx.font = `${this.style.fontSize}px ${this.style.fontFamily}`;
1030
- this.ctx.fillText(label, x, y + this.style.fontSize);
1031
- const colorY = y + this.style.fontSize + this.style.itemSpacing;
1032
- const hovered = this.isInRect(x, colorY, size, size);
1033
- // Color swatch
1034
- this.ctx.fillStyle = `rgba(${color.r * 255}, ${color.g * 255}, ${color.b * 255}, ${color.a ?? 1})`;
1035
- this.roundRect(x, colorY, size, size, 4);
1036
- this.ctx.fill();
1037
- // Border
1038
- this.ctx.strokeStyle = hovered ? this.style.accentColor : this.style.inputBorder;
1039
- this.ctx.lineWidth = 1;
1040
- this.roundRect(x, colorY, size, size, 4);
1041
- this.ctx.stroke();
1042
- this.advanceCursor(size + this.ctx.measureText(label).width + this.style.itemSpacing, size + this.style.fontSize + this.style.itemSpacing);
1043
- if (hovered) {
1044
- this._isHovered = true;
1045
- }
1046
- return { r: color.r, g: color.g, b: color.b, a: color.a ?? 1 };
1047
- }
1048
- image(_src, width, height) {
1049
- const x = this.getX();
1050
- const y = this.getY();
1051
- // Placeholder
1052
- this.ctx.fillStyle = this.style.panelBg;
1053
- this.roundRect(x, y, width, height, this.style.borderRadius);
1054
- this.ctx.fill();
1055
- this.advanceCursor(width, height + this.style.itemSpacing);
1056
- }
1057
- progressBar(value, max = 1) {
1058
- const x = this.getX();
1059
- const y = this.getY();
1060
- const width = 200;
1061
- const height = 8;
1062
- // Background
1063
- this.ctx.fillStyle = this.style.sliderBg;
1064
- this.roundRect(x, y, width, height, 4);
1065
- this.ctx.fill();
1066
- // Fill
1067
- const fillWidth = (value / max) * width;
1068
- this.ctx.fillStyle = this.style.accentColor;
1069
- this.roundRect(x, y, fillWidth, height, 4);
1070
- this.ctx.fill();
1071
- this.advanceCursor(width, height + this.style.itemSpacing);
1072
- }
1073
- // ─── Layout ────────────────────────────────────────────
1074
- sameLine() {
1075
- this.currentState.sameLine = true;
1076
- this.currentState.cursorY -= this.currentState.lastWidgetHeight;
1077
- this.currentState.cursorX += this.currentState.maxWidgetWidth + this.style.itemSpacing;
1078
- }
1079
- newLine() {
1080
- this.currentState.cursorX =
1081
- this.currentState.windowX + this.style.padding + this.currentState.indentLevel * 20;
1082
- this.currentState.cursorY += this.style.itemSpacing;
1083
- }
1084
- indent() {
1085
- this.currentState.indentLevel++;
1086
- this.currentState.cursorX += 20;
1087
- }
1088
- unindent() {
1089
- if (this.currentState.indentLevel > 0) {
1090
- this.currentState.indentLevel--;
1091
- this.currentState.cursorX -= 20;
1092
- }
1093
- }
1094
- separator() {
1095
- const x = this.currentState.windowX + this.style.padding;
1096
- const y = this.getY() + this.style.itemSpacing;
1097
- const width = this.currentState.windowWidth - this.style.padding * 2;
1098
- this.ctx.strokeStyle = this.style.windowBorder;
1099
- this.ctx.beginPath();
1100
- this.ctx.moveTo(x, y);
1101
- this.ctx.lineTo(x + width, y);
1102
- this.ctx.stroke();
1103
- this.currentState.cursorY = y + this.style.itemSpacing * 2;
1104
- }
1105
- spacing(amount) {
1106
- this.currentState.cursorY += amount;
1107
- }
1108
- tooltip(content) {
1109
- if (!this._isHovered) {
1110
- return;
1111
- }
1112
- const x = this.mousePos.x + 10;
1113
- const y = this.mousePos.y + 10;
1114
- const padding = 4;
1115
- this.ctx.font = `${this.style.fontSize - 2}px ${this.style.fontFamily}`;
1116
- const width = this.ctx.measureText(content).width + padding * 2;
1117
- const height = this.style.fontSize + padding * 2;
1118
- // Background
1119
- this.ctx.fillStyle = 'rgba(0, 0, 0, 0.9)';
1120
- this.roundRect(x, y, width, height, 2);
1121
- this.ctx.fill();
1122
- // Text
1123
- this.ctx.fillStyle = this.style.textColor;
1124
- this.ctx.fillText(content, x + padding, y + padding + this.style.fontSize - 2);
1125
- }
1126
- isHovered() {
1127
- return this._isHovered;
1128
- }
1129
- // ─── Helpers ───────────────────────────────────────────
1130
- getX() {
1131
- return this.currentState.cursorX;
1132
- }
1133
- getY() {
1134
- return this.currentState.cursorY;
1135
- }
1136
- advanceCursor(width, height) {
1137
- if (!this.currentState.sameLine) {
1138
- this.currentState.cursorX =
1139
- this.currentState.windowX + this.style.padding + this.currentState.indentLevel * 20;
1140
- this.currentState.cursorY += height;
1141
- }
1142
- this.currentState.maxWidgetWidth = Math.max(this.currentState.maxWidgetWidth, width);
1143
- this.currentState.lastWidgetHeight = height;
1144
- this.currentState.sameLine = false;
1145
- }
1146
- isInRect(x, y, width, height) {
1147
- return (this.mousePos.x >= x &&
1148
- this.mousePos.x <= x + width &&
1149
- this.mousePos.y >= y &&
1150
- this.mousePos.y <= y + height);
1151
- }
1152
- roundRect(x, y, width, height, radius) {
1153
- this.ctx.beginPath();
1154
- this.ctx.moveTo(x + radius, y);
1155
- this.ctx.lineTo(x + width - radius, y);
1156
- this.ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
1157
- this.ctx.lineTo(x + width, y + height - radius);
1158
- this.ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
1159
- this.ctx.lineTo(x + radius, y + height);
1160
- this.ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
1161
- this.ctx.lineTo(x, y + radius);
1162
- this.ctx.quadraticCurveTo(x, y, x + radius, y);
1163
- this.ctx.closePath();
1164
- }
647
+ constructor(canvas) {
648
+ this.stateStack = [];
649
+ this.hotWidget = null;
650
+ this.activeWidget = null;
651
+ this.mousePos = { x: 0, y: 0 };
652
+ this.mouseDown = false;
653
+ this.mouseClicked = false;
654
+ this.keyboardInput = "";
655
+ this._isHovered = false;
656
+ this.style = {
657
+ windowBg: "rgba(30, 30, 30, 0.95)",
658
+ windowBorder: "rgba(60, 60, 60, 1)",
659
+ panelBg: "rgba(40, 40, 40, 0.8)",
660
+ buttonBg: "rgba(60, 60, 60, 1)",
661
+ buttonHover: "rgba(80, 80, 80, 1)",
662
+ buttonActive: "rgba(100, 100, 100, 1)",
663
+ inputBg: "rgba(20, 20, 20, 1)",
664
+ inputBorder: "rgba(80, 80, 80, 1)",
665
+ sliderBg: "rgba(40, 40, 40, 1)",
666
+ sliderFill: "rgba(70, 130, 180, 1)",
667
+ textColor: "rgba(220, 220, 220, 1)",
668
+ textDim: "rgba(150, 150, 150, 1)",
669
+ accentColor: "rgba(70, 130, 180, 1)",
670
+ fontSize: 14,
671
+ fontFamily: "Arial, sans-serif",
672
+ padding: 8,
673
+ borderRadius: 4,
674
+ itemSpacing: 4
675
+ };
676
+ this.canvas = canvas;
677
+ this.ctx = canvas.getContext("2d");
678
+ this.currentState = this.createState();
679
+ canvas.addEventListener("mousemove", (e) => {
680
+ const rect = canvas.getBoundingClientRect();
681
+ this.mousePos.x = e.clientX - rect.left;
682
+ this.mousePos.y = e.clientY - rect.top;
683
+ });
684
+ canvas.addEventListener("mousedown", () => {
685
+ this.mouseDown = true;
686
+ this.mouseClicked = true;
687
+ });
688
+ canvas.addEventListener("mouseup", () => {
689
+ this.mouseDown = false;
690
+ });
691
+ window.addEventListener("keypress", (e) => {
692
+ this.keyboardInput += e.key;
693
+ });
694
+ }
695
+ createState() {
696
+ return {
697
+ cursorX: 0,
698
+ cursorY: 0,
699
+ windowX: 0,
700
+ windowY: 0,
701
+ windowWidth: 0,
702
+ windowHeight: 0,
703
+ indentLevel: 0,
704
+ sameLine: false,
705
+ maxWidgetWidth: 0,
706
+ lastWidgetHeight: 0
707
+ };
708
+ }
709
+ beginFrame() {
710
+ this._isHovered = false;
711
+ this.keyboardInput = "";
712
+ }
713
+ endFrame() {
714
+ this.mouseClicked = false;
715
+ this.hotWidget = null;
716
+ }
717
+ // ─── Window ────────────────────────────────────────────
718
+ beginWindow(title, x, y, width, height) {
719
+ this.stateStack.push({ ...this.currentState });
720
+ this.currentState.windowX = x;
721
+ this.currentState.windowY = y;
722
+ this.currentState.windowWidth = width;
723
+ this.currentState.windowHeight = height;
724
+ this.currentState.cursorX = x + this.style.padding;
725
+ this.currentState.cursorY = y + this.style.padding + 20;
726
+ this.ctx.fillStyle = this.style.windowBg;
727
+ this.roundRect(x, y, width, height, this.style.borderRadius);
728
+ this.ctx.fill();
729
+ this.ctx.strokeStyle = this.style.windowBorder;
730
+ this.ctx.lineWidth = 1;
731
+ this.roundRect(x, y, width, height, this.style.borderRadius);
732
+ this.ctx.stroke();
733
+ this.ctx.fillStyle = this.style.textColor;
734
+ this.ctx.font = `bold ${this.style.fontSize}px ${this.style.fontFamily}`;
735
+ this.ctx.fillText(title, x + this.style.padding, y + this.style.fontSize + 4);
736
+ this.ctx.strokeStyle = this.style.windowBorder;
737
+ this.ctx.beginPath();
738
+ this.ctx.moveTo(x, y + 24);
739
+ this.ctx.lineTo(x + width, y + 24);
740
+ this.ctx.stroke();
741
+ return true;
742
+ }
743
+ endWindow() {
744
+ if (this.stateStack.length > 0) {
745
+ this.currentState = this.stateStack.pop();
746
+ }
747
+ }
748
+ beginPanel(_id) {
749
+ this.stateStack.push({ ...this.currentState });
750
+ const x = this.currentState.cursorX;
751
+ const y = this.currentState.cursorY;
752
+ const width = this.currentState.windowWidth - this.style.padding * 2;
753
+ this.ctx.fillStyle = this.style.panelBg;
754
+ this.roundRect(x, y, width, 100, this.style.borderRadius);
755
+ this.ctx.fill();
756
+ this.currentState.cursorX += this.style.padding;
757
+ this.currentState.cursorY += this.style.padding;
758
+ }
759
+ endPanel() {
760
+ if (this.stateStack.length > 0) {
761
+ const prevState = this.stateStack.pop();
762
+ this.currentState.cursorX = prevState.cursorX;
763
+ this.currentState.cursorY += this.style.padding;
764
+ }
765
+ }
766
+ // ─── Elements ──────────────────────────────────────────
767
+ text(content) {
768
+ const x = this.getX();
769
+ const y = this.getY();
770
+ this.ctx.fillStyle = this.style.textColor;
771
+ this.ctx.font = `${this.style.fontSize}px ${this.style.fontFamily}`;
772
+ this.ctx.fillText(content, x, y + this.style.fontSize);
773
+ this.advanceCursor(
774
+ this.ctx.measureText(content).width,
775
+ this.style.fontSize + this.style.itemSpacing
776
+ );
777
+ }
778
+ button(label) {
779
+ const id = `button_${label}`;
780
+ const x = this.getX();
781
+ const y = this.getY();
782
+ const width = Math.max(100, this.ctx.measureText(label).width + this.style.padding * 2);
783
+ const height = this.style.fontSize + this.style.padding * 2;
784
+ const hovered = this.isInRect(x, y, width, height);
785
+ const clicked = hovered && this.mouseClicked;
786
+ if (this.mouseDown && hovered) {
787
+ this.ctx.fillStyle = this.style.buttonActive;
788
+ } else if (hovered) {
789
+ this.ctx.fillStyle = this.style.buttonHover;
790
+ this.hotWidget = id;
791
+ } else {
792
+ this.ctx.fillStyle = this.style.buttonBg;
793
+ }
794
+ this.roundRect(x, y, width, height, this.style.borderRadius);
795
+ this.ctx.fill();
796
+ this.ctx.fillStyle = this.style.textColor;
797
+ this.ctx.font = `${this.style.fontSize}px ${this.style.fontFamily}`;
798
+ const textWidth = this.ctx.measureText(label).width;
799
+ this.ctx.fillText(label, x + (width - textWidth) / 2, y + height / 2 + this.style.fontSize / 3);
800
+ this.advanceCursor(width, height + this.style.itemSpacing);
801
+ if (hovered) {
802
+ this._isHovered = true;
803
+ }
804
+ return clicked;
805
+ }
806
+ checkbox(label, checked) {
807
+ const id = `checkbox_${label}`;
808
+ const x = this.getX();
809
+ const y = this.getY();
810
+ const boxSize = this.style.fontSize + 4;
811
+ const hovered = this.isInRect(x, y, boxSize, boxSize);
812
+ const clicked = hovered && this.mouseClicked;
813
+ this.ctx.fillStyle = this.style.inputBg;
814
+ this.roundRect(x, y, boxSize, boxSize, 2);
815
+ this.ctx.fill();
816
+ this.ctx.strokeStyle = hovered ? this.style.accentColor : this.style.inputBorder;
817
+ this.ctx.lineWidth = 1;
818
+ this.roundRect(x, y, boxSize, boxSize, 2);
819
+ this.ctx.stroke();
820
+ if (checked) {
821
+ this.ctx.fillStyle = this.style.accentColor;
822
+ this.roundRect(x + 3, y + 3, boxSize - 6, boxSize - 6, 2);
823
+ this.ctx.fill();
824
+ }
825
+ this.ctx.fillStyle = this.style.textColor;
826
+ this.ctx.font = `${this.style.fontSize}px ${this.style.fontFamily}`;
827
+ this.ctx.fillText(
828
+ label,
829
+ x + boxSize + this.style.itemSpacing,
830
+ y + boxSize / 2 + this.style.fontSize / 3
831
+ );
832
+ const width = boxSize + this.style.itemSpacing + this.ctx.measureText(label).width;
833
+ this.advanceCursor(width, boxSize + this.style.itemSpacing);
834
+ if (hovered) {
835
+ this._isHovered = true;
836
+ this.hotWidget = id;
837
+ }
838
+ return clicked ? !checked : checked;
839
+ }
840
+ slider(label, value, min, max) {
841
+ const id = `slider_${label}`;
842
+ const x = this.getX();
843
+ const y = this.getY();
844
+ const width = 200;
845
+ const height = this.style.fontSize + this.style.padding;
846
+ const trackHeight = 6;
847
+ this.ctx.fillStyle = this.style.textColor;
848
+ this.ctx.font = `${this.style.fontSize}px ${this.style.fontFamily}`;
849
+ this.ctx.fillText(label, x, y + this.style.fontSize);
850
+ const trackY = y + this.style.fontSize + this.style.itemSpacing;
851
+ const hovered = this.isInRect(x, trackY, width, trackHeight);
852
+ this.ctx.fillStyle = this.style.sliderBg;
853
+ this.roundRect(x, trackY, width, trackHeight, 3);
854
+ this.ctx.fill();
855
+ const normalizedValue = (value - min) / (max - min);
856
+ const fillWidth = width * normalizedValue;
857
+ this.ctx.fillStyle = this.style.sliderFill;
858
+ this.roundRect(x, trackY, fillWidth, trackHeight, 3);
859
+ this.ctx.fill();
860
+ const handleX = x + fillWidth - 6;
861
+ this.ctx.fillStyle = this.style.textColor;
862
+ this.ctx.beginPath();
863
+ this.ctx.arc(handleX + 6, trackY + trackHeight / 2, 8, 0, Math.PI * 2);
864
+ this.ctx.fill();
865
+ const valueText = value.toFixed(2);
866
+ this.ctx.fillStyle = this.style.textDim;
867
+ this.ctx.fillText(
868
+ valueText,
869
+ x + width + this.style.itemSpacing,
870
+ trackY + this.style.fontSize / 2
871
+ );
872
+ let newValue = value;
873
+ if (hovered && this.mouseDown) {
874
+ const localX = this.mousePos.x - x;
875
+ const t = Math.max(0, Math.min(1, localX / width));
876
+ newValue = min + t * (max - min);
877
+ this.activeWidget = id;
878
+ }
879
+ this.advanceCursor(width + 50, height + trackHeight + this.style.itemSpacing);
880
+ if (hovered) {
881
+ this._isHovered = true;
882
+ this.hotWidget = id;
883
+ }
884
+ return newValue;
885
+ }
886
+ textInput(label, value) {
887
+ const id = `input_${label}`;
888
+ const x = this.getX();
889
+ const y = this.getY();
890
+ const width = 200;
891
+ const height = this.style.fontSize + this.style.padding * 2;
892
+ this.ctx.fillStyle = this.style.textColor;
893
+ this.ctx.font = `${this.style.fontSize}px ${this.style.fontFamily}`;
894
+ this.ctx.fillText(label, x, y + this.style.fontSize);
895
+ const inputY = y + this.style.fontSize + this.style.itemSpacing;
896
+ const hovered = this.isInRect(x, inputY, width, height);
897
+ const isActive = this.activeWidget === id;
898
+ this.ctx.fillStyle = this.style.inputBg;
899
+ this.roundRect(x, inputY, width, height, this.style.borderRadius);
900
+ this.ctx.fill();
901
+ this.ctx.strokeStyle = isActive ? this.style.accentColor : hovered ? this.style.textDim : this.style.inputBorder;
902
+ this.ctx.lineWidth = 1;
903
+ this.roundRect(x, inputY, width, height, this.style.borderRadius);
904
+ this.ctx.stroke();
905
+ this.ctx.fillStyle = this.style.textColor;
906
+ this.ctx.fillText(value, x + this.style.padding, inputY + height / 2 + this.style.fontSize / 3);
907
+ if (isActive) {
908
+ const cursorX = x + this.style.padding + this.ctx.measureText(value).width;
909
+ this.ctx.fillStyle = this.style.textColor;
910
+ this.ctx.fillRect(cursorX + 2, inputY + 4, 2, height - 8);
911
+ }
912
+ if (hovered && this.mouseClicked) {
913
+ this.activeWidget = id;
914
+ }
915
+ let newValue = value;
916
+ if (isActive && this.keyboardInput) {
917
+ newValue = value + this.keyboardInput;
918
+ }
919
+ this.advanceCursor(width, height + this.style.fontSize + this.style.itemSpacing);
920
+ if (hovered) {
921
+ this._isHovered = true;
922
+ this.hotWidget = id;
923
+ }
924
+ return newValue;
925
+ }
926
+ dropdown(label, selected, options) {
927
+ const x = this.getX();
928
+ const y = this.getY();
929
+ const width = 200;
930
+ const height = this.style.fontSize + this.style.padding * 2;
931
+ this.ctx.fillStyle = this.style.textColor;
932
+ this.ctx.font = `${this.style.fontSize}px ${this.style.fontFamily}`;
933
+ this.ctx.fillText(label, x, y + this.style.fontSize);
934
+ const dropdownY = y + this.style.fontSize + this.style.itemSpacing;
935
+ const hovered = this.isInRect(x, dropdownY, width, height);
936
+ this.ctx.fillStyle = this.style.inputBg;
937
+ this.roundRect(x, dropdownY, width, height, this.style.borderRadius);
938
+ this.ctx.fill();
939
+ this.ctx.strokeStyle = hovered ? this.style.accentColor : this.style.inputBorder;
940
+ this.ctx.lineWidth = 1;
941
+ this.roundRect(x, dropdownY, width, height, this.style.borderRadius);
942
+ this.ctx.stroke();
943
+ this.ctx.fillStyle = this.style.textColor;
944
+ this.ctx.fillText(
945
+ options[selected] ?? "",
946
+ x + this.style.padding,
947
+ dropdownY + height / 2 + this.style.fontSize / 3
948
+ );
949
+ const arrowX = x + width - 16;
950
+ const arrowY = dropdownY + height / 2;
951
+ this.ctx.beginPath();
952
+ this.ctx.moveTo(arrowX - 5, arrowY - 3);
953
+ this.ctx.lineTo(arrowX + 5, arrowY - 3);
954
+ this.ctx.lineTo(arrowX, arrowY + 3);
955
+ this.ctx.closePath();
956
+ this.ctx.fill();
957
+ let newSelected = selected;
958
+ if (hovered && this.mouseClicked) {
959
+ newSelected = (selected + 1) % options.length;
960
+ }
961
+ this.advanceCursor(width, height + this.style.fontSize + this.style.itemSpacing);
962
+ if (hovered) {
963
+ this._isHovered = true;
964
+ }
965
+ return newSelected;
966
+ }
967
+ colorPicker(label, color) {
968
+ const x = this.getX();
969
+ const y = this.getY();
970
+ const size = 24;
971
+ this.ctx.fillStyle = this.style.textColor;
972
+ this.ctx.font = `${this.style.fontSize}px ${this.style.fontFamily}`;
973
+ this.ctx.fillText(label, x, y + this.style.fontSize);
974
+ const colorY = y + this.style.fontSize + this.style.itemSpacing;
975
+ const hovered = this.isInRect(x, colorY, size, size);
976
+ this.ctx.fillStyle = `rgba(${color.r * 255}, ${color.g * 255}, ${color.b * 255}, ${color.a ?? 1})`;
977
+ this.roundRect(x, colorY, size, size, 4);
978
+ this.ctx.fill();
979
+ this.ctx.strokeStyle = hovered ? this.style.accentColor : this.style.inputBorder;
980
+ this.ctx.lineWidth = 1;
981
+ this.roundRect(x, colorY, size, size, 4);
982
+ this.ctx.stroke();
983
+ this.advanceCursor(
984
+ size + this.ctx.measureText(label).width + this.style.itemSpacing,
985
+ size + this.style.fontSize + this.style.itemSpacing
986
+ );
987
+ if (hovered) {
988
+ this._isHovered = true;
989
+ }
990
+ return { r: color.r, g: color.g, b: color.b, a: color.a ?? 1 };
991
+ }
992
+ image(_src, width, height) {
993
+ const x = this.getX();
994
+ const y = this.getY();
995
+ this.ctx.fillStyle = this.style.panelBg;
996
+ this.roundRect(x, y, width, height, this.style.borderRadius);
997
+ this.ctx.fill();
998
+ this.advanceCursor(width, height + this.style.itemSpacing);
999
+ }
1000
+ progressBar(value, max = 1) {
1001
+ const x = this.getX();
1002
+ const y = this.getY();
1003
+ const width = 200;
1004
+ const height = 8;
1005
+ this.ctx.fillStyle = this.style.sliderBg;
1006
+ this.roundRect(x, y, width, height, 4);
1007
+ this.ctx.fill();
1008
+ const fillWidth = value / max * width;
1009
+ this.ctx.fillStyle = this.style.accentColor;
1010
+ this.roundRect(x, y, fillWidth, height, 4);
1011
+ this.ctx.fill();
1012
+ this.advanceCursor(width, height + this.style.itemSpacing);
1013
+ }
1014
+ // ─── Layout ────────────────────────────────────────────
1015
+ sameLine() {
1016
+ this.currentState.sameLine = true;
1017
+ this.currentState.cursorY -= this.currentState.lastWidgetHeight;
1018
+ this.currentState.cursorX += this.currentState.maxWidgetWidth + this.style.itemSpacing;
1019
+ }
1020
+ newLine() {
1021
+ this.currentState.cursorX = this.currentState.windowX + this.style.padding + this.currentState.indentLevel * 20;
1022
+ this.currentState.cursorY += this.style.itemSpacing;
1023
+ }
1024
+ indent() {
1025
+ this.currentState.indentLevel++;
1026
+ this.currentState.cursorX += 20;
1027
+ }
1028
+ unindent() {
1029
+ if (this.currentState.indentLevel > 0) {
1030
+ this.currentState.indentLevel--;
1031
+ this.currentState.cursorX -= 20;
1032
+ }
1033
+ }
1034
+ separator() {
1035
+ const x = this.currentState.windowX + this.style.padding;
1036
+ const y = this.getY() + this.style.itemSpacing;
1037
+ const width = this.currentState.windowWidth - this.style.padding * 2;
1038
+ this.ctx.strokeStyle = this.style.windowBorder;
1039
+ this.ctx.beginPath();
1040
+ this.ctx.moveTo(x, y);
1041
+ this.ctx.lineTo(x + width, y);
1042
+ this.ctx.stroke();
1043
+ this.currentState.cursorY = y + this.style.itemSpacing * 2;
1044
+ }
1045
+ spacing(amount) {
1046
+ this.currentState.cursorY += amount;
1047
+ }
1048
+ tooltip(content) {
1049
+ if (!this._isHovered) {
1050
+ return;
1051
+ }
1052
+ const x = this.mousePos.x + 10;
1053
+ const y = this.mousePos.y + 10;
1054
+ const padding = 4;
1055
+ this.ctx.font = `${this.style.fontSize - 2}px ${this.style.fontFamily}`;
1056
+ const width = this.ctx.measureText(content).width + padding * 2;
1057
+ const height = this.style.fontSize + padding * 2;
1058
+ this.ctx.fillStyle = "rgba(0, 0, 0, 0.9)";
1059
+ this.roundRect(x, y, width, height, 2);
1060
+ this.ctx.fill();
1061
+ this.ctx.fillStyle = this.style.textColor;
1062
+ this.ctx.fillText(content, x + padding, y + padding + this.style.fontSize - 2);
1063
+ }
1064
+ isHovered() {
1065
+ return this._isHovered;
1066
+ }
1067
+ // ─── Helpers ───────────────────────────────────────────
1068
+ getX() {
1069
+ return this.currentState.cursorX;
1070
+ }
1071
+ getY() {
1072
+ return this.currentState.cursorY;
1073
+ }
1074
+ advanceCursor(width, height) {
1075
+ if (!this.currentState.sameLine) {
1076
+ this.currentState.cursorX = this.currentState.windowX + this.style.padding + this.currentState.indentLevel * 20;
1077
+ this.currentState.cursorY += height;
1078
+ }
1079
+ this.currentState.maxWidgetWidth = Math.max(this.currentState.maxWidgetWidth, width);
1080
+ this.currentState.lastWidgetHeight = height;
1081
+ this.currentState.sameLine = false;
1082
+ }
1083
+ isInRect(x, y, width, height) {
1084
+ return this.mousePos.x >= x && this.mousePos.x <= x + width && this.mousePos.y >= y && this.mousePos.y <= y + height;
1085
+ }
1086
+ roundRect(x, y, width, height, radius) {
1087
+ this.ctx.beginPath();
1088
+ this.ctx.moveTo(x + radius, y);
1089
+ this.ctx.lineTo(x + width - radius, y);
1090
+ this.ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
1091
+ this.ctx.lineTo(x + width, y + height - radius);
1092
+ this.ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
1093
+ this.ctx.lineTo(x + radius, y + height);
1094
+ this.ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
1095
+ this.ctx.lineTo(x, y + radius);
1096
+ this.ctx.quadraticCurveTo(x, y, x + radius, y);
1097
+ this.ctx.closePath();
1098
+ }
1165
1099
  }
1166
- // ============================================================
1167
- // Factory Functions
1168
- // ============================================================
1169
1100
  function createInputSystem() {
1170
- return new InputSystem();
1101
+ return new InputSystem();
1171
1102
  }
1172
1103
  function createUISystem(canvas) {
1173
- return new UISystem(canvas);
1104
+ return new UISystem(canvas);
1174
1105
  }
1175
-
1176
- export { InputSystem, UISystem, createInputSystem, createUISystem };
1106
+ export {
1107
+ InputSystem,
1108
+ UISystem,
1109
+ createInputSystem,
1110
+ createUISystem
1111
+ };