@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.
- package/CHANGELOG.md +9 -0
- package/dist/cjs/accessibility/Accessibility.js +152 -165
- package/dist/cjs/ai/AI.js +292 -294
- package/dist/cjs/ai/BehaviorTree.js +1029 -1113
- package/dist/cjs/ai/StateMachine.js +694 -756
- package/dist/cjs/animation/Animation.js +232 -241
- package/dist/cjs/audio/AudioAdvanced.js +221 -236
- package/dist/cjs/audio/AudioBridge.js +441 -435
- package/dist/cjs/audio/AudioManager.js +242 -259
- package/dist/cjs/build-cloud/BuildOrchestration.js +1059 -1098
- package/dist/cjs/build-cloud/GodotBuildCloud.js +641 -670
- package/dist/cjs/build-cloud/UnityBuildCloud.js +563 -610
- package/dist/cjs/build-cloud/UnrealBuildCloud.js +610 -635
- package/dist/cjs/core/EventBus.js +51 -56
- package/dist/cjs/core/GameClock.js +62 -66
- package/dist/cjs/core/GameConfig.js +72 -79
- package/dist/cjs/core/GameLoop.js +80 -89
- package/dist/cjs/core/ServiceLocator.js +61 -65
- package/dist/cjs/core/Validation.js +72 -82
- package/dist/cjs/core/math.js +108 -112
- package/dist/cjs/devtools/DevTools.js +542 -563
- package/dist/cjs/devtools/DeveloperExperience.js +521 -559
- package/dist/cjs/devtools/GameplayAnalytics.js +636 -646
- package/dist/cjs/dialogue/DialogueSystem.js +984 -986
- package/dist/cjs/docs/DocGenerator.js +339 -364
- package/dist/cjs/ecs/World.js +355 -371
- package/dist/cjs/editor/AchievementEditor.js +580 -636
- package/dist/cjs/editor/AdvancedEditor.js +184 -191
- package/dist/cjs/editor/AnimationRetargeting.js +696 -741
- package/dist/cjs/editor/AssetBrowser.js +1072 -1160
- package/dist/cjs/editor/AssetManager.js +187 -192
- package/dist/cjs/editor/ConsolePro.js +971 -1061
- package/dist/cjs/editor/CraftingEditor.js +680 -730
- package/dist/cjs/editor/DebugTools.js +187 -185
- package/dist/cjs/editor/DialogueSystem.js +844 -901
- package/dist/cjs/editor/LeaderboardSystem.js +429 -483
- package/dist/cjs/editor/NiceGameEditor.js +1903 -1201
- package/dist/cjs/editor/PrefabSystem.js +772 -838
- package/dist/cjs/editor/ProfilerPanel.js +649 -700
- package/dist/cjs/editor/QuestEditor.js +792 -839
- package/dist/cjs/editor/ReplaySystem.js +585 -634
- package/dist/cjs/editor/SceneEditor.js +176 -200
- package/dist/cjs/editor/ScreenshotMode.js +621 -688
- package/dist/cjs/editor/ShaderGraph.js +1556 -1582
- package/dist/cjs/editor/TimelineEditor.js +715 -778
- package/dist/cjs/editor/UndoRedoPro.js +830 -904
- package/dist/cjs/editor/VRARMode.js +582 -645
- package/dist/cjs/engine/NiceGameEngine.js +141 -164
- package/dist/cjs/engine/SaveSystem.js +441 -495
- package/dist/cjs/enterprise/Enterprise.js +254 -261
- package/dist/cjs/export/BevyExporter.js +927 -967
- package/dist/cjs/export/CocosExporter.js +644 -673
- package/dist/cjs/export/Construct3Exporter.js +783 -794
- package/dist/cjs/export/DefoldExporter.js +1028 -1069
- package/dist/cjs/export/GDevelopExporter.js +674 -708
- package/dist/cjs/export/GameMakerExporter.js +791 -805
- package/dist/cjs/export/GodotExporter.js +1003 -1045
- package/dist/cjs/export/MinecraftBedrockExporter.js +573 -578
- package/dist/cjs/export/MonoGameExporter.js +1265 -1293
- package/dist/cjs/export/Pico8Exporter.js +766 -812
- package/dist/cjs/export/PlatformExporter.js +188 -206
- package/dist/cjs/export/RPGMakerExporter.js +860 -879
- package/dist/cjs/export/RobloxExporter.js +883 -919
- package/dist/cjs/export/Solar2DExporter.js +1218 -1256
- package/dist/cjs/export/ThreeJSExporter.js +1006 -1073
- package/dist/cjs/export/Tic80Exporter.js +1210 -1267
- package/dist/cjs/export/UnityExporter.js +1116 -1131
- package/dist/cjs/export/UnrealExporter.js +889 -919
- package/dist/cjs/export/WebExporter.js +931 -970
- package/dist/cjs/export/index.js +42 -65
- package/dist/cjs/godot-integration/GodotAssetLibrary.js +659 -692
- package/dist/cjs/godot-integration/GodotImport.js +929 -1027
- package/dist/cjs/godot-integration/GodotLiveLink.js +915 -945
- package/dist/cjs/godot-integration/components/GodotProjectBrowser.js +911 -611
- package/dist/cjs/i18n/I18n.js +860 -900
- package/dist/cjs/i18n/useTranslation.js +84 -89
- package/dist/cjs/import/AsepriteImporter.js +658 -716
- package/dist/cjs/import/DragonBonesImporter.js +437 -461
- package/dist/cjs/import/GameMakerImporter.js +511 -521
- package/dist/cjs/import/GodotSceneImporter.js +788 -822
- package/dist/cjs/import/LDtkImporter.js +436 -454
- package/dist/cjs/import/Live2DImporter.js +497 -518
- package/dist/cjs/import/NdgFormat.js +424 -457
- package/dist/cjs/import/OgmoImporter.js +466 -493
- package/dist/cjs/import/RPGMakerImporter.js +451 -477
- package/dist/cjs/import/SceneImporter.js +378 -423
- package/dist/cjs/import/SpineImporter.js +511 -546
- package/dist/cjs/import/SpriterImporter.js +590 -613
- package/dist/cjs/import/TiledMapImporter.js +811 -846
- package/dist/cjs/import/UnitySceneImporter.js +687 -703
- package/dist/cjs/import/index.js +206 -251
- package/dist/cjs/index.js +275 -278
- package/dist/cjs/input/GamepadNavigation.js +185 -205
- package/dist/cjs/input/InputManager.js +397 -421
- package/dist/cjs/input/useGamepads.js +70 -81
- package/dist/cjs/integration/IconSprite.js +129 -256
- package/dist/cjs/inventory/InventorySystem.js +920 -995
- package/dist/cjs/kids/KidMode.js +997 -1022
- package/dist/cjs/kids/KidTools.js +570 -594
- package/dist/cjs/monetization/Monetization.js +170 -177
- package/dist/cjs/multiplayer/LocalMultiplayer.js +287 -287
- package/dist/cjs/multiplayer/MiniGameTypes.js +49 -59
- package/dist/cjs/native-engine/AnimationSystem.js +731 -806
- package/dist/cjs/native-engine/AssetPipeline.js +454 -515
- package/dist/cjs/native-engine/AudioEngine.js +763 -804
- package/dist/cjs/native-engine/InputSystem.js +1075 -1145
- package/dist/cjs/native-engine/NetworkingSystem.js +733 -793
- package/dist/cjs/native-engine/PhysicsEngine.js +583 -607
- package/dist/cjs/native-engine/RenderingEngine.js +302 -350
- package/dist/cjs/native-engine/SceneGraph.js +769 -808
- package/dist/cjs/network/MultiplayerTransport.js +97 -132
- package/dist/cjs/network/Networking.js +549 -564
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AbortController.js +21 -29
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +40 -48
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +35 -43
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +10 -15
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Errors.js +103 -135
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +131 -158
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +39 -53
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +5 -8
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +40 -48
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +494 -572
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +826 -953
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +125 -146
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +13 -23
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ILogger.js +11 -25
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ITransport.js +13 -24
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +108 -121
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Loggers.js +10 -14
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +150 -185
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +158 -196
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +90 -105
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Subject.js +30 -35
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +16 -21
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Utils.js +215 -248
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +135 -157
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +76 -85
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/index.js +24 -27
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +3 -4
- package/dist/cjs/pathfinding/Pathfinding.js +245 -263
- package/dist/cjs/performance/AssetStreaming.js +561 -635
- package/dist/cjs/performance/BenchmarkSuite.js +283 -311
- package/dist/cjs/performance/DeltaCompression.js +467 -526
- package/dist/cjs/performance/DeterministicPhysics.js +450 -498
- package/dist/cjs/performance/ECSOptimization.js +644 -695
- package/dist/cjs/performance/GameSaveSystem.js +509 -556
- package/dist/cjs/performance/HotReload.js +447 -500
- package/dist/cjs/performance/InputRecording.js +511 -561
- package/dist/cjs/performance/InterestManagement.js +453 -500
- package/dist/cjs/performance/LocalizationRuntime.js +376 -423
- package/dist/cjs/performance/MemoryManagement.js +410 -470
- package/dist/cjs/performance/ModSupport.js +445 -496
- package/dist/cjs/performance/MultiThreadedPhysics.js +400 -443
- package/dist/cjs/performance/NetworkPrediction.js +424 -482
- package/dist/cjs/performance/ObjectPooling.js +569 -617
- package/dist/cjs/performance/Performance.js +174 -190
- package/dist/cjs/performance/PerformanceAdvanced.js +614 -637
- package/dist/cjs/performance/WebGPURenderer.js +656 -683
- package/dist/cjs/physics/PhysicsAdvanced.js +345 -379
- package/dist/cjs/physics/PhysicsEngine2D.js +391 -427
- package/dist/cjs/plugins/PluginSDK.js +432 -466
- package/dist/cjs/plugins/PluginTestKit.js +307 -330
- package/dist/cjs/procedural/Procedural.js +243 -254
- package/dist/cjs/procedural/WorldBuilding.js +297 -314
- package/dist/cjs/quest/QuestSystem.js +975 -932
- package/dist/cjs/release/MobileExport.js +157 -163
- package/dist/cjs/release/Release.js +225 -238
- package/dist/cjs/rendering/Camera2D.js +121 -124
- package/dist/cjs/rendering/Renderer2D.js +321 -335
- package/dist/cjs/rendering/WebGPURenderPipeline.js +632 -651
- package/dist/cjs/runtime3d/Runtime3D.js +359 -378
- package/dist/cjs/runtime3d/SceneEditor3D.js +252 -263
- package/dist/cjs/scene/SceneManager.js +177 -193
- package/dist/cjs/scripting/GraphToAST.js +574 -547
- package/dist/cjs/scripting/LanguageExporter.js +254 -279
- package/dist/cjs/scripting/NodeGraph.js +546 -570
- package/dist/cjs/scripting/ScriptAST.js +31 -39
- package/dist/cjs/scripting/VisualScripting2.js +1016 -1065
- package/dist/cjs/scripting/exporters/CSharpExporter.js +464 -496
- package/dist/cjs/scripting/exporters/GDScriptExporter.js +390 -442
- package/dist/cjs/scripting/exporters/LuaExporter.js +406 -447
- package/dist/cjs/scripting/exporters/PythonExporter.js +484 -549
- package/dist/cjs/scripting/exporters/RustExporter.js +459 -512
- package/dist/cjs/scripting/exporters/TypeScriptExporter.js +505 -556
- package/dist/cjs/social/Social.js +72 -80
- package/dist/cjs/systems/LightingSystem.js +844 -931
- package/dist/cjs/systems/ParticleSystem2.js +1447 -1451
- package/dist/cjs/systems/PhysicsDebugSystem.js +1070 -1141
- package/dist/cjs/systems/TerrainSystem.js +985 -1098
- package/dist/cjs/templates/ActionTemplates.js +296 -309
- package/dist/cjs/templates/FightingTemplate.js +417 -463
- package/dist/cjs/templates/MetroidvaniaTemplate.js +353 -405
- package/dist/cjs/templates/PartyTemplates.js +190 -202
- package/dist/cjs/templates/PuzzleTemplates.js +245 -261
- package/dist/cjs/templates/RPGTemplates.js +160 -178
- package/dist/cjs/templates/SportsTemplates.js +237 -250
- package/dist/cjs/templates/StrategyTemplates.js +143 -153
- package/dist/cjs/templates/SurvivalTemplate.js +336 -380
- package/dist/cjs/templates/WaveDefense.js +499 -526
- package/dist/cjs/tilemap/Tilemap.js +207 -214
- package/dist/cjs/tutorials/TutorialBranching.js +396 -417
- package/dist/cjs/tutorials/TutorialEngine.js +888 -931
- package/dist/cjs/tutorials/TutorialOverlay.js +602 -640
- package/dist/cjs/tutorials/content/Tutorials_T05_T08.js +787 -809
- package/dist/cjs/tutorials/content/Tutorials_T09_T11.js +736 -756
- package/dist/cjs/tutorials/content/Tutorials_T12_T15.js +754 -778
- package/dist/cjs/ui/GameUI.js +295 -312
- package/dist/cjs/unity-integration/UnityAssetStore.js +700 -741
- package/dist/cjs/unity-integration/UnityImport.js +1066 -1176
- package/dist/cjs/unity-integration/UnityLiveLink.js +934 -981
- package/dist/cjs/unity-integration/components/UnityAssetStoreBrowser.js +1233 -757
- package/dist/cjs/unity-integration/components/UnityProjectBrowser.js +1240 -768
- package/dist/cjs/unreal-integration/UnrealImport.js +391 -412
- package/dist/cjs/unreal-integration/UnrealLiveLink.js +1102 -1137
- package/dist/cjs/unreal-integration/UnrealMarketplace.js +436 -473
- package/dist/cjs/unreal-integration/components/UnrealProjectBrowser.js +1150 -767
- package/dist/cjs/xr/ARVR.js +167 -175
- package/dist/esm/accessibility/Accessibility.js +160 -164
- package/dist/esm/ai/AI.js +310 -293
- package/dist/esm/ai/BehaviorTree.js +1057 -1112
- package/dist/esm/ai/StateMachine.js +709 -755
- package/dist/esm/animation/Animation.js +237 -240
- package/dist/esm/audio/AudioAdvanced.js +239 -235
- package/dist/esm/audio/AudioBridge.js +448 -434
- package/dist/esm/audio/AudioManager.js +243 -258
- package/dist/esm/build-cloud/BuildOrchestration.js +1071 -1097
- package/dist/esm/build-cloud/GodotBuildCloud.js +647 -669
- package/dist/esm/build-cloud/UnityBuildCloud.js +571 -609
- package/dist/esm/build-cloud/UnrealBuildCloud.js +615 -634
- package/dist/esm/core/EventBus.js +52 -55
- package/dist/esm/core/GameClock.js +63 -65
- package/dist/esm/core/GameConfig.js +77 -78
- package/dist/esm/core/GameLoop.js +81 -88
- package/dist/esm/core/ServiceLocator.js +63 -64
- package/dist/esm/core/Validation.js +82 -81
- package/dist/esm/core/math.js +109 -111
- package/dist/esm/devtools/DevTools.js +546 -562
- package/dist/esm/devtools/DeveloperExperience.js +535 -558
- package/dist/esm/devtools/GameplayAnalytics.js +647 -645
- package/dist/esm/dialogue/DialogueSystem.js +998 -985
- package/dist/esm/docs/DocGenerator.js +342 -363
- package/dist/esm/ecs/World.js +358 -370
- package/dist/esm/editor/AchievementEditor.js +584 -635
- package/dist/esm/editor/AdvancedEditor.js +191 -190
- package/dist/esm/editor/AnimationRetargeting.js +700 -740
- package/dist/esm/editor/AssetBrowser.js +1078 -1159
- package/dist/esm/editor/AssetManager.js +188 -191
- package/dist/esm/editor/ConsolePro.js +977 -1060
- package/dist/esm/editor/CraftingEditor.js +684 -729
- package/dist/esm/editor/DebugTools.js +194 -184
- package/dist/esm/editor/DialogueSystem.js +849 -900
- package/dist/esm/editor/LeaderboardSystem.js +433 -482
- package/dist/esm/editor/NiceGameEditor.js +1908 -1200
- package/dist/esm/editor/PrefabSystem.js +777 -837
- package/dist/esm/editor/ProfilerPanel.js +654 -699
- package/dist/esm/editor/QuestEditor.js +795 -838
- package/dist/esm/editor/ReplaySystem.js +591 -633
- package/dist/esm/editor/SceneEditor.js +189 -199
- package/dist/esm/editor/ScreenshotMode.js +628 -687
- package/dist/esm/editor/ShaderGraph.js +1565 -1581
- package/dist/esm/editor/TimelineEditor.js +733 -777
- package/dist/esm/editor/UndoRedoPro.js +835 -903
- package/dist/esm/editor/VRARMode.js +586 -644
- package/dist/esm/engine/NiceGameEngine.js +142 -163
- package/dist/esm/engine/SaveSystem.js +447 -494
- package/dist/esm/enterprise/Enterprise.js +265 -260
- package/dist/esm/export/BevyExporter.js +929 -966
- package/dist/esm/export/CocosExporter.js +646 -672
- package/dist/esm/export/Construct3Exporter.js +785 -793
- package/dist/esm/export/DefoldExporter.js +1030 -1068
- package/dist/esm/export/GDevelopExporter.js +676 -707
- package/dist/esm/export/GameMakerExporter.js +793 -804
- package/dist/esm/export/GodotExporter.js +1004 -1044
- package/dist/esm/export/MinecraftBedrockExporter.js +575 -577
- package/dist/esm/export/MonoGameExporter.js +1267 -1292
- package/dist/esm/export/Pico8Exporter.js +768 -811
- package/dist/esm/export/PlatformExporter.js +193 -205
- package/dist/esm/export/RPGMakerExporter.js +862 -878
- package/dist/esm/export/RobloxExporter.js +885 -918
- package/dist/esm/export/Solar2DExporter.js +1220 -1255
- package/dist/esm/export/ThreeJSExporter.js +1007 -1072
- package/dist/esm/export/Tic80Exporter.js +1212 -1266
- package/dist/esm/export/UnityExporter.js +1117 -1130
- package/dist/esm/export/UnrealExporter.js +891 -918
- package/dist/esm/export/WebExporter.js +933 -969
- package/dist/esm/export/index.js +86 -71
- package/dist/esm/godot-integration/GodotAssetLibrary.js +663 -691
- package/dist/esm/godot-integration/GodotImport.js +935 -1026
- package/dist/esm/godot-integration/GodotLiveLink.js +918 -944
- package/dist/esm/godot-integration/components/GodotProjectBrowser.js +912 -610
- package/dist/esm/i18n/I18n.js +871 -899
- package/dist/esm/i18n/useTranslation.js +88 -88
- package/dist/esm/import/AsepriteImporter.js +637 -715
- package/dist/esm/import/DragonBonesImporter.js +417 -460
- package/dist/esm/import/GameMakerImporter.js +491 -520
- package/dist/esm/import/GodotSceneImporter.js +767 -821
- package/dist/esm/import/LDtkImporter.js +415 -453
- package/dist/esm/import/Live2DImporter.js +477 -517
- package/dist/esm/import/NdgFormat.js +410 -456
- package/dist/esm/import/OgmoImporter.js +446 -492
- package/dist/esm/import/RPGMakerImporter.js +431 -476
- package/dist/esm/import/SceneImporter.js +385 -422
- package/dist/esm/import/SpineImporter.js +491 -545
- package/dist/esm/import/SpriterImporter.js +570 -612
- package/dist/esm/import/TiledMapImporter.js +790 -845
- package/dist/esm/import/UnitySceneImporter.js +666 -702
- package/dist/esm/import/index.js +247 -258
- package/dist/esm/index.js +1332 -188
- package/dist/esm/input/GamepadNavigation.js +187 -204
- package/dist/esm/input/InputManager.js +401 -420
- package/dist/esm/input/useGamepads.js +72 -80
- package/dist/esm/integration/IconSprite.js +143 -255
- package/dist/esm/inventory/InventorySystem.js +925 -994
- package/dist/esm/kids/KidMode.js +1003 -1021
- package/dist/esm/kids/KidTools.js +573 -593
- package/dist/esm/monetization/Monetization.js +180 -176
- package/dist/esm/multiplayer/LocalMultiplayer.js +290 -286
- package/dist/esm/multiplayer/MiniGameTypes.js +58 -58
- package/dist/esm/native-engine/AnimationSystem.js +735 -805
- package/dist/esm/native-engine/AssetPipeline.js +456 -514
- package/dist/esm/native-engine/AudioEngine.js +765 -803
- package/dist/esm/native-engine/InputSystem.js +1079 -1144
- package/dist/esm/native-engine/NetworkingSystem.js +740 -792
- package/dist/esm/native-engine/PhysicsEngine.js +585 -606
- package/dist/esm/native-engine/RenderingEngine.js +304 -349
- package/dist/esm/native-engine/SceneGraph.js +773 -807
- package/dist/esm/network/MultiplayerTransport.js +99 -131
- package/dist/esm/network/Networking.js +556 -563
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AbortController.js +22 -28
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +41 -47
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +36 -42
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +11 -14
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Errors.js +111 -134
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +132 -157
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +40 -52
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +6 -7
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +42 -47
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +496 -571
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +828 -952
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +126 -145
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +14 -23
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ILogger.js +12 -25
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ITransport.js +15 -24
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +109 -120
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Loggers.js +11 -13
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +151 -184
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +159 -195
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +91 -104
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Subject.js +31 -34
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +17 -20
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Utils.js +230 -248
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +136 -156
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +77 -84
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/index.js +31 -12
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +4 -3
- package/dist/esm/pathfinding/Pathfinding.js +249 -262
- package/dist/esm/performance/AssetStreaming.js +567 -634
- package/dist/esm/performance/BenchmarkSuite.js +285 -310
- package/dist/esm/performance/DeltaCompression.js +478 -525
- package/dist/esm/performance/DeterministicPhysics.js +479 -497
- package/dist/esm/performance/ECSOptimization.js +653 -694
- package/dist/esm/performance/GameSaveSystem.js +515 -555
- package/dist/esm/performance/HotReload.js +454 -499
- package/dist/esm/performance/InputRecording.js +520 -560
- package/dist/esm/performance/InterestManagement.js +460 -499
- package/dist/esm/performance/LocalizationRuntime.js +382 -422
- package/dist/esm/performance/MemoryManagement.js +415 -469
- package/dist/esm/performance/ModSupport.js +455 -495
- package/dist/esm/performance/MultiThreadedPhysics.js +408 -442
- package/dist/esm/performance/NetworkPrediction.js +436 -481
- package/dist/esm/performance/ObjectPooling.js +582 -616
- package/dist/esm/performance/Performance.js +182 -189
- package/dist/esm/performance/PerformanceAdvanced.js +621 -636
- package/dist/esm/performance/WebGPURenderer.js +660 -682
- package/dist/esm/physics/PhysicsAdvanced.js +359 -378
- package/dist/esm/physics/PhysicsEngine2D.js +393 -426
- package/dist/esm/plugins/PluginSDK.js +435 -465
- package/dist/esm/plugins/PluginTestKit.js +315 -329
- package/dist/esm/procedural/Procedural.js +248 -253
- package/dist/esm/procedural/WorldBuilding.js +316 -313
- package/dist/esm/quest/QuestSystem.js +982 -931
- package/dist/esm/release/MobileExport.js +163 -162
- package/dist/esm/release/Release.js +234 -237
- package/dist/esm/rendering/Camera2D.js +122 -123
- package/dist/esm/rendering/Renderer2D.js +323 -334
- package/dist/esm/rendering/WebGPURenderPipeline.js +647 -650
- package/dist/esm/runtime3d/Runtime3D.js +368 -377
- package/dist/esm/runtime3d/SceneEditor3D.js +268 -262
- package/dist/esm/scene/SceneManager.js +178 -192
- package/dist/esm/scripting/GraphToAST.js +576 -546
- package/dist/esm/scripting/LanguageExporter.js +263 -278
- package/dist/esm/scripting/NodeGraph.js +550 -569
- package/dist/esm/scripting/ScriptAST.js +45 -38
- package/dist/esm/scripting/VisualScripting2.js +1025 -1064
- package/dist/esm/scripting/exporters/CSharpExporter.js +465 -495
- package/dist/esm/scripting/exporters/GDScriptExporter.js +391 -441
- package/dist/esm/scripting/exporters/LuaExporter.js +407 -446
- package/dist/esm/scripting/exporters/PythonExporter.js +485 -548
- package/dist/esm/scripting/exporters/RustExporter.js +460 -511
- package/dist/esm/scripting/exporters/TypeScriptExporter.js +506 -555
- package/dist/esm/social/Social.js +77 -79
- package/dist/esm/systems/LightingSystem.js +855 -930
- package/dist/esm/systems/ParticleSystem2.js +1453 -1450
- package/dist/esm/systems/PhysicsDebugSystem.js +1078 -1140
- package/dist/esm/systems/TerrainSystem.js +996 -1097
- package/dist/esm/templates/ActionTemplates.js +307 -308
- package/dist/esm/templates/FightingTemplate.js +439 -462
- package/dist/esm/templates/MetroidvaniaTemplate.js +391 -404
- package/dist/esm/templates/PartyTemplates.js +206 -201
- package/dist/esm/templates/PuzzleTemplates.js +260 -260
- package/dist/esm/templates/RPGTemplates.js +172 -177
- package/dist/esm/templates/SportsTemplates.js +251 -249
- package/dist/esm/templates/StrategyTemplates.js +158 -152
- package/dist/esm/templates/SurvivalTemplate.js +367 -379
- package/dist/esm/templates/WaveDefense.js +501 -525
- package/dist/esm/tilemap/Tilemap.js +209 -213
- package/dist/esm/tutorials/TutorialBranching.js +399 -416
- package/dist/esm/tutorials/TutorialEngine.js +893 -930
- package/dist/esm/tutorials/TutorialOverlay.js +603 -639
- package/dist/esm/tutorials/content/Tutorials_T05_T08.js +792 -808
- package/dist/esm/tutorials/content/Tutorials_T09_T11.js +740 -755
- package/dist/esm/tutorials/content/Tutorials_T12_T15.js +759 -777
- package/dist/esm/ui/GameUI.js +296 -311
- package/dist/esm/unity-integration/UnityAssetStore.js +704 -740
- package/dist/esm/unity-integration/UnityImport.js +1071 -1175
- package/dist/esm/unity-integration/UnityLiveLink.js +938 -980
- package/dist/esm/unity-integration/components/UnityAssetStoreBrowser.js +1234 -756
- package/dist/esm/unity-integration/components/UnityProjectBrowser.js +1241 -767
- package/dist/esm/unreal-integration/UnrealImport.js +395 -411
- package/dist/esm/unreal-integration/UnrealLiveLink.js +1105 -1136
- package/dist/esm/unreal-integration/UnrealMarketplace.js +442 -472
- package/dist/esm/unreal-integration/components/UnrealProjectBrowser.js +1151 -766
- package/dist/esm/xr/ARVR.js +181 -174
- 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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
106
|
-
x += vec.x;
|
|
107
|
-
y += vec.y;
|
|
181
|
+
}
|
|
108
182
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (
|
|
112
|
-
|
|
113
|
-
y /= mag;
|
|
183
|
+
break;
|
|
184
|
+
case "touch":
|
|
185
|
+
if (this.touch.activeTouches > 0) {
|
|
186
|
+
value = 1;
|
|
114
187
|
}
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
return
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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
|
-
|
|
354
|
-
|
|
355
|
-
|
|
228
|
+
}
|
|
229
|
+
checkModifiers(modifiers) {
|
|
230
|
+
if (!modifiers || modifiers.length === 0) {
|
|
231
|
+
return true;
|
|
356
232
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
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
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
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
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
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
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
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
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
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
|
-
|
|
566
|
+
_GamepadStateImpl.AXIS_MAP = ["left-x", "left-y", "right-x", "right-y"];
|
|
567
|
+
let GamepadStateImpl = _GamepadStateImpl;
|
|
603
568
|
class TouchStateImpl {
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
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
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
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
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
}
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
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
|
-
|
|
1101
|
+
return new InputSystem();
|
|
1171
1102
|
}
|
|
1172
1103
|
function createUISystem(canvas) {
|
|
1173
|
-
|
|
1104
|
+
return new UISystem(canvas);
|
|
1174
1105
|
}
|
|
1175
|
-
|
|
1176
|
-
|
|
1106
|
+
export {
|
|
1107
|
+
InputSystem,
|
|
1108
|
+
UISystem,
|
|
1109
|
+
createInputSystem,
|
|
1110
|
+
createUISystem
|
|
1111
|
+
};
|