@zylem/game-lib 0.4.1 → 0.5.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/README.md +23 -41
- package/dist/actions.d.ts +25 -0
- package/dist/actions.js +287 -8
- package/dist/actions.js.map +1 -0
- package/dist/behaviors.d.ts +108 -0
- package/dist/behaviors.js +396 -6
- package/dist/behaviors.js.map +1 -0
- package/dist/{lib/camera/zylem-camera.d.ts → camera-Dk-fOVZE.d.ts} +55 -8
- package/dist/camera.d.ts +5 -0
- package/dist/camera.js +504 -4
- package/dist/camera.js.map +1 -0
- package/dist/core-C2mjetAd.d.ts +431 -0
- package/dist/core.d.ts +9 -0
- package/dist/core.js +4780 -9
- package/dist/core.js.map +1 -0
- package/dist/entities.d.ts +269 -0
- package/dist/entities.js +2161 -17
- package/dist/entities.js.map +1 -0
- package/dist/entity-bQElAdpo.d.ts +347 -0
- package/dist/entity-spawner-DNnLYnZq.d.ts +11 -0
- package/dist/main.d.ts +135 -0
- package/dist/main.js +6599 -56
- package/dist/main.js.map +1 -0
- package/dist/moveable-B_vyA6cw.d.ts +67 -0
- package/dist/stage-CrmY7V0i.d.ts +287 -0
- package/dist/stage.d.ts +26 -0
- package/dist/stage.js +2229 -15
- package/dist/stage.js.map +1 -0
- package/dist/transformable-CUhvyuYO.d.ts +67 -0
- package/package.json +12 -42
- package/LICENSE +0 -21
- package/dist/.vite/manifest.json +0 -676
- package/dist/api/actions.d.ts +0 -5
- package/dist/api/actions.d.ts.map +0 -1
- package/dist/api/behaviors.d.ts +0 -4
- package/dist/api/behaviors.d.ts.map +0 -1
- package/dist/api/camera.d.ts +0 -4
- package/dist/api/camera.d.ts.map +0 -1
- package/dist/api/core.d.ts +0 -6
- package/dist/api/core.d.ts.map +0 -1
- package/dist/api/entities.d.ts +0 -9
- package/dist/api/entities.d.ts.map +0 -1
- package/dist/api/main.d.ts +0 -32
- package/dist/api/main.d.ts.map +0 -1
- package/dist/api/stage.d.ts +0 -6
- package/dist/api/stage.d.ts.map +0 -1
- package/dist/assets/zylem-logo.png +0 -0
- package/dist/lib/actions/behaviors/actions.d.ts +0 -11
- package/dist/lib/actions/behaviors/actions.d.ts.map +0 -1
- package/dist/lib/actions/behaviors/actions.js +0 -35
- package/dist/lib/actions/behaviors/behavior.d.ts +0 -6
- package/dist/lib/actions/behaviors/behavior.d.ts.map +0 -1
- package/dist/lib/actions/behaviors/boundaries/boundary.d.ts +0 -37
- package/dist/lib/actions/behaviors/boundaries/boundary.d.ts.map +0 -1
- package/dist/lib/actions/behaviors/boundaries/boundary.js +0 -40
- package/dist/lib/actions/behaviors/character-controller.d.ts +0 -6
- package/dist/lib/actions/behaviors/character-controller.d.ts.map +0 -1
- package/dist/lib/actions/behaviors/debug/debug-collision.d.ts +0 -6
- package/dist/lib/actions/behaviors/debug/debug-collision.d.ts.map +0 -1
- package/dist/lib/actions/behaviors/debug/debug-update.d.ts +0 -5
- package/dist/lib/actions/behaviors/debug/debug-update.d.ts.map +0 -1
- package/dist/lib/actions/behaviors/debug/debug.d.ts +0 -10
- package/dist/lib/actions/behaviors/debug/debug.d.ts.map +0 -1
- package/dist/lib/actions/behaviors/movement/movement-sequence-2d.d.ts +0 -24
- package/dist/lib/actions/behaviors/movement/movement-sequence-2d.d.ts.map +0 -1
- package/dist/lib/actions/behaviors/ricochet/ricochet-2d-collision.d.ts +0 -11
- package/dist/lib/actions/behaviors/ricochet/ricochet-2d-collision.d.ts.map +0 -1
- package/dist/lib/actions/behaviors/ricochet/ricochet-2d-collision.js +0 -100
- package/dist/lib/actions/behaviors/ricochet/ricochet-2d-in-bounds.d.ts +0 -12
- package/dist/lib/actions/behaviors/ricochet/ricochet-2d-in-bounds.d.ts.map +0 -1
- package/dist/lib/actions/behaviors/ricochet/ricochet-2d-in-bounds.js +0 -37
- package/dist/lib/actions/behaviors/ricochet/ricochet.d.ts +0 -44
- package/dist/lib/actions/behaviors/ricochet/ricochet.d.ts.map +0 -1
- package/dist/lib/actions/behaviors/ricochet/ricochet.js +0 -6
- package/dist/lib/actions/behaviors/zylem-behavior.d.ts +0 -2
- package/dist/lib/actions/behaviors/zylem-behavior.d.ts.map +0 -1
- package/dist/lib/actions/capabilities/moveable.d.ts +0 -125
- package/dist/lib/actions/capabilities/moveable.d.ts.map +0 -1
- package/dist/lib/actions/capabilities/moveable.js +0 -108
- package/dist/lib/actions/capabilities/rotatable.d.ts +0 -111
- package/dist/lib/actions/capabilities/rotatable.d.ts.map +0 -1
- package/dist/lib/actions/capabilities/rotatable.js +0 -82
- package/dist/lib/actions/capabilities/transformable.d.ts +0 -7
- package/dist/lib/actions/capabilities/transformable.d.ts.map +0 -1
- package/dist/lib/actions/capabilities/transformable.js +0 -9
- package/dist/lib/actions/global-change.d.ts +0 -23
- package/dist/lib/actions/global-change.d.ts.map +0 -1
- package/dist/lib/actions/global-change.js +0 -40
- package/dist/lib/camera/camera.d.ts +0 -16
- package/dist/lib/camera/camera.d.ts.map +0 -1
- package/dist/lib/camera/camera.js +0 -19
- package/dist/lib/camera/fixed-2d.d.ts +0 -32
- package/dist/lib/camera/fixed-2d.d.ts.map +0 -1
- package/dist/lib/camera/fixed-2d.js +0 -30
- package/dist/lib/camera/perspective.d.ts +0 -9
- package/dist/lib/camera/perspective.d.ts.map +0 -1
- package/dist/lib/camera/perspective.js +0 -10
- package/dist/lib/camera/third-person.d.ts +0 -32
- package/dist/lib/camera/third-person.d.ts.map +0 -1
- package/dist/lib/camera/third-person.js +0 -42
- package/dist/lib/camera/zylem-camera.d.ts.map +0 -1
- package/dist/lib/camera/zylem-camera.js +0 -208
- package/dist/lib/collision/collision-builder.d.ts +0 -17
- package/dist/lib/collision/collision-builder.d.ts.map +0 -1
- package/dist/lib/collision/collision-builder.js +0 -46
- package/dist/lib/collision/collision-delegate.d.ts +0 -6
- package/dist/lib/collision/collision-delegate.d.ts.map +0 -1
- package/dist/lib/collision/collision-delegate.js +0 -6
- package/dist/lib/collision/collision-group.d.ts +0 -11
- package/dist/lib/collision/collision-group.d.ts.map +0 -1
- package/dist/lib/collision/collision-mask.d.ts +0 -18
- package/dist/lib/collision/collision-mask.d.ts.map +0 -1
- package/dist/lib/collision/collision.d.ts +0 -19
- package/dist/lib/collision/collision.d.ts.map +0 -1
- package/dist/lib/collision/utils.d.ts +0 -15
- package/dist/lib/collision/utils.d.ts.map +0 -1
- package/dist/lib/collision/utils.js +0 -24
- package/dist/lib/collision/world.d.ts +0 -23
- package/dist/lib/collision/world.d.ts.map +0 -1
- package/dist/lib/collision/world.js +0 -77
- package/dist/lib/core/asset-manager.d.ts +0 -2
- package/dist/lib/core/asset-manager.d.ts.map +0 -1
- package/dist/lib/core/base-node-life-cycle.d.ts +0 -68
- package/dist/lib/core/base-node-life-cycle.d.ts.map +0 -1
- package/dist/lib/core/base-node.d.ts +0 -37
- package/dist/lib/core/base-node.d.ts.map +0 -1
- package/dist/lib/core/base-node.js +0 -62
- package/dist/lib/core/entity-asset-loader.d.ts +0 -16
- package/dist/lib/core/entity-asset-loader.d.ts.map +0 -1
- package/dist/lib/core/entity-asset-loader.js +0 -54
- package/dist/lib/core/errors.d.ts +0 -5
- package/dist/lib/core/errors.d.ts.map +0 -1
- package/dist/lib/core/flags.d.ts +0 -3
- package/dist/lib/core/flags.d.ts.map +0 -1
- package/dist/lib/core/index.d.ts +0 -5
- package/dist/lib/core/index.d.ts.map +0 -1
- package/dist/lib/core/lazy-loader.d.ts +0 -80
- package/dist/lib/core/lazy-loader.d.ts.map +0 -1
- package/dist/lib/core/lifecycle-base.d.ts +0 -17
- package/dist/lib/core/lifecycle-base.d.ts.map +0 -1
- package/dist/lib/core/lifecycle-base.js +0 -20
- package/dist/lib/core/preset-shader.d.ts +0 -8
- package/dist/lib/core/preset-shader.d.ts.map +0 -1
- package/dist/lib/core/preset-shader.js +0 -26
- package/dist/lib/core/three-addons/Timer.d.ts +0 -92
- package/dist/lib/core/three-addons/Timer.d.ts.map +0 -1
- package/dist/lib/core/three-addons/Timer.js +0 -103
- package/dist/lib/core/utility/nodes.d.ts +0 -13
- package/dist/lib/core/utility/nodes.d.ts.map +0 -1
- package/dist/lib/core/utility/nodes.js +0 -31
- package/dist/lib/core/utility/strings.d.ts +0 -3
- package/dist/lib/core/utility/strings.d.ts.map +0 -1
- package/dist/lib/core/utility/strings.js +0 -14
- package/dist/lib/core/utility/vector.d.ts +0 -8
- package/dist/lib/core/utility/vector.d.ts.map +0 -1
- package/dist/lib/core/utility/vector.js +0 -8
- package/dist/lib/core/vector.d.ts +0 -4
- package/dist/lib/core/vector.d.ts.map +0 -1
- package/dist/lib/core/vessel.d.ts +0 -13
- package/dist/lib/core/vessel.d.ts.map +0 -1
- package/dist/lib/core/vessel.js +0 -26
- package/dist/lib/debug/console/console-state.d.ts +0 -20
- package/dist/lib/debug/console/console-state.d.ts.map +0 -1
- package/dist/lib/debug/console/console-state.js +0 -11
- package/dist/lib/debug/console/console-store.d.ts +0 -6
- package/dist/lib/debug/console/console-store.d.ts.map +0 -1
- package/dist/lib/debug/debug-state.d.ts +0 -38
- package/dist/lib/debug/debug-state.d.ts.map +0 -1
- package/dist/lib/debug/debug-state.js +0 -40
- package/dist/lib/debug/debug-store.d.ts +0 -15
- package/dist/lib/debug/debug-store.d.ts.map +0 -1
- package/dist/lib/debug/state-based-debug-loader.d.ts +0 -8
- package/dist/lib/debug/state-based-debug-loader.d.ts.map +0 -1
- package/dist/lib/device/aspect-ratio.d.ts +0 -38
- package/dist/lib/device/aspect-ratio.d.ts.map +0 -1
- package/dist/lib/device/aspect-ratio.js +0 -44
- package/dist/lib/device/desktop.d.ts +0 -2
- package/dist/lib/device/desktop.d.ts.map +0 -1
- package/dist/lib/device/mobile.d.ts +0 -2
- package/dist/lib/device/mobile.d.ts.map +0 -1
- package/dist/lib/device/tablet.d.ts +0 -2
- package/dist/lib/device/tablet.d.ts.map +0 -1
- package/dist/lib/entities/actor.d.ts +0 -44
- package/dist/lib/entities/actor.d.ts.map +0 -1
- package/dist/lib/entities/actor.js +0 -122
- package/dist/lib/entities/box.d.ts +0 -27
- package/dist/lib/entities/box.d.ts.map +0 -1
- package/dist/lib/entities/box.js +0 -68
- package/dist/lib/entities/builder.d.ts +0 -28
- package/dist/lib/entities/builder.d.ts.map +0 -1
- package/dist/lib/entities/builder.js +0 -79
- package/dist/lib/entities/create.d.ts +0 -15
- package/dist/lib/entities/create.d.ts.map +0 -1
- package/dist/lib/entities/create.js +0 -31
- package/dist/lib/entities/delegates/animation.d.ts +0 -33
- package/dist/lib/entities/delegates/animation.d.ts.map +0 -1
- package/dist/lib/entities/delegates/animation.js +0 -58
- package/dist/lib/entities/delegates/debug.d.ts +0 -29
- package/dist/lib/entities/delegates/debug.d.ts.map +0 -1
- package/dist/lib/entities/delegates/debug.js +0 -71
- package/dist/lib/entities/delegates/loader.d.ts +0 -12
- package/dist/lib/entities/delegates/loader.d.ts.map +0 -1
- package/dist/lib/entities/delegates/loader.js +0 -19
- package/dist/lib/entities/destroy.d.ts +0 -4
- package/dist/lib/entities/destroy.d.ts.map +0 -1
- package/dist/lib/entities/destroy.js +0 -15
- package/dist/lib/entities/entity.d.ts +0 -96
- package/dist/lib/entities/entity.d.ts.map +0 -1
- package/dist/lib/entities/entity.js +0 -120
- package/dist/lib/entities/index.d.ts +0 -12
- package/dist/lib/entities/index.d.ts.map +0 -1
- package/dist/lib/entities/plane.d.ts +0 -36
- package/dist/lib/entities/plane.d.ts.map +0 -1
- package/dist/lib/entities/plane.js +0 -81
- package/dist/lib/entities/rect.d.ts +0 -63
- package/dist/lib/entities/rect.d.ts.map +0 -1
- package/dist/lib/entities/rect.js +0 -160
- package/dist/lib/entities/sphere.d.ts +0 -29
- package/dist/lib/entities/sphere.d.ts.map +0 -1
- package/dist/lib/entities/sphere.js +0 -68
- package/dist/lib/entities/sprite.d.ts +0 -53
- package/dist/lib/entities/sprite.d.ts.map +0 -1
- package/dist/lib/entities/sprite.js +0 -118
- package/dist/lib/entities/text.d.ts +0 -49
- package/dist/lib/entities/text.d.ts.map +0 -1
- package/dist/lib/entities/text.js +0 -140
- package/dist/lib/entities/zone.d.ts +0 -54
- package/dist/lib/entities/zone.d.ts.map +0 -1
- package/dist/lib/entities/zone.js +0 -103
- package/dist/lib/game/game-blueprint.d.ts +0 -38
- package/dist/lib/game/game-blueprint.d.ts.map +0 -1
- package/dist/lib/game/game-canvas.d.ts +0 -35
- package/dist/lib/game/game-canvas.d.ts.map +0 -1
- package/dist/lib/game/game-canvas.js +0 -57
- package/dist/lib/game/game-config.d.ts +0 -59
- package/dist/lib/game/game-config.d.ts.map +0 -1
- package/dist/lib/game/game-config.js +0 -78
- package/dist/lib/game/game-default.d.ts +0 -14
- package/dist/lib/game/game-default.d.ts.map +0 -1
- package/dist/lib/game/game-default.js +0 -23
- package/dist/lib/game/game-interfaces.d.ts +0 -29
- package/dist/lib/game/game-interfaces.d.ts.map +0 -1
- package/dist/lib/game/game-retro-resolutions.d.ts +0 -25
- package/dist/lib/game/game-retro-resolutions.d.ts.map +0 -1
- package/dist/lib/game/game-retro-resolutions.js +0 -80
- package/dist/lib/game/game-state.d.ts +0 -11
- package/dist/lib/game/game-state.d.ts.map +0 -1
- package/dist/lib/game/game-state.js +0 -17
- package/dist/lib/game/game.d.ts +0 -37
- package/dist/lib/game/game.d.ts.map +0 -1
- package/dist/lib/game/game.js +0 -109
- package/dist/lib/game/zylem-game.d.ts +0 -58
- package/dist/lib/game/zylem-game.d.ts.map +0 -1
- package/dist/lib/game/zylem-game.js +0 -140
- package/dist/lib/graphics/geometries/XZPlaneGeometry.d.ts +0 -8
- package/dist/lib/graphics/geometries/XZPlaneGeometry.d.ts.map +0 -1
- package/dist/lib/graphics/geometries/XZPlaneGeometry.js +0 -34
- package/dist/lib/graphics/material.d.ts +0 -29
- package/dist/lib/graphics/material.d.ts.map +0 -1
- package/dist/lib/graphics/material.js +0 -64
- package/dist/lib/graphics/mesh.d.ts +0 -19
- package/dist/lib/graphics/mesh.d.ts.map +0 -1
- package/dist/lib/graphics/mesh.js +0 -14
- package/dist/lib/graphics/render-pass.d.ts +0 -17
- package/dist/lib/graphics/render-pass.d.ts.map +0 -1
- package/dist/lib/graphics/render-pass.js +0 -56
- package/dist/lib/graphics/shaders/fragment/debug.glsl.js +0 -23
- package/dist/lib/graphics/shaders/fragment/fire.glsl.js +0 -52
- package/dist/lib/graphics/shaders/fragment/standard.glsl.js +0 -11
- package/dist/lib/graphics/shaders/fragment/stars.glsl.js +0 -44
- package/dist/lib/graphics/shaders/vertex/debug.glsl.js +0 -15
- package/dist/lib/graphics/shaders/vertex/object-shader.glsl.js +0 -11
- package/dist/lib/graphics/shaders/vertex/standard.glsl.js +0 -9
- package/dist/lib/graphics/zylem-scene.d.ts +0 -50
- package/dist/lib/graphics/zylem-scene.d.ts.map +0 -1
- package/dist/lib/graphics/zylem-scene.js +0 -75
- package/dist/lib/input/gamepad-provider.d.ts +0 -14
- package/dist/lib/input/gamepad-provider.d.ts.map +0 -1
- package/dist/lib/input/gamepad-provider.js +0 -58
- package/dist/lib/input/input-manager.d.ts +0 -15
- package/dist/lib/input/input-manager.d.ts.map +0 -1
- package/dist/lib/input/input-manager.js +0 -70
- package/dist/lib/input/input-provider.d.ts +0 -7
- package/dist/lib/input/input-provider.d.ts.map +0 -1
- package/dist/lib/input/input.d.ts +0 -48
- package/dist/lib/input/input.d.ts.map +0 -1
- package/dist/lib/input/keyboard-provider.d.ts +0 -21
- package/dist/lib/input/keyboard-provider.d.ts.map +0 -1
- package/dist/lib/input/keyboard-provider.js +0 -120
- package/dist/lib/interfaces/entity.d.ts +0 -26
- package/dist/lib/interfaces/entity.d.ts.map +0 -1
- package/dist/lib/sounds/index.d.ts +0 -3
- package/dist/lib/sounds/index.d.ts.map +0 -1
- package/dist/lib/sounds/ping-pong-sound.d.ts +0 -5
- package/dist/lib/sounds/ping-pong-sound.d.ts.map +0 -1
- package/dist/lib/sounds/ricochet-sound.d.ts +0 -5
- package/dist/lib/sounds/ricochet-sound.d.ts.map +0 -1
- package/dist/lib/stage/debug-entity-cursor.d.ts +0 -24
- package/dist/lib/stage/debug-entity-cursor.d.ts.map +0 -1
- package/dist/lib/stage/debug-entity-cursor.js +0 -53
- package/dist/lib/stage/entity-spawner.d.ts +0 -9
- package/dist/lib/stage/entity-spawner.d.ts.map +0 -1
- package/dist/lib/stage/entity-spawner.js +0 -27
- package/dist/lib/stage/stage-blueprint.d.ts +0 -45
- package/dist/lib/stage/stage-blueprint.d.ts.map +0 -1
- package/dist/lib/stage/stage-blueprint.js +0 -56
- package/dist/lib/stage/stage-camera-debug-delegate.d.ts +0 -14
- package/dist/lib/stage/stage-camera-debug-delegate.d.ts.map +0 -1
- package/dist/lib/stage/stage-debug-delegate.d.ts +0 -26
- package/dist/lib/stage/stage-debug-delegate.d.ts.map +0 -1
- package/dist/lib/stage/stage-debug-delegate.js +0 -100
- package/dist/lib/stage/stage-default.d.ts +0 -3
- package/dist/lib/stage/stage-default.d.ts.map +0 -1
- package/dist/lib/stage/stage-default.js +0 -32
- package/dist/lib/stage/stage-state.d.ts +0 -14
- package/dist/lib/stage/stage-state.d.ts.map +0 -1
- package/dist/lib/stage/stage-state.js +0 -36
- package/dist/lib/stage/stage.d.ts +0 -33
- package/dist/lib/stage/stage.d.ts.map +0 -1
- package/dist/lib/stage/stage.js +0 -60
- package/dist/lib/stage/zylem-stage.d.ts +0 -128
- package/dist/lib/stage/zylem-stage.d.ts.map +0 -1
- package/dist/lib/stage/zylem-stage.js +0 -268
- package/dist/lib/systems/test-system.d.ts +0 -2
- package/dist/lib/systems/test-system.d.ts.map +0 -1
- package/dist/lib/systems/transformable.system.d.ts +0 -25
- package/dist/lib/systems/transformable.system.d.ts.map +0 -1
- package/dist/lib/systems/transformable.system.js +0 -43
- package/dist/lib/types/entity-types.d.ts +0 -24
- package/dist/lib/types/entity-types.d.ts.map +0 -1
- package/dist/lib/types/index.d.ts +0 -3
- package/dist/lib/types/index.d.ts.map +0 -1
- package/dist/lib/types/stage-types.d.ts +0 -26
- package/dist/lib/types/stage-types.d.ts.map +0 -1
- package/dist/lib/ui/Debug.d.ts +0 -6
- package/dist/lib/ui/Debug.d.ts.map +0 -1
- package/dist/lib/ui/console/Console.d.ts +0 -7
- package/dist/lib/ui/console/Console.d.ts.map +0 -1
- package/dist/lib/ui/debug-panel/AccordionMenu.d.ts +0 -7
- package/dist/lib/ui/debug-panel/AccordionMenu.d.ts.map +0 -1
- package/dist/lib/ui/debug-panel/Menu.d.ts +0 -6
- package/dist/lib/ui/debug-panel/Menu.d.ts.map +0 -1
- package/dist/lib/ui/debug-panel/sections/EntitiesSection.d.ts +0 -4
- package/dist/lib/ui/debug-panel/sections/EntitiesSection.d.ts.map +0 -1
- package/dist/lib/ui/debug-panel/sections/GameSection.d.ts +0 -3
- package/dist/lib/ui/debug-panel/sections/GameSection.d.ts.map +0 -1
- package/dist/lib/ui/debug-panel/sections/StagesSection.d.ts +0 -3
- package/dist/lib/ui/debug-panel/sections/StagesSection.d.ts.map +0 -1
- package/dist/lib/ui/debug-panel/sections/all.d.ts +0 -4
- package/dist/lib/ui/debug-panel/sections/all.d.ts.map +0 -1
- package/dist/lib/ui/toolbar/Toolbar.d.ts +0 -6
- package/dist/lib/ui/toolbar/Toolbar.d.ts.map +0 -1
- package/dist/tests/integration/debug.sim.spec.d.ts +0 -2
- package/dist/tests/integration/debug.sim.spec.d.ts.map +0 -1
- package/dist/tests/unit/collision/collision.spec.d.ts +0 -2
- package/dist/tests/unit/collision/collision.spec.d.ts.map +0 -1
- package/dist/tests/unit/core/game.spec.d.ts +0 -2
- package/dist/tests/unit/core/game.spec.d.ts.map +0 -1
- package/dist/tests/unit/core/stage.spec.d.ts +0 -2
- package/dist/tests/unit/core/stage.spec.d.ts.map +0 -1
- package/dist/tests/unit/core/vessel.spec.d.ts +0 -2
- package/dist/tests/unit/core/vessel.spec.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Zylem
|
|
1
|
+
# Zylem Game Library
|
|
2
2
|
|
|
3
3
|
A powerful and easy-to-use framework for creating simple 3D digital interactive applications using TypeScript.
|
|
4
4
|
|
|
@@ -19,45 +19,26 @@ The goal is to give you tools to build simple 3D games. It's basically comprised
|
|
|
19
19
|
- Game state management with Valtio [Valtio](https://valtio.dev/)
|
|
20
20
|
- Simplified input handling (gamepad, keyboard, mouse)
|
|
21
21
|
|
|
22
|
-
>Note: This project is still in alpha. There are unfinished features and some APIs that may change.
|
|
22
|
+
> Note: This project is still in alpha. There are unfinished features and some APIs that may change.
|
|
23
23
|
|
|
24
24
|
## Installation
|
|
25
25
|
|
|
26
26
|
```bash
|
|
27
|
-
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
```bash
|
|
31
|
-
npm run dev
|
|
27
|
+
npm install @zylem/game-lib
|
|
32
28
|
```
|
|
33
29
|
|
|
34
30
|
## Getting started with a basic game
|
|
35
31
|
|
|
36
32
|
[Basic example](https://github.com/zylem-game-lib/zylem-basic)
|
|
37
33
|
|
|
38
|
-
```html
|
|
39
|
-
<!DOCTYPE html>
|
|
40
|
-
<html lang="en">
|
|
41
|
-
<head>
|
|
42
|
-
<meta charset="UTF-8" />
|
|
43
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
44
|
-
<title>Zylem - Basic Usage</title>
|
|
45
|
-
<link rel="stylesheet" href="./index.css" />
|
|
46
|
-
</head>
|
|
47
|
-
<body>
|
|
48
|
-
<script src="./src/index.ts" type="module"></script>
|
|
49
|
-
</body>
|
|
50
|
-
</html>
|
|
51
|
-
```
|
|
52
|
-
|
|
53
34
|
```typescript
|
|
54
35
|
/**
|
|
55
36
|
* @author: Tim Cool
|
|
56
|
-
*
|
|
37
|
+
*
|
|
57
38
|
* @description: basic ball movement
|
|
58
39
|
* the ball can be controlled with the arrow keys or gamepad
|
|
59
40
|
* the ball cannot go outside the boundaries
|
|
60
|
-
*/
|
|
41
|
+
*/
|
|
61
42
|
import { boundary2d, createGame, makeMoveable, sphere } from '@zylem/game-lib';
|
|
62
43
|
|
|
63
44
|
// Creates a moveable sphere
|
|
@@ -65,29 +46,30 @@ const ball = makeMoveable(await sphere());
|
|
|
65
46
|
|
|
66
47
|
// when the ball is updated, move it based on the inputs
|
|
67
48
|
ball.onUpdate(({ me, inputs, delta }) => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
Horizontal.value * speed,
|
|
75
|
-
-Vertical.value * speed
|
|
76
|
-
);
|
|
49
|
+
// get the horizontal and vertical inputs from player one's controller
|
|
50
|
+
const { Horizontal, Vertical } = inputs.p1.axes;
|
|
51
|
+
// set the speed of the ball based on the delta time for smoother movement
|
|
52
|
+
const speed = 600 * delta;
|
|
53
|
+
// move the ball based on the inputs and the speed
|
|
54
|
+
me.moveXY(Horizontal.value * speed, -Vertical.value * speed);
|
|
77
55
|
});
|
|
78
56
|
|
|
79
57
|
// add a boundary behavior to the ball
|
|
80
58
|
ball.addBehavior(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
59
|
+
boundary2d({
|
|
60
|
+
boundaries: {
|
|
61
|
+
top: 3,
|
|
62
|
+
bottom: -3,
|
|
63
|
+
left: -6,
|
|
64
|
+
right: 6,
|
|
65
|
+
},
|
|
66
|
+
}),
|
|
89
67
|
);
|
|
90
68
|
|
|
91
69
|
// start the game with the ball
|
|
92
70
|
createGame(ball).start();
|
|
93
71
|
```
|
|
72
|
+
|
|
73
|
+
## Development
|
|
74
|
+
|
|
75
|
+
This package is part of the Zylem monorepo. See the main repository README for development setup.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export { m as makeMoveable } from './moveable-B_vyA6cw.js';
|
|
2
|
+
export { m as makeRotatable, a as makeTransformable } from './transformable-CUhvyuYO.js';
|
|
3
|
+
import 'three';
|
|
4
|
+
import '@dimforge/rapier3d-compat';
|
|
5
|
+
|
|
6
|
+
declare function wait(delay: number, callback: Function): void;
|
|
7
|
+
declare const actionOnPress: (isPressed: boolean, callback: Function) => void;
|
|
8
|
+
declare const actionOnRelease: (isPressed: boolean, callback: Function) => void;
|
|
9
|
+
type CooldownOptions = {
|
|
10
|
+
timer: number;
|
|
11
|
+
immediate?: boolean;
|
|
12
|
+
};
|
|
13
|
+
declare const actionWithCooldown: ({ timer, immediate }: CooldownOptions, callback: Function, update: Function) => void;
|
|
14
|
+
declare const actionWithThrottle: (timer: number, callback: Function) => void;
|
|
15
|
+
|
|
16
|
+
declare const actions_actionOnPress: typeof actionOnPress;
|
|
17
|
+
declare const actions_actionOnRelease: typeof actionOnRelease;
|
|
18
|
+
declare const actions_actionWithCooldown: typeof actionWithCooldown;
|
|
19
|
+
declare const actions_actionWithThrottle: typeof actionWithThrottle;
|
|
20
|
+
declare const actions_wait: typeof wait;
|
|
21
|
+
declare namespace actions {
|
|
22
|
+
export { actions_actionOnPress as actionOnPress, actions_actionOnRelease as actionOnRelease, actions_actionWithCooldown as actionWithCooldown, actions_actionWithThrottle as actionWithThrottle, actions_wait as wait };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { actions };
|
package/dist/actions.js
CHANGED
|
@@ -1,10 +1,289 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/lib/actions/behaviors/actions.ts
|
|
8
|
+
var actions_exports = {};
|
|
9
|
+
__export(actions_exports, {
|
|
10
|
+
actionOnPress: () => actionOnPress,
|
|
11
|
+
actionOnRelease: () => actionOnRelease,
|
|
12
|
+
actionWithCooldown: () => actionWithCooldown,
|
|
13
|
+
actionWithThrottle: () => actionWithThrottle,
|
|
14
|
+
wait: () => wait
|
|
15
|
+
});
|
|
16
|
+
function wait(delay, callback) {
|
|
17
|
+
setTimeout(callback, delay);
|
|
18
|
+
}
|
|
19
|
+
var actionOnPress = /* @__PURE__ */ (() => {
|
|
20
|
+
let buttonPressed = false;
|
|
21
|
+
return (isPressed, callback) => {
|
|
22
|
+
if (isPressed && !buttonPressed) {
|
|
23
|
+
buttonPressed = true;
|
|
24
|
+
callback();
|
|
25
|
+
} else if (!isPressed) {
|
|
26
|
+
buttonPressed = false;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
})();
|
|
30
|
+
var actionOnRelease = /* @__PURE__ */ (() => {
|
|
31
|
+
let buttonPressed = false;
|
|
32
|
+
return (isPressed, callback) => {
|
|
33
|
+
if (!isPressed && buttonPressed) {
|
|
34
|
+
buttonPressed = false;
|
|
35
|
+
callback();
|
|
36
|
+
} else if (isPressed) {
|
|
37
|
+
buttonPressed = true;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var actionWithCooldown = /* @__PURE__ */ (() => {
|
|
42
|
+
let lastExecutionTime = -Infinity;
|
|
43
|
+
let flagImmediate = false;
|
|
44
|
+
return ({ timer, immediate = true }, callback, update) => {
|
|
45
|
+
let currentTime = Date.now();
|
|
46
|
+
if (!flagImmediate && !immediate) {
|
|
47
|
+
flagImmediate = true;
|
|
48
|
+
lastExecutionTime = currentTime;
|
|
49
|
+
}
|
|
50
|
+
const delta = currentTime - lastExecutionTime;
|
|
51
|
+
if (delta >= timer) {
|
|
52
|
+
lastExecutionTime = currentTime;
|
|
53
|
+
callback();
|
|
54
|
+
}
|
|
55
|
+
update({ delta });
|
|
56
|
+
};
|
|
57
|
+
})();
|
|
58
|
+
var actionWithThrottle = /* @__PURE__ */ (() => {
|
|
59
|
+
let lastExecutionTime = 0;
|
|
60
|
+
return (timer, callback) => {
|
|
61
|
+
const currentTime = Date.now();
|
|
62
|
+
const delta = currentTime - lastExecutionTime;
|
|
63
|
+
if (delta >= timer) {
|
|
64
|
+
lastExecutionTime = currentTime;
|
|
65
|
+
callback();
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
})();
|
|
69
|
+
|
|
70
|
+
// src/lib/actions/capabilities/moveable.ts
|
|
71
|
+
import { Vector3 } from "three";
|
|
72
|
+
function moveX(entity, delta) {
|
|
73
|
+
if (!entity.body) return;
|
|
74
|
+
const currentVelocity = entity.body.linvel();
|
|
75
|
+
const newVelocity = new Vector3(delta, currentVelocity.y, currentVelocity.z);
|
|
76
|
+
entity.body.setLinvel(newVelocity, true);
|
|
77
|
+
}
|
|
78
|
+
function moveY(entity, delta) {
|
|
79
|
+
if (!entity.body) return;
|
|
80
|
+
const currentVelocity = entity.body.linvel();
|
|
81
|
+
const newVelocity = new Vector3(currentVelocity.x, delta, currentVelocity.z);
|
|
82
|
+
entity.body.setLinvel(newVelocity, true);
|
|
83
|
+
}
|
|
84
|
+
function moveZ(entity, delta) {
|
|
85
|
+
if (!entity.body) return;
|
|
86
|
+
const currentVelocity = entity.body.linvel();
|
|
87
|
+
const newVelocity = new Vector3(currentVelocity.x, currentVelocity.y, delta);
|
|
88
|
+
entity.body.setLinvel(newVelocity, true);
|
|
89
|
+
}
|
|
90
|
+
function moveXY(entity, deltaX, deltaY) {
|
|
91
|
+
if (!entity.body) return;
|
|
92
|
+
const currentVelocity = entity.body.linvel();
|
|
93
|
+
const newVelocity = new Vector3(deltaX, deltaY, currentVelocity.z);
|
|
94
|
+
entity.body.setLinvel(newVelocity, true);
|
|
95
|
+
}
|
|
96
|
+
function moveXZ(entity, deltaX, deltaZ) {
|
|
97
|
+
if (!entity.body) return;
|
|
98
|
+
const currentVelocity = entity.body.linvel();
|
|
99
|
+
const newVelocity = new Vector3(deltaX, currentVelocity.y, deltaZ);
|
|
100
|
+
entity.body.setLinvel(newVelocity, true);
|
|
101
|
+
}
|
|
102
|
+
function move(entity, vector) {
|
|
103
|
+
if (!entity.body) return;
|
|
104
|
+
const currentVelocity = entity.body.linvel();
|
|
105
|
+
const newVelocity = new Vector3(
|
|
106
|
+
currentVelocity.x + vector.x,
|
|
107
|
+
currentVelocity.y + vector.y,
|
|
108
|
+
currentVelocity.z + vector.z
|
|
109
|
+
);
|
|
110
|
+
entity.body.setLinvel(newVelocity, true);
|
|
111
|
+
}
|
|
112
|
+
function resetVelocity(entity) {
|
|
113
|
+
if (!entity.body) return;
|
|
114
|
+
entity.body.setLinvel(new Vector3(0, 0, 0), true);
|
|
115
|
+
entity.body.setLinearDamping(5);
|
|
116
|
+
}
|
|
117
|
+
function moveForwardXY(entity, delta, rotation2DAngle) {
|
|
118
|
+
const deltaX = Math.sin(-rotation2DAngle) * delta;
|
|
119
|
+
const deltaY = Math.cos(-rotation2DAngle) * delta;
|
|
120
|
+
moveXY(entity, deltaX, deltaY);
|
|
121
|
+
}
|
|
122
|
+
function getPosition(entity) {
|
|
123
|
+
if (!entity.body) return null;
|
|
124
|
+
return entity.body.translation();
|
|
125
|
+
}
|
|
126
|
+
function getVelocity(entity) {
|
|
127
|
+
if (!entity.body) return null;
|
|
128
|
+
return entity.body.linvel();
|
|
129
|
+
}
|
|
130
|
+
function setPosition(entity, x, y, z) {
|
|
131
|
+
if (!entity.body) return;
|
|
132
|
+
entity.body.setTranslation({ x, y, z }, true);
|
|
133
|
+
}
|
|
134
|
+
function setPositionX(entity, x) {
|
|
135
|
+
if (!entity.body) return;
|
|
136
|
+
const { y, z } = entity.body.translation();
|
|
137
|
+
entity.body.setTranslation({ x, y, z }, true);
|
|
138
|
+
}
|
|
139
|
+
function setPositionY(entity, y) {
|
|
140
|
+
if (!entity.body) return;
|
|
141
|
+
const { x, z } = entity.body.translation();
|
|
142
|
+
entity.body.setTranslation({ x, y, z }, true);
|
|
143
|
+
}
|
|
144
|
+
function setPositionZ(entity, z) {
|
|
145
|
+
if (!entity.body) return;
|
|
146
|
+
const { x, y } = entity.body.translation();
|
|
147
|
+
entity.body.setTranslation({ x, y, z }, true);
|
|
148
|
+
}
|
|
149
|
+
function wrapAroundXY(entity, boundsX, boundsY) {
|
|
150
|
+
const position = getPosition(entity);
|
|
151
|
+
if (!position) return;
|
|
152
|
+
const { x, y } = position;
|
|
153
|
+
const newX = x > boundsX ? -boundsX : x < -boundsX ? boundsX : x;
|
|
154
|
+
const newY = y > boundsY ? -boundsY : y < -boundsY ? boundsY : y;
|
|
155
|
+
if (newX !== x || newY !== y) {
|
|
156
|
+
setPosition(entity, newX, newY, 0);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function wrapAround3D(entity, boundsX, boundsY, boundsZ) {
|
|
160
|
+
const position = getPosition(entity);
|
|
161
|
+
if (!position) return;
|
|
162
|
+
const { x, y, z } = position;
|
|
163
|
+
const newX = x > boundsX ? -boundsX : x < -boundsX ? boundsX : x;
|
|
164
|
+
const newY = y > boundsY ? -boundsY : y < -boundsY ? boundsY : y;
|
|
165
|
+
const newZ = z > boundsZ ? -boundsZ : z < -boundsZ ? boundsZ : z;
|
|
166
|
+
if (newX !== x || newY !== y || newZ !== z) {
|
|
167
|
+
setPosition(entity, newX, newY, newZ);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function makeMoveable(entity) {
|
|
171
|
+
const moveable = entity;
|
|
172
|
+
moveable.moveX = (delta) => moveX(entity, delta);
|
|
173
|
+
moveable.moveY = (delta) => moveY(entity, delta);
|
|
174
|
+
moveable.moveZ = (delta) => moveZ(entity, delta);
|
|
175
|
+
moveable.moveXY = (deltaX, deltaY) => moveXY(entity, deltaX, deltaY);
|
|
176
|
+
moveable.moveXZ = (deltaX, deltaZ) => moveXZ(entity, deltaX, deltaZ);
|
|
177
|
+
moveable.move = (vector) => move(entity, vector);
|
|
178
|
+
moveable.resetVelocity = () => resetVelocity(entity);
|
|
179
|
+
moveable.moveForwardXY = (delta, rotation2DAngle) => moveForwardXY(entity, delta, rotation2DAngle);
|
|
180
|
+
moveable.getPosition = () => getPosition(entity);
|
|
181
|
+
moveable.getVelocity = () => getVelocity(entity);
|
|
182
|
+
moveable.setPosition = (x, y, z) => setPosition(entity, x, y, z);
|
|
183
|
+
moveable.setPositionX = (x) => setPositionX(entity, x);
|
|
184
|
+
moveable.setPositionY = (y) => setPositionY(entity, y);
|
|
185
|
+
moveable.setPositionZ = (z) => setPositionZ(entity, z);
|
|
186
|
+
moveable.wrapAroundXY = (boundsX, boundsY) => wrapAroundXY(entity, boundsX, boundsY);
|
|
187
|
+
moveable.wrapAround3D = (boundsX, boundsY, boundsZ) => wrapAround3D(entity, boundsX, boundsY, boundsZ);
|
|
188
|
+
return moveable;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// src/lib/actions/capabilities/rotatable.ts
|
|
192
|
+
import { Euler, Vector3 as Vector32, MathUtils, Quaternion } from "three";
|
|
193
|
+
function rotateInDirection(entity, moveVector) {
|
|
194
|
+
if (!entity.body) return;
|
|
195
|
+
const rotate = Math.atan2(-moveVector.x, moveVector.z);
|
|
196
|
+
rotateYEuler(entity, rotate);
|
|
197
|
+
}
|
|
198
|
+
function rotateYEuler(entity, amount) {
|
|
199
|
+
rotateEuler(entity, new Vector32(0, -amount, 0));
|
|
200
|
+
}
|
|
201
|
+
function rotateEuler(entity, rotation) {
|
|
202
|
+
if (!entity.group) return;
|
|
203
|
+
const euler = new Euler(rotation.x, rotation.y, rotation.z);
|
|
204
|
+
entity.group.setRotationFromEuler(euler);
|
|
205
|
+
}
|
|
206
|
+
function rotateY(entity, delta) {
|
|
207
|
+
setRotationY(entity, delta);
|
|
208
|
+
}
|
|
209
|
+
function rotateZ(entity, delta) {
|
|
210
|
+
setRotationZ(entity, delta);
|
|
211
|
+
}
|
|
212
|
+
function setRotationY(entity, y) {
|
|
213
|
+
if (!entity.body) return;
|
|
214
|
+
const halfAngle = y / 2;
|
|
215
|
+
const w = Math.cos(halfAngle);
|
|
216
|
+
const yComponent = Math.sin(halfAngle);
|
|
217
|
+
entity.body.setRotation({ w, x: 0, y: yComponent, z: 0 }, true);
|
|
218
|
+
}
|
|
219
|
+
function setRotationDegreesY(entity, y) {
|
|
220
|
+
if (!entity.body) return;
|
|
221
|
+
setRotationY(entity, MathUtils.degToRad(y));
|
|
222
|
+
}
|
|
223
|
+
function setRotationX(entity, x) {
|
|
224
|
+
if (!entity.body) return;
|
|
225
|
+
const halfAngle = x / 2;
|
|
226
|
+
const w = Math.cos(halfAngle);
|
|
227
|
+
const xComponent = Math.sin(halfAngle);
|
|
228
|
+
entity.body.setRotation({ w, x: xComponent, y: 0, z: 0 }, true);
|
|
229
|
+
}
|
|
230
|
+
function setRotationDegreesX(entity, x) {
|
|
231
|
+
if (!entity.body) return;
|
|
232
|
+
setRotationX(entity, MathUtils.degToRad(x));
|
|
233
|
+
}
|
|
234
|
+
function setRotationZ(entity, z) {
|
|
235
|
+
if (!entity.body) return;
|
|
236
|
+
const halfAngle = z / 2;
|
|
237
|
+
const w = Math.cos(halfAngle);
|
|
238
|
+
const zComponent = Math.sin(halfAngle);
|
|
239
|
+
entity.body.setRotation({ w, x: 0, y: 0, z: zComponent }, true);
|
|
240
|
+
}
|
|
241
|
+
function setRotationDegreesZ(entity, z) {
|
|
242
|
+
if (!entity.body) return;
|
|
243
|
+
setRotationZ(entity, MathUtils.degToRad(z));
|
|
244
|
+
}
|
|
245
|
+
function setRotation(entity, x, y, z) {
|
|
246
|
+
if (!entity.body) return;
|
|
247
|
+
const quat = new Quaternion().setFromEuler(new Euler(x, y, z));
|
|
248
|
+
entity.body.setRotation({ w: quat.w, x: quat.x, y: quat.y, z: quat.z }, true);
|
|
249
|
+
}
|
|
250
|
+
function setRotationDegrees(entity, x, y, z) {
|
|
251
|
+
if (!entity.body) return;
|
|
252
|
+
setRotation(entity, MathUtils.degToRad(x), MathUtils.degToRad(y), MathUtils.degToRad(z));
|
|
253
|
+
}
|
|
254
|
+
function getRotation(entity) {
|
|
255
|
+
if (!entity.body) return null;
|
|
256
|
+
return entity.body.rotation();
|
|
257
|
+
}
|
|
258
|
+
function makeRotatable(entity) {
|
|
259
|
+
const rotatableEntity = entity;
|
|
260
|
+
rotatableEntity.rotateInDirection = (moveVector) => rotateInDirection(entity, moveVector);
|
|
261
|
+
rotatableEntity.rotateYEuler = (amount) => rotateYEuler(entity, amount);
|
|
262
|
+
rotatableEntity.rotateEuler = (rotation) => rotateEuler(entity, rotation);
|
|
263
|
+
rotatableEntity.rotateY = (delta) => rotateY(entity, delta);
|
|
264
|
+
rotatableEntity.rotateZ = (delta) => rotateZ(entity, delta);
|
|
265
|
+
rotatableEntity.setRotationY = (y) => setRotationY(entity, y);
|
|
266
|
+
rotatableEntity.setRotationX = (x) => setRotationX(entity, x);
|
|
267
|
+
rotatableEntity.setRotationZ = (z) => setRotationZ(entity, z);
|
|
268
|
+
rotatableEntity.setRotationDegreesY = (y) => setRotationDegreesY(entity, y);
|
|
269
|
+
rotatableEntity.setRotationDegreesX = (x) => setRotationDegreesX(entity, x);
|
|
270
|
+
rotatableEntity.setRotationDegreesZ = (z) => setRotationDegreesZ(entity, z);
|
|
271
|
+
rotatableEntity.setRotationDegrees = (x, y, z) => setRotationDegrees(entity, x, y, z);
|
|
272
|
+
rotatableEntity.setRotation = (x, y, z) => setRotation(entity, x, y, z);
|
|
273
|
+
rotatableEntity.getRotation = () => getRotation(entity);
|
|
274
|
+
return rotatableEntity;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// src/lib/actions/capabilities/transformable.ts
|
|
278
|
+
function makeTransformable(entity) {
|
|
279
|
+
const withMovement = makeMoveable(entity);
|
|
280
|
+
const withRotation = makeRotatable(withMovement);
|
|
281
|
+
return withRotation;
|
|
282
|
+
}
|
|
5
283
|
export {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
284
|
+
actions_exports as actions,
|
|
285
|
+
makeMoveable,
|
|
286
|
+
makeRotatable,
|
|
287
|
+
makeTransformable
|
|
10
288
|
};
|
|
289
|
+
//# sourceMappingURL=actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/actions/behaviors/actions.ts","../src/lib/actions/capabilities/moveable.ts","../src/lib/actions/capabilities/rotatable.ts","../src/lib/actions/capabilities/transformable.ts"],"sourcesContent":["// TODO: rewrite these functions to work well within game loop\n\nexport function wait(delay: number, callback: Function) {\n\t// TODO: needs ticks from loop\n\tsetTimeout(callback, delay);\n}\n\nexport const actionOnPress = (() => {\n\tlet buttonPressed = false;\n\n\treturn (isPressed: boolean, callback: Function) => {\n\t\tif (isPressed && !buttonPressed) {\n\t\t\tbuttonPressed = true;\n\t\t\tcallback();\n\t\t} else if (!isPressed) {\n\t\t\tbuttonPressed = false;\n\t\t}\n\t};\n})();\n\nexport const actionOnRelease = (() => {\n\tlet buttonPressed = false;\n\n\treturn (isPressed: boolean, callback: Function) => {\n\t\tif (!isPressed && buttonPressed) {\n\t\t\tbuttonPressed = false;\n\t\t\tcallback();\n\t\t} else if (isPressed) {\n\t\t\tbuttonPressed = true;\n\t\t}\n\t};\n})();\n\ntype CooldownOptions = { timer: number; immediate?: boolean };\n\nexport const actionWithCooldown = (() => {\n\tlet lastExecutionTime = -Infinity;\n\tlet flagImmediate = false;\n\n\treturn ({ timer, immediate = true }: CooldownOptions, callback: Function, update: Function) => {\n\t\tlet currentTime = Date.now();\n\n\t\tif (!flagImmediate && !immediate) {\n\t\t\tflagImmediate = true;\n\t\t\tlastExecutionTime = currentTime;\n\t\t}\n\n\t\tconst delta = currentTime - lastExecutionTime;\n\n\t\tif (delta >= timer) {\n\t\t\tlastExecutionTime = currentTime;\n\t\t\tcallback();\n\t\t}\n\t\tupdate({ delta });\n\t};\n})();\n\nexport const actionWithThrottle = (() => {\n\tlet lastExecutionTime = 0;\n\n\treturn (timer: number, callback: Function) => {\n\t\tconst currentTime = Date.now();\n\t\tconst delta = currentTime - lastExecutionTime;\n\n\t\tif (delta >= timer) {\n\t\t\tlastExecutionTime = currentTime;\n\t\t\tcallback();\n\t\t}\n\t};\n})();\n","import { Vector3 } from 'three';\nimport { RigidBody, Vector } from '@dimforge/rapier3d-compat';\n\nexport interface EntityWithBody {\n\tbody: RigidBody | null;\n}\n\n/**\n * Move an entity along the X axis, preserving other velocities\n */\nexport function moveX(entity: EntityWithBody, delta: number): void {\n\tif (!entity.body) return;\n\tconst currentVelocity = entity.body.linvel();\n\tconst newVelocity = new Vector3(delta, currentVelocity.y, currentVelocity.z);\n\tentity.body.setLinvel(newVelocity, true);\n}\n\n/**\n * Move an entity along the Y axis, preserving other velocities\n */\nexport function moveY(entity: EntityWithBody, delta: number): void {\n\tif (!entity.body) return;\n\tconst currentVelocity = entity.body.linvel();\n\tconst newVelocity = new Vector3(currentVelocity.x, delta, currentVelocity.z);\n\tentity.body.setLinvel(newVelocity, true);\n}\n\n/**\n * Move an entity along the Z axis, preserving other velocities\n */\nexport function moveZ(entity: EntityWithBody, delta: number): void {\n\tif (!entity.body) return;\n\tconst currentVelocity = entity.body.linvel();\n\tconst newVelocity = new Vector3(currentVelocity.x, currentVelocity.y, delta);\n\tentity.body.setLinvel(newVelocity, true);\n}\n\n/**\n * Move an entity along the X and Y axis, preserving Z velocity\n */\nexport function moveXY(entity: EntityWithBody, deltaX: number, deltaY: number): void {\n\tif (!entity.body) return;\n\tconst currentVelocity = entity.body.linvel();\n\tconst newVelocity = new Vector3(deltaX, deltaY, currentVelocity.z);\n\tentity.body.setLinvel(newVelocity, true);\n}\n\n/**\n * Move an entity along the X and Z axis, preserving Y velocity\n */\nexport function moveXZ(entity: EntityWithBody, deltaX: number, deltaZ: number): void {\n\tif (!entity.body) return;\n\tconst currentVelocity = entity.body.linvel();\n\tconst newVelocity = new Vector3(deltaX, currentVelocity.y, deltaZ);\n\tentity.body.setLinvel(newVelocity, true);\n}\n\n/**\n * Move entity based on a vector, adding to existing velocities\n */\nexport function move(entity: EntityWithBody, vector: Vector3): void {\n\tif (!entity.body) return;\n\tconst currentVelocity = entity.body.linvel();\n\tconst newVelocity = new Vector3(\n\t\tcurrentVelocity.x + vector.x,\n\t\tcurrentVelocity.y + vector.y,\n\t\tcurrentVelocity.z + vector.z\n\t);\n\tentity.body.setLinvel(newVelocity, true);\n}\n\n/**\n * Reset entity velocity\n */\nexport function resetVelocity(entity: EntityWithBody): void {\n\tif (!entity.body) return;\n\tentity.body.setLinvel(new Vector3(0, 0, 0), true);\n\tentity.body.setLinearDamping(5);\n}\n\n/**\n * Move entity forward in 2D space, preserving Z velocity\n */\nexport function moveForwardXY(entity: EntityWithBody, delta: number, rotation2DAngle: number): void {\n\tconst deltaX = Math.sin(-rotation2DAngle) * delta;\n\tconst deltaY = Math.cos(-rotation2DAngle) * delta;\n\tmoveXY(entity, deltaX, deltaY);\n}\n\n/**\n * Get entity position\n */\nexport function getPosition(entity: EntityWithBody): Vector | null {\n\tif (!entity.body) return null;\n\treturn entity.body.translation();\n}\n\n/**\n * Get entity velocity\n */\nexport function getVelocity(entity: EntityWithBody): Vector | null {\n\tif (!entity.body) return null;\n\treturn entity.body.linvel();\n}\n\n/**\n * Set entity position\n */\nexport function setPosition(entity: EntityWithBody, x: number, y: number, z: number): void {\n\tif (!entity.body) return;\n\tentity.body.setTranslation({ x, y, z }, true);\n}\n\n/**\n * Set entity X position\n */\nexport function setPositionX(entity: EntityWithBody, x: number): void {\n\tif (!entity.body) return;\n\tconst { y, z } = entity.body.translation();\n\tentity.body.setTranslation({ x, y, z }, true);\n}\n\n/**\n * Set entity Y position\n */\nexport function setPositionY(entity: EntityWithBody, y: number): void {\n\tif (!entity.body) return;\n\tconst { x, z } = entity.body.translation();\n\tentity.body.setTranslation({ x, y, z }, true);\n}\n\n/**\n * Set entity Z position\n */\nexport function setPositionZ(entity: EntityWithBody, z: number): void {\n\tif (!entity.body) return;\n\tconst { x, y } = entity.body.translation();\n\tentity.body.setTranslation({ x, y, z }, true);\n}\n\n/**\n * Wrap entity around 2D bounds\n */\nexport function wrapAroundXY(entity: EntityWithBody, boundsX: number, boundsY: number): void {\n\tconst position = getPosition(entity);\n\tif (!position) return;\n\n\tconst { x, y } = position;\n\tconst newX = x > boundsX ? -boundsX : (x < -boundsX ? boundsX : x);\n\tconst newY = y > boundsY ? -boundsY : (y < -boundsY ? boundsY : y);\n\n\tif (newX !== x || newY !== y) {\n\t\tsetPosition(entity, newX, newY, 0);\n\t}\n}\n\n/**\n * Wrap entity around 3D bounds\n */\nexport function wrapAround3D(entity: EntityWithBody, boundsX: number, boundsY: number, boundsZ: number): void {\n\tconst position = getPosition(entity);\n\tif (!position) return;\n\n\tconst { x, y, z } = position;\n\tconst newX = x > boundsX ? -boundsX : (x < -boundsX ? boundsX : x);\n\tconst newY = y > boundsY ? -boundsY : (y < -boundsY ? boundsY : y);\n\tconst newZ = z > boundsZ ? -boundsZ : (z < -boundsZ ? boundsZ : z);\n\n\tif (newX !== x || newY !== y || newZ !== z) {\n\t\tsetPosition(entity, newX, newY, newZ);\n\t}\n}\n\n/**\n * Enhanced moveable entity with bound methods\n */\nexport interface MoveableEntity extends EntityWithBody {\n\tmoveX(delta: number): void;\n\tmoveY(delta: number): void;\n\tmoveZ(delta: number): void;\n\tmoveXY(deltaX: number, deltaY: number): void;\n\tmoveXZ(deltaX: number, deltaZ: number): void;\n\tmove(vector: Vector3): void;\n\tresetVelocity(): void;\n\tmoveForwardXY(delta: number, rotation2DAngle: number): void;\n\tgetPosition(): Vector | null;\n\tgetVelocity(): Vector | null;\n\tsetPosition(x: number, y: number, z: number): void;\n\tsetPositionX(x: number): void;\n\tsetPositionY(y: number): void;\n\tsetPositionZ(z: number): void;\n\twrapAroundXY(boundsX: number, boundsY: number): void;\n\twrapAround3D(boundsX: number, boundsY: number, boundsZ: number): void;\n}\n\n/**\n * Class decorator to enhance an entity with additive movement methods\n */\nexport function moveable<T extends { new(...args: any[]): EntityWithBody }>(constructor: T) {\n\treturn class extends constructor implements MoveableEntity {\n\t\tmoveX(delta: number): void {\n\t\t\tmoveX(this, delta);\n\t\t}\n\t\tmoveY(delta: number): void {\n\t\t\tmoveY(this, delta);\n\t\t}\n\t\tmoveZ(delta: number): void {\n\t\t\tmoveZ(this, delta);\n\t\t}\n\t\tmoveXY(deltaX: number, deltaY: number): void {\n\t\t\tmoveXY(this, deltaX, deltaY);\n\t\t}\n\t\tmoveXZ(deltaX: number, deltaZ: number): void {\n\t\t\tmoveXZ(this, deltaX, deltaZ);\n\t\t}\n\t\tmove(vector: Vector3): void {\n\t\t\tmove(this, vector);\n\t\t}\n\t\tresetVelocity(): void {\n\t\t\tresetVelocity(this);\n\t\t}\n\t\tmoveForwardXY(delta: number, rotation2DAngle: number): void {\n\t\t\tmoveForwardXY(this, delta, rotation2DAngle);\n\t\t}\n\t\tgetPosition(): Vector | null {\n\t\t\treturn getPosition(this);\n\t\t}\n\t\tgetVelocity(): Vector | null {\n\t\t\treturn getVelocity(this);\n\t\t}\n\t\tsetPosition(x: number, y: number, z: number): void {\n\t\t\tsetPosition(this, x, y, z);\n\t\t}\n\t\tsetPositionX(x: number): void {\n\t\t\tsetPositionX(this, x);\n\t\t}\n\t\tsetPositionY(y: number): void {\n\t\t\tsetPositionY(this, y);\n\t\t}\n\t\tsetPositionZ(z: number): void {\n\t\t\tsetPositionZ(this, z);\n\t\t}\n\t\twrapAroundXY(boundsX: number, boundsY: number): void {\n\t\t\twrapAroundXY(this, boundsX, boundsY);\n\t\t}\n\t\twrapAround3D(boundsX: number, boundsY: number, boundsZ: number): void {\n\t\t\twrapAround3D(this, boundsX, boundsY, boundsZ);\n\t\t}\n\t};\n}\n\n/**\n * Enhance an entity with additive movement methods (retained for compatibility)\n */\nexport function makeMoveable<T extends EntityWithBody>(entity: T): T & MoveableEntity {\n\tconst moveable = entity as T & MoveableEntity;\n\n\tmoveable.moveX = (delta: number) => moveX(entity, delta);\n\tmoveable.moveY = (delta: number) => moveY(entity, delta);\n\tmoveable.moveZ = (delta: number) => moveZ(entity, delta);\n\tmoveable.moveXY = (deltaX: number, deltaY: number) => moveXY(entity, deltaX, deltaY);\n\tmoveable.moveXZ = (deltaX: number, deltaZ: number) => moveXZ(entity, deltaX, deltaZ);\n\tmoveable.move = (vector: Vector3) => move(entity, vector);\n\tmoveable.resetVelocity = () => resetVelocity(entity);\n\tmoveable.moveForwardXY = (delta: number, rotation2DAngle: number) => moveForwardXY(entity, delta, rotation2DAngle);\n\tmoveable.getPosition = () => getPosition(entity);\n\tmoveable.getVelocity = () => getVelocity(entity);\n\tmoveable.setPosition = (x: number, y: number, z: number) => setPosition(entity, x, y, z);\n\tmoveable.setPositionX = (x: number) => setPositionX(entity, x);\n\tmoveable.setPositionY = (y: number) => setPositionY(entity, y);\n\tmoveable.setPositionZ = (z: number) => setPositionZ(entity, z);\n\tmoveable.wrapAroundXY = (boundsX: number, boundsY: number) => wrapAroundXY(entity, boundsX, boundsY);\n\tmoveable.wrapAround3D = (boundsX: number, boundsY: number, boundsZ: number) => wrapAround3D(entity, boundsX, boundsY, boundsZ);\n\n\treturn moveable;\n}\n\n/**\n * Wrap a standalone function with movement capabilities\n */\nexport function withMovement<T extends (...args: any[]) => any>(\n\tfn: T,\n\tentity: EntityWithBody\n): (...args: Parameters<T>) => ReturnType<T> & MoveableEntity {\n\tconst wrapped = (...args: Parameters<T>) => {\n\t\tconst result = fn(...args);\n\t\tconst moveableEntity = makeMoveable(entity);\n\t\treturn Object.assign(result, moveableEntity);\n\t};\n\treturn wrapped as (...args: Parameters<T>) => ReturnType<T> & MoveableEntity;\n}","import { Euler, Vector3, MathUtils, Quaternion } from 'three';\nimport { RigidBody } from '@dimforge/rapier3d-compat';\n\nexport interface RotatableEntity {\n\tbody: RigidBody | null;\n\tgroup: any;\n}\n\n/**\n * Rotate an entity in the direction of a movement vector\n */\nexport function rotateInDirection(entity: RotatableEntity, moveVector: Vector3): void {\n\tif (!entity.body) return;\n\tconst rotate = Math.atan2(-moveVector.x, moveVector.z);\n\trotateYEuler(entity, rotate);\n}\n\n/**\n * Rotate an entity around the Y axis using Euler angles\n */\nexport function rotateYEuler(entity: RotatableEntity, amount: number): void {\n\trotateEuler(entity, new Vector3(0, -amount, 0));\n}\n\n/**\n * Rotate an entity using Euler angles\n */\nexport function rotateEuler(entity: RotatableEntity, rotation: Vector3): void {\n\tif (!entity.group) return;\n\tconst euler = new Euler(rotation.x, rotation.y, rotation.z);\n\tentity.group.setRotationFromEuler(euler);\n}\n\n/**\n * Rotate an entity around the Y axis\n */\nexport function rotateY(entity: RotatableEntity, delta: number): void {\n\tsetRotationY(entity, delta);\n}\n\n/**\n * Rotate an entity around the Z axis\n */\nexport function rotateZ(entity: RotatableEntity, delta: number): void {\n\tsetRotationZ(entity, delta);\n}\n\n/**\n * Set rotation around Y axis\n */\nexport function setRotationY(entity: RotatableEntity, y: number): void {\n\tif (!entity.body) return;\n\tconst halfAngle = y / 2;\n\tconst w = Math.cos(halfAngle);\n\tconst yComponent = Math.sin(halfAngle);\n\tentity.body.setRotation({ w: w, x: 0, y: yComponent, z: 0 }, true);\n}\n\n/**\n * Set rotation around Y axis\n */\nexport function setRotationDegreesY(entity: RotatableEntity, y: number): void {\n\tif (!entity.body) return;\n\tsetRotationY(entity, MathUtils.degToRad(y));\n}\n\n/**\n * Set rotation around X axis\n */\nexport function setRotationX(entity: RotatableEntity, x: number): void {\n\tif (!entity.body) return;\n\tconst halfAngle = x / 2;\n\tconst w = Math.cos(halfAngle);\n\tconst xComponent = Math.sin(halfAngle);\n\tentity.body.setRotation({ w: w, x: xComponent, y: 0, z: 0 }, true);\n}\n\n/**\n * Set rotation around X axis\n */\nexport function setRotationDegreesX(entity: RotatableEntity, x: number): void {\n\tif (!entity.body) return;\n\tsetRotationX(entity, MathUtils.degToRad(x));\n}\n\n/**\n * Set rotation around Z axis\n */\nexport function setRotationZ(entity: RotatableEntity, z: number): void {\n\tif (!entity.body) return;\n\tconst halfAngle = z / 2;\n\tconst w = Math.cos(halfAngle);\n\tconst zComponent = Math.sin(halfAngle);\n\tentity.body.setRotation({ w: w, x: 0, y: 0, z: zComponent }, true);\n}\n\n/**\n * Set rotation around Z axis\n */\nexport function setRotationDegreesZ(entity: RotatableEntity, z: number): void {\n\tif (!entity.body) return;\n\tsetRotationZ(entity, MathUtils.degToRad(z));\n}\n\n/**\n * Set rotation for all axes\n */\nexport function setRotation(entity: RotatableEntity, x: number, y: number, z: number): void {\n\tif (!entity.body) return;\n\tconst quat = new Quaternion().setFromEuler(new Euler(x, y, z));\n\tentity.body.setRotation({ w: quat.w, x: quat.x, y: quat.y, z: quat.z }, true);\n}\n\n/**\n * Set rotation for all axes\n */\nexport function setRotationDegrees(entity: RotatableEntity, x: number, y: number, z: number): void {\n\tif (!entity.body) return;\n\tsetRotation(entity, MathUtils.degToRad(x), MathUtils.degToRad(y), MathUtils.degToRad(z));\n}\n\n/**\n * Get current rotation\n */\nexport function getRotation(entity: RotatableEntity): any {\n\tif (!entity.body) return null;\n\treturn entity.body.rotation();\n}\n\n/**\n * Rotatable entity API with bound methods\n */\nexport interface RotatableEntityAPI extends RotatableEntity {\n\trotateInDirection(moveVector: Vector3): void;\n\trotateYEuler(amount: number): void;\n\trotateEuler(rotation: Vector3): void;\n\trotateY(delta: number): void;\n\trotateZ(delta: number): void;\n\tsetRotationY(y: number): void;\n\tsetRotationX(x: number): void;\n\tsetRotationZ(z: number): void;\n\tsetRotationDegrees(x: number, y: number, z: number): void;\n\tsetRotationDegreesY(y: number): void;\n\tsetRotationDegreesX(x: number): void;\n\tsetRotationDegreesZ(z: number): void;\n\tsetRotation(x: number, y: number, z: number): void;\n\tgetRotation(): any;\n}\n\n/**\n * Class decorator to enhance an entity with rotatable methods\n */\nexport function rotatable<T extends { new(...args: any[]): RotatableEntity }>(constructor: T) {\n\treturn class extends constructor implements RotatableEntityAPI {\n\t\trotateInDirection(moveVector: Vector3): void {\n\t\t\trotateInDirection(this, moveVector);\n\t\t}\n\t\trotateYEuler(amount: number): void {\n\t\t\trotateYEuler(this, amount);\n\t\t}\n\t\trotateEuler(rotation: Vector3): void {\n\t\t\trotateEuler(this, rotation);\n\t\t}\n\t\trotateY(delta: number): void {\n\t\t\trotateY(this, delta);\n\t\t}\n\t\trotateZ(delta: number): void {\n\t\t\trotateZ(this, delta);\n\t\t}\n\t\tsetRotationY(y: number): void {\n\t\t\tsetRotationY(this, y);\n\t\t}\n\t\tsetRotationX(x: number): void {\n\t\t\tsetRotationX(this, x);\n\t\t}\n\t\tsetRotationZ(z: number): void {\n\t\t\tsetRotationZ(this, z);\n\t\t}\n\t\tsetRotationDegrees(x: number, y: number, z: number): void {\n\t\t\tsetRotationDegrees(this, x, y, z);\n\t\t}\n\t\tsetRotationDegreesY(y: number): void {\n\t\t\tsetRotationDegreesY(this, y);\n\t\t}\n\t\tsetRotationDegreesX(x: number): void {\n\t\t\tsetRotationDegreesX(this, x);\n\t\t}\n\t\tsetRotationDegreesZ(z: number): void {\n\t\t\tsetRotationDegreesZ(this, z);\n\t\t}\n\t\tsetRotation(x: number, y: number, z: number): void {\n\t\t\tsetRotation(this, x, y, z);\n\t\t}\n\t\tgetRotation(): any {\n\t\t\treturn getRotation(this);\n\t\t}\n\t};\n}\n\n/**\n * Enhance an entity instance with rotatable methods\n */\nexport function makeRotatable<T extends RotatableEntity>(entity: T): T & RotatableEntityAPI {\n\tconst rotatableEntity = entity as T & RotatableEntityAPI;\n\n\trotatableEntity.rotateInDirection = (moveVector: Vector3) => rotateInDirection(entity, moveVector);\n\trotatableEntity.rotateYEuler = (amount: number) => rotateYEuler(entity, amount);\n\trotatableEntity.rotateEuler = (rotation: Vector3) => rotateEuler(entity, rotation);\n\trotatableEntity.rotateY = (delta: number) => rotateY(entity, delta);\n\trotatableEntity.rotateZ = (delta: number) => rotateZ(entity, delta);\n\trotatableEntity.setRotationY = (y: number) => setRotationY(entity, y);\n\trotatableEntity.setRotationX = (x: number) => setRotationX(entity, x);\n\trotatableEntity.setRotationZ = (z: number) => setRotationZ(entity, z);\n\trotatableEntity.setRotationDegreesY = (y: number) => setRotationDegreesY(entity, y);\n\trotatableEntity.setRotationDegreesX = (x: number) => setRotationDegreesX(entity, x);\n\trotatableEntity.setRotationDegreesZ = (z: number) => setRotationDegreesZ(entity, z);\n\trotatableEntity.setRotationDegrees = (x: number, y: number, z: number) => setRotationDegrees(entity, x, y, z);\n\trotatableEntity.setRotation = (x: number, y: number, z: number) => setRotation(entity, x, y, z);\n\trotatableEntity.getRotation = () => getRotation(entity);\n\n\treturn rotatableEntity;\n}","import { makeMoveable, EntityWithBody, MoveableEntity } from './moveable';\nimport { makeRotatable, RotatableEntity, RotatableEntityAPI } from './rotatable';\n\n/**\n * Enhance an entity with both movement and rotation capabilities.\n */\nexport function makeTransformable<\n\tT extends RotatableEntity & EntityWithBody\n>(entity: T): T & MoveableEntity & RotatableEntityAPI {\n\tconst withMovement = makeMoveable(entity);\n\tconst withRotation = makeRotatable(withMovement);\n\treturn withRotation;\n}\n\n\n"],"mappings":";;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,SAAS,KAAK,OAAe,UAAoB;AAEvD,aAAW,UAAU,KAAK;AAC3B;AAEO,IAAM,gBAAiB,uBAAM;AACnC,MAAI,gBAAgB;AAEpB,SAAO,CAAC,WAAoB,aAAuB;AAClD,QAAI,aAAa,CAAC,eAAe;AAChC,sBAAgB;AAChB,eAAS;AAAA,IACV,WAAW,CAAC,WAAW;AACtB,sBAAgB;AAAA,IACjB;AAAA,EACD;AACD,GAAG;AAEI,IAAM,kBAAmB,uBAAM;AACrC,MAAI,gBAAgB;AAEpB,SAAO,CAAC,WAAoB,aAAuB;AAClD,QAAI,CAAC,aAAa,eAAe;AAChC,sBAAgB;AAChB,eAAS;AAAA,IACV,WAAW,WAAW;AACrB,sBAAgB;AAAA,IACjB;AAAA,EACD;AACD,GAAG;AAII,IAAM,qBAAsB,uBAAM;AACxC,MAAI,oBAAoB;AACxB,MAAI,gBAAgB;AAEpB,SAAO,CAAC,EAAE,OAAO,YAAY,KAAK,GAAoB,UAAoB,WAAqB;AAC9F,QAAI,cAAc,KAAK,IAAI;AAE3B,QAAI,CAAC,iBAAiB,CAAC,WAAW;AACjC,sBAAgB;AAChB,0BAAoB;AAAA,IACrB;AAEA,UAAM,QA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,kBAAgB,eAAe,CAAC,MAAc,aAAa,QAAQ,CAAC;AACpE,kBAAgB,sBAAsB,CAAC,MAAc,oBAAoB,QAAQ,CAAC;AAClF,kBAAgB,sBAAsB,CAAC,MAAc,oBAAoB,QAAQ,CAAC;AAClF,kBAAgB,sBAAsB,CAAC,MAAc,oBAAoB,QAAQ,CAAC;AAClF,kBAAgB,qBAAqB,CAAC,GAAW,GAAW,MAAc,mBAAmB,QAAQ,GAAG,GAAG,CAAC;AAC5G,kBAAgB,cAAc,CAAC,GAAW,GAAW,MAAc,YAAY,QAAQ,GAAG,GAAG,CAAC;AAC9F,kBAAgB,cAAc,MAAM,YAAY,MAAM;AAEtD,SAAO;AACR;;;ACvNO,SAAS,kBAEd,QAAoD;AACrD,QAAM,eAAe,aAAa,MAAM;AACxC,QAAM,eAAe,cAAc,YAAY;AAC/C,SAAO;AACR;","names":["Vector3"]}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { G as GameEntity, m as CollisionContext, U as UpdateContext, B as BehaviorCallbackType } from './entity-bQElAdpo.js';
|
|
2
|
+
import { M as MoveableEntity } from './moveable-B_vyA6cw.js';
|
|
3
|
+
import { Vector } from '@dimforge/rapier3d-compat';
|
|
4
|
+
import 'three';
|
|
5
|
+
import 'bitecs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A branded bitmask representing a set of collision types.
|
|
9
|
+
* Construct with {@link buildCollisionMask}.
|
|
10
|
+
*/
|
|
11
|
+
type CollisionMask = number & {
|
|
12
|
+
readonly __brand: "CollisionMask";
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
type NameSelector = string | string[] | RegExp;
|
|
16
|
+
type CollisionSelector = {
|
|
17
|
+
name: NameSelector;
|
|
18
|
+
} | {
|
|
19
|
+
mask: CollisionMask | RegExp;
|
|
20
|
+
} | {
|
|
21
|
+
test: (other: GameEntity<any>) => boolean;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Behavior for ricocheting an entity off other objects in 2D
|
|
26
|
+
*/
|
|
27
|
+
declare function ricochet2DCollision(options?: Partial<Ricochet2DCollisionOptions>, callback?: Ricochet2DCollisionCallback): {
|
|
28
|
+
type: 'collision';
|
|
29
|
+
handler: (ctx: CollisionContext<MoveableEntity, GameEntity<any>>) => void;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
interface RicochetEvent extends Partial<UpdateContext<MoveableEntity>> {
|
|
33
|
+
boundary?: 'top' | 'bottom' | 'left' | 'right';
|
|
34
|
+
position: Vector;
|
|
35
|
+
velocityBefore: Vector;
|
|
36
|
+
velocityAfter: Vector;
|
|
37
|
+
}
|
|
38
|
+
interface RicochetCollisionEvent extends CollisionContext<MoveableEntity, GameEntity<any>> {
|
|
39
|
+
position: Vector;
|
|
40
|
+
}
|
|
41
|
+
interface Ricochet2DInBoundsOptions {
|
|
42
|
+
restitution?: number;
|
|
43
|
+
minSpeed?: number;
|
|
44
|
+
maxSpeed?: number;
|
|
45
|
+
boundaries: {
|
|
46
|
+
top: number;
|
|
47
|
+
bottom: number;
|
|
48
|
+
left: number;
|
|
49
|
+
right: number;
|
|
50
|
+
};
|
|
51
|
+
separation?: number;
|
|
52
|
+
}
|
|
53
|
+
interface Ricochet2DCollisionOptions {
|
|
54
|
+
restitution?: number;
|
|
55
|
+
minSpeed?: number;
|
|
56
|
+
maxSpeed?: number;
|
|
57
|
+
separation?: number;
|
|
58
|
+
collisionWith?: CollisionSelector;
|
|
59
|
+
/**
|
|
60
|
+
* Choose between simple axis inversion or angled (paddle-style) reflection.
|
|
61
|
+
* Defaults to 'angled'.
|
|
62
|
+
*/
|
|
63
|
+
reflectionMode?: 'simple' | 'angled';
|
|
64
|
+
}
|
|
65
|
+
type Ricochet2DCallback = (event: RicochetEvent) => void;
|
|
66
|
+
type Ricochet2DCollisionCallback = (event: RicochetCollisionEvent) => void;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Behavior for ricocheting an entity within fixed 2D boundaries
|
|
70
|
+
*/
|
|
71
|
+
declare function ricochet2DInBounds(options?: Partial<Ricochet2DInBoundsOptions>, callback?: Ricochet2DCallback): {
|
|
72
|
+
type: BehaviorCallbackType;
|
|
73
|
+
handler: (ctx: UpdateContext<MoveableEntity>) => void;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
interface BoundaryEvent {
|
|
77
|
+
me: MoveableEntity;
|
|
78
|
+
boundary: BoundaryHits;
|
|
79
|
+
position: Vector;
|
|
80
|
+
updateContext: UpdateContext<MoveableEntity>;
|
|
81
|
+
}
|
|
82
|
+
interface BoundaryOptions {
|
|
83
|
+
boundaries: {
|
|
84
|
+
top: number;
|
|
85
|
+
bottom: number;
|
|
86
|
+
left: number;
|
|
87
|
+
right: number;
|
|
88
|
+
};
|
|
89
|
+
onBoundary?: (event: BoundaryEvent) => void;
|
|
90
|
+
stopMovement?: boolean;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Checks if the entity has hit a boundary and stops its movement if it has
|
|
94
|
+
*
|
|
95
|
+
* @param options Configuration options for the boundary behavior
|
|
96
|
+
* @param options.boundaries The boundaries of the stage
|
|
97
|
+
* @param options.onBoundary A callback function that is called when the entity hits a boundary
|
|
98
|
+
* @param options.stopMovement Whether to stop the entity's movement when it hits a boundary
|
|
99
|
+
* @returns A behavior callback with type 'update' and a handler function
|
|
100
|
+
*/
|
|
101
|
+
declare function boundary2d(options?: Partial<BoundaryOptions>): {
|
|
102
|
+
type: BehaviorCallbackType;
|
|
103
|
+
handler: (ctx: UpdateContext<MoveableEntity>) => void;
|
|
104
|
+
};
|
|
105
|
+
type BoundaryHit = 'top' | 'bottom' | 'left' | 'right';
|
|
106
|
+
type BoundaryHits = Record<BoundaryHit, boolean>;
|
|
107
|
+
|
|
108
|
+
export { boundary2d, ricochet2DCollision, ricochet2DInBounds };
|