1681-engine 0.0.0-stage → 0.5.8
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 +304 -0
- package/LICENSE +21 -0
- package/README.md +164 -2
- package/dist/1681-engine.js +417 -0
- package/dist/1681-engine.js.map +1 -0
- package/dist/ambient/ColorGrade.js +41 -0
- package/dist/ambient/ColorGrade.js.map +1 -0
- package/dist/ambient/DayClock.js +57 -0
- package/dist/ambient/DayClock.js.map +1 -0
- package/dist/ambient/WeatherLayer.js +91 -0
- package/dist/ambient/WeatherLayer.js.map +1 -0
- package/dist/ambient/grade.js +13 -0
- package/dist/ambient/grade.js.map +1 -0
- package/dist/ambient/weather.js +52 -0
- package/dist/ambient/weather.js.map +1 -0
- package/dist/anim/AnimStateMachine.js +164 -0
- package/dist/anim/AnimStateMachine.js.map +1 -0
- package/dist/anim/Animator.js +67 -0
- package/dist/anim/Animator.js.map +1 -0
- package/dist/anim/animStateCompile.js +113 -0
- package/dist/anim/animStateCompile.js.map +1 -0
- package/dist/anim/animStateSystem.js +17 -0
- package/dist/anim/animStateSystem.js.map +1 -0
- package/dist/anim/animationSystem.js +15 -0
- package/dist/anim/animationSystem.js.map +1 -0
- package/dist/anim/asepriteSlices.js +22 -0
- package/dist/anim/asepriteSlices.js.map +1 -0
- package/dist/anim/asepriteTags.js +35 -0
- package/dist/anim/asepriteTags.js.map +1 -0
- package/dist/anim/parseAseprite.js +83 -0
- package/dist/anim/parseAseprite.js.map +1 -0
- package/dist/assets/AssetLoader.js +104 -0
- package/dist/assets/AssetLoader.js.map +1 -0
- package/dist/assets/loadAseprite.js +50 -0
- package/dist/assets/loadAseprite.js.map +1 -0
- package/dist/assets/takeCleanerWorker-DTcI_Jqr.js +31 -0
- package/dist/assets/takeCleanerWorker-DTcI_Jqr.js.map +1 -0
- package/dist/audio/Footsteps.js +26 -0
- package/dist/audio/Footsteps.js.map +1 -0
- package/dist/audio/MusicPlayer.js +78 -0
- package/dist/audio/MusicPlayer.js.map +1 -0
- package/dist/audio/SoundEngine.js +119 -0
- package/dist/audio/SoundEngine.js.map +1 -0
- package/dist/audio/cleanTake.js +30 -0
- package/dist/audio/cleanTake.js.map +1 -0
- package/dist/audio/music/ElementVoice.js +35 -0
- package/dist/audio/music/ElementVoice.js.map +1 -0
- package/dist/audio/music/GraphVoice.js +39 -0
- package/dist/audio/music/GraphVoice.js.map +1 -0
- package/dist/audio/music/MusicChannel.js +58 -0
- package/dist/audio/music/MusicChannel.js.map +1 -0
- package/dist/audio/music/musicVoice.js +13 -0
- package/dist/audio/music/musicVoice.js.map +1 -0
- package/dist/audio/sampleBank.js +82 -0
- package/dist/audio/sampleBank.js.map +1 -0
- package/dist/audio/soundTable.js +9 -0
- package/dist/audio/soundTable.js.map +1 -0
- package/dist/audio/synth.js +36 -0
- package/dist/audio/synth.js.map +1 -0
- package/dist/core/BitmapLabel.js +49 -0
- package/dist/core/BitmapLabel.js.map +1 -0
- package/dist/core/Camera.js +150 -0
- package/dist/core/Camera.js.map +1 -0
- package/dist/core/Clock.js +30 -0
- package/dist/core/Clock.js.map +1 -0
- package/dist/core/Graphics.js +69 -0
- package/dist/core/Graphics.js.map +1 -0
- package/dist/core/Group.js +29 -0
- package/dist/core/Group.js.map +1 -0
- package/dist/core/Image.js +51 -0
- package/dist/core/Image.js.map +1 -0
- package/dist/core/ObjectFactory.js +55 -0
- package/dist/core/ObjectFactory.js.map +1 -0
- package/dist/core/Pointer.js +58 -0
- package/dist/core/Pointer.js.map +1 -0
- package/dist/core/Rectangle.js +51 -0
- package/dist/core/Rectangle.js.map +1 -0
- package/dist/core/Stage.js +86 -0
- package/dist/core/Stage.js.map +1 -0
- package/dist/core/Text.js +22 -0
- package/dist/core/Text.js.map +1 -0
- package/dist/core/TextureRegistry.js +111 -0
- package/dist/core/TextureRegistry.js.map +1 -0
- package/dist/core/Timeline.js +211 -0
- package/dist/core/Timeline.js.map +1 -0
- package/dist/core/TimelineBuilder.js +73 -0
- package/dist/core/TimelineBuilder.js.map +1 -0
- package/dist/core/TimelineChild.js +84 -0
- package/dist/core/TimelineChild.js.map +1 -0
- package/dist/core/Tweener.js +136 -0
- package/dist/core/Tweener.js.map +1 -0
- package/dist/core/atlas.js +38 -0
- package/dist/core/atlas.js.map +1 -0
- package/dist/core/atlasPlan.js +22 -0
- package/dist/core/atlasPlan.js.map +1 -0
- package/dist/core/eases.js +21 -0
- package/dist/core/eases.js.map +1 -0
- package/dist/core/gameObject.js +115 -0
- package/dist/core/gameObject.js.map +1 -0
- package/dist/core/pixiPatches.js +18 -0
- package/dist/core/pixiPatches.js.map +1 -0
- package/dist/core/timelinePlace.js +24 -0
- package/dist/core/timelinePlace.js.map +1 -0
- package/dist/core/tweenProps.js +12 -0
- package/dist/core/tweenProps.js.map +1 -0
- package/dist/debug/DebugOverlay.js +94 -0
- package/dist/debug/DebugOverlay.js.map +1 -0
- package/dist/debug/DrawCallCounter.js +41 -0
- package/dist/debug/DrawCallCounter.js.map +1 -0
- package/dist/debug/ErrorLog.js +22 -0
- package/dist/debug/ErrorLog.js.map +1 -0
- package/dist/debug/FrameStats.js +42 -0
- package/dist/debug/FrameStats.js.map +1 -0
- package/dist/debug/inspectWorld.js +29 -0
- package/dist/debug/inspectWorld.js.map +1 -0
- package/dist/diagnostics/ErrorDeduper.js +27 -0
- package/dist/diagnostics/ErrorDeduper.js.map +1 -0
- package/dist/diagnostics/FrameSampler.js +42 -0
- package/dist/diagnostics/FrameSampler.js.map +1 -0
- package/dist/diagnostics/bootWatch.js +21 -0
- package/dist/diagnostics/bootWatch.js.map +1 -0
- package/dist/diagnostics/captureErrors.js +27 -0
- package/dist/diagnostics/captureErrors.js.map +1 -0
- package/dist/diagnostics/contextLoss.js +25 -0
- package/dist/diagnostics/contextLoss.js.map +1 -0
- package/dist/diagnostics/frameStats.js +31 -0
- package/dist/diagnostics/frameStats.js.map +1 -0
- package/dist/diagnostics/gpuInfo.js +22 -0
- package/dist/diagnostics/gpuInfo.js.map +1 -0
- package/dist/diagnostics/renderGuard.js +24 -0
- package/dist/diagnostics/renderGuard.js.map +1 -0
- package/dist/ecs/SparseSet.js +55 -0
- package/dist/ecs/SparseSet.js.map +1 -0
- package/dist/ecs/World.js +307 -0
- package/dist/ecs/World.js.map +1 -0
- package/dist/ecs/fields.js +26 -0
- package/dist/ecs/fields.js.map +1 -0
- package/dist/engine/Engine.js +82 -0
- package/dist/engine/Engine.js.map +1 -0
- package/dist/engine/FixedLoop.js +37 -0
- package/dist/engine/FixedLoop.js.map +1 -0
- package/dist/engine/Scene.js +79 -0
- package/dist/engine/Scene.js.map +1 -0
- package/dist/engine/SceneManager.js +73 -0
- package/dist/engine/SceneManager.js.map +1 -0
- package/dist/events/EventBus.js +42 -0
- package/dist/events/EventBus.js.map +1 -0
- package/dist/fx/FloatingText.js +72 -0
- package/dist/fx/FloatingText.js.map +1 -0
- package/dist/fx/hitStop.js +28 -0
- package/dist/fx/hitStop.js.map +1 -0
- package/dist/fx/viewCull.js +10 -0
- package/dist/fx/viewCull.js.map +1 -0
- package/dist/i18n/Translator.js +72 -0
- package/dist/i18n/Translator.js.map +1 -0
- package/dist/i18n/extractStrings.js +58 -0
- package/dist/i18n/extractStrings.js.map +1 -0
- package/dist/i18n/formatMessage.js +19 -0
- package/dist/i18n/formatMessage.js.map +1 -0
- package/dist/input/Actions.js +131 -0
- package/dist/input/Actions.js.map +1 -0
- package/dist/input/AimGesture.js +75 -0
- package/dist/input/AimGesture.js.map +1 -0
- package/dist/input/Keyboard.js +54 -0
- package/dist/input/Keyboard.js.map +1 -0
- package/dist/input/Keymap.js +171 -0
- package/dist/input/Keymap.js.map +1 -0
- package/dist/input/TargetLock.js +73 -0
- package/dist/input/TargetLock.js.map +1 -0
- package/dist/input/aimAxis.js +8 -0
- package/dist/input/aimAxis.js.map +1 -0
- package/dist/input/keyChord.js +29 -0
- package/dist/input/keyChord.js.map +1 -0
- package/dist/input/longPress.js +32 -0
- package/dist/input/longPress.js.map +1 -0
- package/dist/input/stickAxis.js +23 -0
- package/dist/input/stickAxis.js.map +1 -0
- package/dist/input/touchDetect.js +7 -0
- package/dist/input/touchDetect.js.map +1 -0
- package/dist/light/LightLayer.js +84 -0
- package/dist/light/LightLayer.js.map +1 -0
- package/dist/nav/MinHeap.js +39 -0
- package/dist/nav/MinHeap.js.map +1 -0
- package/dist/nav/findPath.js +78 -0
- package/dist/nav/findPath.js.map +1 -0
- package/dist/nav/navGrid.js +36 -0
- package/dist/nav/navGrid.js.map +1 -0
- package/dist/nav/nearestOpen.js +19 -0
- package/dist/nav/nearestOpen.js.map +1 -0
- package/dist/nav/straightenPath.js +51 -0
- package/dist/nav/straightenPath.js.map +1 -0
- package/dist/net/Connection.js +84 -0
- package/dist/net/Connection.js.map +1 -0
- package/dist/net/InterpolationBuffer.js +57 -0
- package/dist/net/InterpolationBuffer.js.map +1 -0
- package/dist/net/PredictedMover.js +61 -0
- package/dist/net/PredictedMover.js.map +1 -0
- package/dist/net/Room.js +92 -0
- package/dist/net/Room.js.map +1 -0
- package/dist/net/RoomHost.js +101 -0
- package/dist/net/RoomHost.js.map +1 -0
- package/dist/net/cadence.js +22 -0
- package/dist/net/cadence.js.map +1 -0
- package/dist/net/constants.js +11 -0
- package/dist/net/constants.js.map +1 -0
- package/dist/net/lobby/LobbyClient.js +124 -0
- package/dist/net/lobby/LobbyClient.js.map +1 -0
- package/dist/net/lobby/LobbyHost.js +366 -0
- package/dist/net/lobby/LobbyHost.js.map +1 -0
- package/dist/net/lobby/LobbyRooms.js +66 -0
- package/dist/net/lobby/LobbyRooms.js.map +1 -0
- package/dist/net/lobby/Matchmaker.js +106 -0
- package/dist/net/lobby/Matchmaker.js.map +1 -0
- package/dist/net/movement.js +83 -0
- package/dist/net/movement.js.map +1 -0
- package/dist/net/protocol.js +11 -0
- package/dist/net/protocol.js.map +1 -0
- package/dist/net/serverClock.js +22 -0
- package/dist/net/serverClock.js.map +1 -0
- package/dist/net/snapshotCodec.js +92 -0
- package/dist/net/snapshotCodec.js.map +1 -0
- package/dist/parallax/Parallax.js +32 -0
- package/dist/parallax/Parallax.js.map +1 -0
- package/dist/parallax/ParallaxLayer.js +70 -0
- package/dist/parallax/ParallaxLayer.js.map +1 -0
- package/dist/parallax/parallaxMath.js +27 -0
- package/dist/parallax/parallaxMath.js.map +1 -0
- package/dist/particles/Emitter.js +108 -0
- package/dist/particles/Emitter.js.map +1 -0
- package/dist/particles/ParticleBudget.js +32 -0
- package/dist/particles/ParticleBudget.js.map +1 -0
- package/dist/particles/ParticleSim.js +60 -0
- package/dist/particles/ParticleSim.js.map +1 -0
- package/dist/particles/particleCurves.js +48 -0
- package/dist/particles/particleCurves.js.map +1 -0
- package/dist/particles/particleSampling.js +30 -0
- package/dist/particles/particleSampling.js.map +1 -0
- package/dist/physics/Body.js +202 -0
- package/dist/physics/Body.js.map +1 -0
- package/dist/physics/BroadPhase.js +56 -0
- package/dist/physics/BroadPhase.js.map +1 -0
- package/dist/physics/Contact.js +76 -0
- package/dist/physics/Contact.js.map +1 -0
- package/dist/physics/ContactSolver.js +70 -0
- package/dist/physics/ContactSolver.js.map +1 -0
- package/dist/physics/PhysicsWorld.js +221 -0
- package/dist/physics/PhysicsWorld.js.map +1 -0
- package/dist/physics/SpatialHash.js +39 -0
- package/dist/physics/SpatialHash.js.map +1 -0
- package/dist/physics/collide.js +76 -0
- package/dist/physics/collide.js.map +1 -0
- package/dist/physics/collidePolygon.js +94 -0
- package/dist/physics/collidePolygon.js.map +1 -0
- package/dist/physics/contactReport.js +14 -0
- package/dist/physics/contactReport.js.map +1 -0
- package/dist/physics/drawColliders.js +31 -0
- package/dist/physics/drawColliders.js.map +1 -0
- package/dist/physics/physicsSystem.js +8 -0
- package/dist/physics/physicsSystem.js.map +1 -0
- package/dist/physics/polygon.js +80 -0
- package/dist/physics/polygon.js.map +1 -0
- package/dist/physics/raycast.js +62 -0
- package/dist/physics/raycast.js.map +1 -0
- package/dist/physics/syncToBody.js +19 -0
- package/dist/physics/syncToBody.js.map +1 -0
- package/dist/physics/tileBodies.js +59 -0
- package/dist/physics/tileBodies.js.map +1 -0
- package/dist/physics/types.js +8 -0
- package/dist/physics/types.js.map +1 -0
- package/dist/pixel/Darkness.js +166 -0
- package/dist/pixel/Darkness.js.map +1 -0
- package/dist/pixel/DitherVignette.js +57 -0
- package/dist/pixel/DitherVignette.js.map +1 -0
- package/dist/pixel/Evaporation.js +85 -0
- package/dist/pixel/Evaporation.js.map +1 -0
- package/dist/pixel/NightShade.js +34 -0
- package/dist/pixel/NightShade.js.map +1 -0
- package/dist/pixel/PixelLayer.js +211 -0
- package/dist/pixel/PixelLayer.js.map +1 -0
- package/dist/pixel/SwayProp.js +75 -0
- package/dist/pixel/SwayProp.js.map +1 -0
- package/dist/pixel/lights.js +44 -0
- package/dist/pixel/lights.js.map +1 -0
- package/dist/pixel/nineSlice.js +62 -0
- package/dist/pixel/nineSlice.js.map +1 -0
- package/dist/pixel/paintLayer.js +36 -0
- package/dist/pixel/paintLayer.js.map +1 -0
- package/dist/pixel/palette.js +57 -0
- package/dist/pixel/palette.js.map +1 -0
- package/dist/pixel/pixel.js +278 -0
- package/dist/pixel/pixel.js.map +1 -0
- package/dist/pixel/pixelPaint.js +194 -0
- package/dist/pixel/pixelPaint.js.map +1 -0
- package/dist/pixel/pixelTone.js +164 -0
- package/dist/pixel/pixelTone.js.map +1 -0
- package/dist/pixel/propKit.js +41 -0
- package/dist/pixel/propKit.js.map +1 -0
- package/dist/pixel/ramp.js +102 -0
- package/dist/pixel/ramp.js.map +1 -0
- package/dist/pixel/selout.js +35 -0
- package/dist/pixel/selout.js.map +1 -0
- package/dist/pixel/spritePixels.js +59 -0
- package/dist/pixel/spritePixels.js.map +1 -0
- package/dist/pixel/swayRig.js +87 -0
- package/dist/pixel/swayRig.js.map +1 -0
- package/dist/pixel/vignetteMask.js +24 -0
- package/dist/pixel/vignetteMask.js.map +1 -0
- package/dist/pixel/weatherArt.js +61 -0
- package/dist/pixel/weatherArt.js.map +1 -0
- package/dist/pixel.js +90 -0
- package/dist/pixel.js.map +1 -0
- package/dist/platform/touch.js +33 -0
- package/dist/platform/touch.js.map +1 -0
- package/dist/postfx/BloomFilter.js +65 -0
- package/dist/postfx/BloomFilter.js.map +1 -0
- package/dist/postfx/ChromaticAberrationFilter.js +25 -0
- package/dist/postfx/ChromaticAberrationFilter.js.map +1 -0
- package/dist/postfx/ColorAdjustFilter.js +76 -0
- package/dist/postfx/ColorAdjustFilter.js.map +1 -0
- package/dist/postfx/CrtFilter.js +42 -0
- package/dist/postfx/CrtFilter.js.map +1 -0
- package/dist/postfx/PixelateFilter.js +27 -0
- package/dist/postfx/PixelateFilter.js.map +1 -0
- package/dist/postfx/PostFx.js +123 -0
- package/dist/postfx/PostFx.js.map +1 -0
- package/dist/postfx/ShockwaveFilter.js +49 -0
- package/dist/postfx/ShockwaveFilter.js.map +1 -0
- package/dist/postfx/VignetteFilter.js +37 -0
- package/dist/postfx/VignetteFilter.js.map +1 -0
- package/dist/postfx/fxAnimator.js +38 -0
- package/dist/postfx/fxAnimator.js.map +1 -0
- package/dist/postfx/fxShader.js +128 -0
- package/dist/postfx/fxShader.js.map +1 -0
- package/dist/postfx.js +26 -0
- package/dist/postfx.js.map +1 -0
- package/dist/react/ChoiceDialog.js +51 -0
- package/dist/react/ChoiceDialog.js.map +1 -0
- package/dist/react/ConfirmDialog.js +53 -0
- package/dist/react/ConfirmDialog.js.map +1 -0
- package/dist/react/Glyph.js +63 -0
- package/dist/react/Glyph.js.map +1 -0
- package/dist/react/Modal.js +38 -0
- package/dist/react/Modal.js.map +1 -0
- package/dist/react/Panel.js +24 -0
- package/dist/react/Panel.js.map +1 -0
- package/dist/react/PixelImage.js +24 -0
- package/dist/react/PixelImage.js.map +1 -0
- package/dist/react/Select.js +99 -0
- package/dist/react/Select.js.map +1 -0
- package/dist/react/Slider.js +62 -0
- package/dist/react/Slider.js.map +1 -0
- package/dist/react/SplitPane.js +24 -0
- package/dist/react/SplitPane.js.map +1 -0
- package/dist/react/TabStrip.js +32 -0
- package/dist/react/TabStrip.js.map +1 -0
- package/dist/react/TitleTips.js +42 -0
- package/dist/react/TitleTips.js.map +1 -0
- package/dist/react/Tooltip.js +28 -0
- package/dist/react/Tooltip.js.map +1 -0
- package/dist/react/UiProvider.js +50 -0
- package/dist/react/UiProvider.js.map +1 -0
- package/dist/react/baseCss.js +222 -0
- package/dist/react/baseCss.js.map +1 -0
- package/dist/react/choiceStore.js +23 -0
- package/dist/react/choiceStore.js.map +1 -0
- package/dist/react/classNames.js +19 -0
- package/dist/react/classNames.js.map +1 -0
- package/dist/react/confirmStore.js +30 -0
- package/dist/react/confirmStore.js.map +1 -0
- package/dist/react/labels.js +18 -0
- package/dist/react/labels.js.map +1 -0
- package/dist/react/placement.js +49 -0
- package/dist/react/placement.js.map +1 -0
- package/dist/react/useFillSheet.js +23 -0
- package/dist/react/useFillSheet.js.map +1 -0
- package/dist/react/useFitToViewport.js +29 -0
- package/dist/react/useFitToViewport.js.map +1 -0
- package/dist/react/usePicked.js +13 -0
- package/dist/react/usePicked.js.map +1 -0
- package/dist/react/useStore.js +9 -0
- package/dist/react/useStore.js.map +1 -0
- package/dist/react/useViewport.js +17 -0
- package/dist/react/useViewport.js.map +1 -0
- package/dist/react.js +78 -0
- package/dist/react.js.map +1 -0
- package/dist/rig/PosePlayer.js +92 -0
- package/dist/rig/PosePlayer.js.map +1 -0
- package/dist/rig/RigView.js +125 -0
- package/dist/rig/RigView.js.map +1 -0
- package/dist/rig/Skeleton.js +31 -0
- package/dist/rig/Skeleton.js.map +1 -0
- package/dist/rig/humanoid.js +6 -0
- package/dist/rig/humanoid.js.map +1 -0
- package/dist/rig/humanoid.json.js +30 -0
- package/dist/rig/humanoid.json.js.map +1 -0
- package/dist/rig/humanoidPoses.js +30 -0
- package/dist/rig/humanoidPoses.js.map +1 -0
- package/dist/rig/poseMath.js +54 -0
- package/dist/rig/poseMath.js.map +1 -0
- package/dist/rig/poses.json.js +150 -0
- package/dist/rig/poses.json.js.map +1 -0
- package/dist/save/Autosaver.js +54 -0
- package/dist/save/Autosaver.js.map +1 -0
- package/dist/save/MemoryBackend.js +19 -0
- package/dist/save/MemoryBackend.js.map +1 -0
- package/dist/save/SaveStore.js +103 -0
- package/dist/save/SaveStore.js.map +1 -0
- package/dist/save/WebStorageBackend.js +27 -0
- package/dist/save/WebStorageBackend.js.map +1 -0
- package/dist/save/checksum.js +10 -0
- package/dist/save/checksum.js.map +1 -0
- package/dist/save/migrateSave.js +27 -0
- package/dist/save/migrateSave.js.map +1 -0
- package/dist/settings.js +27 -0
- package/dist/settings.js.map +1 -0
- package/dist/tilemap/TilemapView.js +69 -0
- package/dist/tilemap/TilemapView.js.map +1 -0
- package/dist/tilemap/collision.js +25 -0
- package/dist/tilemap/collision.js.map +1 -0
- package/dist/tilemap/tiled.js +138 -0
- package/dist/tilemap/tiled.js.map +1 -0
- package/dist/transitions/CrossfadeTransition.js +24 -0
- package/dist/transitions/CrossfadeTransition.js.map +1 -0
- package/dist/transitions/DitherWipeTransition.js +70 -0
- package/dist/transitions/DitherWipeTransition.js.map +1 -0
- package/dist/transitions/FadeTransition.js +34 -0
- package/dist/transitions/FadeTransition.js.map +1 -0
- package/dist/transitions/Letterbox.js +42 -0
- package/dist/transitions/Letterbox.js.map +1 -0
- package/dist/transitions/ditherMask.js +15 -0
- package/dist/transitions/ditherMask.js.map +1 -0
- package/dist/transitions/transitionTo.js +28 -0
- package/dist/transitions/transitionTo.js.map +1 -0
- package/dist/transitions/tweenDone.js +15 -0
- package/dist/transitions/tweenDone.js.map +1 -0
- package/dist/types/ambient/ColorGrade.d.ts +41 -0
- package/dist/types/ambient/ColorGrade.d.ts.map +1 -0
- package/dist/types/ambient/DayClock.d.ts +80 -0
- package/dist/types/ambient/DayClock.d.ts.map +1 -0
- package/dist/types/ambient/WeatherLayer.d.ts +78 -0
- package/dist/types/ambient/WeatherLayer.d.ts.map +1 -0
- package/dist/types/ambient/grade.d.ts +22 -0
- package/dist/types/ambient/grade.d.ts.map +1 -0
- package/dist/types/ambient/weather.d.ts +49 -0
- package/dist/types/ambient/weather.d.ts.map +1 -0
- package/dist/types/anim/AnimStateMachine.d.ts +80 -0
- package/dist/types/anim/AnimStateMachine.d.ts.map +1 -0
- package/dist/types/anim/Animator.d.ts +50 -0
- package/dist/types/anim/Animator.d.ts.map +1 -0
- package/dist/types/anim/animStateCompile.d.ts +52 -0
- package/dist/types/anim/animStateCompile.d.ts.map +1 -0
- package/dist/types/anim/animStateSystem.d.ts +10 -0
- package/dist/types/anim/animStateSystem.d.ts.map +1 -0
- package/dist/types/anim/animStateTypes.d.ts +50 -0
- package/dist/types/anim/animStateTypes.d.ts.map +1 -0
- package/dist/types/anim/animationSystem.d.ts +13 -0
- package/dist/types/anim/animationSystem.d.ts.map +1 -0
- package/dist/types/anim/asepriteSlices.d.ts +19 -0
- package/dist/types/anim/asepriteSlices.d.ts.map +1 -0
- package/dist/types/anim/asepriteTags.d.ts +16 -0
- package/dist/types/anim/asepriteTags.d.ts.map +1 -0
- package/dist/types/anim/asepriteTypes.d.ts +159 -0
- package/dist/types/anim/asepriteTypes.d.ts.map +1 -0
- package/dist/types/anim/parseAseprite.d.ts +21 -0
- package/dist/types/anim/parseAseprite.d.ts.map +1 -0
- package/dist/types/assets/AssetLoader.d.ts +85 -0
- package/dist/types/assets/AssetLoader.d.ts.map +1 -0
- package/dist/types/assets/loadAseprite.d.ts +27 -0
- package/dist/types/assets/loadAseprite.d.ts.map +1 -0
- package/dist/types/audio/Footsteps.d.ts +33 -0
- package/dist/types/audio/Footsteps.d.ts.map +1 -0
- package/dist/types/audio/MusicPlayer.d.ts +65 -0
- package/dist/types/audio/MusicPlayer.d.ts.map +1 -0
- package/dist/types/audio/SoundEngine.d.ts +42 -0
- package/dist/types/audio/SoundEngine.d.ts.map +1 -0
- package/dist/types/audio/cleanTake.d.ts +3 -0
- package/dist/types/audio/cleanTake.d.ts.map +1 -0
- package/dist/types/audio/music/ElementVoice.d.ts +14 -0
- package/dist/types/audio/music/ElementVoice.d.ts.map +1 -0
- package/dist/types/audio/music/GraphVoice.d.ts +22 -0
- package/dist/types/audio/music/GraphVoice.d.ts.map +1 -0
- package/dist/types/audio/music/MusicChannel.d.ts +35 -0
- package/dist/types/audio/music/MusicChannel.d.ts.map +1 -0
- package/dist/types/audio/music/musicVoice.d.ts +26 -0
- package/dist/types/audio/music/musicVoice.d.ts.map +1 -0
- package/dist/types/audio/sampleBank.d.ts +27 -0
- package/dist/types/audio/sampleBank.d.ts.map +1 -0
- package/dist/types/audio/soundTable.d.ts +14 -0
- package/dist/types/audio/soundTable.d.ts.map +1 -0
- package/dist/types/audio/synth.d.ts +34 -0
- package/dist/types/audio/synth.d.ts.map +1 -0
- package/dist/types/audio/takeCleanerWorker.d.ts +2 -0
- package/dist/types/audio/takeCleanerWorker.d.ts.map +1 -0
- package/dist/types/core/BitmapLabel.d.ts +36 -0
- package/dist/types/core/BitmapLabel.d.ts.map +1 -0
- package/dist/types/core/Camera.d.ts +115 -0
- package/dist/types/core/Camera.d.ts.map +1 -0
- package/dist/types/core/Clock.d.ts +11 -0
- package/dist/types/core/Clock.d.ts.map +1 -0
- package/dist/types/core/Graphics.d.ts +37 -0
- package/dist/types/core/Graphics.d.ts.map +1 -0
- package/dist/types/core/Group.d.ts +15 -0
- package/dist/types/core/Group.d.ts.map +1 -0
- package/dist/types/core/Image.d.ts +25 -0
- package/dist/types/core/Image.d.ts.map +1 -0
- package/dist/types/core/ObjectFactory.d.ts +34 -0
- package/dist/types/core/ObjectFactory.d.ts.map +1 -0
- package/dist/types/core/Pointer.d.ts +27 -0
- package/dist/types/core/Pointer.d.ts.map +1 -0
- package/dist/types/core/Rectangle.d.ts +26 -0
- package/dist/types/core/Rectangle.d.ts.map +1 -0
- package/dist/types/core/Stage.d.ts +58 -0
- package/dist/types/core/Stage.d.ts.map +1 -0
- package/dist/types/core/Text.d.ts +22 -0
- package/dist/types/core/Text.d.ts.map +1 -0
- package/dist/types/core/TextureRegistry.d.ts +51 -0
- package/dist/types/core/TextureRegistry.d.ts.map +1 -0
- package/dist/types/core/Timeline.d.ts +115 -0
- package/dist/types/core/Timeline.d.ts.map +1 -0
- package/dist/types/core/TimelineBuilder.d.ts +53 -0
- package/dist/types/core/TimelineBuilder.d.ts.map +1 -0
- package/dist/types/core/TimelineChild.d.ts +51 -0
- package/dist/types/core/TimelineChild.d.ts.map +1 -0
- package/dist/types/core/Tweener.d.ts +70 -0
- package/dist/types/core/Tweener.d.ts.map +1 -0
- package/dist/types/core/atlas.d.ts +16 -0
- package/dist/types/core/atlas.d.ts.map +1 -0
- package/dist/types/core/atlasPlan.d.ts +34 -0
- package/dist/types/core/atlasPlan.d.ts.map +1 -0
- package/dist/types/core/eases.d.ts +3 -0
- package/dist/types/core/eases.d.ts.map +1 -0
- package/dist/types/core/gameObject.d.ts +42 -0
- package/dist/types/core/gameObject.d.ts.map +1 -0
- package/dist/types/core/pixiPatches.d.ts +9 -0
- package/dist/types/core/pixiPatches.d.ts.map +1 -0
- package/dist/types/core/timelinePlace.d.ts +23 -0
- package/dist/types/core/timelinePlace.d.ts.map +1 -0
- package/dist/types/core/tweenProps.d.ts +8 -0
- package/dist/types/core/tweenProps.d.ts.map +1 -0
- package/dist/types/core/types.d.ts +4 -0
- package/dist/types/core/types.d.ts.map +1 -0
- package/dist/types/debug/DebugOverlay.d.ts +63 -0
- package/dist/types/debug/DebugOverlay.d.ts.map +1 -0
- package/dist/types/debug/DrawCallCounter.d.ts +20 -0
- package/dist/types/debug/DrawCallCounter.d.ts.map +1 -0
- package/dist/types/debug/ErrorLog.d.ts +20 -0
- package/dist/types/debug/ErrorLog.d.ts.map +1 -0
- package/dist/types/debug/FrameStats.d.ts +21 -0
- package/dist/types/debug/FrameStats.d.ts.map +1 -0
- package/dist/types/debug/inspectWorld.d.ts +14 -0
- package/dist/types/debug/inspectWorld.d.ts.map +1 -0
- package/dist/types/diagnostics/ErrorDeduper.d.ts +17 -0
- package/dist/types/diagnostics/ErrorDeduper.d.ts.map +1 -0
- package/dist/types/diagnostics/FrameSampler.d.ts +37 -0
- package/dist/types/diagnostics/FrameSampler.d.ts.map +1 -0
- package/dist/types/diagnostics/bootWatch.d.ts +25 -0
- package/dist/types/diagnostics/bootWatch.d.ts.map +1 -0
- package/dist/types/diagnostics/captureErrors.d.ts +24 -0
- package/dist/types/diagnostics/captureErrors.d.ts.map +1 -0
- package/dist/types/diagnostics/contextLoss.d.ts +35 -0
- package/dist/types/diagnostics/contextLoss.d.ts.map +1 -0
- package/dist/types/diagnostics/frameStats.d.ts +30 -0
- package/dist/types/diagnostics/frameStats.d.ts.map +1 -0
- package/dist/types/diagnostics/gpuInfo.d.ts +9 -0
- package/dist/types/diagnostics/gpuInfo.d.ts.map +1 -0
- package/dist/types/diagnostics/renderGuard.d.ts +12 -0
- package/dist/types/diagnostics/renderGuard.d.ts.map +1 -0
- package/dist/types/ecs/SparseSet.d.ts +25 -0
- package/dist/types/ecs/SparseSet.d.ts.map +1 -0
- package/dist/types/ecs/World.d.ts +137 -0
- package/dist/types/ecs/World.d.ts.map +1 -0
- package/dist/types/ecs/fields.d.ts +34 -0
- package/dist/types/ecs/fields.d.ts.map +1 -0
- package/dist/types/engine/Engine.d.ts +80 -0
- package/dist/types/engine/Engine.d.ts.map +1 -0
- package/dist/types/engine/FixedLoop.d.ts +32 -0
- package/dist/types/engine/FixedLoop.d.ts.map +1 -0
- package/dist/types/engine/Scene.d.ts +67 -0
- package/dist/types/engine/Scene.d.ts.map +1 -0
- package/dist/types/engine/SceneManager.d.ts +36 -0
- package/dist/types/engine/SceneManager.d.ts.map +1 -0
- package/dist/types/events/EventBus.d.ts +20 -0
- package/dist/types/events/EventBus.d.ts.map +1 -0
- package/dist/types/fx/FloatingText.d.ts +71 -0
- package/dist/types/fx/FloatingText.d.ts.map +1 -0
- package/dist/types/fx/hitStop.d.ts +20 -0
- package/dist/types/fx/hitStop.d.ts.map +1 -0
- package/dist/types/fx/viewCull.d.ts +14 -0
- package/dist/types/fx/viewCull.d.ts.map +1 -0
- package/dist/types/i18n/Translator.d.ts +52 -0
- package/dist/types/i18n/Translator.d.ts.map +1 -0
- package/dist/types/i18n/extractStrings.d.ts +25 -0
- package/dist/types/i18n/extractStrings.d.ts.map +1 -0
- package/dist/types/i18n/formatMessage.d.ts +10 -0
- package/dist/types/i18n/formatMessage.d.ts.map +1 -0
- package/dist/types/index.d.ts +149 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/input/Actions.d.ts +94 -0
- package/dist/types/input/Actions.d.ts.map +1 -0
- package/dist/types/input/AimGesture.d.ts +106 -0
- package/dist/types/input/AimGesture.d.ts.map +1 -0
- package/dist/types/input/Keyboard.d.ts +30 -0
- package/dist/types/input/Keyboard.d.ts.map +1 -0
- package/dist/types/input/Keymap.d.ts +85 -0
- package/dist/types/input/Keymap.d.ts.map +1 -0
- package/dist/types/input/TargetLock.d.ts +56 -0
- package/dist/types/input/TargetLock.d.ts.map +1 -0
- package/dist/types/input/aimAxis.d.ts +9 -0
- package/dist/types/input/aimAxis.d.ts.map +1 -0
- package/dist/types/input/keyChord.d.ts +15 -0
- package/dist/types/input/keyChord.d.ts.map +1 -0
- package/dist/types/input/longPress.d.ts +21 -0
- package/dist/types/input/longPress.d.ts.map +1 -0
- package/dist/types/input/stickAxis.d.ts +26 -0
- package/dist/types/input/stickAxis.d.ts.map +1 -0
- package/dist/types/input/touchDetect.d.ts +18 -0
- package/dist/types/input/touchDetect.d.ts.map +1 -0
- package/dist/types/light/LightLayer.d.ts +65 -0
- package/dist/types/light/LightLayer.d.ts.map +1 -0
- package/dist/types/nav/MinHeap.d.ts +15 -0
- package/dist/types/nav/MinHeap.d.ts.map +1 -0
- package/dist/types/nav/findPath.d.ts +38 -0
- package/dist/types/nav/findPath.d.ts.map +1 -0
- package/dist/types/nav/navGrid.d.ts +48 -0
- package/dist/types/nav/navGrid.d.ts.map +1 -0
- package/dist/types/nav/nearestOpen.d.ts +8 -0
- package/dist/types/nav/nearestOpen.d.ts.map +1 -0
- package/dist/types/nav/straightenPath.d.ts +13 -0
- package/dist/types/nav/straightenPath.d.ts.map +1 -0
- package/dist/types/net/Connection.d.ts +66 -0
- package/dist/types/net/Connection.d.ts.map +1 -0
- package/dist/types/net/InterpolationBuffer.d.ts +36 -0
- package/dist/types/net/InterpolationBuffer.d.ts.map +1 -0
- package/dist/types/net/PredictedMover.d.ts +43 -0
- package/dist/types/net/PredictedMover.d.ts.map +1 -0
- package/dist/types/net/Room.d.ts +69 -0
- package/dist/types/net/Room.d.ts.map +1 -0
- package/dist/types/net/RoomHost.d.ts +74 -0
- package/dist/types/net/RoomHost.d.ts.map +1 -0
- package/dist/types/net/cadence.d.ts +22 -0
- package/dist/types/net/cadence.d.ts.map +1 -0
- package/dist/types/net/constants.d.ts +24 -0
- package/dist/types/net/constants.d.ts.map +1 -0
- package/dist/types/net/lobby/LobbyClient.d.ts +107 -0
- package/dist/types/net/lobby/LobbyClient.d.ts.map +1 -0
- package/dist/types/net/lobby/LobbyHost.d.ts +147 -0
- package/dist/types/net/lobby/LobbyHost.d.ts.map +1 -0
- package/dist/types/net/lobby/LobbyRooms.d.ts +56 -0
- package/dist/types/net/lobby/LobbyRooms.d.ts.map +1 -0
- package/dist/types/net/lobby/Matchmaker.d.ts +57 -0
- package/dist/types/net/lobby/Matchmaker.d.ts.map +1 -0
- package/dist/types/net/lobby/index.d.ts +6 -0
- package/dist/types/net/lobby/index.d.ts.map +1 -0
- package/dist/types/net/lobby/lobbyProtocol.d.ts +143 -0
- package/dist/types/net/lobby/lobbyProtocol.d.ts.map +1 -0
- package/dist/types/net/movement.d.ts +50 -0
- package/dist/types/net/movement.d.ts.map +1 -0
- package/dist/types/net/protocol.d.ts +59 -0
- package/dist/types/net/protocol.d.ts.map +1 -0
- package/dist/types/net/serverClock.d.ts +14 -0
- package/dist/types/net/serverClock.d.ts.map +1 -0
- package/dist/types/net/snapshotCodec.d.ts +55 -0
- package/dist/types/net/snapshotCodec.d.ts.map +1 -0
- package/dist/types/parallax/Parallax.d.ts +37 -0
- package/dist/types/parallax/Parallax.d.ts.map +1 -0
- package/dist/types/parallax/ParallaxLayer.d.ts +80 -0
- package/dist/types/parallax/ParallaxLayer.d.ts.map +1 -0
- package/dist/types/parallax/parallaxMath.d.ts +50 -0
- package/dist/types/parallax/parallaxMath.d.ts.map +1 -0
- package/dist/types/particles/Emitter.d.ts +97 -0
- package/dist/types/particles/Emitter.d.ts.map +1 -0
- package/dist/types/particles/ParticleBudget.d.ts +28 -0
- package/dist/types/particles/ParticleBudget.d.ts.map +1 -0
- package/dist/types/particles/ParticleSim.d.ts +38 -0
- package/dist/types/particles/ParticleSim.d.ts.map +1 -0
- package/dist/types/particles/particleCurves.d.ts +21 -0
- package/dist/types/particles/particleCurves.d.ts.map +1 -0
- package/dist/types/particles/particleSampling.d.ts +20 -0
- package/dist/types/particles/particleSampling.d.ts.map +1 -0
- package/dist/types/physics/Body.d.ts +130 -0
- package/dist/types/physics/Body.d.ts.map +1 -0
- package/dist/types/physics/BroadPhase.d.ts +26 -0
- package/dist/types/physics/BroadPhase.d.ts.map +1 -0
- package/dist/types/physics/Contact.d.ts +62 -0
- package/dist/types/physics/Contact.d.ts.map +1 -0
- package/dist/types/physics/ContactSolver.d.ts +29 -0
- package/dist/types/physics/ContactSolver.d.ts.map +1 -0
- package/dist/types/physics/PhysicsWorld.d.ts +78 -0
- package/dist/types/physics/PhysicsWorld.d.ts.map +1 -0
- package/dist/types/physics/PhysicsWorldOptions.d.ts +24 -0
- package/dist/types/physics/PhysicsWorldOptions.d.ts.map +1 -0
- package/dist/types/physics/SpatialHash.d.ts +23 -0
- package/dist/types/physics/SpatialHash.d.ts.map +1 -0
- package/dist/types/physics/collide.d.ts +27 -0
- package/dist/types/physics/collide.d.ts.map +1 -0
- package/dist/types/physics/collidePolygon.d.ts +14 -0
- package/dist/types/physics/collidePolygon.d.ts.map +1 -0
- package/dist/types/physics/contactReport.d.ts +8 -0
- package/dist/types/physics/contactReport.d.ts.map +1 -0
- package/dist/types/physics/drawColliders.d.ts +43 -0
- package/dist/types/physics/drawColliders.d.ts.map +1 -0
- package/dist/types/physics/physicsSystem.d.ts +5 -0
- package/dist/types/physics/physicsSystem.d.ts.map +1 -0
- package/dist/types/physics/polygon.d.ts +28 -0
- package/dist/types/physics/polygon.d.ts.map +1 -0
- package/dist/types/physics/raycast.d.ts +19 -0
- package/dist/types/physics/raycast.d.ts.map +1 -0
- package/dist/types/physics/syncToBody.d.ts +16 -0
- package/dist/types/physics/syncToBody.d.ts.map +1 -0
- package/dist/types/physics/tileBodies.d.ts +36 -0
- package/dist/types/physics/tileBodies.d.ts.map +1 -0
- package/dist/types/physics/types.d.ts +116 -0
- package/dist/types/physics/types.d.ts.map +1 -0
- package/dist/types/pixel/Darkness.d.ts +78 -0
- package/dist/types/pixel/Darkness.d.ts.map +1 -0
- package/dist/types/pixel/DitherVignette.d.ts +35 -0
- package/dist/types/pixel/DitherVignette.d.ts.map +1 -0
- package/dist/types/pixel/Evaporation.d.ts +30 -0
- package/dist/types/pixel/Evaporation.d.ts.map +1 -0
- package/dist/types/pixel/NightShade.d.ts +38 -0
- package/dist/types/pixel/NightShade.d.ts.map +1 -0
- package/dist/types/pixel/PixelLayer.d.ts +85 -0
- package/dist/types/pixel/PixelLayer.d.ts.map +1 -0
- package/dist/types/pixel/SwayProp.d.ts +52 -0
- package/dist/types/pixel/SwayProp.d.ts.map +1 -0
- package/dist/types/pixel/index.d.ts +31 -0
- package/dist/types/pixel/index.d.ts.map +1 -0
- package/dist/types/pixel/lights.d.ts +34 -0
- package/dist/types/pixel/lights.d.ts.map +1 -0
- package/dist/types/pixel/nineSlice.d.ts +71 -0
- package/dist/types/pixel/nineSlice.d.ts.map +1 -0
- package/dist/types/pixel/paintLayer.d.ts +35 -0
- package/dist/types/pixel/paintLayer.d.ts.map +1 -0
- package/dist/types/pixel/palette.d.ts +58 -0
- package/dist/types/pixel/palette.d.ts.map +1 -0
- package/dist/types/pixel/pixel.d.ts +80 -0
- package/dist/types/pixel/pixel.d.ts.map +1 -0
- package/dist/types/pixel/pixelPaint.d.ts +43 -0
- package/dist/types/pixel/pixelPaint.d.ts.map +1 -0
- package/dist/types/pixel/pixelTone.d.ts +51 -0
- package/dist/types/pixel/pixelTone.d.ts.map +1 -0
- package/dist/types/pixel/propKit.d.ts +26 -0
- package/dist/types/pixel/propKit.d.ts.map +1 -0
- package/dist/types/pixel/ramp.d.ts +57 -0
- package/dist/types/pixel/ramp.d.ts.map +1 -0
- package/dist/types/pixel/selout.d.ts +3 -0
- package/dist/types/pixel/selout.d.ts.map +1 -0
- package/dist/types/pixel/spritePixels.d.ts +29 -0
- package/dist/types/pixel/spritePixels.d.ts.map +1 -0
- package/dist/types/pixel/swayRig.d.ts +72 -0
- package/dist/types/pixel/swayRig.d.ts.map +1 -0
- package/dist/types/pixel/vignetteMask.d.ts +16 -0
- package/dist/types/pixel/vignetteMask.d.ts.map +1 -0
- package/dist/types/pixel/weatherArt.d.ts +29 -0
- package/dist/types/pixel/weatherArt.d.ts.map +1 -0
- package/dist/types/platform/touch.d.ts +10 -0
- package/dist/types/platform/touch.d.ts.map +1 -0
- package/dist/types/postfx/BloomFilter.d.ts +33 -0
- package/dist/types/postfx/BloomFilter.d.ts.map +1 -0
- package/dist/types/postfx/ChromaticAberrationFilter.d.ts +11 -0
- package/dist/types/postfx/ChromaticAberrationFilter.d.ts.map +1 -0
- package/dist/types/postfx/ColorAdjustFilter.d.ts +32 -0
- package/dist/types/postfx/ColorAdjustFilter.d.ts.map +1 -0
- package/dist/types/postfx/CrtFilter.d.ts +16 -0
- package/dist/types/postfx/CrtFilter.d.ts.map +1 -0
- package/dist/types/postfx/PixelateFilter.d.ts +8 -0
- package/dist/types/postfx/PixelateFilter.d.ts.map +1 -0
- package/dist/types/postfx/PostFx.d.ts +92 -0
- package/dist/types/postfx/PostFx.d.ts.map +1 -0
- package/dist/types/postfx/ShockwaveFilter.d.ts +20 -0
- package/dist/types/postfx/ShockwaveFilter.d.ts.map +1 -0
- package/dist/types/postfx/VignetteFilter.d.ts +19 -0
- package/dist/types/postfx/VignetteFilter.d.ts.map +1 -0
- package/dist/types/postfx/fxAnimator.d.ts +32 -0
- package/dist/types/postfx/fxAnimator.d.ts.map +1 -0
- package/dist/types/postfx/fxShader.d.ts +49 -0
- package/dist/types/postfx/fxShader.d.ts.map +1 -0
- package/dist/types/postfx/index.d.ts +11 -0
- package/dist/types/postfx/index.d.ts.map +1 -0
- package/dist/types/react/ChoiceDialog.d.ts +8 -0
- package/dist/types/react/ChoiceDialog.d.ts.map +1 -0
- package/dist/types/react/ConfirmDialog.d.ts +9 -0
- package/dist/types/react/ConfirmDialog.d.ts.map +1 -0
- package/dist/types/react/Glyph.d.ts +54 -0
- package/dist/types/react/Glyph.d.ts.map +1 -0
- package/dist/types/react/Modal.d.ts +22 -0
- package/dist/types/react/Modal.d.ts.map +1 -0
- package/dist/types/react/Panel.d.ts +29 -0
- package/dist/types/react/Panel.d.ts.map +1 -0
- package/dist/types/react/PixelImage.d.ts +19 -0
- package/dist/types/react/PixelImage.d.ts.map +1 -0
- package/dist/types/react/Select.d.ts +27 -0
- package/dist/types/react/Select.d.ts.map +1 -0
- package/dist/types/react/Slider.d.ts +24 -0
- package/dist/types/react/Slider.d.ts.map +1 -0
- package/dist/types/react/SplitPane.d.ts +26 -0
- package/dist/types/react/SplitPane.d.ts.map +1 -0
- package/dist/types/react/TabStrip.d.ts +31 -0
- package/dist/types/react/TabStrip.d.ts.map +1 -0
- package/dist/types/react/TitleTips.d.ts +15 -0
- package/dist/types/react/TitleTips.d.ts.map +1 -0
- package/dist/types/react/Tooltip.d.ts +22 -0
- package/dist/types/react/Tooltip.d.ts.map +1 -0
- package/dist/types/react/UiProvider.d.ts +52 -0
- package/dist/types/react/UiProvider.d.ts.map +1 -0
- package/dist/types/react/baseCss.d.ts +27 -0
- package/dist/types/react/baseCss.d.ts.map +1 -0
- package/dist/types/react/choiceStore.d.ts +34 -0
- package/dist/types/react/choiceStore.d.ts.map +1 -0
- package/dist/types/react/classNames.d.ts +12 -0
- package/dist/types/react/classNames.d.ts.map +1 -0
- package/dist/types/react/confirmStore.d.ts +30 -0
- package/dist/types/react/confirmStore.d.ts.map +1 -0
- package/dist/types/react/index.d.ts +33 -0
- package/dist/types/react/index.d.ts.map +1 -0
- package/dist/types/react/labels.d.ts +24 -0
- package/dist/types/react/labels.d.ts.map +1 -0
- package/dist/types/react/placement.d.ts +59 -0
- package/dist/types/react/placement.d.ts.map +1 -0
- package/dist/types/react/useFillSheet.d.ts +9 -0
- package/dist/types/react/useFillSheet.d.ts.map +1 -0
- package/dist/types/react/useFitToViewport.d.ts +20 -0
- package/dist/types/react/useFitToViewport.d.ts.map +1 -0
- package/dist/types/react/usePicked.d.ts +9 -0
- package/dist/types/react/usePicked.d.ts.map +1 -0
- package/dist/types/react/useStore.d.ts +8 -0
- package/dist/types/react/useStore.d.ts.map +1 -0
- package/dist/types/react/useViewport.d.ts +4 -0
- package/dist/types/react/useViewport.d.ts.map +1 -0
- package/dist/types/rig/PosePlayer.d.ts +64 -0
- package/dist/types/rig/PosePlayer.d.ts.map +1 -0
- package/dist/types/rig/RigView.d.ts +68 -0
- package/dist/types/rig/RigView.d.ts.map +1 -0
- package/dist/types/rig/Skeleton.d.ts +14 -0
- package/dist/types/rig/Skeleton.d.ts.map +1 -0
- package/dist/types/rig/humanoid.d.ts +4 -0
- package/dist/types/rig/humanoid.d.ts.map +1 -0
- package/dist/types/rig/humanoidPoses.d.ts +117 -0
- package/dist/types/rig/humanoidPoses.d.ts.map +1 -0
- package/dist/types/rig/poseMath.d.ts +14 -0
- package/dist/types/rig/poseMath.d.ts.map +1 -0
- package/dist/types/rig/rigTypes.d.ts +82 -0
- package/dist/types/rig/rigTypes.d.ts.map +1 -0
- package/dist/types/save/Autosaver.d.ts +43 -0
- package/dist/types/save/Autosaver.d.ts.map +1 -0
- package/dist/types/save/MemoryBackend.d.ts +10 -0
- package/dist/types/save/MemoryBackend.d.ts.map +1 -0
- package/dist/types/save/SaveBackend.d.ts +14 -0
- package/dist/types/save/SaveBackend.d.ts.map +1 -0
- package/dist/types/save/SaveStore.d.ts +73 -0
- package/dist/types/save/SaveStore.d.ts.map +1 -0
- package/dist/types/save/WebStorageBackend.d.ts +14 -0
- package/dist/types/save/WebStorageBackend.d.ts.map +1 -0
- package/dist/types/save/checksum.d.ts +7 -0
- package/dist/types/save/checksum.d.ts.map +1 -0
- package/dist/types/save/migrateSave.d.ts +17 -0
- package/dist/types/save/migrateSave.d.ts.map +1 -0
- package/dist/types/settings.d.ts +25 -0
- package/dist/types/settings.d.ts.map +1 -0
- package/dist/types/tilemap/TilemapView.d.ts +42 -0
- package/dist/types/tilemap/TilemapView.d.ts.map +1 -0
- package/dist/types/tilemap/collision.d.ts +16 -0
- package/dist/types/tilemap/collision.d.ts.map +1 -0
- package/dist/types/tilemap/tiled.d.ts +104 -0
- package/dist/types/tilemap/tiled.d.ts.map +1 -0
- package/dist/types/transitions/CrossfadeTransition.d.ts +20 -0
- package/dist/types/transitions/CrossfadeTransition.d.ts.map +1 -0
- package/dist/types/transitions/DitherWipeTransition.d.ts +35 -0
- package/dist/types/transitions/DitherWipeTransition.d.ts.map +1 -0
- package/dist/types/transitions/FadeTransition.d.ts +20 -0
- package/dist/types/transitions/FadeTransition.d.ts.map +1 -0
- package/dist/types/transitions/Letterbox.d.ts +33 -0
- package/dist/types/transitions/Letterbox.d.ts.map +1 -0
- package/dist/types/transitions/Transition.d.ts +22 -0
- package/dist/types/transitions/Transition.d.ts.map +1 -0
- package/dist/types/transitions/ditherMask.d.ts +13 -0
- package/dist/types/transitions/ditherMask.d.ts.map +1 -0
- package/dist/types/transitions/transitionTo.d.ts +16 -0
- package/dist/types/transitions/transitionTo.d.ts.map +1 -0
- package/dist/types/transitions/tweenDone.d.ts +5 -0
- package/dist/types/transitions/tweenDone.d.ts.map +1 -0
- package/dist/types/ui/Bar.d.ts +41 -0
- package/dist/types/ui/Bar.d.ts.map +1 -0
- package/dist/types/ui/Button.d.ts +47 -0
- package/dist/types/ui/Button.d.ts.map +1 -0
- package/dist/types/ui/Dialog.d.ts +47 -0
- package/dist/types/ui/Dialog.d.ts.map +1 -0
- package/dist/types/ui/FocusManager.d.ts +53 -0
- package/dist/types/ui/FocusManager.d.ts.map +1 -0
- package/dist/types/ui/Label.d.ts +24 -0
- package/dist/types/ui/Label.d.ts.map +1 -0
- package/dist/types/ui/List.d.ts +23 -0
- package/dist/types/ui/List.d.ts.map +1 -0
- package/dist/types/ui/Panel.d.ts +38 -0
- package/dist/types/ui/Panel.d.ts.map +1 -0
- package/dist/types/ui/ScrollView.d.ts +56 -0
- package/dist/types/ui/ScrollView.d.ts.map +1 -0
- package/dist/types/ui/Slider.d.ts +47 -0
- package/dist/types/ui/Slider.d.ts.map +1 -0
- package/dist/types/ui/Stack.d.ts +16 -0
- package/dist/types/ui/Stack.d.ts.map +1 -0
- package/dist/types/ui/Toggle.d.ts +31 -0
- package/dist/types/ui/Toggle.d.ts.map +1 -0
- package/dist/types/ui/UiHost.d.ts +18 -0
- package/dist/types/ui/UiHost.d.ts.map +1 -0
- package/dist/types/ui/UiPointerGate.d.ts +17 -0
- package/dist/types/ui/UiPointerGate.d.ts.map +1 -0
- package/dist/types/ui/UiRoot.d.ts +73 -0
- package/dist/types/ui/UiRoot.d.ts.map +1 -0
- package/dist/types/ui/Widget.d.ts +56 -0
- package/dist/types/ui/Widget.d.ts.map +1 -0
- package/dist/types/ui/dom/DomOverlay.d.ts +52 -0
- package/dist/types/ui/dom/DomOverlay.d.ts.map +1 -0
- package/dist/types/ui/dom/DomWorldAnchors.d.ts +50 -0
- package/dist/types/ui/dom/DomWorldAnchors.d.ts.map +1 -0
- package/dist/types/ui/dom/InputShield.d.ts +20 -0
- package/dist/types/ui/dom/InputShield.d.ts.map +1 -0
- package/dist/types/ui/dom/createStore.d.ts +22 -0
- package/dist/types/ui/dom/createStore.d.ts.map +1 -0
- package/dist/types/ui/dom/shieldDecision.d.ts +34 -0
- package/dist/types/ui/dom/shieldDecision.d.ts.map +1 -0
- package/dist/types/ui/dom/worldToScreen.d.ts +24 -0
- package/dist/types/ui/dom/worldToScreen.d.ts.map +1 -0
- package/dist/types/ui/index.d.ts +38 -0
- package/dist/types/ui/index.d.ts.map +1 -0
- package/dist/types/ui/layout/anchor.d.ts +9 -0
- package/dist/types/ui/layout/anchor.d.ts.map +1 -0
- package/dist/types/ui/layout/barDrain.d.ts +25 -0
- package/dist/types/ui/layout/barDrain.d.ts.map +1 -0
- package/dist/types/ui/layout/fitToViewport.d.ts +32 -0
- package/dist/types/ui/layout/fitToViewport.d.ts.map +1 -0
- package/dist/types/ui/layout/focusNav.d.ts +13 -0
- package/dist/types/ui/layout/focusNav.d.ts.map +1 -0
- package/dist/types/ui/layout/geometry.d.ts +35 -0
- package/dist/types/ui/layout/geometry.d.ts.map +1 -0
- package/dist/types/ui/layout/listWidth.d.ts +13 -0
- package/dist/types/ui/layout/listWidth.d.ts.map +1 -0
- package/dist/types/ui/layout/placeTooltip.d.ts +23 -0
- package/dist/types/ui/layout/placeTooltip.d.ts.map +1 -0
- package/dist/types/ui/layout/scroll.d.ts +17 -0
- package/dist/types/ui/layout/scroll.d.ts.map +1 -0
- package/dist/types/ui/layout/slider.d.ts +7 -0
- package/dist/types/ui/layout/slider.d.ts.map +1 -0
- package/dist/types/ui/layout/stack.d.ts +26 -0
- package/dist/types/ui/layout/stack.d.ts.map +1 -0
- package/dist/types/ui/layout/wrapRow.d.ts +6 -0
- package/dist/types/ui/layout/wrapRow.d.ts.map +1 -0
- package/dist/ui/Bar.js +54 -0
- package/dist/ui/Bar.js.map +1 -0
- package/dist/ui/Button.js +58 -0
- package/dist/ui/Button.js.map +1 -0
- package/dist/ui/Dialog.js +56 -0
- package/dist/ui/Dialog.js.map +1 -0
- package/dist/ui/FocusManager.js +97 -0
- package/dist/ui/FocusManager.js.map +1 -0
- package/dist/ui/Label.js +36 -0
- package/dist/ui/Label.js.map +1 -0
- package/dist/ui/List.js +45 -0
- package/dist/ui/List.js.map +1 -0
- package/dist/ui/Panel.js +38 -0
- package/dist/ui/Panel.js.map +1 -0
- package/dist/ui/ScrollView.js +96 -0
- package/dist/ui/ScrollView.js.map +1 -0
- package/dist/ui/Slider.js +55 -0
- package/dist/ui/Slider.js.map +1 -0
- package/dist/ui/Stack.js +28 -0
- package/dist/ui/Stack.js.map +1 -0
- package/dist/ui/Toggle.js +37 -0
- package/dist/ui/Toggle.js.map +1 -0
- package/dist/ui/UiHost.js +9 -0
- package/dist/ui/UiHost.js.map +1 -0
- package/dist/ui/UiPointerGate.js +25 -0
- package/dist/ui/UiPointerGate.js.map +1 -0
- package/dist/ui/UiRoot.js +93 -0
- package/dist/ui/UiRoot.js.map +1 -0
- package/dist/ui/Widget.js +90 -0
- package/dist/ui/Widget.js.map +1 -0
- package/dist/ui/dom/DomOverlay.js +59 -0
- package/dist/ui/dom/DomOverlay.js.map +1 -0
- package/dist/ui/dom/DomWorldAnchors.js +59 -0
- package/dist/ui/dom/DomWorldAnchors.js.map +1 -0
- package/dist/ui/dom/InputShield.js +27 -0
- package/dist/ui/dom/InputShield.js.map +1 -0
- package/dist/ui/dom/createStore.js +42 -0
- package/dist/ui/dom/createStore.js.map +1 -0
- package/dist/ui/dom/shieldDecision.js +36 -0
- package/dist/ui/dom/shieldDecision.js.map +1 -0
- package/dist/ui/dom/worldToScreen.js +11 -0
- package/dist/ui/dom/worldToScreen.js.map +1 -0
- package/dist/ui/layout/anchor.js +20 -0
- package/dist/ui/layout/anchor.js.map +1 -0
- package/dist/ui/layout/barDrain.js +25 -0
- package/dist/ui/layout/barDrain.js.map +1 -0
- package/dist/ui/layout/fitToViewport.js +17 -0
- package/dist/ui/layout/fitToViewport.js.map +1 -0
- package/dist/ui/layout/focusNav.js +42 -0
- package/dist/ui/layout/focusNav.js.map +1 -0
- package/dist/ui/layout/geometry.js +21 -0
- package/dist/ui/layout/geometry.js.map +1 -0
- package/dist/ui/layout/listWidth.js +10 -0
- package/dist/ui/layout/listWidth.js.map +1 -0
- package/dist/ui/layout/placeTooltip.js +28 -0
- package/dist/ui/layout/placeTooltip.js.map +1 -0
- package/dist/ui/layout/scroll.js +24 -0
- package/dist/ui/layout/scroll.js.map +1 -0
- package/dist/ui/layout/slider.js +20 -0
- package/dist/ui/layout/slider.js.map +1 -0
- package/dist/ui/layout/stack.js +27 -0
- package/dist/ui/layout/stack.js.map +1 -0
- package/dist/ui/layout/wrapRow.js +13 -0
- package/dist/ui/layout/wrapRow.js.map +1 -0
- package/dist/ui.js +85 -0
- package/dist/ui.js.map +1 -0
- package/package.json +115 -4
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { parseChord as c, chordHeld as l } from "./keyChord.js";
|
|
2
|
+
const f = ["a", "b", "x", "y", "lb", "rb", "lt", "rt", "select", "start", "ls", "rs", "up", "down", "left", "right", "home"], u = ["lx", "ly", "rx", "ry"];
|
|
3
|
+
class g {
|
|
4
|
+
constructor(t, e, i = {}) {
|
|
5
|
+
this.keyboard = t, this.bindings = new Map(Object.entries(e)), this.deadZone = i.deadZone ?? 0.25, this.gamepads = i.gamepads ?? (() => typeof navigator < "u" && typeof navigator.getGamepads == "function" ? navigator.getGamepads() : []);
|
|
6
|
+
}
|
|
7
|
+
keyboard;
|
|
8
|
+
bindings;
|
|
9
|
+
virtual = /* @__PURE__ */ new Set();
|
|
10
|
+
virtualDown = /* @__PURE__ */ new Set();
|
|
11
|
+
/** Analog value of each action this step (0–1), and last step's, for edges. */
|
|
12
|
+
now = /* @__PURE__ */ new Map();
|
|
13
|
+
before = /* @__PURE__ */ new Map();
|
|
14
|
+
deadZone;
|
|
15
|
+
gamepads;
|
|
16
|
+
/** Parsed chords by binding string; null for a plain key. */
|
|
17
|
+
chords = /* @__PURE__ */ new Map();
|
|
18
|
+
/** Keys a chord holds this step: their bare bindings read 0 until the key comes up. */
|
|
19
|
+
claimed = /* @__PURE__ */ new Set();
|
|
20
|
+
keyDown = (t) => this.keyboard !== null && (this.keyboard.isDown(t) || this.keyboard.pressed(t));
|
|
21
|
+
/** Replaces one action's bindings (a player's rebinding). */
|
|
22
|
+
bind(t, e) {
|
|
23
|
+
this.bindings.set(t, [...e]);
|
|
24
|
+
}
|
|
25
|
+
bindingsOf(t) {
|
|
26
|
+
return this.bindings.get(t) ?? [];
|
|
27
|
+
}
|
|
28
|
+
/** A touch UI's virtual button went down: `touch:<name>` bindings read it. */
|
|
29
|
+
press(t) {
|
|
30
|
+
this.virtual.add(t), this.virtualDown.add(t);
|
|
31
|
+
}
|
|
32
|
+
release(t) {
|
|
33
|
+
this.virtual.delete(t);
|
|
34
|
+
}
|
|
35
|
+
/** Reads every device once; call at the start of each simulation step. */
|
|
36
|
+
poll() {
|
|
37
|
+
[this.before, this.now] = [this.now, this.before], this.now.clear();
|
|
38
|
+
const t = this.gamepads().filter((e) => e !== null);
|
|
39
|
+
this.claimChords();
|
|
40
|
+
for (const [e, i] of this.bindings) {
|
|
41
|
+
let s = 0;
|
|
42
|
+
for (const o of i) s = Math.max(s, this.read(o, t));
|
|
43
|
+
s > 0 && this.now.set(e, s);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** Held this step. */
|
|
47
|
+
down(t) {
|
|
48
|
+
return (this.now.get(t) ?? 0) > 0;
|
|
49
|
+
}
|
|
50
|
+
/** How far it is held (0–1): 1 for a key, the trigger or stick amount for analog input. */
|
|
51
|
+
value(t) {
|
|
52
|
+
return this.now.get(t) ?? 0;
|
|
53
|
+
}
|
|
54
|
+
/** Went down this step. */
|
|
55
|
+
pressed(t) {
|
|
56
|
+
return this.down(t) && !((this.before.get(t) ?? 0) > 0);
|
|
57
|
+
}
|
|
58
|
+
/** Came up this step. */
|
|
59
|
+
released(t) {
|
|
60
|
+
return !this.down(t) && (this.before.get(t) ?? 0) > 0;
|
|
61
|
+
}
|
|
62
|
+
/** `value(positive) - value(negative)`, in −1…1. */
|
|
63
|
+
axis(t, e) {
|
|
64
|
+
return this.value(e) - this.value(t);
|
|
65
|
+
}
|
|
66
|
+
/** A 2D direction from four actions, never longer than 1 (a diagonal is not faster). */
|
|
67
|
+
vector(t, e, i, s) {
|
|
68
|
+
const o = this.axis(t, e), r = this.axis(i, s), n = Math.hypot(o, r);
|
|
69
|
+
return n > 1 ? [o / n, r / n] : [o, r];
|
|
70
|
+
}
|
|
71
|
+
/** Ends the step: the keyboard forgets its edges; virtual taps shorter than a step have now been seen. */
|
|
72
|
+
endStep() {
|
|
73
|
+
this.keyboard?.endStep(), this.virtualDown.clear();
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Drops every pending edge: what went down or up since the last step is forgotten, and what is held now counts as
|
|
77
|
+
* already held, so the next `poll` reports no `pressed` or `released` for it. For input that sat unread while
|
|
78
|
+
* something else had the keys (a pause menu over the level; `SceneManager.pop` calls it through `Scene.useInput`).
|
|
79
|
+
*/
|
|
80
|
+
flush() {
|
|
81
|
+
this.keyboard?.endStep(), this.virtualDown.clear(), this.poll(), this.before = new Map(this.now);
|
|
82
|
+
}
|
|
83
|
+
chordOf(t) {
|
|
84
|
+
let e = this.chords.get(t);
|
|
85
|
+
return e === void 0 && (e = t.startsWith("pad:") || t.startsWith("touch:") ? null : c(t), this.chords.set(t, e)), e;
|
|
86
|
+
}
|
|
87
|
+
/** Marks the keys held chords use, and frees those whose key has come up. */
|
|
88
|
+
claimChords() {
|
|
89
|
+
for (const t of this.claimed) this.keyDown(t) || this.claimed.delete(t);
|
|
90
|
+
if (this.keyboard)
|
|
91
|
+
for (const t of this.bindings.values())
|
|
92
|
+
for (const e of t) {
|
|
93
|
+
const i = this.chordOf(e);
|
|
94
|
+
i && l(i, this.keyDown) && this.claimed.add(i.code);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
read(t, e) {
|
|
98
|
+
if (t.startsWith("touch:")) {
|
|
99
|
+
const s = t.slice(6);
|
|
100
|
+
return this.virtual.has(s) || this.virtualDown.has(s) ? 1 : 0;
|
|
101
|
+
}
|
|
102
|
+
if (t.startsWith("pad:")) {
|
|
103
|
+
const s = t.slice(4);
|
|
104
|
+
let o = 0;
|
|
105
|
+
const r = s.endsWith("+") ? 1 : s.endsWith("-") ? -1 : 0;
|
|
106
|
+
if (r !== 0) {
|
|
107
|
+
const h = u.indexOf(s.slice(0, -1));
|
|
108
|
+
if (h < 0) return 0;
|
|
109
|
+
for (const a of e) {
|
|
110
|
+
const d = (a.axes[h] ?? 0) * r;
|
|
111
|
+
d > this.deadZone && (o = Math.max(o, (d - this.deadZone) / (1 - this.deadZone)));
|
|
112
|
+
}
|
|
113
|
+
return Math.min(1, o);
|
|
114
|
+
}
|
|
115
|
+
const n = f.indexOf(s);
|
|
116
|
+
if (n < 0) return 0;
|
|
117
|
+
for (const h of e) {
|
|
118
|
+
const a = h.buttons[n];
|
|
119
|
+
a?.pressed && (o = Math.max(o, a.value > 0 ? a.value : 1));
|
|
120
|
+
}
|
|
121
|
+
return Math.min(1, o);
|
|
122
|
+
}
|
|
123
|
+
const i = this.chordOf(t);
|
|
124
|
+
return i ? l(i, this.keyDown) ? 1 : 0 : this.claimed.has(t) ? 0 : this.keyDown(t) ? 1 : 0;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
export {
|
|
128
|
+
g as Actions,
|
|
129
|
+
f as PAD_BUTTONS
|
|
130
|
+
};
|
|
131
|
+
//# sourceMappingURL=Actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Actions.js","sources":["../../src/input/Actions.ts"],"sourcesContent":["import type { Keyboard } from './Keyboard';\nimport { chordHeld, parseChord, type KeyChord } from './keyChord';\n\n/**\n * Named actions bound to any input: keys, gamepad buttons and sticks, and virtual buttons a touch UI presses. Game\n * code asks for `'jump'`, never for `Space`, so players can rebind and every device works the same.\n *\n * ```ts\n * const input = new Actions(keyboard, {\n * left: ['KeyA', 'ArrowLeft', 'pad:left', 'pad:lx-'],\n * right: ['KeyD', 'ArrowRight', 'pad:right', 'pad:lx+'],\n * jump: ['Space', 'pad:a'],\n * });\n * // in a fixed system:\n * input.poll();\n * if (input.pressed('jump')) …\n * const [x, y] = input.vector('left', 'right', 'up', 'down');\n * input.endStep();\n * ```\n *\n * Bindings: a `KeyboardEvent.code` (`KeyW`, `Space`, `ArrowUp`), a chord of modifiers and a code (`Shift+Tab`,\n * `Ctrl+KeyS`: `Shift`, `Ctrl`, `Alt`, `Meta`, either side), `pad:<button>` (standard mapping names below),\n * `pad:<axis>+` / `pad:<axis>-` for a stick half (`lx`, `ly`, `rx`, `ry`), or `touch:<name>` for a virtual button\n * (`press`/`release`).\n *\n * A chord wins over its bare key: while `Shift+Tab` is held, an action bound to plain `Tab` is not, and it stays off\n * until Tab itself comes up (letting Shift go first must not turn a Shift+Tab into a Tab). A bare key held with a\n * modifier no chord names still counts (Shift held to run does not stop the jump key).\n */\nexport type Bindings<A extends string> = Record<A, readonly string[]>;\n\n/** Button names of the browser's standard gamepad mapping, in index order. */\nexport const PAD_BUTTONS = ['a', 'b', 'x', 'y', 'lb', 'rb', 'lt', 'rt', 'select', 'start', 'ls', 'rs', 'up', 'down', 'left', 'right', 'home'] as const;\nconst PAD_AXES = ['lx', 'ly', 'rx', 'ry'] as const;\n\n/** What the actions read from a gamepad; `navigator.getGamepads()` entries satisfy it. */\nexport interface PadState {\n readonly buttons: readonly { readonly pressed: boolean; readonly value: number }[];\n readonly axes: readonly number[];\n}\n\nexport interface ActionsOptions {\n /** Stick values under this count as 0 (default 0.25). */\n deadZone?: number;\n /** Where gamepads come from (default `navigator.getGamepads`); tests pass their own. */\n gamepads?: () => readonly (PadState | null)[];\n}\n\nexport class Actions<A extends string> {\n private bindings: Map<A, readonly string[]>;\n private readonly virtual = new Set<string>();\n private readonly virtualDown = new Set<string>();\n /** Analog value of each action this step (0–1), and last step's, for edges. */\n private now = new Map<A, number>();\n private before = new Map<A, number>();\n private readonly deadZone: number;\n private readonly gamepads: () => readonly (PadState | null)[];\n /** Parsed chords by binding string; null for a plain key. */\n private readonly chords = new Map<string, KeyChord | null>();\n /** Keys a chord holds this step: their bare bindings read 0 until the key comes up. */\n private readonly claimed = new Set<string>();\n private readonly keyDown = (code: string) => this.keyboard !== null && (this.keyboard.isDown(code) || this.keyboard.pressed(code));\n\n constructor(\n private readonly keyboard: Keyboard | null,\n bindings: Bindings<A>,\n options: ActionsOptions = {},\n ) {\n this.bindings = new Map(Object.entries(bindings) as [A, readonly string[]][]);\n this.deadZone = options.deadZone ?? 0.25;\n this.gamepads =\n options.gamepads ?? (() => (typeof navigator !== 'undefined' && typeof navigator.getGamepads === 'function' ? navigator.getGamepads() : []));\n }\n\n /** Replaces one action's bindings (a player's rebinding). */\n bind(action: A, inputs: readonly string[]): void {\n this.bindings.set(action, [...inputs]);\n }\n\n bindingsOf(action: A): readonly string[] {\n return this.bindings.get(action) ?? [];\n }\n\n /** A touch UI's virtual button went down: `touch:<name>` bindings read it. */\n press(name: string): void {\n this.virtual.add(name);\n this.virtualDown.add(name);\n }\n\n release(name: string): void {\n this.virtual.delete(name);\n }\n\n /** Reads every device once; call at the start of each simulation step. */\n poll(): void {\n [this.before, this.now] = [this.now, this.before];\n this.now.clear();\n const pads = this.gamepads().filter((p): p is PadState => p !== null);\n this.claimChords();\n for (const [action, inputs] of this.bindings) {\n let v = 0;\n for (const input of inputs) v = Math.max(v, this.read(input, pads));\n if (v > 0) this.now.set(action, v);\n }\n }\n\n /** Held this step. */\n down(action: A): boolean {\n return (this.now.get(action) ?? 0) > 0;\n }\n\n /** How far it is held (0–1): 1 for a key, the trigger or stick amount for analog input. */\n value(action: A): number {\n return this.now.get(action) ?? 0;\n }\n\n /** Went down this step. */\n pressed(action: A): boolean {\n return this.down(action) && !((this.before.get(action) ?? 0) > 0);\n }\n\n /** Came up this step. */\n released(action: A): boolean {\n return !this.down(action) && (this.before.get(action) ?? 0) > 0;\n }\n\n /** `value(positive) - value(negative)`, in −1…1. */\n axis(negative: A, positive: A): number {\n return this.value(positive) - this.value(negative);\n }\n\n /** A 2D direction from four actions, never longer than 1 (a diagonal is not faster). */\n vector(left: A, right: A, up: A, down: A): [number, number] {\n const x = this.axis(left, right);\n const y = this.axis(up, down);\n const len = Math.hypot(x, y);\n return len > 1 ? [x / len, y / len] : [x, y];\n }\n\n /** Ends the step: the keyboard forgets its edges; virtual taps shorter than a step have now been seen. */\n endStep(): void {\n this.keyboard?.endStep();\n this.virtualDown.clear();\n }\n\n /**\n * Drops every pending edge: what went down or up since the last step is forgotten, and what is held now counts as\n * already held, so the next `poll` reports no `pressed` or `released` for it. For input that sat unread while\n * something else had the keys (a pause menu over the level; `SceneManager.pop` calls it through `Scene.useInput`).\n */\n flush(): void {\n this.keyboard?.endStep();\n this.virtualDown.clear();\n this.poll();\n this.before = new Map(this.now);\n }\n\n private chordOf(input: string): KeyChord | null {\n let c = this.chords.get(input);\n if (c === undefined) {\n c = input.startsWith('pad:') || input.startsWith('touch:') ? null : parseChord(input);\n this.chords.set(input, c);\n }\n return c;\n }\n\n /** Marks the keys held chords use, and frees those whose key has come up. */\n private claimChords(): void {\n for (const code of this.claimed) if (!this.keyDown(code)) this.claimed.delete(code);\n if (!this.keyboard) return;\n for (const inputs of this.bindings.values())\n for (const input of inputs) {\n const chord = this.chordOf(input);\n if (chord && chordHeld(chord, this.keyDown)) this.claimed.add(chord.code);\n }\n }\n\n private read(input: string, pads: readonly PadState[]): number {\n if (input.startsWith('touch:')) {\n const name = input.slice(6);\n return this.virtual.has(name) || this.virtualDown.has(name) ? 1 : 0;\n }\n if (input.startsWith('pad:')) {\n const what = input.slice(4);\n let v = 0;\n const sign = what.endsWith('+') ? 1 : what.endsWith('-') ? -1 : 0;\n if (sign !== 0) {\n const axis = PAD_AXES.indexOf(what.slice(0, -1) as (typeof PAD_AXES)[number]);\n if (axis < 0) return 0;\n for (const p of pads) {\n const raw = (p.axes[axis] ?? 0) * sign;\n if (raw > this.deadZone) v = Math.max(v, (raw - this.deadZone) / (1 - this.deadZone));\n }\n return Math.min(1, v);\n }\n const button = PAD_BUTTONS.indexOf(what as (typeof PAD_BUTTONS)[number]);\n if (button < 0) return 0;\n // a digital button reports value 1 when pressed; an analog trigger its depth (some pads report 0 for a press)\n for (const p of pads) {\n const b = p.buttons[button];\n if (b?.pressed) v = Math.max(v, b.value > 0 ? b.value : 1);\n }\n return Math.min(1, v);\n }\n const chord = this.chordOf(input);\n if (chord) return chordHeld(chord, this.keyDown) ? 1 : 0;\n if (this.claimed.has(input)) return 0;\n return this.keyDown(input) ? 1 : 0;\n }\n}\n"],"names":["PAD_BUTTONS","PAD_AXES","Actions","keyboard","bindings","options","code","action","inputs","name","pads","p","v","input","negative","positive","left","right","up","down","x","y","len","c","parseChord","chord","chordHeld","what","sign","axis","raw","button","b"],"mappings":";AAgCO,MAAMA,IAAc,CAAC,KAAK,KAAK,KAAK,KAAK,MAAM,MAAM,MAAM,MAAM,UAAU,SAAS,MAAM,MAAM,MAAM,QAAQ,QAAQ,SAAS,MAAM,GACtIC,IAAW,CAAC,MAAM,MAAM,MAAM,IAAI;AAejC,MAAMC,EAA0B;AAAA,EAerC,YACmBC,GACjBC,GACAC,IAA0B,CAAA,GAC1B;AAHiB,SAAA,WAAAF,GAIjB,KAAK,WAAW,IAAI,IAAI,OAAO,QAAQC,CAAQ,CAA6B,GAC5E,KAAK,WAAWC,EAAQ,YAAY,MACpC,KAAK,WACHA,EAAQ,aAAa,MAAO,OAAO,YAAc,OAAe,OAAO,UAAU,eAAgB,aAAa,UAAU,YAAA,IAAgB,CAAA;AAAA,EAC5I;AAAA,EARmB;AAAA,EAfX;AAAA,EACS,8BAAc,IAAA;AAAA,EACd,kCAAkB,IAAA;AAAA;AAAA,EAE3B,0BAAU,IAAA;AAAA,EACV,6BAAa,IAAA;AAAA,EACJ;AAAA,EACA;AAAA;AAAA,EAEA,6BAAa,IAAA;AAAA;AAAA,EAEb,8BAAc,IAAA;AAAA,EACd,UAAU,CAACC,MAAiB,KAAK,aAAa,SAAS,KAAK,SAAS,OAAOA,C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AAK,QAAQ,IAAIZ,CAAK,IAAU,IAC7B,KAAK,QAAQA,CAAK,IAAI,IAAI;AAAA,EACnC;AACF;"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const u = 10, y = 28, d = 180, S = 0.2;
|
|
2
|
+
function o(s, t = !0, n = 10, i = 28, e = 180) {
|
|
3
|
+
return t && s < e ? i : n;
|
|
4
|
+
}
|
|
5
|
+
class _ {
|
|
6
|
+
dragged = !1;
|
|
7
|
+
over = !1;
|
|
8
|
+
/** Where the knob is drawn, clamped to the circle, relative to the button's centre. */
|
|
9
|
+
knob = { x: 0, y: 0 };
|
|
10
|
+
/** The knob as a vector of length ≤ 1: what the world reads. */
|
|
11
|
+
share = { x: 0, y: 0 };
|
|
12
|
+
radius;
|
|
13
|
+
sensitivity;
|
|
14
|
+
centreCancels;
|
|
15
|
+
tapSlop;
|
|
16
|
+
earlySlop;
|
|
17
|
+
pressMs;
|
|
18
|
+
centre;
|
|
19
|
+
constructor(t) {
|
|
20
|
+
this.radius = Math.max(1e-6, t.radius), this.sensitivity = t.sensitivity ?? 1, this.centreCancels = t.centreCancels ?? !0, this.tapSlop = t.tapSlop ?? 10, this.earlySlop = t.earlySlop ?? 28, this.pressMs = t.pressMs ?? 180, this.centre = t.centre ?? 0.2;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The thumb at `rawX, rawY` from the button's centre, `overCancel` when it is over the cancel zone, `ms` since it
|
|
24
|
+
* went down (Infinity skips the landing slop). Once a drag, always a drag for this press.
|
|
25
|
+
*/
|
|
26
|
+
move(t, n, i = !1, e = 1 / 0) {
|
|
27
|
+
Math.hypot(t, n) > o(e, !0, this.tapSlop, this.earlySlop, this.pressMs) && (this.dragged = !0), this.over = i;
|
|
28
|
+
const r = t * this.sensitivity, a = n * this.sensitivity, c = Math.hypot(r, a), h = c > this.radius ? this.radius / c : 1;
|
|
29
|
+
this.knob = { x: r * h, y: a * h }, this.share = { x: this.knob.x / this.radius, y: this.knob.y / this.radius };
|
|
30
|
+
}
|
|
31
|
+
/** A drag has begun: show the aim from now on. */
|
|
32
|
+
get aiming() {
|
|
33
|
+
return this.dragged;
|
|
34
|
+
}
|
|
35
|
+
get centred() {
|
|
36
|
+
return Math.hypot(this.share.x, this.share.y) < this.centre;
|
|
37
|
+
}
|
|
38
|
+
/** Letting go now would cast nothing (draw the cancel zone lit). */
|
|
39
|
+
get cancelling() {
|
|
40
|
+
return this.dragged && (this.over || this.centreCancels && this.centred);
|
|
41
|
+
}
|
|
42
|
+
up() {
|
|
43
|
+
return this.dragged ? this.cancelling ? "cancel" : this.centred ? "tap" : "cast" : "tap";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function l(s, t = 0.2) {
|
|
47
|
+
return Math.max(0, Math.min(1, (s - t) / (1 - t)));
|
|
48
|
+
}
|
|
49
|
+
function g(s, t, n, i = 0.2) {
|
|
50
|
+
const e = Math.hypot(s, t);
|
|
51
|
+
if (e < 1e-6) return { x: 0, y: 0 };
|
|
52
|
+
const r = i + (1 - i) * Math.min(1, e / n);
|
|
53
|
+
return { x: s / e * r, y: t / e * r };
|
|
54
|
+
}
|
|
55
|
+
function p(s, t, n, i, e = 0.2) {
|
|
56
|
+
const r = Math.hypot(n.x, n.y), a = r > 1e-6 ? Math.atan2(n.y, n.x) : i;
|
|
57
|
+
if (t.kind === "point") {
|
|
58
|
+
const M = l(r, e) * t.range;
|
|
59
|
+
return { aim: a, x: s.x + Math.cos(a) * M, y: s.y + Math.sin(a) * M };
|
|
60
|
+
}
|
|
61
|
+
const c = t.snap ? Math.round(a / t.snap) * t.snap : a, h = t.backwards ? c + Math.PI : c;
|
|
62
|
+
return { aim: h, x: s.x + Math.cos(h) * t.length, y: s.y + Math.sin(h) * t.length };
|
|
63
|
+
}
|
|
64
|
+
export {
|
|
65
|
+
S as AIM_CENTRE,
|
|
66
|
+
y as AIM_EARLY_SLOP,
|
|
67
|
+
d as AIM_PRESS_MS,
|
|
68
|
+
u as AIM_TAP_SLOP,
|
|
69
|
+
_ as AimGesture,
|
|
70
|
+
p as aimPoint,
|
|
71
|
+
o as dragSlop,
|
|
72
|
+
l as spotReach,
|
|
73
|
+
g as spotShare
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=AimGesture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AimGesture.js","sources":["../../src/input/AimGesture.ts"],"sourcesContent":["/**\n * The drag-to-aim gesture of a touch skill button (the MOBA way), kept pure so it can be tested. Pressing an aimed\n * button opens a circle round it with a knob under the thumb; where the knob sits in that circle is where the skill\n * goes. A press that never wanders past the tap slop is a tap (the game casts it the way a tap always does: at the\n * locked target, the nearest enemy, the facing). Letting go over a cancel zone casts nothing; letting go with the knob\n * back on the button casts as a tap, or cancels when `centreCancels` (the one way to cancel when there is no zone).\n *\n * The thumb gets a longer slop in the first `pressMs` of a press: a hard press slides as it lands, and a quick tap\n * that slid past the plain slop became a drag that flew wherever the slide pointed.\n *\n * ```ts\n * const g = new AimGesture({ radius: 90, centreCancels: !hasCancelZone });\n * // pointermove: g.move(dx, dy, overCancelZone, now - downAt)\n * // pointerup: const end = g.up(); // 'tap' | 'cast' | 'cancel'\n * // while g.aiming, draw the aim from aimPoint(caster, shape, g.share, facing)\n * ```\n */\n\nexport type AimEnd = 'tap' | 'cast' | 'cancel';\n\nexport interface AimGestureOptions {\n /** The circle's radius, in the same units as the thumb's offsets (CSS px). */\n radius: number;\n /** Scales the thumb's travel into the knob's (a sensitivity setting); the slops stay the thumb's own (default 1). */\n sensitivity?: number;\n /** The knob let go back on the button cancels rather than casting as a tap (default true). */\n centreCancels?: boolean;\n /** How far the thumb may wander before a press is a drag (default 10). */\n tapSlop?: number;\n /** The slop in a press's first `pressMs` (default 28). */\n earlySlop?: number;\n /** How long a press is \"landing\" (default 180 ms). */\n pressMs?: number;\n /** Inside this share of the radius the knob is back on the button (default 0.2). */\n centre?: number;\n}\n\nexport const AIM_TAP_SLOP = 10;\nexport const AIM_EARLY_SLOP = 28;\nexport const AIM_PRESS_MS = 180;\nexport const AIM_CENTRE = 0.2;\n\n/**\n * How far the thumb must wander, `ms` into a press, before it drags. `early` false keeps the plain slop throughout\n * (an attack button with nothing locked: there a slide is as good as a drag).\n */\nexport function dragSlop(ms: number, early = true, tapSlop = AIM_TAP_SLOP, earlySlop = AIM_EARLY_SLOP, pressMs = AIM_PRESS_MS): number {\n return early && ms < pressMs ? earlySlop : tapSlop;\n}\n\ntype Point = { x: number; y: number };\n\nexport class AimGesture {\n private dragged = false;\n private over = false;\n /** Where the knob is drawn, clamped to the circle, relative to the button's centre. */\n knob: Point = { x: 0, y: 0 };\n /** The knob as a vector of length ≤ 1: what the world reads. */\n share: Point = { x: 0, y: 0 };\n private readonly radius: number;\n private readonly sensitivity: number;\n private readonly centreCancels: boolean;\n private readonly tapSlop: number;\n private readonly earlySlop: number;\n private readonly pressMs: number;\n private readonly centre: number;\n\n constructor(options: AimGestureOptions) {\n this.radius = Math.max(1e-6, options.radius);\n this.sensitivity = options.sensitivity ?? 1;\n this.centreCancels = options.centreCancels ?? true;\n this.tapSlop = options.tapSlop ?? AIM_TAP_SLOP;\n this.earlySlop = options.earlySlop ?? AIM_EARLY_SLOP;\n this.pressMs = options.pressMs ?? AIM_PRESS_MS;\n this.centre = options.centre ?? AIM_CENTRE;\n }\n\n /**\n * The thumb at `rawX, rawY` from the button's centre, `overCancel` when it is over the cancel zone, `ms` since it\n * went down (Infinity skips the landing slop). Once a drag, always a drag for this press.\n */\n move(rawX: number, rawY: number, overCancel = false, ms = Infinity): void {\n if (Math.hypot(rawX, rawY) > dragSlop(ms, true, this.tapSlop, this.earlySlop, this.pressMs)) this.dragged = true;\n this.over = overCancel;\n const dx = rawX * this.sensitivity;\n const dy = rawY * this.sensitivity;\n const len = Math.hypot(dx, dy);\n const k = len > this.radius ? this.radius / len : 1;\n this.knob = { x: dx * k, y: dy * k };\n this.share = { x: this.knob.x / this.radius, y: this.knob.y / this.radius };\n }\n\n /** A drag has begun: show the aim from now on. */\n get aiming(): boolean {\n return this.dragged;\n }\n\n private get centred(): boolean {\n return Math.hypot(this.share.x, this.share.y) < this.centre;\n }\n\n /** Letting go now would cast nothing (draw the cancel zone lit). */\n get cancelling(): boolean {\n return this.dragged && (this.over || (this.centreCancels && this.centred));\n }\n\n up(): AimEnd {\n if (!this.dragged) return 'tap';\n if (this.cancelling) return 'cancel';\n return this.centred ? 'tap' : 'cast';\n }\n}\n\n/**\n * How a skill is aimed: at a spot within `range` (a blast, a blink), or along a direction for `length` (a shot, a\n * dash; `backwards` for a leap away from the aim).\n */\nexport type AimShape =\n | { kind: 'point'; range: number }\n | { kind: 'direction'; length: number; backwards?: boolean; snap?: number };\n\n/**\n * How far out a spot skill's knob puts it, as a share of its range: from the centre ring's edge to the rim is the\n * whole reach, so a knob just out of the ring lands at the caster's feet — with `share × range`, nothing nearer than\n * the ring could ever be reached.\n */\nexport function spotReach(len: number, centre = AIM_CENTRE): number {\n return Math.max(0, Math.min(1, (len - centre) / (1 - centre)));\n}\n\n/** The knob that puts a spot skill `dx, dy` from the caster: `spotReach`'s inverse (aim assist, replays). */\nexport function spotShare(dx: number, dy: number, range: number, centre = AIM_CENTRE): Point {\n const d = Math.hypot(dx, dy);\n if (d < 1e-6) return { x: 0, y: 0 };\n const len = centre + (1 - centre) * Math.min(1, d / range);\n return { x: (dx / d) * len, y: (dy / d) * len };\n}\n\n/**\n * Where an aimed skill goes, as a mouse would have said it: the aim angle and the ground point. A knob with no length\n * keeps `lastAim`. A direction may snap to `snap` radians (0 or none for free aim).\n */\nexport function aimPoint(from: Point, shape: AimShape, share: Point, lastAim: number, centre = AIM_CENTRE): { aim: number; x: number; y: number } {\n const len = Math.hypot(share.x, share.y);\n const angle = len > 1e-6 ? Math.atan2(share.y, share.x) : lastAim;\n if (shape.kind === 'point') {\n const d = spotReach(len, centre) * shape.range;\n return { aim: angle, x: from.x + Math.cos(angle) * d, y: from.y + Math.sin(angle) * d };\n }\n const snapped = shape.snap ? Math.round(angle / shape.snap) * shape.snap : angle;\n const aim = shape.backwards ? snapped + Math.PI : snapped;\n return { aim, x: from.x + Math.cos(aim) * shape.length, y: from.y + Math.sin(aim) * shape.length };\n}\n"],"names":["AIM_TAP_SLOP","AIM_EARLY_SLOP","AIM_PRESS_MS","AIM_CENTRE","dragSlop","ms","early","tapSlop","earlySlop","pressMs","AimGesture","options","rawX","rawY","overCancel","dx","dy","len","k","spotReach","centre","spotShare","range","d","aimPoint","from","shape","share","lastAim","angle","snapped","aim"],"mappings":"AAqCO,MAAMA,IAAe,IACfC,IAAiB,IACjBC,IAAe,KACfC,IAAa;AAMnB,SAASC,EAASC,GAAYC,IAAQ,IAAMC,IAAU,IAAcC,IAAY,IAAgBC,IAAU,KAAsB;AACrI,SAAOH,KAASD,IAAKI,IAAUD,IAAYD;AAC7C;AAIO,MAAMG,EAAW;AAAA,EACd,UAAU;AAAA,EACV,OAAO;AAAA;AAAA,EAEf,OAAc,EAAE,GAAG,GAAG,GAAG,EAAA;AAAA;AAAA,EAEzB,QAAe,EAAE,GAAG,GAAG,GAAG,EAAA;AAAA,EACT;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEjB,YAAYC,GAA4B;AACtC,SAAK,SAAS,KAAK,IAAI,MAAMA,EAAQ,MAAM,GAC3C,KAAK,cAAcA,EAAQ,eAAe,GAC1C,KAAK,gBAAgBA,EAAQ,iBAAiB,IAC9C,KAAK,UAAUA,EAAQ,WAAW,IAClC,KAAK,YAAYA,EAAQ,aAAa,IACtC,KAAK,UAAUA,EAAQ,WAAW,KAClC,KAAK,SAASA,EAAQ,UAAU;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,KAAKC,GAAcC,GAAcC,IAAa,IAAOT,IAAK,OAAgB;AACxE,IAAI,KAAK,MAAMO,GAAMC,CAAI,IAAIT,EAASC,GAAI,IAAM,KAAK,SAAS,KAAK,WAAW,KAAK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IAAS,KAAmD;AAChJ,QAAMH,IAAM,KAAK,MAAMU,EAAM,GAAGA,EAAM,CAAC,GACjCE,IAAQZ,IAAM,OAAO,KAAK,MAAMU,EAAM,GAAGA,EAAM,CAAC,IAAIC;AAC1D,MAAIF,EAAM,SAAS,SAAS;AAC1B,UAAMH,IAAIJ,EAAUF,GAAKG,CAAM,IAAIM,EAAM;AACzC,WAAO,EAAE,KAAKG,GAAO,GAAGJ,EAAK,IAAI,KAAK,IAAII,CAAK,IAAIN,GAAG,GAAGE,EAAK,IAAI,KAAK,IAAII,CAAK,IAAIN,EAAA;AAAA,EACtF;AACA,QAAMO,IAAUJ,EAAM,OAAO,KAAK,MAAMG,IAAQH,EAAM,IAAI,IAAIA,EAAM,OAAOG,GACrEE,IAAML,EAAM,YAAYI,IAAU,KAAK,KAAKA;AAClD,SAAO,EAAE,KAAAC,GAAK,GAAGN,EAAK,IAAI,KAAK,IAAIM,CAAG,IAAIL,EAAM,QAAQ,GAAGD,EAAK,IAAI,KAAK,IAAIM,CAAG,IAAIL,EAAM,OAAA;AAC5F;"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
class h {
|
|
2
|
+
held = /* @__PURE__ */ new Set();
|
|
3
|
+
down = /* @__PURE__ */ new Set();
|
|
4
|
+
up = /* @__PURE__ */ new Set();
|
|
5
|
+
cleanup = [];
|
|
6
|
+
constructor(e = window) {
|
|
7
|
+
const n = (t) => {
|
|
8
|
+
const s = t.code;
|
|
9
|
+
t.repeat || this.held.has(s) || (this.held.add(s), this.down.add(s));
|
|
10
|
+
}, d = (t) => {
|
|
11
|
+
const s = t.code;
|
|
12
|
+
this.held.delete(s) && this.up.add(s);
|
|
13
|
+
}, r = () => {
|
|
14
|
+
for (const t of this.held) this.up.add(t);
|
|
15
|
+
this.held.clear();
|
|
16
|
+
};
|
|
17
|
+
e.addEventListener("keydown", n), e.addEventListener("keyup", d), window.addEventListener("blur", r), this.cleanup.push(
|
|
18
|
+
() => e.removeEventListener("keydown", n),
|
|
19
|
+
() => e.removeEventListener("keyup", d),
|
|
20
|
+
() => window.removeEventListener("blur", r)
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
isDown(e) {
|
|
24
|
+
return this.held.has(e);
|
|
25
|
+
}
|
|
26
|
+
/** Any of these keys is held. */
|
|
27
|
+
anyDown(...e) {
|
|
28
|
+
return e.some((n) => this.held.has(n));
|
|
29
|
+
}
|
|
30
|
+
/** Went down since the last `endStep`. */
|
|
31
|
+
pressed(e) {
|
|
32
|
+
return this.down.has(e);
|
|
33
|
+
}
|
|
34
|
+
/** Came up since the last `endStep`. */
|
|
35
|
+
released(e) {
|
|
36
|
+
return this.up.has(e);
|
|
37
|
+
}
|
|
38
|
+
/** -1, 0 or 1 from two sets of keys: `axis(['KeyA', 'ArrowLeft'], ['KeyD', 'ArrowRight'])`. */
|
|
39
|
+
axis(e, n) {
|
|
40
|
+
return (this.anyDown(...n) ? 1 : 0) - (this.anyDown(...e) ? 1 : 0);
|
|
41
|
+
}
|
|
42
|
+
/** Forgets this step's edges; held keys stay held. */
|
|
43
|
+
endStep() {
|
|
44
|
+
this.down.clear(), this.up.clear();
|
|
45
|
+
}
|
|
46
|
+
destroy() {
|
|
47
|
+
for (const e of this.cleanup.splice(0)) e();
|
|
48
|
+
this.held.clear(), this.endStep();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
h as Keyboard
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=Keyboard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Keyboard.js","sources":["../../src/input/Keyboard.ts"],"sourcesContent":["/**\n * Which keys are held, by `KeyboardEvent.code` (the physical key, so WASD stays WASD on any layout). `pressed` and\n * `released` report edges since the last `endStep`; call that once per simulation step so a tap shorter than a frame\n * is still seen by exactly one step.\n *\n * It only knows keys pressed **after** it was made: a key already held when it is created (the Enter that started a\n * level, held into it) is not down here until it is pressed again. A scene that makes its own keyboard in a field\n * therefore starts with every key up, which is usually what a new screen wants; share one keyboard across scenes when\n * a held key must carry over. Modifier keys are ordinary codes here (`ShiftLeft`); `Actions` reads chords from them.\n */\nexport class Keyboard {\n private readonly held = new Set<string>();\n private readonly down = new Set<string>();\n private readonly up = new Set<string>();\n private readonly cleanup: (() => void)[] = [];\n\n constructor(target: Window | HTMLElement = window) {\n const keydown = (e: Event) => {\n const k = (e as KeyboardEvent).code;\n if ((e as KeyboardEvent).repeat || this.held.has(k)) return;\n this.held.add(k);\n this.down.add(k);\n };\n const keyup = (e: Event) => {\n const k = (e as KeyboardEvent).code;\n if (!this.held.delete(k)) return;\n this.up.add(k);\n };\n // a key held while the window loses focus never sends its keyup: let everything go\n const blur = () => {\n for (const k of this.held) this.up.add(k);\n this.held.clear();\n };\n target.addEventListener('keydown', keydown);\n target.addEventListener('keyup', keyup);\n window.addEventListener('blur', blur);\n this.cleanup.push(\n () => target.removeEventListener('keydown', keydown),\n () => target.removeEventListener('keyup', keyup),\n () => window.removeEventListener('blur', blur),\n );\n }\n\n isDown(code: string): boolean {\n return this.held.has(code);\n }\n\n /** Any of these keys is held. */\n anyDown(...codes: string[]): boolean {\n return codes.some((c) => this.held.has(c));\n }\n\n /** Went down since the last `endStep`. */\n pressed(code: string): boolean {\n return this.down.has(code);\n }\n\n /** Came up since the last `endStep`. */\n released(code: string): boolean {\n return this.up.has(code);\n }\n\n /** -1, 0 or 1 from two sets of keys: `axis(['KeyA', 'ArrowLeft'], ['KeyD', 'ArrowRight'])`. */\n axis(negative: string[], positive: string[]): number {\n return (this.anyDown(...positive) ? 1 : 0) - (this.anyDown(...negative) ? 1 : 0);\n }\n\n /** Forgets this step's edges; held keys stay held. */\n endStep(): void {\n this.down.clear();\n this.up.clear();\n }\n\n destroy(): void {\n for (const fn of this.cleanup.splice(0)) fn();\n this.held.clear();\n this.endStep();\n }\n}\n"],"names":["Keyboard","target","keydown","e","k","keyup","blur","code","codes","c","negative","positive","fn"],"mappings":"AAUO,MA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AA,EAGA,KAAKG,GAAoBC,GAA4B;AACnD,YAAQ,KAAK,QAAQ,GAAGA,CAAQ,IAAI,IAAI,MAAM,KAAK,QAAQ,GAAGD,CAAQ,IAAI,IAAI;AAAA,EAChF;AAAA;AAAA,EAGA,UAAgB;AACd,SAAK,KAAK,MAAA,GACV,KAAK,GAAG,MAAA;AAAA,EACV;AAAA,EAEA,UAAgB;AACd,eAAWE,KAAM,KAAK,QAAQ,OAAO,CAAC,EAAG,CAAAA,EAAA;AACzC,SAAK,KAAK,MAAA,GACV,KAAK,QAAA;AAAA,EACP;AACF;"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
class g {
|
|
2
|
+
binds;
|
|
3
|
+
defaults;
|
|
4
|
+
reserved;
|
|
5
|
+
fixed;
|
|
6
|
+
listeners = [];
|
|
7
|
+
/**
|
|
8
|
+
* `reserved`: keys never bound (default Escape, Enter, Tab; pass `undefined` for the default). `fixed`: inputs each
|
|
9
|
+
* action always has besides the player's keys (gamepad, touch, a reserved key), never saved or rebound.
|
|
10
|
+
*/
|
|
11
|
+
constructor(t, s = ["Escape", "Enter", "Tab"], e = {}) {
|
|
12
|
+
this.defaults = { ...t }, this.reserved = new Set(s), this.fixed = { ...e }, this.binds = this.fresh();
|
|
13
|
+
}
|
|
14
|
+
fresh() {
|
|
15
|
+
const t = {};
|
|
16
|
+
for (const s of this.actions()) t[s] = this.defaults[s].filter((e) => !this.reserved.has(e));
|
|
17
|
+
return t;
|
|
18
|
+
}
|
|
19
|
+
/** Every action, in the order the defaults named them. */
|
|
20
|
+
actions() {
|
|
21
|
+
return Object.keys(this.defaults);
|
|
22
|
+
}
|
|
23
|
+
isReserved(t) {
|
|
24
|
+
return this.reserved.has(t);
|
|
25
|
+
}
|
|
26
|
+
/** The keys of one action; the first is the one a settings screen shows and edits. */
|
|
27
|
+
keysFor(t) {
|
|
28
|
+
return this.binds[t] ?? [];
|
|
29
|
+
}
|
|
30
|
+
/** The inputs an action always has besides the player's keys (the constructor's `fixed`). */
|
|
31
|
+
fixedFor(t) {
|
|
32
|
+
return this.fixed[t] ?? [];
|
|
33
|
+
}
|
|
34
|
+
/** Which action a key belongs to, or undefined. */
|
|
35
|
+
actionFor(t) {
|
|
36
|
+
for (const s of this.actions()) if (this.binds[s].includes(t)) return s;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Puts `code` first on `action`, taking it off whatever else held it; returns the actions that lost it (to tell the
|
|
40
|
+
* player). A reserved key is refused (returns null). An action stripped of its last key keeps none: it is unbound
|
|
41
|
+
* until something is put back on it.
|
|
42
|
+
*/
|
|
43
|
+
bind(t, s) {
|
|
44
|
+
if (this.reserved.has(s) || !(t in this.binds)) return null;
|
|
45
|
+
const e = [];
|
|
46
|
+
for (const n of this.actions())
|
|
47
|
+
n === t || !this.binds[n].includes(s) || (this.binds[n] = this.binds[n].filter((a) => a !== s), e.push(n));
|
|
48
|
+
const h = this.binds[t].slice(1).filter((n) => n !== s);
|
|
49
|
+
return this.binds[t] = [s, ...h], this.changed(), e;
|
|
50
|
+
}
|
|
51
|
+
/** Takes every key off `action`. */
|
|
52
|
+
unbind(t) {
|
|
53
|
+
this.binds[t]?.length && (this.binds[t] = [], this.changed());
|
|
54
|
+
}
|
|
55
|
+
/** Every action back on its defaults. */
|
|
56
|
+
reset() {
|
|
57
|
+
this.binds = this.fresh(), this.changed();
|
|
58
|
+
}
|
|
59
|
+
/** A plain object to store wherever the game keeps its settings. */
|
|
60
|
+
toJSON() {
|
|
61
|
+
const t = {};
|
|
62
|
+
for (const s of this.actions()) t[s] = [...this.binds[s]];
|
|
63
|
+
return t;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A saved set laid over this build's defaults. Only actions this build knows are read, so an old save cannot leave
|
|
67
|
+
* a key bound to nothing; an action newer than the save keeps its defaults only where no saved action holds that key
|
|
68
|
+
* (the saved one is what the player chose). Anything malformed is ignored.
|
|
69
|
+
*/
|
|
70
|
+
load(t) {
|
|
71
|
+
this.binds = u(this.defaults, t, this.reserved), this.changed();
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Hands the bindings to an `Actions`: each action's keys, then its fixed inputs, then its `extra` ones. Only the
|
|
75
|
+
* keymap's actions are bound, so the `Actions` may hold more (menu actions alongside the rebindable ones, each on
|
|
76
|
+
* its own fixed inputs); those are left as they are. Fixed and extra inputs are the game's, so neither the reserved
|
|
77
|
+
* keys nor one-key-one-action apply to them.
|
|
78
|
+
*/
|
|
79
|
+
applyTo(t, s = {}) {
|
|
80
|
+
for (const e of this.actions()) t.bind(e, [...this.binds[e], ...this.fixed[e] ?? [], ...s[e] ?? []]);
|
|
81
|
+
}
|
|
82
|
+
/** Called after every change; returns a function that stops it. */
|
|
83
|
+
onChange(t) {
|
|
84
|
+
return this.listeners.push(t), () => {
|
|
85
|
+
const s = this.listeners.indexOf(t);
|
|
86
|
+
s >= 0 && this.listeners.splice(s, 1);
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
changed() {
|
|
90
|
+
for (const t of [...this.listeners]) t();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function u(i, t, s = /* @__PURE__ */ new Set()) {
|
|
94
|
+
const e = Object.keys(i), h = {}, n = /* @__PURE__ */ new Set(), a = t && typeof t == "object" ? t : {};
|
|
95
|
+
for (const r of e) {
|
|
96
|
+
const o = a[r];
|
|
97
|
+
Array.isArray(o) && o.every((f) => typeof f == "string") ? (h[r] = [...new Set(o)].filter((f) => !s.has(f)), n.add(r)) : h[r] = i[r].filter((f) => !s.has(f));
|
|
98
|
+
}
|
|
99
|
+
const l = /* @__PURE__ */ new Map();
|
|
100
|
+
for (const r of e)
|
|
101
|
+
n.has(r) && (h[r] = h[r].filter((o) => l.has(o) ? !1 : (l.set(o, r), !0)));
|
|
102
|
+
for (const r of e) n.has(r) || (h[r] = h[r].filter((o) => !l.has(o)));
|
|
103
|
+
return h;
|
|
104
|
+
}
|
|
105
|
+
function b(i) {
|
|
106
|
+
const t = () => {
|
|
107
|
+
try {
|
|
108
|
+
return typeof localStorage > "u" ? null : localStorage;
|
|
109
|
+
} catch {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
return {
|
|
114
|
+
read() {
|
|
115
|
+
try {
|
|
116
|
+
const s = t()?.getItem(i);
|
|
117
|
+
return s ? JSON.parse(s) : null;
|
|
118
|
+
} catch {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
write(s) {
|
|
123
|
+
try {
|
|
124
|
+
t()?.setItem(i, JSON.stringify(s));
|
|
125
|
+
} catch {
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
clear() {
|
|
129
|
+
try {
|
|
130
|
+
t()?.removeItem(i);
|
|
131
|
+
} catch {
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const c = {
|
|
137
|
+
Space: "Space",
|
|
138
|
+
ShiftLeft: "Shift",
|
|
139
|
+
ShiftRight: "Right Shift",
|
|
140
|
+
ControlLeft: "Ctrl",
|
|
141
|
+
ControlRight: "Right Ctrl",
|
|
142
|
+
AltLeft: "Alt",
|
|
143
|
+
AltRight: "Right Alt",
|
|
144
|
+
ArrowUp: "Up",
|
|
145
|
+
ArrowDown: "Down",
|
|
146
|
+
ArrowLeft: "Left",
|
|
147
|
+
ArrowRight: "Right",
|
|
148
|
+
Backquote: "`",
|
|
149
|
+
Minus: "-",
|
|
150
|
+
Equal: "=",
|
|
151
|
+
Semicolon: ";",
|
|
152
|
+
Quote: "'",
|
|
153
|
+
Comma: ",",
|
|
154
|
+
Period: ".",
|
|
155
|
+
Slash: "/",
|
|
156
|
+
Backslash: "\\",
|
|
157
|
+
BracketLeft: "[",
|
|
158
|
+
BracketRight: "]"
|
|
159
|
+
};
|
|
160
|
+
function d(i, t = {}) {
|
|
161
|
+
if (i.length > 1 && i.includes("+")) return i.split("+").map((e) => d(e, t)).join("+");
|
|
162
|
+
const s = t[i];
|
|
163
|
+
return s !== void 0 ? s : i.startsWith("Key") ? i.slice(3) : i.startsWith("Digit") ? i.slice(5) : i.startsWith("Numpad") ? `Num ${i.slice(6)}` : c[i] ?? i;
|
|
164
|
+
}
|
|
165
|
+
export {
|
|
166
|
+
g as Keymap,
|
|
167
|
+
d as keyLabel,
|
|
168
|
+
b as keymapStorage,
|
|
169
|
+
u as mergeKeymap
|
|
170
|
+
};
|
|
171
|
+
//# sourceMappingURL=Keymap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Keymap.js","sources":["../../src/input/Keymap.ts"],"sourcesContent":["import type { Actions } from './Actions';\n\n/**\n * Which keys each action sits on, as the player has rebound them: one table the input, the key hints on screen and\n * a settings screen all read. A binding is a `KeyboardEvent.code` (`KeyW`, `Digit1`), so it means the same physical\n * key on every layout. Each action keeps a list (W and ArrowUp, 1 and Q); a settings screen edits the **first** and\n * leaves the alternates alone.\n *\n * Two rules: one key serves one action at a time (a key bound twice would fire both, and the player could not tell\n * which they meant), and reserved keys (Escape, Enter, Tab by default: the interface's own) are never taken.\n *\n * Inputs the player cannot rebind — the gamepad's, a touch button, a reserved key an action should still answer to\n * (Escape also pausing) — are the keymap's **fixed** inputs: given once to the constructor, laid after the player's\n * keys by `applyTo`, and untouched by either rule above.\n *\n * ```ts\n * const keys = new Keymap({ jump: ['Space'], left: ['KeyA', 'ArrowLeft'], pause: ['KeyP'] }, undefined, { jump: ['pad:a'], pause: ['Escape'] });\n * keys.load(keymapStorage('my-game.keys').read());\n * keys.onChange(() => { keys.applyTo(actions); storage.write(keys.toJSON()); });\n * keys.bind('pause', 'KeyA'); // 'left' keeps only ArrowLeft\n * ```\n */\nexport class Keymap<A extends string> {\n private binds: Record<A, string[]>;\n private readonly defaults: Record<A, readonly string[]>;\n private readonly reserved: ReadonlySet<string>;\n private readonly fixed: Partial<Record<A, readonly string[]>>;\n private readonly listeners: (() => void)[] = [];\n\n /**\n * `reserved`: keys never bound (default Escape, Enter, Tab; pass `undefined` for the default). `fixed`: inputs each\n * action always has besides the player's keys (gamepad, touch, a reserved key), never saved or rebound.\n */\n constructor(\n defaults: Readonly<Record<A, readonly string[]>>,\n reserved: Iterable<string> = ['Escape', 'Enter', 'Tab'],\n fixed: Partial<Record<A, readonly string[]>> = {},\n ) {\n this.defaults = { ...defaults };\n this.reserved = new Set(reserved);\n this.fixed = { ...fixed };\n this.binds = this.fresh();\n }\n\n private fresh(): Record<A, string[]> {\n const out = {} as Record<A, string[]>;\n for (const id of this.actions()) out[id] = this.defaults[id].filter((c) => !this.reserved.has(c));\n return out;\n }\n\n /** Every action, in the order the defaults named them. */\n actions(): A[] {\n return Object.keys(this.defaults) as A[];\n }\n\n isReserved(code: string): boolean {\n return this.reserved.has(code);\n }\n\n /** The keys of one action; the first is the one a settings screen shows and edits. */\n keysFor(action: A): readonly string[] {\n return this.binds[action] ?? [];\n }\n\n /** The inputs an action always has besides the player's keys (the constructor's `fixed`). */\n fixedFor(action: A): readonly string[] {\n return this.fixed[action] ?? [];\n }\n\n /** Which action a key belongs to, or undefined. */\n actionFor(code: string): A | undefined {\n for (const id of this.actions()) if (this.binds[id].includes(code)) return id;\n return undefined;\n }\n\n /**\n * Puts `code` first on `action`, taking it off whatever else held it; returns the actions that lost it (to tell the\n * player). A reserved key is refused (returns null). An action stripped of its last key keeps none: it is unbound\n * until something is put back on it.\n */\n bind(action: A, code: string): A[] | null {\n if (this.reserved.has(code) || !(action in this.binds)) return null;\n const lost: A[] = [];\n for (const id of this.actions()) {\n if (id === action || !this.binds[id].includes(code)) continue;\n this.binds[id] = this.binds[id].filter((c) => c !== code);\n lost.push(id);\n }\n const rest = this.binds[action].slice(1).filter((c) => c !== code);\n this.binds[action] = [code, ...rest];\n this.changed();\n return lost;\n }\n\n /** Takes every key off `action`. */\n unbind(action: A): void {\n if (!this.binds[action]?.length) return;\n this.binds[action] = [];\n this.changed();\n }\n\n /** Every action back on its defaults. */\n reset(): void {\n this.binds = this.fresh();\n this.changed();\n }\n\n /** A plain object to store wherever the game keeps its settings. */\n toJSON(): Record<A, string[]> {\n const out = {} as Record<A, string[]>;\n for (const id of this.actions()) out[id] = [...this.binds[id]];\n return out;\n }\n\n /**\n * A saved set laid over this build's defaults. Only actions this build knows are read, so an old save cannot leave\n * a key bound to nothing; an action newer than the save keeps its defaults only where no saved action holds that key\n * (the saved one is what the player chose). Anything malformed is ignored.\n */\n load(saved: unknown): void {\n this.binds = mergeKeymap(this.defaults, saved, this.reserved);\n this.changed();\n }\n\n /**\n * Hands the bindings to an `Actions`: each action's keys, then its fixed inputs, then its `extra` ones. Only the\n * keymap's actions are bound, so the `Actions` may hold more (menu actions alongside the rebindable ones, each on\n * its own fixed inputs); those are left as they are. Fixed and extra inputs are the game's, so neither the reserved\n * keys nor one-key-one-action apply to them.\n */\n applyTo<B extends string>(actions: Actions<A | B>, extra: Partial<Record<A, readonly string[]>> = {}): void {\n for (const id of this.actions()) actions.bind(id, [...this.binds[id], ...(this.fixed[id] ?? []), ...(extra[id] ?? [])]);\n }\n\n /** Called after every change; returns a function that stops it. */\n onChange(fn: () => void): () => void {\n this.listeners.push(fn);\n return () => {\n const i = this.listeners.indexOf(fn);\n if (i >= 0) this.listeners.splice(i, 1);\n };\n }\n\n private changed(): void {\n for (const fn of [...this.listeners]) fn();\n }\n}\n\n/** `saved` laid over `defaults` by `Keymap.load`'s rules, as a fresh object. */\nexport function mergeKeymap<A extends string>(\n defaults: Readonly<Record<A, readonly string[]>>,\n saved: unknown,\n reserved: ReadonlySet<string> = new Set(),\n): Record<A, string[]> {\n const ids = Object.keys(defaults) as A[];\n const out = {} as Record<A, string[]>;\n const kept = new Set<A>();\n const s: Partial<Record<A, unknown>> = saved && typeof saved === 'object' ? (saved as Partial<Record<A, unknown>>) : {};\n for (const id of ids) {\n const codes = s[id];\n if (Array.isArray(codes) && codes.every((c) => typeof c === 'string')) {\n // a saved empty list is a choice too: the player unbound it\n out[id] = [...new Set(codes as string[])].filter((c) => !reserved.has(c));\n kept.add(id);\n } else out[id] = defaults[id].filter((c) => !reserved.has(c));\n }\n // one key one action, even in a hand-edited save: the first action listed keeps it\n const owner = new Map<string, A>();\n for (const id of ids)\n if (kept.has(id))\n out[id] = out[id].filter((c) => {\n if (owner.has(c)) return false;\n owner.set(c, id);\n return true;\n });\n for (const id of ids) if (!kept.has(id)) out[id] = out[id].filter((c) => !owner.has(c));\n return out;\n}\n\n/** A place to keep a keymap in the browser, under a key the game names; every failure falls back quietly. */\nexport function keymapStorage(key: string): { read(): unknown; write(binds: object): void; clear(): void } {\n const store = (): Storage | null => {\n try {\n return typeof localStorage === 'undefined' ? null : localStorage;\n } catch {\n return null;\n }\n };\n return {\n read() {\n try {\n const raw = store()?.getItem(key);\n return raw ? (JSON.parse(raw) as unknown) : null;\n } catch {\n // unreadable or blocked storage: the defaults are a complete set on their own\n return null;\n }\n },\n write(binds) {\n try {\n store()?.setItem(key, JSON.stringify(binds));\n } catch {\n // storage unavailable: the change lasts until the page is reloaded\n }\n },\n clear() {\n try {\n store()?.removeItem(key);\n } catch {\n // nothing to clear\n }\n },\n };\n}\n\nconst KEY_NAMES: Readonly<Record<string, string>> = {\n Space: 'Space',\n ShiftLeft: 'Shift',\n ShiftRight: 'Right Shift',\n ControlLeft: 'Ctrl',\n ControlRight: 'Right Ctrl',\n AltLeft: 'Alt',\n AltRight: 'Right Alt',\n ArrowUp: 'Up',\n ArrowDown: 'Down',\n ArrowLeft: 'Left',\n ArrowRight: 'Right',\n Backquote: '`',\n Minus: '-',\n Equal: '=',\n Semicolon: ';',\n Quote: \"'\",\n Comma: ',',\n Period: '.',\n Slash: '/',\n Backslash: '\\\\',\n BracketLeft: '[',\n BracketRight: ']',\n};\n\n/**\n * How a key code reads on screen: \"KeyW\" is W, \"Digit1\" is 1, \"Numpad3\" is \"Num 3\", a chord \"Shift+Tab\" each part in\n * turn. `names` overrides any code or modifier (a game's own language for the arrows and modifiers).\n */\nexport function keyLabel(code: string, names: Readonly<Record<string, string>> = {}): string {\n if (code.length > 1 && code.includes('+')) return code.split('+').map((part) => keyLabel(part, names)).join('+');\n const own = names[code];\n if (own !== undefined) return own;\n if (code.startsWith('Key')) return code.slice(3);\n if (code.startsWith('Digit')) return code.slice(5);\n if (code.startsWith('Numpad')) return `Num ${code.slice(6)}`;\n return KEY_NAMES[code] ?? code;\n}\n"],"names":["Keymap","defaults","reserved","fixed","out","id","c","code","action","lost","rest","saved","mergeKeymap","actions","extra","fn","i","ids","kept","s","codes","owner","keymapStorage","key","store","raw","binds","KEY_NAMES","keyLabel","names","part","own"],"mappings":"AAsBO,MAAMA,EAAyB;AAAA,EAC5B;AAAA,EACS;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAA4B,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM7C,YACEC,GACAC,IAA6B,CAAC,UAAU,SAAS,KAAK,GACtDC,IAA+C,IAC/C;AACA,SAAK,WAAW,EAAE,GAAGF,EAAA,GACrB,KAAK,WAAW,IAAI,IAAIC,CAAQ,GAChC,KAAK,QAAQ,EAAE,GAAGC,EAAA,GAClB,KAAK,QAAQ,KAAK,MAAA;AAAA,EACpB;AAAA,EAEQ,QAA6B;AACnC,UAAMC,IAAM,CAAA;AACZ,eAAWC,KAAM,KAAK,QAAA,EAAW,CAAAD,EAAIC,CAAE,IAAI,KAAK,SAASA,CAAE,EAAE,OAAO,CAACC,MAAM,CAAC,KAAK,SAAS,IAAIA,CAAC,CAAC;AAChG,WAAOF;AAAA,EACT;AAAA;AAAA,EAGA,UAAe;AACb,WAAO,OAAO,KAAK,KAAK,QAAQ;AAAA,EAClC;AAAA,EAEA,WAAWG,GAAuB;AAChC,WAAO,KAAK,SAAS,IAAIA,CAAI;AAAA,EAC/B;AAAA;AAAA,EAGA,QAAQC,GAA8B;AACpC,WAAO,KAAK,MAAMA,CAAM,KAAK,CAAA;AAAA,EAC/B;AAAA;AAAA,EAGA,SAASA,GAA8B;AACrC,WAAO,KAAK,MAAMA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X,OAAO;AAAA,EACP,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,WAAW;AAAA,EACX,aAAa;AAAA,EACb,cAAc;AAChB;AAMO,SAASC,EAASrB,GAAcsB,IAA0C,IAAY;AAC3F,MAAItB,EAAK,SAAS,KAAKA,EAAK,SAAS,GAAG,UAAUA,EAAK,MAAM,GAAG,EAAE,IAAI,CAACuB,MAASF,EAASE,GAAMD,CAAK,CAAC,EAAE,KAAK,GAAG;AAC/G,QAAME,IAAMF,EAAMtB,CAAI;AACtB,SAAIwB,MAAQ,SAAkBA,IAC1BxB,EAAK,WAAW,KAAK,IAAUA,EAAK,MAAM,CAAC,IAC3CA,EAAK,WAAW,OAAO,IAAUA,EAAK,MAAM,CAAC,IAC7CA,EAAK,WAAW,QAAQ,IAAU,OAAOA,EAAK,MAAM,CAAC,CAAC,KACnDoB,EAAUpB,CAAI,KAAKA;AAC5B;"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const _ = 220, g = 300, d = 50 * Math.PI / 180;
|
|
2
|
+
function p(e, n) {
|
|
3
|
+
let t = (e - n) % (Math.PI * 2);
|
|
4
|
+
return t > Math.PI && (t -= Math.PI * 2), t < -Math.PI && (t += Math.PI * 2), t;
|
|
5
|
+
}
|
|
6
|
+
function y(e, n, t, i = 220, s = d) {
|
|
7
|
+
if (Math.hypot(n.x, n.y) < 1e-6) return null;
|
|
8
|
+
const h = Math.atan2(n.y, n.x);
|
|
9
|
+
let l = null, u = 1 / 0;
|
|
10
|
+
for (const a of t) {
|
|
11
|
+
const o = Math.hypot(a.x - e.x, a.y - e.y);
|
|
12
|
+
if (o > i) continue;
|
|
13
|
+
const r = o < 1 ? 0 : Math.abs(p(Math.atan2(a.y - e.y, a.x - e.x), h));
|
|
14
|
+
if (r > s) continue;
|
|
15
|
+
const f = r / s + 0.35 * o / i;
|
|
16
|
+
f < u && (u = f, l = a.id);
|
|
17
|
+
}
|
|
18
|
+
return l;
|
|
19
|
+
}
|
|
20
|
+
function K(e, n, t = 220) {
|
|
21
|
+
let i = null, s = 1 / 0;
|
|
22
|
+
for (const c of n) {
|
|
23
|
+
const h = Math.hypot(c.x - e.x, c.y - e.y);
|
|
24
|
+
h > t || (h < s || h === s && i !== null && c.id < i) && (s = h, i = c.id);
|
|
25
|
+
}
|
|
26
|
+
return i;
|
|
27
|
+
}
|
|
28
|
+
function R(e, n, t, i = 300) {
|
|
29
|
+
if (n === null) return null;
|
|
30
|
+
const s = t.find((c) => c.id === n);
|
|
31
|
+
return !s || Math.hypot(s.x - e.x, s.y - e.y) > i ? null : s;
|
|
32
|
+
}
|
|
33
|
+
class b {
|
|
34
|
+
constructor(n, t = {}) {
|
|
35
|
+
this.bodies = n, this.pickRange = t.pickRange ?? 220, this.keepRange = t.keepRange ?? 300, this.cone = t.cone ?? d;
|
|
36
|
+
}
|
|
37
|
+
bodies;
|
|
38
|
+
id = null;
|
|
39
|
+
pickRange;
|
|
40
|
+
keepRange;
|
|
41
|
+
cone;
|
|
42
|
+
/** The id held, without checking it still stands (use `current` for that). */
|
|
43
|
+
get locked() {
|
|
44
|
+
return this.id;
|
|
45
|
+
}
|
|
46
|
+
/** A drag in `dir` from `from`: locks what it points at; pointing at nothing keeps the old lock. */
|
|
47
|
+
pick(n, t) {
|
|
48
|
+
const i = y(n, t, this.bodies(), this.pickRange, this.cone);
|
|
49
|
+
return i !== null && (this.id = i), this.id;
|
|
50
|
+
}
|
|
51
|
+
/** Locks the nearest body, every call, whatever was held. */
|
|
52
|
+
pickNearest(n) {
|
|
53
|
+
return this.id = K(n, this.bodies(), this.pickRange), this.id;
|
|
54
|
+
}
|
|
55
|
+
/** The held body if it still holds; a lock that no longer does is dropped. */
|
|
56
|
+
current(n) {
|
|
57
|
+
const t = R(n, this.id, this.bodies(), this.keepRange);
|
|
58
|
+
return t || (this.id = null), t;
|
|
59
|
+
}
|
|
60
|
+
clear() {
|
|
61
|
+
this.id = null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export {
|
|
65
|
+
g as LOCK_KEEP_RANGE,
|
|
66
|
+
d as LOCK_PICK_CONE,
|
|
67
|
+
_ as LOCK_PICK_RANGE,
|
|
68
|
+
b as TargetLock,
|
|
69
|
+
R as keptTarget,
|
|
70
|
+
K as nearestTarget,
|
|
71
|
+
y as pickTarget
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=TargetLock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TargetLock.js","sources":["../../src/input/TargetLock.ts"],"sourcesContent":["/**\n * Picking and holding a target on a touch screen, kept pure so it can be tested. Dragging an attack button points:\n * the body lying closest to that direction is picked (and of two about as close to it, the nearer). A target button\n * picks the nearest. The lock then holds — every attack, skill and the facing goes at it, even while a stick walks\n * the body elsewhere — until that body is gone or leaves `keepRange`; a later drag that points at nothing keeps it.\n *\n * Bodies come from a callback as `{ id, x, y }`: the game decides what may be locked (monsters, a duel's opponent).\n */\n\nexport interface LockBody {\n id: number;\n x: number;\n y: number;\n}\n\ntype Point = { x: number; y: number };\n\nexport const LOCK_PICK_RANGE = 220;\nexport const LOCK_KEEP_RANGE = 300;\n/** Widest angle off the drag a body may stand and still be picked: 50° each side. */\nexport const LOCK_PICK_CONE = (50 * Math.PI) / 180;\n\n/** The signed difference a − b, wrapped into −π…π. */\nfunction angleDiff(a: number, b: number): number {\n let d = (a - b) % (Math.PI * 2);\n if (d > Math.PI) d -= Math.PI * 2;\n if (d < -Math.PI) d += Math.PI * 2;\n return d;\n}\n\n/**\n * The body a drag in direction `dir` (any length > 0) picks from `from`, or null. Scored by how far off the drag's\n * line it stands, with distance as a lighter second weight, so a far body dead ahead beats a near one off to the side.\n */\nexport function pickTarget(from: Point, dir: Point, bodies: readonly LockBody[], range = LOCK_PICK_RANGE, cone = LOCK_PICK_CONE): number | null {\n const len = Math.hypot(dir.x, dir.y);\n if (len < 1e-6) return null;\n const heading = Math.atan2(dir.y, dir.x);\n let best: number | null = null;\n let bestScore = Infinity;\n for (const b of bodies) {\n const d = Math.hypot(b.x - from.x, b.y - from.y);\n if (d > range) continue;\n // a body right on top of the player is in every direction\n const off = d < 1 ? 0 : Math.abs(angleDiff(Math.atan2(b.y - from.y, b.x - from.x), heading));\n if (off > cone) continue;\n const score = off / cone + (0.35 * d) / range;\n if (score < bestScore) {\n bestScore = score;\n best = b.id;\n }\n }\n return best;\n}\n\n/** The nearest body within `range` (ties to the lower id, so two clients pick alike), or null. */\nexport function nearestTarget(from: Point, bodies: readonly LockBody[], range = LOCK_PICK_RANGE): number | null {\n let best: number | null = null;\n let bestD = Infinity;\n for (const b of bodies) {\n const d = Math.hypot(b.x - from.x, b.y - from.y);\n if (d > range) continue;\n if (d < bestD || (d === bestD && best !== null && b.id < best)) {\n bestD = d;\n best = b.id;\n }\n }\n return best;\n}\n\n/** The locked body while the lock still holds (present, within `range`), else null. */\nexport function keptTarget<T extends LockBody>(from: Point, locked: number | null, bodies: readonly T[], range = LOCK_KEEP_RANGE): T | null {\n if (locked === null) return null;\n const b = bodies.find((c) => c.id === locked);\n if (!b || Math.hypot(b.x - from.x, b.y - from.y) > range) return null;\n return b;\n}\n\nexport interface TargetLockOptions {\n pickRange?: number;\n keepRange?: number;\n /** Half-angle (radians) a drag picks within. */\n cone?: number;\n}\n\n/** The lock as state: which body is held, picked by a drag or the nearest, let go when it is gone or too far. */\nexport class TargetLock<T extends LockBody = LockBody> {\n private id: number | null = null;\n private readonly pickRange: number;\n private readonly keepRange: number;\n private readonly cone: number;\n\n constructor(\n private readonly bodies: () => readonly T[],\n options: TargetLockOptions = {},\n ) {\n this.pickRange = options.pickRange ?? LOCK_PICK_RANGE;\n this.keepRange = options.keepRange ?? LOCK_KEEP_RANGE;\n this.cone = options.cone ?? LOCK_PICK_CONE;\n }\n\n /** The id held, without checking it still stands (use `current` for that). */\n get locked(): number | null {\n return this.id;\n }\n\n /** A drag in `dir` from `from`: locks what it points at; pointing at nothing keeps the old lock. */\n pick(from: Point, dir: Point): number | null {\n const id = pickTarget(from, dir, this.bodies(), this.pickRange, this.cone);\n if (id !== null) this.id = id;\n return this.id;\n }\n\n /** Locks the nearest body, every call, whatever was held. */\n pickNearest(from: Point): number | null {\n this.id = nearestTarget(from, this.bodies(), this.pickRange);\n return this.id;\n }\n\n /** The held body if it still holds; a lock that no longer does is dropped. */\n current(from: Point): T | null {\n const b = keptTarget(from, this.id, this.bodies(), this.keepRange);\n if (!b) this.id = null;\n return b;\n }\n\n clear(): void {\n this.id = null;\n }\n}\n"],"names":["LOCK_PICK_RANGE","LOCK_KEEP_RANGE","LOCK_PICK_CONE","angleDiff","a","b","d","pickTarget","from","dir","bodies","range","cone","heading","best","bestScore","off","score","nearestTarget","bestD","keptTarget","locked","TargetLock","options","id"],"mappings":"AAiBO,MAAMA,IAAkB,KAClBC,IAAkB,KAElBC,IAAkB,KAAK,KAAK,KAAM;AAG/C,SAASC,EAAUC,GAAWC,GAAmB;AAC/C,MAAIC,KAAKF,IAAIC,MAAM,KAAK,KAAK;AAC7B,SAAIC,IAAI,KAAK,OAAIA,KAAK,KAAK,KAAK,IAC5BA,IAAI,CAAC,KAAK,OAAIA,KAAK,KAAK,KAAK,IAC1BA;AACT;AAMO,SAASC,EAAWC,GAAaC,GAAYC,GAA6BC,IAAQ,KAAiBC,IAAOV,GAA+B;AAE9I,MADY,KAAK,MAAMO,EAAI,GAAGA,EAAI,CAAC,IACzB,KAAM,QAAO;AACvB,QAAMI,IAAU,KAAK,MAAMJ,EAAI,GAAGA,EAAI,CAAC;AACvC,MAAIK,IAAsB,MACtBC,IAAY;AAChB,aAAWV,KAAKK,GAAQ;AACtB,UAAMJ,IAAI,KAAK,MAAMD,EAAE,IAAIG,EAAK,GAAGH,EAAE,IAAIG,EAAK,CAAC;AAC/C,QAAIF,IAAIK,EAAO;AAEf,UAAMK,IAAMV,IAAI,IAAI,IAAI,KAAK,IAAIH,EAAU,KAAK,MAAME,EAAE,IAAIG,EAAK,GAAGH,EAAE,IAAIG,EAAK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,WAAW,KAAK,IAAI;AACzE,WAAIe,MAAO,SAAM,KAAK,KAAKA,IACpB,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,YAAYhB,GAA4B;AACtC,gBAAK,KAAKU,EAAcV,GAAM,KAAK,OAAA,GAAU,KAAK,SAAS,GACpD,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,QAAQA,GAAuB;AAC7B,UAAMH,IAAIe,EAAWZ,GAAM,KAAK,IAAI,KAAK,OAAA,GAAU,KAAK,SAAS;AACjE,WAAKH,MAAG,KAAK,KAAK,OACXA;AAAA,EACT;AAAA,EAEA,QAAc;AACZ,SAAK,KAAK;AAAA,EACZ;AACF;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aimAxis.js","sources":["../../src/input/aimAxis.ts"],"sourcesContent":["/**\n * An aim turned into the eight-way axis the keyboard makes (each part -1, 0 or 1; `stepMover` scales a diagonal),\n * so a step sent along it is one a key could have sent. A part counts once the aim leans past 22.5° towards it.\n */\nexport function aimAxis(aim: number): { dx: number; dy: number } {\n const c = Math.cos(aim);\n const s = Math.sin(aim);\n const lean = Math.sin(Math.PI / 8);\n return { dx: Math.abs(c) > lean ? Math.sign(c) : 0, dy: Math.abs(s) > lean ? Math.sign(s) : 0 };\n}\n"],"names":["aimAxis","aim","c","s","lean"],"mappings":"AAIO,SAASA,EAAQC,GAAyC;AAC/D,QAAMC,IAAI,KAAK,IAAID,CAAG,GAChBE,IAAI,KAAK,IAAIF,CAAG,GAChBG,IAAO,KAAK,IAAI,KAAK,KAAK,CAAC;AACjC,SAAO,EAAE,IAAI,KAAK,IAAIF,CAAC,IAAIE,IAAO,KAAK,KAAKF,CAAC,IAAI,GAAG,IAAI,KAAK,IAAIC,CAAC,IAAIC,IAAO,KAAK,KAAKD,CAAC,IAAI,EAAA;AAC9F;"}
|