rn-gamekit 0.1.0 → 0.2.1
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 +75 -0
- package/README.md +97 -16
- package/lib/module/assets/defineAssets.js +28 -3
- package/lib/module/assets/defineAssets.js.map +1 -1
- package/lib/module/assets.js +11 -0
- package/lib/module/assets.js.map +1 -0
- package/lib/module/audio/createGameAudio.js +784 -0
- package/lib/module/audio/createGameAudio.js.map +1 -0
- package/lib/module/audio/errors.js +12 -0
- package/lib/module/audio/errors.js.map +1 -0
- package/lib/module/audio/index.js +5 -0
- package/lib/module/audio/index.js.map +1 -0
- package/lib/module/audio/resolver.js +37 -0
- package/lib/module/audio/resolver.js.map +1 -0
- package/lib/module/audio/types.js +4 -0
- package/lib/module/audio/types.js.map +1 -0
- package/lib/module/audio.js +9 -0
- package/lib/module/audio.js.map +1 -0
- package/lib/module/camera2d/bounds.js +59 -0
- package/lib/module/camera2d/bounds.js.map +1 -0
- package/lib/module/camera2d/extents.js +25 -0
- package/lib/module/camera2d/extents.js.map +1 -0
- package/lib/module/camera2d/follow.js +138 -0
- package/lib/module/camera2d/follow.js.map +1 -0
- package/lib/module/camera2d/index.js +20 -0
- package/lib/module/camera2d/index.js.map +1 -0
- package/lib/module/camera2d/interpolation.js +98 -0
- package/lib/module/camera2d/interpolation.js.map +1 -0
- package/lib/module/camera2d/shake.js +85 -0
- package/lib/module/camera2d/shake.js.map +1 -0
- package/lib/module/camera2d/transform.js +151 -0
- package/lib/module/camera2d/transform.js.map +1 -0
- package/lib/module/camera2d/types.js +4 -0
- package/lib/module/camera2d/types.js.map +1 -0
- package/lib/module/camera2d/validation.js +98 -0
- package/lib/module/camera2d/validation.js.map +1 -0
- package/lib/module/camera2d/visibility.js +138 -0
- package/lib/module/camera2d/visibility.js.map +1 -0
- package/lib/module/camera2d.js +9 -0
- package/lib/module/camera2d.js.map +1 -0
- package/lib/module/collision2d/colliders.js +266 -0
- package/lib/module/collision2d/colliders.js.map +1 -0
- package/lib/module/collision2d/debug.js +105 -0
- package/lib/module/collision2d/debug.js.map +1 -0
- package/lib/module/collision2d/filters.js +40 -0
- package/lib/module/collision2d/filters.js.map +1 -0
- package/lib/module/collision2d/index.js +12 -0
- package/lib/module/collision2d/index.js.map +1 -0
- package/lib/module/collision2d/intersections.js +67 -0
- package/lib/module/collision2d/intersections.js.map +1 -0
- package/lib/module/collision2d/manifolds.js +218 -0
- package/lib/module/collision2d/manifolds.js.map +1 -0
- package/lib/module/collision2d/segments.js +187 -0
- package/lib/module/collision2d/segments.js.map +1 -0
- package/lib/module/collision2d/spatialHash.js +167 -0
- package/lib/module/collision2d/spatialHash.js.map +1 -0
- package/lib/module/collision2d/sweeps.js +255 -0
- package/lib/module/collision2d/sweeps.js.map +1 -0
- package/lib/module/collision2d.js +9 -0
- package/lib/module/collision2d.js.map +1 -0
- package/lib/module/core/input/buttonPad.js +214 -0
- package/lib/module/core/input/buttonPad.js.map +1 -0
- package/lib/module/core/input/createInputBuffer.js +66 -14
- package/lib/module/core/input/createInputBuffer.js.map +1 -1
- package/lib/module/core/session/createGameSession.js +454 -50
- package/lib/module/core/session/createGameSession.js.map +1 -1
- package/lib/module/core/session/deepFreeze.js +92 -2
- package/lib/module/core/session/deepFreeze.js.map +1 -1
- package/lib/module/core/session/types.js +12 -0
- package/lib/module/core/session/types.js.map +1 -1
- package/lib/module/definition/defineGame.js +23 -0
- package/lib/module/definition/defineGame.js.map +1 -1
- package/lib/module/events/defineGameEvents.js +46 -0
- package/lib/module/events/defineGameEvents.js.map +1 -0
- package/lib/module/events/errors.js +16 -0
- package/lib/module/events/errors.js.map +1 -0
- package/lib/module/events/index.js +7 -0
- package/lib/module/events/index.js.map +1 -0
- package/lib/module/events/payload.js +219 -0
- package/lib/module/events/payload.js.map +1 -0
- package/lib/module/events/seed.js +33 -0
- package/lib/module/events/seed.js.map +1 -0
- package/lib/module/events/types.js +4 -0
- package/lib/module/events/types.js.map +1 -0
- package/lib/module/events.js +13 -0
- package/lib/module/events.js.map +1 -0
- package/lib/module/geometry/helpers.js +140 -0
- package/lib/module/geometry/helpers.js.map +1 -0
- package/lib/module/geometry/index.js +5 -0
- package/lib/module/geometry/index.js.map +1 -0
- package/lib/module/geometry/validation.js +104 -0
- package/lib/module/geometry/validation.js.map +1 -0
- package/lib/module/geometry.js +9 -0
- package/lib/module/geometry.js.map +1 -0
- package/lib/module/haptics/createGameHaptics.js +214 -0
- package/lib/module/haptics/createGameHaptics.js.map +1 -0
- package/lib/module/haptics/errors.js +12 -0
- package/lib/module/haptics/errors.js.map +1 -0
- package/lib/module/haptics/index.js +5 -0
- package/lib/module/haptics/index.js.map +1 -0
- package/lib/module/haptics/resolver.js +37 -0
- package/lib/module/haptics/resolver.js.map +1 -0
- package/lib/module/haptics/types.js +4 -0
- package/lib/module/haptics/types.js.map +1 -0
- package/lib/module/haptics.js +9 -0
- package/lib/module/haptics.js.map +1 -0
- package/lib/module/index.js +8 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/particles/createParticleSystem.js +481 -0
- package/lib/module/particles/createParticleSystem.js.map +1 -0
- package/lib/module/particles/defineParticleEffect.js +178 -0
- package/lib/module/particles/defineParticleEffect.js.map +1 -0
- package/lib/module/particles/errors.js +9 -0
- package/lib/module/particles/errors.js.map +1 -0
- package/lib/module/particles/index.js +8 -0
- package/lib/module/particles/index.js.map +1 -0
- package/lib/module/particles/sampling.js +121 -0
- package/lib/module/particles/sampling.js.map +1 -0
- package/lib/module/particles/types.js +4 -0
- package/lib/module/particles/types.js.map +1 -0
- package/lib/module/particles.js +4 -0
- package/lib/module/particles.js.map +1 -0
- package/lib/module/react/GameButtonPad.js +344 -0
- package/lib/module/react/GameButtonPad.js.map +1 -0
- package/lib/module/react/GamePointerInput.js +74 -16
- package/lib/module/react/GamePointerInput.js.map +1 -1
- package/lib/module/react/GameView.js +139 -60
- package/lib/module/react/GameView.js.map +1 -1
- package/lib/module/react/assets/createGameAssetStore.js +145 -95
- package/lib/module/react/assets/createGameAssetStore.js.map +1 -1
- package/lib/module/react/assets/useGameAssets.js +60 -35
- package/lib/module/react/assets/useGameAssets.js.map +1 -1
- package/lib/module/react/bindAppLifecycle.js +46 -17
- package/lib/module/react/bindAppLifecycle.js.map +1 -1
- package/lib/module/react/bindGameSession.js +13 -2
- package/lib/module/react/bindGameSession.js.map +1 -1
- package/lib/module/react/camera2d/GameLayer2D.js +50 -0
- package/lib/module/react/camera2d/GameLayer2D.js.map +1 -0
- package/lib/module/react/camera2d/defineGameCamera2D.js +30 -0
- package/lib/module/react/camera2d/defineGameCamera2D.js.map +1 -0
- package/lib/module/react/camera2d/usePresentedCameraBinding.js +177 -0
- package/lib/module/react/camera2d/usePresentedCameraBinding.js.map +1 -0
- package/lib/module/react/cleanupList.js +38 -0
- package/lib/module/react/cleanupList.js.map +1 -0
- package/lib/module/react/lifecycleSource.js +49 -0
- package/lib/module/react/lifecycleSource.js.map +1 -0
- package/lib/module/react/particles/ParticleView.js +308 -0
- package/lib/module/react/particles/ParticleView.js.map +1 -0
- package/lib/module/react/particles/culling.js +115 -0
- package/lib/module/react/particles/culling.js.map +1 -0
- package/lib/module/react/particles/index.js +7 -0
- package/lib/module/react/particles/index.js.map +1 -0
- package/lib/module/react/particles/spriteXForm.js +45 -0
- package/lib/module/react/particles/spriteXForm.js.map +1 -0
- package/lib/module/react/particles/useParticlePresentation.js +204 -0
- package/lib/module/react/particles/useParticlePresentation.js.map +1 -0
- package/lib/module/react/pointerBinding.js +55 -17
- package/lib/module/react/pointerBinding.js.map +1 -1
- package/lib/module/react/pointerCamera.js +28 -0
- package/lib/module/react/pointerCamera.js.map +1 -0
- package/lib/module/react/pointerCoalescer.js +16 -9
- package/lib/module/react/pointerCoalescer.js.map +1 -1
- package/lib/module/react/sprites/GameSprite.js +5 -17
- package/lib/module/react/sprites/GameSprite.js.map +1 -1
- package/lib/module/react/sprites/GameWorld2D.js +112 -9
- package/lib/module/react/sprites/GameWorld2D.js.map +1 -1
- package/lib/module/react/sprites/Sprite.js +48 -63
- package/lib/module/react/sprites/Sprite.js.map +1 -1
- package/lib/module/react/sprites/SpriteBatch.js +53 -28
- package/lib/module/react/sprites/SpriteBatch.js.map +1 -1
- package/lib/module/react/sprites/batchVisibility.js +58 -0
- package/lib/module/react/sprites/batchVisibility.js.map +1 -0
- package/lib/module/react/sprites/spriteSelection.js +103 -0
- package/lib/module/react/sprites/spriteSelection.js.map +1 -0
- package/lib/module/react/sprites/spriteTransform.js +46 -25
- package/lib/module/react/sprites/spriteTransform.js.map +1 -1
- package/lib/module/react/tilemap/TileMapLayer2D.js +217 -0
- package/lib/module/react/tilemap/TileMapLayer2D.js.map +1 -0
- package/lib/module/react/tilemap/tilePresentation.js +374 -0
- package/lib/module/react/tilemap/tilePresentation.js.map +1 -0
- package/lib/module/react/useGameSession.js +70 -0
- package/lib/module/react/useGameSession.js.map +1 -0
- package/lib/module/react/useGameSessionStatus.js +46 -0
- package/lib/module/react/useGameSessionStatus.js.map +1 -0
- package/lib/module/react/viewportBinding.js +5 -1
- package/lib/module/react/viewportBinding.js.map +1 -1
- package/lib/module/react.js +12 -1
- package/lib/module/react.js.map +1 -1
- package/lib/module/scene/defineScene.js +17 -0
- package/lib/module/scene/defineScene.js.map +1 -1
- package/lib/module/sprites/sampleSpriteClip.js +66 -6
- package/lib/module/sprites/sampleSpriteClip.js.map +1 -1
- package/lib/module/sprites/spriteAnimationState.js +10 -20
- package/lib/module/sprites/spriteAnimationState.js.map +1 -1
- package/lib/module/sprites.js +11 -0
- package/lib/module/sprites.js.map +1 -0
- package/lib/module/storage/adapters/asyncStorage.js +57 -0
- package/lib/module/storage/adapters/asyncStorage.js.map +1 -0
- package/lib/module/storage/adapters/memory.js +50 -0
- package/lib/module/storage/adapters/memory.js.map +1 -0
- package/lib/module/storage/errors.js +34 -0
- package/lib/module/storage/errors.js.map +1 -0
- package/lib/module/storage/index.js +11 -0
- package/lib/module/storage/index.js.map +1 -0
- package/lib/module/storage/schema.js +151 -0
- package/lib/module/storage/schema.js.map +1 -0
- package/lib/module/storage/serialization.js +249 -0
- package/lib/module/storage/serialization.js.map +1 -0
- package/lib/module/storage/store.js +387 -0
- package/lib/module/storage/store.js.map +1 -0
- package/lib/module/storage/types.js +16 -0
- package/lib/module/storage/types.js.map +1 -0
- package/lib/module/storage/validation.js +111 -0
- package/lib/module/storage/validation.js.map +1 -0
- package/lib/module/storage.js +4 -0
- package/lib/module/storage.js.map +1 -0
- package/lib/module/testing.js +4 -0
- package/lib/module/testing.js.map +1 -1
- package/lib/module/tilemap/chunkStats.js +27 -0
- package/lib/module/tilemap/chunkStats.js.map +1 -0
- package/lib/module/tilemap/definitions.js +308 -0
- package/lib/module/tilemap/definitions.js.map +1 -0
- package/lib/module/tilemap/errors.js +13 -0
- package/lib/module/tilemap/errors.js.map +1 -0
- package/lib/module/tilemap/index.js +10 -0
- package/lib/module/tilemap/index.js.map +1 -0
- package/lib/module/tilemap/movement.js +379 -0
- package/lib/module/tilemap/movement.js.map +1 -0
- package/lib/module/tilemap/queries.js +114 -0
- package/lib/module/tilemap/queries.js.map +1 -0
- package/lib/module/tilemap/tiledAdapter.js +141 -0
- package/lib/module/tilemap/tiledAdapter.js.map +1 -0
- package/lib/module/tilemap/types.js +4 -0
- package/lib/module/tilemap/types.js.map +1 -0
- package/lib/module/tilemap.js +4 -0
- package/lib/module/tilemap.js.map +1 -0
- package/lib/typescript/src/assets/defineAssets.d.ts +1 -1
- package/lib/typescript/src/assets/defineAssets.d.ts.map +1 -1
- package/lib/typescript/src/assets.d.ts +11 -0
- package/lib/typescript/src/assets.d.ts.map +1 -0
- package/lib/typescript/src/audio/createGameAudio.d.ts +5 -0
- package/lib/typescript/src/audio/createGameAudio.d.ts.map +1 -0
- package/lib/typescript/src/audio/errors.d.ts +6 -0
- package/lib/typescript/src/audio/errors.d.ts.map +1 -0
- package/lib/typescript/src/audio/index.d.ts +4 -0
- package/lib/typescript/src/audio/index.d.ts.map +1 -0
- package/lib/typescript/src/audio/resolver.d.ts +44 -0
- package/lib/typescript/src/audio/resolver.d.ts.map +1 -0
- package/lib/typescript/src/audio/types.d.ts +42 -0
- package/lib/typescript/src/audio/types.d.ts.map +1 -0
- package/lib/typescript/src/audio.d.ts +8 -0
- package/lib/typescript/src/audio.d.ts.map +1 -0
- package/lib/typescript/src/camera2d/bounds.d.ts +25 -0
- package/lib/typescript/src/camera2d/bounds.d.ts.map +1 -0
- package/lib/typescript/src/camera2d/extents.d.ts +17 -0
- package/lib/typescript/src/camera2d/extents.d.ts.map +1 -0
- package/lib/typescript/src/camera2d/follow.d.ts +24 -0
- package/lib/typescript/src/camera2d/follow.d.ts.map +1 -0
- package/lib/typescript/src/camera2d/index.d.ts +19 -0
- package/lib/typescript/src/camera2d/index.d.ts.map +1 -0
- package/lib/typescript/src/camera2d/interpolation.d.ts +17 -0
- package/lib/typescript/src/camera2d/interpolation.d.ts.map +1 -0
- package/lib/typescript/src/camera2d/shake.d.ts +20 -0
- package/lib/typescript/src/camera2d/shake.d.ts.map +1 -0
- package/lib/typescript/src/camera2d/transform.d.ts +44 -0
- package/lib/typescript/src/camera2d/transform.d.ts.map +1 -0
- package/lib/typescript/src/camera2d/types.d.ts +74 -0
- package/lib/typescript/src/camera2d/types.d.ts.map +1 -0
- package/lib/typescript/src/camera2d/validation.d.ts +30 -0
- package/lib/typescript/src/camera2d/validation.d.ts.map +1 -0
- package/lib/typescript/src/camera2d/visibility.d.ts +47 -0
- package/lib/typescript/src/camera2d/visibility.d.ts.map +1 -0
- package/lib/typescript/src/camera2d.d.ts +7 -0
- package/lib/typescript/src/camera2d.d.ts.map +1 -0
- package/lib/typescript/src/collision2d/colliders.d.ts +120 -0
- package/lib/typescript/src/collision2d/colliders.d.ts.map +1 -0
- package/lib/typescript/src/collision2d/debug.d.ts +67 -0
- package/lib/typescript/src/collision2d/debug.d.ts.map +1 -0
- package/lib/typescript/src/collision2d/filters.d.ts +28 -0
- package/lib/typescript/src/collision2d/filters.d.ts.map +1 -0
- package/lib/typescript/src/collision2d/index.d.ts +17 -0
- package/lib/typescript/src/collision2d/index.d.ts.map +1 -0
- package/lib/typescript/src/collision2d/intersections.d.ts +24 -0
- package/lib/typescript/src/collision2d/intersections.d.ts.map +1 -0
- package/lib/typescript/src/collision2d/manifolds.d.ts +39 -0
- package/lib/typescript/src/collision2d/manifolds.d.ts.map +1 -0
- package/lib/typescript/src/collision2d/segments.d.ts +24 -0
- package/lib/typescript/src/collision2d/segments.d.ts.map +1 -0
- package/lib/typescript/src/collision2d/spatialHash.d.ts +50 -0
- package/lib/typescript/src/collision2d/spatialHash.d.ts.map +1 -0
- package/lib/typescript/src/collision2d/sweeps.d.ts +60 -0
- package/lib/typescript/src/collision2d/sweeps.d.ts.map +1 -0
- package/lib/typescript/src/collision2d.d.ts +7 -0
- package/lib/typescript/src/collision2d.d.ts.map +1 -0
- package/lib/typescript/src/core/input/buttonPad.d.ts +59 -0
- package/lib/typescript/src/core/input/buttonPad.d.ts.map +1 -0
- package/lib/typescript/src/core/input/createInputBuffer.d.ts +1 -1
- package/lib/typescript/src/core/input/createInputBuffer.d.ts.map +1 -1
- package/lib/typescript/src/core/input/types.d.ts +7 -0
- package/lib/typescript/src/core/input/types.d.ts.map +1 -1
- package/lib/typescript/src/core/session/createGameSession.d.ts +4 -2
- package/lib/typescript/src/core/session/createGameSession.d.ts.map +1 -1
- package/lib/typescript/src/core/session/deepFreeze.d.ts +21 -1
- package/lib/typescript/src/core/session/deepFreeze.d.ts.map +1 -1
- package/lib/typescript/src/core/session/diagnostics.d.ts +2 -0
- package/lib/typescript/src/core/session/diagnostics.d.ts.map +1 -1
- package/lib/typescript/src/core/session/types.d.ts +69 -4
- package/lib/typescript/src/core/session/types.d.ts.map +1 -1
- package/lib/typescript/src/definition/defineGame.d.ts +12 -1
- package/lib/typescript/src/definition/defineGame.d.ts.map +1 -1
- package/lib/typescript/src/definition/types.d.ts +10 -1
- package/lib/typescript/src/definition/types.d.ts.map +1 -1
- package/lib/typescript/src/events/defineGameEvents.d.ts +26 -0
- package/lib/typescript/src/events/defineGameEvents.d.ts.map +1 -0
- package/lib/typescript/src/events/errors.d.ts +12 -0
- package/lib/typescript/src/events/errors.d.ts.map +1 -0
- package/lib/typescript/src/events/index.d.ts +6 -0
- package/lib/typescript/src/events/index.d.ts.map +1 -0
- package/lib/typescript/src/events/payload.d.ts +21 -0
- package/lib/typescript/src/events/payload.d.ts.map +1 -0
- package/lib/typescript/src/events/seed.d.ts +3 -0
- package/lib/typescript/src/events/seed.d.ts.map +1 -0
- package/lib/typescript/src/events/types.d.ts +42 -0
- package/lib/typescript/src/events/types.d.ts.map +1 -0
- package/lib/typescript/src/events.d.ts +12 -0
- package/lib/typescript/src/events.d.ts.map +1 -0
- package/lib/typescript/src/geometry/helpers.d.ts +35 -0
- package/lib/typescript/src/geometry/helpers.d.ts.map +1 -0
- package/lib/typescript/src/geometry/index.d.ts +4 -0
- package/lib/typescript/src/geometry/index.d.ts.map +1 -0
- package/lib/typescript/src/geometry/types.d.ts +49 -0
- package/lib/typescript/src/geometry/types.d.ts.map +1 -1
- package/lib/typescript/src/geometry/validation.d.ts +44 -0
- package/lib/typescript/src/geometry/validation.d.ts.map +1 -0
- package/lib/typescript/src/geometry.d.ts +7 -0
- package/lib/typescript/src/geometry.d.ts.map +1 -0
- package/lib/typescript/src/haptics/createGameHaptics.d.ts +3 -0
- package/lib/typescript/src/haptics/createGameHaptics.d.ts.map +1 -0
- package/lib/typescript/src/haptics/errors.d.ts +6 -0
- package/lib/typescript/src/haptics/errors.d.ts.map +1 -0
- package/lib/typescript/src/haptics/index.d.ts +4 -0
- package/lib/typescript/src/haptics/index.d.ts.map +1 -0
- package/lib/typescript/src/haptics/resolver.d.ts +22 -0
- package/lib/typescript/src/haptics/resolver.d.ts.map +1 -0
- package/lib/typescript/src/haptics/types.d.ts +37 -0
- package/lib/typescript/src/haptics/types.d.ts.map +1 -0
- package/lib/typescript/src/haptics.d.ts +8 -0
- package/lib/typescript/src/haptics.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +10 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/particles/createParticleSystem.d.ts +5 -0
- package/lib/typescript/src/particles/createParticleSystem.d.ts.map +1 -0
- package/lib/typescript/src/particles/defineParticleEffect.d.ts +3 -0
- package/lib/typescript/src/particles/defineParticleEffect.d.ts.map +1 -0
- package/lib/typescript/src/particles/errors.d.ts +5 -0
- package/lib/typescript/src/particles/errors.d.ts.map +1 -0
- package/lib/typescript/src/particles/index.d.ts +6 -0
- package/lib/typescript/src/particles/index.d.ts.map +1 -0
- package/lib/typescript/src/particles/sampling.d.ts +54 -0
- package/lib/typescript/src/particles/sampling.d.ts.map +1 -0
- package/lib/typescript/src/particles/types.d.ts +292 -0
- package/lib/typescript/src/particles/types.d.ts.map +1 -0
- package/lib/typescript/src/particles.d.ts +2 -0
- package/lib/typescript/src/particles.d.ts.map +1 -0
- package/lib/typescript/src/react/GameButtonPad.d.ts +84 -0
- package/lib/typescript/src/react/GameButtonPad.d.ts.map +1 -0
- package/lib/typescript/src/react/GamePointerInput.d.ts.map +1 -1
- package/lib/typescript/src/react/GameView.d.ts +27 -1
- package/lib/typescript/src/react/GameView.d.ts.map +1 -1
- package/lib/typescript/src/react/assets/createGameAssetStore.d.ts.map +1 -1
- package/lib/typescript/src/react/assets/useGameAssets.d.ts.map +1 -1
- package/lib/typescript/src/react/bindAppLifecycle.d.ts +7 -1
- package/lib/typescript/src/react/bindAppLifecycle.d.ts.map +1 -1
- package/lib/typescript/src/react/bindGameSession.d.ts.map +1 -1
- package/lib/typescript/src/react/camera2d/GameLayer2D.d.ts +24 -0
- package/lib/typescript/src/react/camera2d/GameLayer2D.d.ts.map +1 -0
- package/lib/typescript/src/react/camera2d/defineGameCamera2D.d.ts +44 -0
- package/lib/typescript/src/react/camera2d/defineGameCamera2D.d.ts.map +1 -0
- package/lib/typescript/src/react/camera2d/usePresentedCameraBinding.d.ts +22 -0
- package/lib/typescript/src/react/camera2d/usePresentedCameraBinding.d.ts.map +1 -0
- package/lib/typescript/src/react/cleanupList.d.ts +21 -0
- package/lib/typescript/src/react/cleanupList.d.ts.map +1 -0
- package/lib/typescript/src/react/instrumentation.d.ts +33 -3
- package/lib/typescript/src/react/instrumentation.d.ts.map +1 -1
- package/lib/typescript/src/react/lifecycleSource.d.ts +21 -0
- package/lib/typescript/src/react/lifecycleSource.d.ts.map +1 -0
- package/lib/typescript/src/react/particles/ParticleView.d.ts +65 -0
- package/lib/typescript/src/react/particles/ParticleView.d.ts.map +1 -0
- package/lib/typescript/src/react/particles/culling.d.ts +70 -0
- package/lib/typescript/src/react/particles/culling.d.ts.map +1 -0
- package/lib/typescript/src/react/particles/index.d.ts +7 -0
- package/lib/typescript/src/react/particles/index.d.ts.map +1 -0
- package/lib/typescript/src/react/particles/spriteXForm.d.ts +28 -0
- package/lib/typescript/src/react/particles/spriteXForm.d.ts.map +1 -0
- package/lib/typescript/src/react/particles/useParticlePresentation.d.ts +48 -0
- package/lib/typescript/src/react/particles/useParticlePresentation.d.ts.map +1 -0
- package/lib/typescript/src/react/pointerBinding.d.ts +38 -8
- package/lib/typescript/src/react/pointerBinding.d.ts.map +1 -1
- package/lib/typescript/src/react/pointerCamera.d.ts +20 -0
- package/lib/typescript/src/react/pointerCamera.d.ts.map +1 -0
- package/lib/typescript/src/react/pointerCoalescer.d.ts +17 -1
- package/lib/typescript/src/react/pointerCoalescer.d.ts.map +1 -1
- package/lib/typescript/src/react/sprites/GameSprite.d.ts +3 -10
- package/lib/typescript/src/react/sprites/GameSprite.d.ts.map +1 -1
- package/lib/typescript/src/react/sprites/GameWorld2D.d.ts +51 -6
- package/lib/typescript/src/react/sprites/GameWorld2D.d.ts.map +1 -1
- package/lib/typescript/src/react/sprites/Sprite.d.ts.map +1 -1
- package/lib/typescript/src/react/sprites/SpriteBatch.d.ts +22 -1
- package/lib/typescript/src/react/sprites/SpriteBatch.d.ts.map +1 -1
- package/lib/typescript/src/react/sprites/batchVisibility.d.ts +28 -0
- package/lib/typescript/src/react/sprites/batchVisibility.d.ts.map +1 -0
- package/lib/typescript/src/react/sprites/spriteSelection.d.ts +58 -0
- package/lib/typescript/src/react/sprites/spriteSelection.d.ts.map +1 -0
- package/lib/typescript/src/react/sprites/spriteTransform.d.ts +27 -12
- package/lib/typescript/src/react/sprites/spriteTransform.d.ts.map +1 -1
- package/lib/typescript/src/react/tilemap/TileMapLayer2D.d.ts +69 -0
- package/lib/typescript/src/react/tilemap/TileMapLayer2D.d.ts.map +1 -0
- package/lib/typescript/src/react/tilemap/tilePresentation.d.ts +217 -0
- package/lib/typescript/src/react/tilemap/tilePresentation.d.ts.map +1 -0
- package/lib/typescript/src/react/useGameSession.d.ts +48 -0
- package/lib/typescript/src/react/useGameSession.d.ts.map +1 -0
- package/lib/typescript/src/react/useGameSessionStatus.d.ts +23 -0
- package/lib/typescript/src/react/useGameSessionStatus.d.ts.map +1 -0
- package/lib/typescript/src/react/viewportBinding.d.ts +5 -1
- package/lib/typescript/src/react/viewportBinding.d.ts.map +1 -1
- package/lib/typescript/src/react.d.ts +18 -1
- package/lib/typescript/src/react.d.ts.map +1 -1
- package/lib/typescript/src/scene/defineScene.d.ts +22 -2
- package/lib/typescript/src/scene/defineScene.d.ts.map +1 -1
- package/lib/typescript/src/scene/types.d.ts +24 -4
- package/lib/typescript/src/scene/types.d.ts.map +1 -1
- package/lib/typescript/src/sprites/sampleSpriteClip.d.ts +26 -2
- package/lib/typescript/src/sprites/sampleSpriteClip.d.ts.map +1 -1
- package/lib/typescript/src/sprites/spriteAnimationState.d.ts +6 -7
- package/lib/typescript/src/sprites/spriteAnimationState.d.ts.map +1 -1
- package/lib/typescript/src/sprites.d.ts +10 -0
- package/lib/typescript/src/sprites.d.ts.map +1 -0
- package/lib/typescript/src/storage/adapters/asyncStorage.d.ts +18 -0
- package/lib/typescript/src/storage/adapters/asyncStorage.d.ts.map +1 -0
- package/lib/typescript/src/storage/adapters/memory.d.ts +16 -0
- package/lib/typescript/src/storage/adapters/memory.d.ts.map +1 -0
- package/lib/typescript/src/storage/errors.d.ts +37 -0
- package/lib/typescript/src/storage/errors.d.ts.map +1 -0
- package/lib/typescript/src/storage/index.d.ts +11 -0
- package/lib/typescript/src/storage/index.d.ts.map +1 -0
- package/lib/typescript/src/storage/schema.d.ts +22 -0
- package/lib/typescript/src/storage/schema.d.ts.map +1 -0
- package/lib/typescript/src/storage/serialization.d.ts +23 -0
- package/lib/typescript/src/storage/serialization.d.ts.map +1 -0
- package/lib/typescript/src/storage/store.d.ts +3 -0
- package/lib/typescript/src/storage/store.d.ts.map +1 -0
- package/lib/typescript/src/storage/types.d.ts +69 -0
- package/lib/typescript/src/storage/types.d.ts.map +1 -0
- package/lib/typescript/src/storage/validation.d.ts +24 -0
- package/lib/typescript/src/storage/validation.d.ts.map +1 -0
- package/lib/typescript/src/storage.d.ts +2 -0
- package/lib/typescript/src/storage.d.ts.map +1 -0
- package/lib/typescript/src/testing.d.ts +1 -0
- package/lib/typescript/src/testing.d.ts.map +1 -1
- package/lib/typescript/src/tilemap/chunkStats.d.ts +14 -0
- package/lib/typescript/src/tilemap/chunkStats.d.ts.map +1 -0
- package/lib/typescript/src/tilemap/definitions.d.ts +38 -0
- package/lib/typescript/src/tilemap/definitions.d.ts.map +1 -0
- package/lib/typescript/src/tilemap/errors.d.ts +7 -0
- package/lib/typescript/src/tilemap/errors.d.ts.map +1 -0
- package/lib/typescript/src/tilemap/index.d.ts +8 -0
- package/lib/typescript/src/tilemap/index.d.ts.map +1 -0
- package/lib/typescript/src/tilemap/movement.d.ts +52 -0
- package/lib/typescript/src/tilemap/movement.d.ts.map +1 -0
- package/lib/typescript/src/tilemap/queries.d.ts +21 -0
- package/lib/typescript/src/tilemap/queries.d.ts.map +1 -0
- package/lib/typescript/src/tilemap/tiledAdapter.d.ts +32 -0
- package/lib/typescript/src/tilemap/tiledAdapter.d.ts.map +1 -0
- package/lib/typescript/src/tilemap/types.d.ts +127 -0
- package/lib/typescript/src/tilemap/types.d.ts.map +1 -0
- package/lib/typescript/src/tilemap.d.ts +2 -0
- package/lib/typescript/src/tilemap.d.ts.map +1 -0
- package/package.json +100 -10
- package/src/assets/defineAssets.ts +31 -5
- package/src/assets.ts +27 -0
- package/src/audio/createGameAudio.ts +749 -0
- package/src/audio/errors.ts +12 -0
- package/src/audio/index.ts +9 -0
- package/src/audio/resolver.ts +74 -0
- package/src/audio/types.ts +47 -0
- package/src/audio.ts +13 -0
- package/src/camera2d/bounds.ts +69 -0
- package/src/camera2d/extents.ts +25 -0
- package/src/camera2d/follow.ts +165 -0
- package/src/camera2d/index.ts +29 -0
- package/src/camera2d/interpolation.ts +113 -0
- package/src/camera2d/shake.ts +90 -0
- package/src/camera2d/transform.ts +148 -0
- package/src/camera2d/types.ts +73 -0
- package/src/camera2d/validation.ts +126 -0
- package/src/camera2d/visibility.ts +181 -0
- package/src/camera2d.ts +6 -0
- package/src/collision2d/colliders.ts +292 -0
- package/src/collision2d/debug.ts +133 -0
- package/src/collision2d/filters.ts +48 -0
- package/src/collision2d/index.ts +74 -0
- package/src/collision2d/intersections.ts +82 -0
- package/src/collision2d/manifolds.ts +191 -0
- package/src/collision2d/segments.ts +176 -0
- package/src/collision2d/spatialHash.ts +211 -0
- package/src/collision2d/sweeps.ts +269 -0
- package/src/collision2d.ts +6 -0
- package/src/core/input/buttonPad.ts +235 -0
- package/src/core/input/createInputBuffer.ts +95 -14
- package/src/core/input/types.ts +7 -0
- package/src/core/session/createGameSession.ts +480 -53
- package/src/core/session/deepFreeze.ts +104 -3
- package/src/core/session/diagnostics.ts +2 -0
- package/src/core/session/types.ts +77 -4
- package/src/definition/defineGame.ts +61 -3
- package/src/definition/types.ts +10 -0
- package/src/events/defineGameEvents.ts +46 -0
- package/src/events/errors.ts +14 -0
- package/src/events/index.ts +14 -0
- package/src/events/payload.ts +234 -0
- package/src/events/seed.ts +33 -0
- package/src/events/types.ts +53 -0
- package/src/events.ts +20 -0
- package/src/geometry/helpers.ts +136 -0
- package/src/geometry/index.ts +14 -0
- package/src/geometry/types.ts +54 -0
- package/src/geometry/validation.ts +131 -0
- package/src/geometry.ts +6 -0
- package/src/haptics/createGameHaptics.ts +214 -0
- package/src/haptics/errors.ts +12 -0
- package/src/haptics/index.ts +3 -0
- package/src/haptics/resolver.ts +58 -0
- package/src/haptics/types.ts +48 -0
- package/src/haptics.ts +7 -0
- package/src/index.ts +37 -1
- package/src/particles/createParticleSystem.ts +505 -0
- package/src/particles/defineParticleEffect.ts +164 -0
- package/src/particles/errors.ts +6 -0
- package/src/particles/index.ts +5 -0
- package/src/particles/sampling.ts +141 -0
- package/src/particles/types.ts +327 -0
- package/src/particles.ts +1 -0
- package/src/react/GameButtonPad.tsx +436 -0
- package/src/react/GamePointerInput.tsx +73 -8
- package/src/react/GameView.tsx +160 -61
- package/src/react/assets/createGameAssetStore.ts +140 -107
- package/src/react/assets/useGameAssets.ts +63 -31
- package/src/react/bindAppLifecycle.ts +55 -19
- package/src/react/bindGameSession.ts +12 -2
- package/src/react/camera2d/GameLayer2D.tsx +43 -0
- package/src/react/camera2d/defineGameCamera2D.ts +59 -0
- package/src/react/camera2d/usePresentedCameraBinding.ts +185 -0
- package/src/react/cleanupList.ts +48 -0
- package/src/react/instrumentation.ts +31 -3
- package/src/react/lifecycleSource.ts +58 -0
- package/src/react/particles/ParticleView.tsx +358 -0
- package/src/react/particles/culling.ts +145 -0
- package/src/react/particles/index.ts +6 -0
- package/src/react/particles/spriteXForm.ts +72 -0
- package/src/react/particles/useParticlePresentation.ts +261 -0
- package/src/react/pointerBinding.ts +74 -16
- package/src/react/pointerCamera.ts +33 -0
- package/src/react/pointerCoalescer.ts +36 -10
- package/src/react/sprites/GameSprite.tsx +4 -33
- package/src/react/sprites/GameWorld2D.tsx +113 -7
- package/src/react/sprites/Sprite.tsx +51 -72
- package/src/react/sprites/SpriteBatch.tsx +74 -22
- package/src/react/sprites/batchVisibility.ts +76 -0
- package/src/react/sprites/spriteSelection.ts +133 -0
- package/src/react/sprites/spriteTransform.ts +46 -26
- package/src/react/tilemap/TileMapLayer2D.tsx +274 -0
- package/src/react/tilemap/tilePresentation.ts +491 -0
- package/src/react/useGameSession.ts +90 -0
- package/src/react/useGameSessionStatus.ts +53 -0
- package/src/react/viewportBinding.ts +5 -1
- package/src/react.ts +18 -1
- package/src/scene/defineScene.ts +47 -5
- package/src/scene/types.ts +37 -3
- package/src/sprites/sampleSpriteClip.ts +82 -14
- package/src/sprites/spriteAnimationState.ts +29 -25
- package/src/sprites.ts +22 -0
- package/src/storage/adapters/asyncStorage.ts +77 -0
- package/src/storage/adapters/memory.ts +58 -0
- package/src/storage/errors.ts +88 -0
- package/src/storage/index.ts +18 -0
- package/src/storage/schema.ts +147 -0
- package/src/storage/serialization.ts +248 -0
- package/src/storage/store.ts +380 -0
- package/src/storage/types.ts +76 -0
- package/src/storage/validation.ts +102 -0
- package/src/storage.ts +1 -0
- package/src/testing.ts +4 -0
- package/src/tilemap/chunkStats.ts +24 -0
- package/src/tilemap/definitions.ts +327 -0
- package/src/tilemap/errors.ts +11 -0
- package/src/tilemap/index.ts +10 -0
- package/src/tilemap/movement.ts +368 -0
- package/src/tilemap/queries.ts +136 -0
- package/src/tilemap/tiledAdapter.ts +165 -0
- package/src/tilemap/types.ts +119 -0
- package/src/tilemap.ts +1 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Swept collision queries (T11.3, repaired in T11-F2, allocation-disciplined
|
|
5
|
+
* in T11-FF7).
|
|
6
|
+
*
|
|
7
|
+
* `time` is normalized to `[0, 1]` along the displacement. A starting
|
|
8
|
+
* overlap returns `time: 0` with the static manifold normal; zero
|
|
9
|
+
* displacement returns `undefined` (never NaN). At equal times the
|
|
10
|
+
* candidate evaluated FIRST wins — the X face before the Y face, faces
|
|
11
|
+
* before corners, corners in index order (T11-TF1). Circle-sweep misses
|
|
12
|
+
* allocate nothing; AABB-AABB sweep misses still allocate the expanded
|
|
13
|
+
* box, segment endpoints, and axis array (GS-COLLISION-03: the old blanket
|
|
14
|
+
* claim overstated this path, which stays scalar-simple by design).
|
|
15
|
+
*
|
|
16
|
+
* Circle-AABB sweeps raycast against the exact Minkowski geometry: the
|
|
17
|
+
* target expanded by the radius with ROUNDED corners. Face candidates come
|
|
18
|
+
* from the four expanded faces (valid only within the face's extent), and
|
|
19
|
+
* corner candidates come from radius circles around each target corner
|
|
20
|
+
* (valid only in the corner's exterior quadrant). AABB-AABB sweeps use the
|
|
21
|
+
* asymmetric expansion for the moving AABB's top-left reference point —
|
|
22
|
+
* the Minkowski sum of two AABBs is an AABB, so the slab method is exact.
|
|
23
|
+
*
|
|
24
|
+
* T11-FF7 allocation discipline: the four corner descriptors are derived
|
|
25
|
+
* arithmetically from the corner index (no per-call arrays or predicate
|
|
26
|
+
* closures), the two quadratic roots are evaluated as scalars, and the best
|
|
27
|
+
* candidate is tracked in scalars; only the final public `SweepHit2D` is
|
|
28
|
+
* allocated.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import { assertValidAabb2D, assertValidCircle2D, assertValidVector2D } from "../geometry/validation.js";
|
|
32
|
+
import { collideAabbAabb2D, collideCircleAabb2D } from "./manifolds.js";
|
|
33
|
+
import { intersectsCircleAabb2D } from "./intersections.js";
|
|
34
|
+
import { intersectSegmentAabb2D } from "./segments.js";
|
|
35
|
+
|
|
36
|
+
/** Earliest impact of a swept circle against an AABB. */
|
|
37
|
+
|
|
38
|
+
/** Earliest impact of a swept AABB against an AABB. */
|
|
39
|
+
|
|
40
|
+
/** Earliest impact of a swept shape against a target. */
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Corner descriptors for index 0..3, derived arithmetically: bit 0 selects
|
|
44
|
+
* the max-x face (else min-x) and bit 1 selects the max-y face (else
|
|
45
|
+
* min-y). The quadrant validity of a hit point is the same bit test.
|
|
46
|
+
*/
|
|
47
|
+
function cornerFaceX(index, minX, maxX) {
|
|
48
|
+
return index & 1 ? maxX : minX;
|
|
49
|
+
}
|
|
50
|
+
function cornerFaceY(index, minY, maxY) {
|
|
51
|
+
return index & 2 ? maxY : minY;
|
|
52
|
+
}
|
|
53
|
+
function beyondFaceX(index, pointX, minX, maxX) {
|
|
54
|
+
return index & 1 ? pointX >= maxX : pointX <= minX;
|
|
55
|
+
}
|
|
56
|
+
function beyondFaceY(index, pointY, minY, maxY) {
|
|
57
|
+
return index & 2 ? pointY >= maxY : pointY <= minY;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Swept circle-AABB against the exact rounded-rectangle Minkowski shape. */
|
|
61
|
+
export function sweepCircleAabb2D(options) {
|
|
62
|
+
const {
|
|
63
|
+
circle,
|
|
64
|
+
displacement,
|
|
65
|
+
target
|
|
66
|
+
} = options;
|
|
67
|
+
assertValidCircle2D(circle);
|
|
68
|
+
assertValidVector2D(displacement, 'displacement');
|
|
69
|
+
assertValidAabb2D(target, 'target');
|
|
70
|
+
|
|
71
|
+
// The starting-overlap check uses the allocation-free predicate; the
|
|
72
|
+
// manifold (and its contact object) runs only after contact is confirmed
|
|
73
|
+
// (T11-SF3).
|
|
74
|
+
if (intersectsCircleAabb2D(circle, target)) {
|
|
75
|
+
const overlap = collideCircleAabb2D(circle, target);
|
|
76
|
+
if (overlap !== undefined) {
|
|
77
|
+
return hitFromManifold(0, overlap);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (displacement.x === 0 && displacement.y === 0) {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
const radius = circle.radius;
|
|
84
|
+
const minX = target.x;
|
|
85
|
+
const maxX = target.x + target.width;
|
|
86
|
+
const minY = target.y;
|
|
87
|
+
const maxY = target.y + target.height;
|
|
88
|
+
const x0 = circle.x;
|
|
89
|
+
const y0 = circle.y;
|
|
90
|
+
const dx = displacement.x;
|
|
91
|
+
const dy = displacement.y;
|
|
92
|
+
|
|
93
|
+
// Scalar best-candidate tracking: nothing is allocated until a hit.
|
|
94
|
+
let hasBest = false;
|
|
95
|
+
let bestTime = 0;
|
|
96
|
+
let bestNX = 0;
|
|
97
|
+
let bestNY = 0;
|
|
98
|
+
let bestPX = 0;
|
|
99
|
+
let bestPY = 0;
|
|
100
|
+
|
|
101
|
+
// Face candidates: the four expanded faces, valid within the face extent.
|
|
102
|
+
// The accept logic is inlined as scalar updates (no local closure). A
|
|
103
|
+
// candidate REPLACES only when strictly earlier; at equal times the
|
|
104
|
+
// candidate evaluated first retains the result (T11-TF1).
|
|
105
|
+
if (dx !== 0) {
|
|
106
|
+
const faceX = dx > 0 ? minX - radius : maxX + radius;
|
|
107
|
+
const time = (faceX - x0) / dx;
|
|
108
|
+
const yAt = y0 + dy * time;
|
|
109
|
+
if (yAt >= minY && yAt <= maxY && time >= 0 && time <= 1 && (!hasBest || bestTime > time)) {
|
|
110
|
+
// The contact point is the closest point on the ORIGINAL target to
|
|
111
|
+
// the impact position (both coordinates clamped).
|
|
112
|
+
hasBest = true;
|
|
113
|
+
bestTime = time;
|
|
114
|
+
bestNX = dx > 0 ? -1 : 1;
|
|
115
|
+
bestNY = 0;
|
|
116
|
+
bestPX = clamp(faceX, minX, maxX);
|
|
117
|
+
bestPY = clamp(yAt, minY, maxY);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (dy !== 0) {
|
|
121
|
+
const faceY = dy > 0 ? minY - radius : maxY + radius;
|
|
122
|
+
const time = (faceY - y0) / dy;
|
|
123
|
+
const xAt = x0 + dx * time;
|
|
124
|
+
if (xAt >= minX && xAt <= maxX && time >= 0 && time <= 1 && (!hasBest || bestTime > time)) {
|
|
125
|
+
hasBest = true;
|
|
126
|
+
bestTime = time;
|
|
127
|
+
bestNX = 0;
|
|
128
|
+
bestNY = dy > 0 ? -1 : 1;
|
|
129
|
+
bestPX = clamp(xAt, minX, maxX);
|
|
130
|
+
bestPY = clamp(faceY, minY, maxY);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Corner candidates: radius circles around each corner, valid in the
|
|
135
|
+
// corner's exterior quadrant. The four descriptors are derived from the
|
|
136
|
+
// corner index arithmetically; both quadratic roots are scalars.
|
|
137
|
+
const a = dx * dx + dy * dy;
|
|
138
|
+
for (let corner = 0; corner < 4; corner += 1) {
|
|
139
|
+
const cornerX = cornerFaceX(corner, minX, maxX);
|
|
140
|
+
const cornerY = cornerFaceY(corner, minY, maxY);
|
|
141
|
+
const fx = x0 - cornerX;
|
|
142
|
+
const fy = y0 - cornerY;
|
|
143
|
+
const b = 2 * (fx * dx + fy * dy);
|
|
144
|
+
const c = fx * fx + fy * fy - radius * radius;
|
|
145
|
+
const discriminant = b * b - 4 * a * c;
|
|
146
|
+
if (discriminant < 0) {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const root = Math.sqrt(discriminant);
|
|
150
|
+
const firstRoot = (-b - root) / (2 * a);
|
|
151
|
+
const secondRoot = (-b + root) / (2 * a);
|
|
152
|
+
for (let pass = 0; pass < 2; pass += 1) {
|
|
153
|
+
const time = pass === 0 ? firstRoot : secondRoot;
|
|
154
|
+
if (time < 0 || time > 1 || hasBest && bestTime < time) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const hitX = x0 + dx * time;
|
|
158
|
+
const hitY = y0 + dy * time;
|
|
159
|
+
if (!beyondFaceX(corner, hitX, minX, maxX) || !beyondFaceY(corner, hitY, minY, maxY)) {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
const outX = hitX - cornerX;
|
|
163
|
+
const outY = hitY - cornerY;
|
|
164
|
+
const outDistance = Math.hypot(outX, outY);
|
|
165
|
+
const nx = outDistance === 0 ? 0 : outX / outDistance;
|
|
166
|
+
const ny = outDistance === 0 ? 1 : outY / outDistance;
|
|
167
|
+
if (!hasBest || time < bestTime) {
|
|
168
|
+
hasBest = true;
|
|
169
|
+
bestTime = time;
|
|
170
|
+
bestNX = nx;
|
|
171
|
+
bestNY = ny;
|
|
172
|
+
bestPX = cornerX;
|
|
173
|
+
bestPY = cornerY;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (!hasBest) {
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
return Object.freeze({
|
|
181
|
+
time: bestTime,
|
|
182
|
+
normal: Object.freeze({
|
|
183
|
+
x: bestNX,
|
|
184
|
+
y: bestNY
|
|
185
|
+
}),
|
|
186
|
+
point: Object.freeze({
|
|
187
|
+
x: bestPX,
|
|
188
|
+
y: bestPY
|
|
189
|
+
})
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** Swept AABB-AABB with the exact asymmetric reference expansion. */
|
|
194
|
+
export function sweepAabbAabb2D(options) {
|
|
195
|
+
const {
|
|
196
|
+
aabb,
|
|
197
|
+
displacement,
|
|
198
|
+
target
|
|
199
|
+
} = options;
|
|
200
|
+
assertValidAabb2D(aabb, 'aabb');
|
|
201
|
+
assertValidVector2D(displacement, 'displacement');
|
|
202
|
+
assertValidAabb2D(target, 'target');
|
|
203
|
+
const startingOverlap = collideAabbAabb2D(aabb, target);
|
|
204
|
+
if (startingOverlap !== undefined) {
|
|
205
|
+
return hitFromManifold(0, startingOverlap);
|
|
206
|
+
}
|
|
207
|
+
if (displacement.x === 0 && displacement.y === 0) {
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Top-left reference: the valid x interval is [target.min - w, target.max]
|
|
212
|
+
// and the valid y interval is [target.min - h, target.max] (asymmetric).
|
|
213
|
+
const expanded = {
|
|
214
|
+
x: target.x - aabb.width,
|
|
215
|
+
y: target.y - aabb.height,
|
|
216
|
+
width: target.width + aabb.width,
|
|
217
|
+
height: target.height + aabb.height
|
|
218
|
+
};
|
|
219
|
+
const segmentHit = intersectSegmentAabb2D({
|
|
220
|
+
start: {
|
|
221
|
+
x: aabb.x,
|
|
222
|
+
y: aabb.y
|
|
223
|
+
},
|
|
224
|
+
end: {
|
|
225
|
+
x: aabb.x + displacement.x,
|
|
226
|
+
y: aabb.y + displacement.y
|
|
227
|
+
}
|
|
228
|
+
}, expanded);
|
|
229
|
+
if (segmentHit === undefined) {
|
|
230
|
+
return undefined;
|
|
231
|
+
}
|
|
232
|
+
const originAtImpact = {
|
|
233
|
+
x: aabb.x + displacement.x * segmentHit.time,
|
|
234
|
+
y: aabb.y + displacement.y * segmentHit.time
|
|
235
|
+
};
|
|
236
|
+
return Object.freeze({
|
|
237
|
+
time: segmentHit.time,
|
|
238
|
+
normal: segmentHit.normal,
|
|
239
|
+
point: Object.freeze({
|
|
240
|
+
x: clamp(originAtImpact.x, target.x, target.x + target.width),
|
|
241
|
+
y: clamp(originAtImpact.y, target.y, target.y + target.height)
|
|
242
|
+
})
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
function hitFromManifold(time, hit) {
|
|
246
|
+
return Object.freeze({
|
|
247
|
+
time,
|
|
248
|
+
normal: hit.normal,
|
|
249
|
+
point: hit.point
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
function clamp(value, min, max) {
|
|
253
|
+
return value < min ? min : value > max ? max : value;
|
|
254
|
+
}
|
|
255
|
+
//# sourceMappingURL=sweeps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["assertValidAabb2D","assertValidCircle2D","assertValidVector2D","collideAabbAabb2D","collideCircleAabb2D","intersectsCircleAabb2D","intersectSegmentAabb2D","cornerFaceX","index","minX","maxX","cornerFaceY","minY","maxY","beyondFaceX","pointX","beyondFaceY","pointY","sweepCircleAabb2D","options","circle","displacement","target","overlap","undefined","hitFromManifold","x","y","radius","width","height","x0","y0","dx","dy","hasBest","bestTime","bestNX","bestNY","bestPX","bestPY","faceX","time","yAt","clamp","faceY","xAt","a","corner","cornerX","cornerY","fx","fy","b","c","discriminant","root","Math","sqrt","firstRoot","secondRoot","pass","hitX","hitY","outX","outY","outDistance","hypot","nx","ny","Object","freeze","normal","point","sweepAabbAabb2D","aabb","startingOverlap","expanded","segmentHit","start","end","originAtImpact","hit","value","min","max"],"sourceRoot":"../../../src","sources":["collision2d/sweeps.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SACEA,iBAAiB,EACjBC,mBAAmB,EACnBC,mBAAmB,QACd,2BAAwB;AAC/B,SAASC,iBAAiB,EAAEC,mBAAmB,QAA6B,gBAAa;AACzF,SAASC,sBAAsB,QAAQ,oBAAiB;AACxD,SAASC,sBAAsB,QAAQ,eAAY;;AAEnD;;AAUA;;AAUA;;AAUA;AACA;AACA;AACA;AACA;AACA,SAASC,WAAWA,CAACC,KAAa,EAAEC,IAAY,EAAEC,IAAY,EAAU;EACtE,OAAOF,KAAK,GAAG,CAAC,GAAGE,IAAI,GAAGD,IAAI;AAChC;AAEA,SAASE,WAAWA,CAACH,KAAa,EAAEI,IAAY,EAAEC,IAAY,EAAU;EACtE,OAAOL,KAAK,GAAG,CAAC,GAAGK,IAAI,GAAGD,IAAI;AAChC;AAEA,SAASE,WAAWA,CAACN,KAAa,EAAEO,MAAc,EAAEN,IAAY,EAAEC,IAAY,EAAW;EACvF,OAAOF,KAAK,GAAG,CAAC,GAAGO,MAAM,IAAIL,IAAI,GAAGK,MAAM,IAAIN,IAAI;AACpD;AAEA,SAASO,WAAWA,CAACR,KAAa,EAAES,MAAc,EAAEL,IAAY,EAAEC,IAAY,EAAW;EACvF,OAAOL,KAAK,GAAG,CAAC,GAAGS,MAAM,IAAIJ,IAAI,GAAGI,MAAM,IAAIL,IAAI;AACpD;;AAEA;AACA,OAAO,SAASM,iBAAiBA,CAACC,OAAiC,EAA0B;EAC3F,MAAM;IAAEC,MAAM;IAAEC,YAAY;IAAEC;EAAO,CAAC,GAAGH,OAAO;EAChDlB,mBAAmB,CAACmB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GAAW,EAAEC,GAAW,EAAU;EAC9D,OAAOF,KAAK,GAAGC,GAAG,GAAGA,GAAG,GAAGD,KAAK,GAAGE,GAAG,GAAGA,GAAG,GAAGF,KAAK;AACtD","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["collision2d.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA,cAAc,wBAAqB","ignoreList":[]}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Multitouch button-pad controller (headless).
|
|
5
|
+
*
|
|
6
|
+
* Maps every active pointer to the button zone it covers and turns touch
|
|
7
|
+
* transitions into press/release diffs for a session input buffer. Pure and
|
|
8
|
+
* React-free: the React surface (`GameButtonPad`) only registers zone rects,
|
|
9
|
+
* feeds touch lists in, and applies the returned diffs to
|
|
10
|
+
* `session.input`.
|
|
11
|
+
*
|
|
12
|
+
* Semantics:
|
|
13
|
+
* - A zone is a rectangle; an optional global hit slop expands it.
|
|
14
|
+
* - Each pointer maps to AT MOST one action (first registered zone wins).
|
|
15
|
+
* - An action is pressed while ANY pointer covers its zone (refcounted);
|
|
16
|
+
* it releases when the last pointer leaves or lifts. Edges fire only on
|
|
17
|
+
* 0-to-1 (press) and 1-to-0 (release) owner transitions — a second owner
|
|
18
|
+
* never re-presses and an unbalanced release never emits.
|
|
19
|
+
* - Sliding between zones reassigns the pointer: release + press diff.
|
|
20
|
+
* - Moves acquire: a pointer that begins in empty space and slides into a
|
|
21
|
+
* zone presses it; leaving a zone releases. Every touch in a move list
|
|
22
|
+
* is hit-tested, mapped or not.
|
|
23
|
+
* - Zone rects are cloned at registration: later caller mutation of the
|
|
24
|
+
* passed object cannot alter hit areas invisibly.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/** A rectangular hit area, in the pad's local coordinate space. */
|
|
28
|
+
|
|
29
|
+
/** One active pointer sample. */
|
|
30
|
+
|
|
31
|
+
/** Press/release transitions derived from one touch event. */
|
|
32
|
+
|
|
33
|
+
const EMPTY_DIFF = {
|
|
34
|
+
pressed: [],
|
|
35
|
+
released: []
|
|
36
|
+
};
|
|
37
|
+
function contains(rect, hitSlop, x, y) {
|
|
38
|
+
return x >= rect.x - hitSlop && x <= rect.x + rect.width + hitSlop && y >= rect.y - hitSlop && y <= rect.y + rect.height + hitSlop;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Create a controller bound to no particular session (diffs are applied by the caller). */
|
|
42
|
+
export function createButtonPadController(options) {
|
|
43
|
+
const hitSlop = options?.hitSlop ?? 0;
|
|
44
|
+
const zones = new Map();
|
|
45
|
+
const pointerAction = new Map();
|
|
46
|
+
const holdCounts = new Map();
|
|
47
|
+
// GS-INPUT-04: pointers that were active across an invalidation (pause,
|
|
48
|
+
// session replacement) must produce a fresh down before their moves can
|
|
49
|
+
// acquire again. A fresh down rehabilitates; lift clears the mark.
|
|
50
|
+
const stalePointerIds = new Set();
|
|
51
|
+
const apply = (action, direction) => {
|
|
52
|
+
// GS-INPUT-02: edges fire only on ownership transitions. A second owner
|
|
53
|
+
// (0 stays > 0) never re-presses; an unbalanced release from zero
|
|
54
|
+
// count never emits.
|
|
55
|
+
const previous = holdCounts.get(action) ?? 0;
|
|
56
|
+
const next = previous + direction;
|
|
57
|
+
if (next <= 0) {
|
|
58
|
+
holdCounts.delete(action);
|
|
59
|
+
return previous > 0 && direction === -1 ? 'released' : undefined;
|
|
60
|
+
}
|
|
61
|
+
holdCounts.set(action, next);
|
|
62
|
+
return previous === 0 && direction === 1 ? 'pressed' : undefined;
|
|
63
|
+
};
|
|
64
|
+
const hitTest = (x, y) => {
|
|
65
|
+
for (const [action, rect] of zones) {
|
|
66
|
+
if (contains(rect, hitSlop, x, y)) {
|
|
67
|
+
return action;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return undefined;
|
|
71
|
+
};
|
|
72
|
+
const retarget = (touchId, action) => {
|
|
73
|
+
const previous = pointerAction.get(touchId);
|
|
74
|
+
if (previous === action) {
|
|
75
|
+
return EMPTY_DIFF;
|
|
76
|
+
}
|
|
77
|
+
const pressed = [];
|
|
78
|
+
const released = [];
|
|
79
|
+
if (previous !== undefined) {
|
|
80
|
+
pointerAction.delete(touchId);
|
|
81
|
+
const result = apply(previous, -1);
|
|
82
|
+
if (result === 'released') {
|
|
83
|
+
released.push(previous);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (action !== undefined) {
|
|
87
|
+
pointerAction.set(touchId, action);
|
|
88
|
+
const result = apply(action, 1);
|
|
89
|
+
if (result === 'pressed') {
|
|
90
|
+
pressed.push(action);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
pressed,
|
|
95
|
+
released
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
const dropPointers = changed => {
|
|
99
|
+
const released = [];
|
|
100
|
+
for (const touch of changed) {
|
|
101
|
+
stalePointerIds.delete(touch.id);
|
|
102
|
+
const previous = pointerAction.get(touch.id);
|
|
103
|
+
if (previous === undefined) {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
pointerAction.delete(touch.id);
|
|
107
|
+
if (apply(previous, -1) === 'released') {
|
|
108
|
+
released.push(previous);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
pressed: [],
|
|
113
|
+
released
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
return {
|
|
117
|
+
setZone(action, rect) {
|
|
118
|
+
// GS-INPUT-02: clone the rect so later caller mutation of the passed
|
|
119
|
+
// object cannot alter hit areas invisibly.
|
|
120
|
+
zones.set(action, {
|
|
121
|
+
x: rect.x,
|
|
122
|
+
y: rect.y,
|
|
123
|
+
width: rect.width,
|
|
124
|
+
height: rect.height
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
removeZone(action) {
|
|
128
|
+
zones.delete(action);
|
|
129
|
+
// GS-INPUT-02: drop every pointer mapped to the removed zone, then
|
|
130
|
+
// release and delete the ENTIRE action count — a single decrement
|
|
131
|
+
// would strand a phantom hold. Pointers stay physically tracked only
|
|
132
|
+
// through future touch events, which re-acquire via hit test.
|
|
133
|
+
for (const [pointerId, mapped] of [...pointerAction]) {
|
|
134
|
+
if (mapped === action) {
|
|
135
|
+
pointerAction.delete(pointerId);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if ((holdCounts.get(action) ?? 0) > 0) {
|
|
139
|
+
holdCounts.delete(action);
|
|
140
|
+
return [action];
|
|
141
|
+
}
|
|
142
|
+
return [];
|
|
143
|
+
},
|
|
144
|
+
touchesDown(touches) {
|
|
145
|
+
const merged = {
|
|
146
|
+
pressed: [],
|
|
147
|
+
released: []
|
|
148
|
+
};
|
|
149
|
+
for (const touch of touches) {
|
|
150
|
+
stalePointerIds.delete(touch.id);
|
|
151
|
+
const diff = retarget(touch.id, hitTest(touch.x, touch.y));
|
|
152
|
+
merged.pressed.push(...diff.pressed);
|
|
153
|
+
merged.released.push(...diff.released);
|
|
154
|
+
}
|
|
155
|
+
return merged;
|
|
156
|
+
},
|
|
157
|
+
touchesMove(touches) {
|
|
158
|
+
// GS-INPUT-02: every touch in the move list is hit-tested, mapped or
|
|
159
|
+
// not — a pointer that left its zone releases, and one that entered
|
|
160
|
+
// a zone (including from empty space) presses it.
|
|
161
|
+
// GS-INPUT-04: pointers marked stale by an invalidation wait for a
|
|
162
|
+
// fresh down first.
|
|
163
|
+
const merged = {
|
|
164
|
+
pressed: [],
|
|
165
|
+
released: []
|
|
166
|
+
};
|
|
167
|
+
for (const touch of touches) {
|
|
168
|
+
if (stalePointerIds.has(touch.id)) {
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
const diff = retarget(touch.id, hitTest(touch.x, touch.y));
|
|
172
|
+
merged.pressed.push(...diff.pressed);
|
|
173
|
+
merged.released.push(...diff.released);
|
|
174
|
+
}
|
|
175
|
+
return merged;
|
|
176
|
+
},
|
|
177
|
+
touchesUp(changed) {
|
|
178
|
+
return dropPointers(changed);
|
|
179
|
+
},
|
|
180
|
+
touchesCancel(changed) {
|
|
181
|
+
return dropPointers(changed);
|
|
182
|
+
},
|
|
183
|
+
releaseAll() {
|
|
184
|
+
const released = new Set();
|
|
185
|
+
for (const action of pointerAction.values()) {
|
|
186
|
+
released.add(action);
|
|
187
|
+
}
|
|
188
|
+
pointerAction.clear();
|
|
189
|
+
for (const action of holdCounts.keys()) {
|
|
190
|
+
released.add(action);
|
|
191
|
+
}
|
|
192
|
+
holdCounts.clear();
|
|
193
|
+
stalePointerIds.clear();
|
|
194
|
+
return [...released];
|
|
195
|
+
},
|
|
196
|
+
/**
|
|
197
|
+
* GS-INPUT-04: invalidate ownership without touching zones — pause,
|
|
198
|
+
* session replacement, or layout teardown snapshot the active pointers
|
|
199
|
+
* as stale and drop all holds. Stale pointers must produce a fresh down
|
|
200
|
+
* before their moves can acquire again; a fresh down rehabilitates.
|
|
201
|
+
*/
|
|
202
|
+
invalidateOwnership() {
|
|
203
|
+
for (const pointerId of pointerAction.keys()) {
|
|
204
|
+
stalePointerIds.add(pointerId);
|
|
205
|
+
}
|
|
206
|
+
pointerAction.clear();
|
|
207
|
+
holdCounts.clear();
|
|
208
|
+
},
|
|
209
|
+
held() {
|
|
210
|
+
return [...holdCounts.keys()];
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=buttonPad.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["EMPTY_DIFF","pressed","released","contains","rect","hitSlop","x","y","width","height","createButtonPadController","options","zones","Map","pointerAction","holdCounts","stalePointerIds","Set","apply","action","direction","previous","get","next","delete","undefined","set","hitTest","retarget","touchId","result","push","dropPointers","changed","touch","id","setZone","removeZone","pointerId","mapped","touchesDown","touches","merged","diff","touchesMove","has","touchesUp","touchesCancel","releaseAll","values","add","clear","keys","invalidateOwnership","held"],"sourceRoot":"../../../../src","sources":["core/input/buttonPad.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAQA;;AAQA;;AAQA,MAAMA,UAAyB,GAAG;EAAEC,OAAO,EAAE,EAAE;EAAEC,QAAQ,EAAE;AAAG,CAAC;AAE/D,SAASC,QAAQA,CACfC,IAAmB,EACnBC,OAAe,EACfC,CAAS,EACTC,CAAS,EACA;EACT,OACED,CAAC,IAAIF,IAAI,CAACE,CAAC,GAAGD,OAAO,IACrBC,CAAC,IAAIF,IAAI,CAACE,CAAC,GAAGF,IAAI,CAACI,KAAK,GAAGH,OAAO,IAClCE,CAAC,IAAIH,IAAI,CAACG,CAAC,GAAGF,OAAO,IACrBE,CAAC,IAAIH,IAAI,CAACG,CAAC,GAAGH,IAAI,CAACK,MAAM,GAAGJ,OAAO;AAEvC;;AAEA;AACA,OAAO,SAASK,yBAAyBA,CAACC,OAAuC,EAU/E;EACA,MAAMN,OAAO,GAAGM,OAAO,EAAEN,OAAO,IAAI,CAAC;EACrC,MAAMO,KAAK,GAAG,IAAIC,GAAG,CAAwB,CAAC;EAC9C,MAAMC,aAAa,GAAG,IAAID,GAAG,CAAiB,CAAC;EAC/C,MAAME,UAAU,GAAG,IAAIF,GAAG,CAAiB,CAAC;EAC5C;EACA;EACA;EACA,MAAMG,eAAe,GAAG,IAAIC,GAAG,CAAS,CAAC;EAEzC,MAAMC,KAAK,GAAGA,CAACC,MAAc,EAAEC,SAAiB,KAAyC;IACvF;IACA;IACA;IACA,MAAMC,QAAQ,GAAGN,UAAU,CAACO,GAAG,CAACH,MAAM,CAAC,IAAI,CAAC;IAC5C,MAAMI,IAAI,GAAGF,QAAQ,GAAGD,SAAS;IACjC,IAAIG,IAAI,IAAI,CAAC,EAAE;MACbR,UAAU,CAACS,MAAM,CAACL,MAAM,CAA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