@benev/tact 0.1.0-3 → 0.1.0-4
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 +111 -103
- package/package.json +7 -7
- package/s/core/bindings/action.ts +14 -4
- package/s/core/bindings/parts/defaults.ts +3 -1
- package/s/core/bindings/parts/lens-algo.ts +17 -13
- package/s/core/bindings/resolver.ts +12 -12
- package/s/core/bindings/sample-map.ts +25 -0
- package/s/core/bindings/types.ts +3 -1
- package/s/core/core.test.ts +46 -34
- package/s/core/devices/auto-gamepads.ts +8 -0
- package/s/core/devices/device.ts +12 -0
- package/s/core/devices/infra/group.ts +24 -0
- package/s/core/devices/infra/sampler.ts +22 -0
- package/s/core/devices/standard/gamepad.ts +83 -0
- package/s/core/{controllers → devices}/standard/index.ts +2 -1
- package/s/core/devices/standard/keyboard.ts +31 -0
- package/s/core/{controllers → devices}/standard/pointer.ts +15 -11
- package/s/core/devices/standard/primary.ts +20 -0
- package/s/core/devices/standard/stick.ts +27 -0
- package/s/core/{controllers/standard/virtual-gamepad.ts → devices/standard/vpad.ts} +9 -9
- package/s/core/{controllers → devices}/types.ts +0 -1
- package/s/core/hub/hub.ts +78 -62
- package/s/core/hub/meta-bindings.ts +23 -0
- package/s/core/hub/parts/connected.ts +15 -0
- package/s/core/hub/port.ts +26 -0
- package/s/core/hub/types.ts +5 -6
- package/s/core/index.ts +12 -14
- package/s/core/testing/testing.ts +19 -14
- package/s/deck/deck.ts +77 -0
- package/s/deck/index.ts +14 -0
- package/s/deck/parts/catalog.ts +58 -0
- package/s/deck/parts/db.ts +66 -0
- package/s/deck/parts/device-skins/device-icons.ts +38 -0
- package/s/deck/parts/device-skins/device-skin.ts +29 -0
- package/s/deck/parts/local-storage-kv.ts +8 -0
- package/s/deck/parts/merge-bindings.ts +21 -0
- package/s/deck/parts/overlay-visibility.ts +49 -0
- package/s/deck/views/deck-overlay/component.ts +48 -0
- package/s/deck/views/deck-overlay/style.css.ts +112 -0
- package/s/deck/views/framework.ts +14 -0
- package/s/demo/game/game.ts +85 -0
- package/s/demo/game/parts/agent.ts +10 -0
- package/s/demo/game/parts/game-bindings.ts +20 -0
- package/s/demo/game/parts/logic.ts +24 -0
- package/s/demo/game/parts/player.ts +32 -0
- package/s/demo/game/parts/renderer.ts +113 -0
- package/s/demo/game/parts/state.ts +24 -0
- package/s/demo/game/parts/virtual-device.ts +13 -0
- package/s/demo/main.bundle.ts +6 -12
- package/s/demo/main.css +30 -2
- package/s/demo/ui/tact-demo/component.ts +13 -0
- package/s/demo/ui/tact-demo/style.css.ts +4 -0
- package/s/demo/ui/theater/styles.css.ts +57 -0
- package/s/demo/ui/theater/view.ts +53 -0
- package/s/demo/ui/theater/virtual/style.css.ts +43 -0
- package/s/demo/ui/theater/virtual/view.ts +31 -0
- package/s/demo/ui/utils/loader.ts +5 -0
- package/s/index.html.ts +16 -6
- package/s/index.ts +3 -1
- package/s/nubs/components.ts +14 -0
- package/s/nubs/index.ts +6 -0
- package/s/nubs/lookpad/component.ts +45 -0
- package/s/nubs/stick/component.ts +115 -0
- package/s/nubs/stick/style.css.ts +70 -0
- package/s/nubs/{virtual-gamepad/view.ts → vpad/component.ts} +21 -11
- package/s/nubs/{virtual-gamepad → vpad}/styles.css.ts +1 -0
- package/s/utils/circular-clamp.ts +15 -0
- package/s/utils/dispensers.ts +20 -0
- package/s/utils/split-axis.ts +10 -2
- package/x/core/bindings/action.d.ts +3 -1
- package/x/core/bindings/action.js +12 -4
- package/x/core/bindings/action.js.map +1 -1
- package/x/core/bindings/parts/defaults.js +3 -1
- package/x/core/bindings/parts/defaults.js.map +1 -1
- package/x/core/bindings/parts/lens-algo.js +14 -7
- package/x/core/bindings/parts/lens-algo.js.map +1 -1
- package/x/core/bindings/resolver.d.ts +5 -4
- package/x/core/bindings/resolver.js +12 -10
- package/x/core/bindings/resolver.js.map +1 -1
- package/x/core/bindings/sample-map.d.ts +7 -0
- package/x/core/bindings/sample-map.js +22 -0
- package/x/core/bindings/sample-map.js.map +1 -0
- package/x/core/bindings/types.d.ts +3 -1
- package/x/core/core.test.d.ts +5 -4
- package/x/core/core.test.js +45 -34
- package/x/core/core.test.js.map +1 -1
- package/x/core/devices/auto-gamepads.d.ts +2 -0
- package/x/core/devices/auto-gamepads.js +6 -0
- package/x/core/devices/auto-gamepads.js.map +1 -0
- package/x/core/devices/device.d.ts +5 -0
- package/x/core/devices/device.js +7 -0
- package/x/core/devices/device.js.map +1 -0
- package/x/core/devices/infra/group.d.ts +8 -0
- package/x/core/devices/infra/group.js +21 -0
- package/x/core/devices/infra/group.js.map +1 -0
- package/x/core/devices/infra/sampler.d.ts +9 -0
- package/x/core/devices/infra/sampler.js +18 -0
- package/x/core/devices/infra/sampler.js.map +1 -0
- package/x/core/devices/standard/gamepad.d.ts +11 -0
- package/x/core/devices/standard/gamepad.js +65 -0
- package/x/core/devices/standard/gamepad.js.map +1 -0
- package/x/core/{controllers → devices}/standard/index.d.ts +2 -1
- package/x/core/{controllers → devices}/standard/index.js +2 -1
- package/x/core/devices/standard/index.js.map +1 -0
- package/x/core/devices/standard/keyboard.d.ts +9 -0
- package/x/core/devices/standard/keyboard.js +28 -0
- package/x/core/devices/standard/keyboard.js.map +1 -0
- package/x/core/devices/standard/pointer.d.ts +15 -0
- package/x/core/{controllers → devices}/standard/pointer.js +14 -11
- package/x/core/devices/standard/pointer.js.map +1 -0
- package/x/core/devices/standard/primary.d.ts +10 -0
- package/x/core/devices/standard/primary.js +17 -0
- package/x/core/devices/standard/primary.js.map +1 -0
- package/x/core/devices/standard/stick.d.ts +15 -0
- package/x/core/devices/standard/stick.js +24 -0
- package/x/core/devices/standard/stick.js.map +1 -0
- package/x/core/devices/standard/vpad.d.ts +7 -0
- package/x/core/{controllers/standard/virtual-gamepad.js → devices/standard/vpad.js} +10 -10
- package/x/core/devices/standard/vpad.js.map +1 -0
- package/x/core/{controllers → devices}/types.d.ts +0 -1
- package/x/core/{controllers → devices}/types.js.map +1 -1
- package/x/core/hub/hub.d.ts +27 -23
- package/x/core/hub/hub.js +71 -61
- package/x/core/hub/hub.js.map +1 -1
- package/x/core/hub/meta-bindings.d.ts +2 -0
- package/x/core/hub/meta-bindings.js +21 -0
- package/x/core/hub/meta-bindings.js.map +1 -0
- package/x/core/hub/parts/connected.d.ts +14 -0
- package/x/core/hub/parts/connected.js +12 -0
- package/x/core/hub/parts/connected.js.map +1 -0
- package/x/core/hub/port.d.ts +10 -0
- package/x/core/hub/port.js +19 -0
- package/x/core/hub/port.js.map +1 -0
- package/x/core/hub/types.d.ts +5 -5
- package/x/core/hub/types.js +1 -1
- package/x/core/hub/types.js.map +1 -1
- package/x/core/index.d.ts +12 -12
- package/x/core/index.js +12 -12
- package/x/core/index.js.map +1 -1
- package/x/core/testing/testing.d.ts +13 -11
- package/x/core/testing/testing.js +14 -13
- package/x/core/testing/testing.js.map +1 -1
- package/x/deck/deck.d.ts +35 -0
- package/x/deck/deck.js +50 -0
- package/x/deck/deck.js.map +1 -0
- package/x/deck/index.d.ts +10 -0
- package/x/deck/index.js +11 -0
- package/x/deck/index.js.map +1 -0
- package/x/deck/parts/catalog.d.ts +23 -0
- package/x/deck/parts/catalog.js +35 -0
- package/x/deck/parts/catalog.js.map +1 -0
- package/x/deck/parts/db.d.ts +20 -0
- package/x/deck/parts/db.js +52 -0
- package/x/deck/parts/db.js.map +1 -0
- package/x/deck/parts/device-skins/device-icons.d.ts +12 -0
- package/x/deck/parts/device-skins/device-icons.js +27 -0
- package/x/deck/parts/device-skins/device-icons.js.map +1 -0
- package/x/deck/parts/device-skins/device-skin.d.ts +14 -0
- package/x/deck/parts/device-skins/device-skin.js +22 -0
- package/x/deck/parts/device-skins/device-skin.js.map +1 -0
- package/x/deck/parts/local-storage-kv.js +6 -0
- package/x/deck/parts/local-storage-kv.js.map +1 -0
- package/x/deck/parts/merge-bindings.d.ts +2 -0
- package/x/deck/parts/merge-bindings.js +15 -0
- package/x/deck/parts/merge-bindings.js.map +1 -0
- package/x/deck/parts/overlay-visibility.d.ts +21 -0
- package/x/deck/parts/overlay-visibility.js +35 -0
- package/x/deck/parts/overlay-visibility.js.map +1 -0
- package/x/deck/views/deck-overlay/component.d.ts +2 -0
- package/x/deck/views/deck-overlay/component.js +40 -0
- package/x/deck/views/deck-overlay/component.js.map +1 -0
- package/x/deck/views/deck-overlay/style.css.js +109 -0
- package/x/deck/views/deck-overlay/style.css.js.map +1 -0
- package/x/deck/views/framework.d.ts +3 -0
- package/x/deck/views/framework.js +8 -0
- package/x/deck/views/framework.js.map +1 -0
- package/x/demo/game/game.d.ts +20 -0
- package/x/demo/game/game.js +63 -0
- package/x/demo/game/game.js.map +1 -0
- package/x/demo/game/parts/agent.d.ts +7 -0
- package/x/demo/game/parts/agent.js +8 -0
- package/x/demo/game/parts/agent.js.map +1 -0
- package/x/demo/game/parts/game-bindings.d.ts +15 -0
- package/x/demo/game/parts/game-bindings.js +10 -0
- package/x/demo/game/parts/game-bindings.js.map +1 -0
- package/x/demo/game/parts/logic.d.ts +8 -0
- package/x/demo/game/parts/logic.js +21 -0
- package/x/demo/game/parts/logic.js.map +1 -0
- package/x/demo/game/parts/player.d.ts +14 -0
- package/x/demo/game/parts/player.js +26 -0
- package/x/demo/game/parts/player.js.map +1 -0
- package/x/demo/game/parts/renderer.d.ts +13 -0
- package/x/demo/game/parts/renderer.js +91 -0
- package/x/demo/game/parts/renderer.js.map +1 -0
- package/x/demo/game/parts/state.d.ts +8 -0
- package/x/demo/game/parts/state.js +20 -0
- package/x/demo/game/parts/state.js.map +1 -0
- package/x/demo/game/parts/virtual-device.d.ts +8 -0
- package/x/demo/game/parts/virtual-device.js +11 -0
- package/x/demo/game/parts/virtual-device.js.map +1 -0
- package/x/demo/main.bundle.js +4 -10
- package/x/demo/main.bundle.js.map +1 -1
- package/x/demo/main.bundle.min.js +315 -54
- package/x/demo/main.bundle.min.js.map +4 -4
- package/x/demo/main.css +30 -2
- package/x/demo/ui/tact-demo/component.d.ts +4 -0
- package/x/demo/ui/tact-demo/component.js +12 -0
- package/x/demo/ui/tact-demo/component.js.map +1 -0
- package/x/demo/ui/tact-demo/style.css.d.ts +2 -0
- package/x/demo/ui/tact-demo/style.css.js +3 -0
- package/x/demo/ui/tact-demo/style.css.js.map +1 -0
- package/x/demo/ui/theater/styles.css.js +56 -0
- package/x/demo/ui/theater/styles.css.js.map +1 -0
- package/x/demo/ui/theater/view.d.ts +2 -0
- package/x/demo/ui/theater/view.js +42 -0
- package/x/demo/ui/theater/view.js.map +1 -0
- package/x/demo/ui/theater/virtual/style.css.d.ts +2 -0
- package/x/demo/ui/theater/virtual/style.css.js +42 -0
- package/x/demo/ui/theater/virtual/style.css.js.map +1 -0
- package/x/demo/ui/theater/virtual/view.d.ts +4 -0
- package/x/demo/ui/theater/virtual/view.js +19 -0
- package/x/demo/ui/theater/virtual/view.js.map +1 -0
- package/x/demo/ui/utils/loader.d.ts +1 -0
- package/x/demo/ui/utils/loader.js +3 -0
- package/x/demo/ui/utils/loader.js.map +1 -0
- package/x/index.d.ts +3 -1
- package/x/index.html +47 -8
- package/x/index.html.js +16 -6
- package/x/index.html.js.map +1 -1
- package/x/index.js +3 -1
- package/x/index.js.map +1 -1
- package/x/nubs/components.d.ts +9 -0
- package/x/nubs/components.js +11 -0
- package/x/nubs/components.js.map +1 -0
- package/x/nubs/index.d.ts +4 -0
- package/x/nubs/index.js +5 -0
- package/x/nubs/index.js.map +1 -0
- package/x/nubs/lookpad/component.d.ts +4 -0
- package/x/nubs/lookpad/component.js +36 -0
- package/x/nubs/lookpad/component.js.map +1 -0
- package/x/nubs/stick/component.d.ts +368 -0
- package/x/nubs/stick/component.js +101 -0
- package/x/nubs/stick/component.js.map +1 -0
- package/x/nubs/stick/style.css.d.ts +2 -0
- package/x/nubs/stick/style.css.js +69 -0
- package/x/nubs/stick/style.css.js.map +1 -0
- package/x/nubs/vpad/component.d.ts +368 -0
- package/x/nubs/{virtual-gamepad/view.js → vpad/component.js} +20 -11
- package/x/nubs/vpad/component.js.map +1 -0
- package/x/nubs/vpad/styles.css.d.ts +2 -0
- package/x/nubs/vpad/styles.css.js.map +1 -0
- package/x/nubs/vpad/utils/gamepad-inputs.js.map +1 -0
- package/x/nubs/vpad/utils/prevent-default-touch-shenanigans.js.map +1 -0
- package/x/nubs/vpad/utils/touch-tracking.js.map +1 -0
- package/x/utils/circular-clamp.d.ts +2 -0
- package/x/utils/circular-clamp.js +8 -0
- package/x/utils/circular-clamp.js.map +1 -0
- package/x/utils/dispensers.d.ts +7 -0
- package/x/utils/dispensers.js +16 -0
- package/x/utils/dispensers.js.map +1 -0
- package/x/utils/split-axis.d.ts +7 -0
- package/x/utils/split-axis.js +7 -2
- package/x/utils/split-axis.js.map +1 -1
- package/s/core/controllers/controller.ts +0 -7
- package/s/core/controllers/infra/group.ts +0 -17
- package/s/core/controllers/infra/sampler.ts +0 -22
- package/s/core/controllers/standard/gamepad.ts +0 -77
- package/s/core/controllers/standard/keyboard.ts +0 -50
- package/s/core/controllers/standard/stick.ts +0 -30
- package/s/core/deck/deck.ts +0 -40
- package/s/core/deck/parts/bindings-depot.ts +0 -24
- package/s/core/deck/parts/local-storage-kv.ts +0 -7
- package/s/core/hub/auto-gamepads.ts +0 -8
- package/s/core/hub/bindings.ts +0 -18
- package/s/core/port/port.ts +0 -34
- package/s/core/port/utils/aggregate_samples_into_map.ts +0 -20
- package/s/core/port/utils/wipe_samples_map.ts +0 -8
- package/s/nubs/lookpad/utils/listeners.ts +0 -53
- package/s/nubs/lookpad/view.ts +0 -32
- package/s/nubs/stick/styles.ts +0 -22
- package/s/nubs/stick/utils/calculate_new_vector_from_pointer_position.ts +0 -27
- package/s/nubs/stick/utils/find_closest_point_on_circle.ts +0 -15
- package/s/nubs/stick/utils/make_pointer_listeners.ts +0 -50
- package/s/nubs/stick/utils/within_radius.ts +0 -6
- package/s/nubs/stick/view.ts +0 -50
- package/s/nubs/stick-graphic/styles.ts +0 -38
- package/s/nubs/stick-graphic/types/basis.ts +0 -5
- package/s/nubs/stick-graphic/utils/calculate_basis.ts +0 -19
- package/s/nubs/stick-graphic/utils/stick_vector_to_pixels.ts +0 -13
- package/s/nubs/stick-graphic/utils/transform.ts +0 -10
- package/s/nubs/stick-graphic/view.ts +0 -43
- package/x/core/controllers/controller.d.ts +0 -4
- package/x/core/controllers/controller.js +0 -3
- package/x/core/controllers/controller.js.map +0 -1
- package/x/core/controllers/infra/group.d.ts +0 -7
- package/x/core/controllers/infra/group.js +0 -13
- package/x/core/controllers/infra/group.js.map +0 -1
- package/x/core/controllers/infra/sampler.d.ts +0 -8
- package/x/core/controllers/infra/sampler.js +0 -17
- package/x/core/controllers/infra/sampler.js.map +0 -1
- package/x/core/controllers/standard/gamepad.d.ts +0 -9
- package/x/core/controllers/standard/gamepad.js +0 -66
- package/x/core/controllers/standard/gamepad.js.map +0 -1
- package/x/core/controllers/standard/index.js.map +0 -1
- package/x/core/controllers/standard/keyboard.d.ts +0 -9
- package/x/core/controllers/standard/keyboard.js +0 -39
- package/x/core/controllers/standard/keyboard.js.map +0 -1
- package/x/core/controllers/standard/pointer.d.ts +0 -11
- package/x/core/controllers/standard/pointer.js.map +0 -1
- package/x/core/controllers/standard/stick.d.ts +0 -15
- package/x/core/controllers/standard/stick.js +0 -27
- package/x/core/controllers/standard/stick.js.map +0 -1
- package/x/core/controllers/standard/virtual-gamepad.d.ts +0 -7
- package/x/core/controllers/standard/virtual-gamepad.js.map +0 -1
- package/x/core/deck/deck.d.ts +0 -16
- package/x/core/deck/deck.js +0 -31
- package/x/core/deck/deck.js.map +0 -1
- package/x/core/deck/parts/bindings-depot.d.ts +0 -9
- package/x/core/deck/parts/bindings-depot.js +0 -19
- package/x/core/deck/parts/bindings-depot.js.map +0 -1
- package/x/core/deck/parts/local-storage-kv.js +0 -5
- package/x/core/deck/parts/local-storage-kv.js.map +0 -1
- package/x/core/hub/auto-gamepads.d.ts +0 -2
- package/x/core/hub/auto-gamepads.js +0 -6
- package/x/core/hub/auto-gamepads.js.map +0 -1
- package/x/core/hub/bindings.d.ts +0 -2
- package/x/core/hub/bindings.js +0 -16
- package/x/core/hub/bindings.js.map +0 -1
- package/x/core/port/port.d.ts +0 -12
- package/x/core/port/port.js +0 -25
- package/x/core/port/port.js.map +0 -1
- package/x/core/port/utils/aggregate_samples_into_map.d.ts +0 -3
- package/x/core/port/utils/aggregate_samples_into_map.js +0 -11
- package/x/core/port/utils/aggregate_samples_into_map.js.map +0 -1
- package/x/core/port/utils/wipe_samples_map.d.ts +0 -2
- package/x/core/port/utils/wipe_samples_map.js +0 -5
- package/x/core/port/utils/wipe_samples_map.js.map +0 -1
- package/x/nubs/lookpad/utils/listeners.d.ts +0 -19
- package/x/nubs/lookpad/utils/listeners.js +0 -37
- package/x/nubs/lookpad/utils/listeners.js.map +0 -1
- package/x/nubs/lookpad/view.d.ts +0 -1
- package/x/nubs/lookpad/view.js +0 -24
- package/x/nubs/lookpad/view.js.map +0 -1
- package/x/nubs/stick/styles.d.ts +0 -1
- package/x/nubs/stick/styles.js +0 -22
- package/x/nubs/stick/styles.js.map +0 -1
- package/x/nubs/stick/utils/calculate_new_vector_from_pointer_position.d.ts +0 -3
- package/x/nubs/stick/utils/calculate_new_vector_from_pointer_position.js +0 -16
- package/x/nubs/stick/utils/calculate_new_vector_from_pointer_position.js.map +0 -1
- package/x/nubs/stick/utils/find_closest_point_on_circle.d.ts +0 -2
- package/x/nubs/stick/utils/find_closest_point_on_circle.js +0 -6
- package/x/nubs/stick/utils/find_closest_point_on_circle.js.map +0 -1
- package/x/nubs/stick/utils/make_pointer_listeners.d.ts +0 -16
- package/x/nubs/stick/utils/make_pointer_listeners.js +0 -34
- package/x/nubs/stick/utils/make_pointer_listeners.js.map +0 -1
- package/x/nubs/stick/utils/within_radius.d.ts +0 -2
- package/x/nubs/stick/utils/within_radius.js +0 -4
- package/x/nubs/stick/utils/within_radius.js.map +0 -1
- package/x/nubs/stick/view.d.ts +0 -2
- package/x/nubs/stick/view.js +0 -38
- package/x/nubs/stick/view.js.map +0 -1
- package/x/nubs/stick-graphic/styles.js +0 -38
- package/x/nubs/stick-graphic/styles.js.map +0 -1
- package/x/nubs/stick-graphic/types/basis.d.ts +0 -4
- package/x/nubs/stick-graphic/types/basis.js +0 -2
- package/x/nubs/stick-graphic/types/basis.js.map +0 -1
- package/x/nubs/stick-graphic/utils/calculate_basis.d.ts +0 -2
- package/x/nubs/stick-graphic/utils/calculate_basis.js +0 -10
- package/x/nubs/stick-graphic/utils/calculate_basis.js.map +0 -1
- package/x/nubs/stick-graphic/utils/stick_vector_to_pixels.d.ts +0 -2
- package/x/nubs/stick-graphic/utils/stick_vector_to_pixels.js +0 -7
- package/x/nubs/stick-graphic/utils/stick_vector_to_pixels.js.map +0 -1
- package/x/nubs/stick-graphic/utils/transform.d.ts +0 -2
- package/x/nubs/stick-graphic/utils/transform.js +0 -7
- package/x/nubs/stick-graphic/utils/transform.js.map +0 -1
- package/x/nubs/stick-graphic/view.d.ts +0 -3
- package/x/nubs/stick-graphic/view.js +0 -30
- package/x/nubs/stick-graphic/view.js.map +0 -1
- package/x/nubs/virtual-gamepad/styles.css.js.map +0 -1
- package/x/nubs/virtual-gamepad/utils/gamepad-inputs.js.map +0 -1
- package/x/nubs/virtual-gamepad/utils/prevent-default-touch-shenanigans.js.map +0 -1
- package/x/nubs/virtual-gamepad/utils/touch-tracking.js.map +0 -1
- package/x/nubs/virtual-gamepad/view.d.ts +0 -2
- package/x/nubs/virtual-gamepad/view.js.map +0 -1
- /package/s/nubs/{virtual-gamepad → vpad}/utils/gamepad-inputs.ts +0 -0
- /package/s/nubs/{virtual-gamepad → vpad}/utils/prevent-default-touch-shenanigans.ts +0 -0
- /package/s/nubs/{virtual-gamepad → vpad}/utils/touch-tracking.ts +0 -0
- /package/x/core/{controllers → devices}/types.js +0 -0
- /package/x/{core/deck → deck}/parts/local-storage-kv.d.ts +0 -0
- /package/x/{nubs/virtual-gamepad/styles.css.d.ts → deck/views/deck-overlay/style.css.d.ts} +0 -0
- /package/x/{nubs/stick-graphic/styles.d.ts → demo/ui/theater/styles.css.d.ts} +0 -0
- /package/x/nubs/{virtual-gamepad → vpad}/styles.css.js +0 -0
- /package/x/nubs/{virtual-gamepad → vpad}/utils/gamepad-inputs.d.ts +0 -0
- /package/x/nubs/{virtual-gamepad → vpad}/utils/gamepad-inputs.js +0 -0
- /package/x/nubs/{virtual-gamepad → vpad}/utils/prevent-default-touch-shenanigans.d.ts +0 -0
- /package/x/nubs/{virtual-gamepad → vpad}/utils/prevent-default-touch-shenanigans.js +0 -0
- /package/x/nubs/{virtual-gamepad → vpad}/utils/touch-tracking.d.ts +0 -0
- /package/x/nubs/{virtual-gamepad → vpad}/utils/touch-tracking.js +0 -0
package/s/core/core.test.ts
CHANGED
|
@@ -1,88 +1,100 @@
|
|
|
1
1
|
|
|
2
2
|
import {Science, test, expect} from "@e280/science"
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import {metaMode} from "./hub/types.js"
|
|
4
|
+
import {SamplerDevice} from "./devices/infra/sampler.js"
|
|
5
|
+
import {testPlug, testSetupAlpha, testSetupBravo} from "./testing/testing.js"
|
|
5
6
|
|
|
6
7
|
export default Science.suite({
|
|
7
8
|
"sample to action value": test(async() => {
|
|
8
|
-
const {
|
|
9
|
+
const {time, device, resolve} = testSetupAlpha()
|
|
9
10
|
{
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
time.frame = 1
|
|
12
|
+
device.setSample("Space", 1)
|
|
13
|
+
const actions = resolve()
|
|
12
14
|
expect(actions.basic.jump.value).is(1)
|
|
13
15
|
expect(actions.basic.shoot.value).is(0)
|
|
14
16
|
}
|
|
15
17
|
{
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
time.frame = 2
|
|
19
|
+
device.setSample("Space", 2)
|
|
20
|
+
device.setSample("pointer.button.left", 3)
|
|
21
|
+
const actions = resolve()
|
|
19
22
|
expect(actions.basic.jump.value).is(2)
|
|
20
23
|
expect(actions.basic.shoot.value).is(3)
|
|
21
24
|
}
|
|
22
25
|
}),
|
|
23
26
|
|
|
24
27
|
"hub": Science.suite({
|
|
25
|
-
"
|
|
28
|
+
"device inputs work": test(async() => {
|
|
26
29
|
const {hub, time} = testSetupBravo()
|
|
27
|
-
const
|
|
28
|
-
|
|
30
|
+
const d1 = testPlug(hub, new SamplerDevice())
|
|
31
|
+
d1.setSample("Space", 1)
|
|
29
32
|
const [p1, p2] = hub.poll(time.now)
|
|
30
|
-
expect(p1.basic.jump.value).is(1)
|
|
31
|
-
expect(p2.basic.jump.value).is(0)
|
|
33
|
+
expect(p1.actions.basic.jump.value).is(1)
|
|
34
|
+
expect(p2.actions.basic.jump.value).is(0)
|
|
35
|
+
}),
|
|
36
|
+
|
|
37
|
+
"reveal overlay works": test(async() => {
|
|
38
|
+
const {hub, time} = testSetupBravo()
|
|
39
|
+
const d1 = testPlug(hub, new SamplerDevice())
|
|
40
|
+
d1.setSample("Backslash", 1)
|
|
41
|
+
hub.poll(time.now)
|
|
42
|
+
expect(hub.metaPort.actions[metaMode].revealOverlay.value)
|
|
43
|
+
.is(1)
|
|
32
44
|
}),
|
|
33
45
|
|
|
34
|
-
"two
|
|
46
|
+
"two devices playing on separate ports": test(async() => {
|
|
35
47
|
const {hub, time} = testSetupBravo()
|
|
36
|
-
const c1 =
|
|
37
|
-
const c2 =
|
|
48
|
+
const c1 = testPlug(hub, new SamplerDevice())
|
|
49
|
+
const c2 = testPlug(hub, new SamplerDevice())
|
|
38
50
|
c1.setSample("Space", 1)
|
|
39
51
|
c2.setSample("Space", 2)
|
|
40
52
|
const [p1, p2] = hub.poll(time.now)
|
|
41
|
-
expect(p1.basic.jump.value).is(1)
|
|
42
|
-
expect(p2.basic.jump.value).is(2)
|
|
53
|
+
expect(p1.actions.basic.jump.value).is(1)
|
|
54
|
+
expect(p2.actions.basic.jump.value).is(2)
|
|
43
55
|
}),
|
|
44
56
|
|
|
45
|
-
"
|
|
57
|
+
"device can shimmy": test(async() => {
|
|
46
58
|
const {hub, time} = testSetupBravo()
|
|
47
|
-
const c1 =
|
|
59
|
+
const c1 = testPlug(hub, new SamplerDevice())
|
|
48
60
|
hub.shimmy(c1, 1)
|
|
49
61
|
c1.setSample("Space", 1)
|
|
50
62
|
const [p1, p2] = hub.poll(time.now)
|
|
51
|
-
expect(p1.basic.jump.value).is(0)
|
|
52
|
-
expect(p2.basic.jump.value).is(1)
|
|
63
|
+
expect(p1.actions.basic.jump.value).is(0)
|
|
64
|
+
expect(p2.actions.basic.jump.value).is(1)
|
|
53
65
|
}),
|
|
54
66
|
|
|
55
|
-
"two
|
|
67
|
+
"two devices can share a port": test(async() => {
|
|
56
68
|
const {hub, time} = testSetupBravo()
|
|
57
|
-
const c1 =
|
|
58
|
-
const c2 =
|
|
69
|
+
const c1 = testPlug(hub, new SamplerDevice())
|
|
70
|
+
const c2 = testPlug(hub, new SamplerDevice())
|
|
59
71
|
hub.shimmy(c2, -1)
|
|
60
|
-
expect(hub.
|
|
72
|
+
expect(hub.portByDevice(c1)).is(hub.portByDevice(c2))
|
|
61
73
|
{
|
|
62
74
|
c1.setSample("Space", 1)
|
|
63
75
|
const [p1, p2] = hub.poll(time.now)
|
|
64
|
-
expect(p1.basic.jump.value).is(1)
|
|
65
|
-
expect(p2.basic.jump.value).is(0)
|
|
76
|
+
expect(p1.actions.basic.jump.value).is(1)
|
|
77
|
+
expect(p2.actions.basic.jump.value).is(0)
|
|
66
78
|
}
|
|
67
79
|
{
|
|
68
80
|
c2.setSample("Space", 1)
|
|
69
81
|
const [p1, p2] = hub.poll(time.now)
|
|
70
|
-
expect(p1.basic.jump.value).is(1)
|
|
71
|
-
expect(p2.basic.jump.value).is(0)
|
|
82
|
+
expect(p1.actions.basic.jump.value).is(1)
|
|
83
|
+
expect(p2.actions.basic.jump.value).is(0)
|
|
72
84
|
}
|
|
73
85
|
{
|
|
74
86
|
c1.setSample("Space", 1)
|
|
75
87
|
c2.setSample("Space", 2)
|
|
76
88
|
const [p1, p2] = hub.poll(time.now)
|
|
77
|
-
expect(p1.basic.jump.value).is(2)
|
|
78
|
-
expect(p2.basic.jump.value).is(0)
|
|
89
|
+
expect(p1.actions.basic.jump.value).is(2)
|
|
90
|
+
expect(p2.actions.basic.jump.value).is(0)
|
|
79
91
|
}
|
|
80
92
|
{
|
|
81
93
|
c1.setSample("Space", 2)
|
|
82
94
|
c2.setSample("Space", 1)
|
|
83
95
|
const [p1, p2] = hub.poll(time.now)
|
|
84
|
-
expect(p1.basic.jump.value).is(2)
|
|
85
|
-
expect(p2.basic.jump.value).is(0)
|
|
96
|
+
expect(p1.actions.basic.jump.value).is(2)
|
|
97
|
+
expect(p2.actions.basic.jump.value).is(0)
|
|
86
98
|
}
|
|
87
99
|
}),
|
|
88
100
|
}),
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
import {SetG} from "@e280/stz"
|
|
3
|
+
import {Device} from "../device.js"
|
|
4
|
+
import {SampleMap} from "../../bindings/sample-map.js"
|
|
5
|
+
|
|
6
|
+
export class GroupDevice extends Device {
|
|
7
|
+
devices = new SetG<Device>()
|
|
8
|
+
#sampleMap = new SampleMap()
|
|
9
|
+
|
|
10
|
+
constructor(...devices: Device[]) {
|
|
11
|
+
super()
|
|
12
|
+
this.devices.adds(...devices)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
;*samples() {
|
|
16
|
+
this.#sampleMap.zero()
|
|
17
|
+
for (const device of this.devices) {
|
|
18
|
+
for (const sample of device.samples())
|
|
19
|
+
this.#sampleMap.mergeSample(sample)
|
|
20
|
+
}
|
|
21
|
+
yield* this.#sampleMap.entries()
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
import {sub} from "@e280/stz"
|
|
3
|
+
import {Sample} from "../types.js"
|
|
4
|
+
import {Device} from "../device.js"
|
|
5
|
+
import {SampleMap} from "../../bindings/sample-map.js"
|
|
6
|
+
|
|
7
|
+
export class SamplerDevice extends Device {
|
|
8
|
+
on = sub<Sample>()
|
|
9
|
+
sampleMap = new SampleMap()
|
|
10
|
+
|
|
11
|
+
setSample(code: string, value: number) {
|
|
12
|
+
this.sampleMap.set(code, value)
|
|
13
|
+
this.on.pub(code, value)
|
|
14
|
+
return this
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
;*samples() {
|
|
18
|
+
for (const sample of this.sampleMap)
|
|
19
|
+
yield sample as Sample
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
|
|
2
|
+
import {Vec2} from "@benev/math"
|
|
3
|
+
import {Pad} from "../../../utils/gamepads.js"
|
|
4
|
+
import {SamplerDevice} from "../infra/sampler.js"
|
|
5
|
+
import {splitVector} from "../../../utils/split-axis.js"
|
|
6
|
+
import {circularClamp} from "../../../utils/circular-clamp.js"
|
|
7
|
+
|
|
8
|
+
const gamepadButtonCodes = [
|
|
9
|
+
"gamepad.a",
|
|
10
|
+
"gamepad.b",
|
|
11
|
+
"gamepad.x",
|
|
12
|
+
"gamepad.y",
|
|
13
|
+
"gamepad.bumper.left",
|
|
14
|
+
"gamepad.bumper.right",
|
|
15
|
+
"gamepad.trigger.left",
|
|
16
|
+
"gamepad.trigger.right",
|
|
17
|
+
"gamepad.alpha",
|
|
18
|
+
"gamepad.beta",
|
|
19
|
+
"gamepad.stick.left.click",
|
|
20
|
+
"gamepad.stick.right.click",
|
|
21
|
+
"gamepad.up",
|
|
22
|
+
"gamepad.down",
|
|
23
|
+
"gamepad.left",
|
|
24
|
+
"gamepad.right",
|
|
25
|
+
"gamepad.gamma",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
export class GamepadDevice extends SamplerDevice {
|
|
29
|
+
range = new Vec2(0.2, 0.9)
|
|
30
|
+
|
|
31
|
+
constructor(public pad: Pad) {
|
|
32
|
+
super()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get gamepad() {
|
|
36
|
+
return this.pad.gamepad
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
samples() {
|
|
40
|
+
this.#pollButtons(this.pad.gamepad)
|
|
41
|
+
this.#pollSticks(this.pad.gamepad)
|
|
42
|
+
return super.samples()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
#pollButtons(gamepad: Gamepad) {
|
|
46
|
+
let anyButtonValue = 0
|
|
47
|
+
|
|
48
|
+
const recordAny = (value: number) => {
|
|
49
|
+
anyButtonValue = Math.max(anyButtonValue, value)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
for (const [index, code] of gamepadButtonCodes.entries()) {
|
|
53
|
+
const value = gamepad.buttons.at(index)?.value ?? 0
|
|
54
|
+
recordAny(value)
|
|
55
|
+
this.setSample(code, value)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
this.setSample("gamepad.any", anyButtonValue)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
#pollSticks(gamepad: Gamepad) {
|
|
62
|
+
const [leftX, leftY, rightX, rightY] = gamepad.axes
|
|
63
|
+
|
|
64
|
+
const stickLeft = splitVector(
|
|
65
|
+
circularClamp(new Vec2(leftX, leftY), this.range)
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
const stickRight = splitVector(
|
|
69
|
+
circularClamp(new Vec2(rightX, rightY), this.range)
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
this.setSample("gamepad.stick.left.up", stickLeft.up)
|
|
73
|
+
this.setSample("gamepad.stick.left.down", stickLeft.down)
|
|
74
|
+
this.setSample("gamepad.stick.left.left", stickLeft.left)
|
|
75
|
+
this.setSample("gamepad.stick.left.right", stickLeft.right)
|
|
76
|
+
|
|
77
|
+
this.setSample("gamepad.stick.right.up", stickRight.up)
|
|
78
|
+
this.setSample("gamepad.stick.right.down", stickRight.down)
|
|
79
|
+
this.setSample("gamepad.stick.right.left", stickRight.left)
|
|
80
|
+
this.setSample("gamepad.stick.right.right", stickRight.right)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
import {disposer, ev} from "@e280/stz"
|
|
3
|
+
import {SamplerDevice} from "../infra/sampler.js"
|
|
4
|
+
|
|
5
|
+
export class KeyboardDevice extends SamplerDevice {
|
|
6
|
+
dispose = disposer()
|
|
7
|
+
|
|
8
|
+
constructor(target: EventTarget = window) {
|
|
9
|
+
super()
|
|
10
|
+
this.dispose.schedule(ev(target, this.#targetListeners))
|
|
11
|
+
this.dispose.schedule(ev(window, this.#windowListeners))
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
#targetListeners = {
|
|
15
|
+
keydown: (event: KeyboardEvent) => {
|
|
16
|
+
if (event.repeat) return null
|
|
17
|
+
this.setSample(event.code, 1)
|
|
18
|
+
},
|
|
19
|
+
keyup: (event: KeyboardEvent) => {
|
|
20
|
+
if (event.repeat) return null
|
|
21
|
+
this.setSample(event.code, 0)
|
|
22
|
+
},
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
#windowListeners = {
|
|
26
|
+
blur: () => {
|
|
27
|
+
this.sampleMap.zero()
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
|
|
2
|
-
import {ev} from "@e280/stz"
|
|
3
2
|
import {Vec2} from "@benev/math"
|
|
3
|
+
import {disposer, ev} from "@e280/stz"
|
|
4
|
+
import {SamplerDevice} from "../infra/sampler.js"
|
|
4
5
|
import {splitAxis} from "../../../utils/split-axis.js"
|
|
5
|
-
import {SamplerController} from "../infra/sampler.js"
|
|
6
6
|
|
|
7
|
-
export class
|
|
7
|
+
export class PointerDevice extends SamplerDevice {
|
|
8
8
|
client = new Vec2(0, 0)
|
|
9
9
|
movement = new Vec2(0, 0)
|
|
10
|
-
dispose
|
|
10
|
+
dispose = disposer()
|
|
11
11
|
|
|
12
12
|
constructor(target: EventTarget = window) {
|
|
13
13
|
super()
|
|
14
14
|
|
|
15
|
-
this.dispose
|
|
15
|
+
this.dispose.schedule(ev(target, {
|
|
16
16
|
pointerdown: (event: PointerEvent) => {
|
|
17
|
-
const code =
|
|
17
|
+
const code = PointerDevice.buttonCode(event)
|
|
18
18
|
this.setSample(code, 1)
|
|
19
19
|
},
|
|
20
20
|
|
|
21
21
|
pointerup: (event: PointerEvent) => {
|
|
22
|
-
const code =
|
|
22
|
+
const code = PointerDevice.buttonCode(event)
|
|
23
23
|
this.setSample(code, 0)
|
|
24
24
|
},
|
|
25
25
|
|
|
@@ -31,10 +31,10 @@ export class PointerController extends SamplerController {
|
|
|
31
31
|
},
|
|
32
32
|
|
|
33
33
|
wheel: (event: WheelEvent) => {
|
|
34
|
-
for (const [code, value] of
|
|
34
|
+
for (const [code, value] of PointerDevice.wheelCodes(event))
|
|
35
35
|
this.setSample(code, value)
|
|
36
36
|
},
|
|
37
|
-
})
|
|
37
|
+
}))
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
static buttonCode(event: PointerEvent) {
|
|
@@ -64,7 +64,12 @@ export class PointerController extends SamplerController {
|
|
|
64
64
|
return movements
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
samples() {
|
|
68
|
+
this.#specialPreProcessing()
|
|
69
|
+
return super.samples()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
#specialPreProcessing() {
|
|
68
73
|
const [x, y] = this.movement
|
|
69
74
|
const [left, right] = splitAxis(x)
|
|
70
75
|
const [down, up] = splitAxis(y)
|
|
@@ -83,7 +88,6 @@ export class PointerController extends SamplerController {
|
|
|
83
88
|
}
|
|
84
89
|
|
|
85
90
|
this.movement.set_(0, 0)
|
|
86
|
-
return super.takeSamples()
|
|
87
91
|
}
|
|
88
92
|
}
|
|
89
93
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
|
|
2
|
+
import {VpadDevice} from "./vpad.js"
|
|
3
|
+
import {PointerDevice} from "./pointer.js"
|
|
4
|
+
import {KeyboardDevice} from "./keyboard.js"
|
|
5
|
+
import {GroupDevice} from "../infra/group.js"
|
|
6
|
+
|
|
7
|
+
export class PrimaryDevice extends GroupDevice {
|
|
8
|
+
keyboard = new KeyboardDevice()
|
|
9
|
+
pointer = new PointerDevice()
|
|
10
|
+
vpad = new VpadDevice()
|
|
11
|
+
|
|
12
|
+
constructor() {
|
|
13
|
+
super()
|
|
14
|
+
this.devices
|
|
15
|
+
.add(this.keyboard)
|
|
16
|
+
.add(this.pointer)
|
|
17
|
+
.add(this.vpad)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
|
|
2
|
+
import {Vec2} from "@benev/math"
|
|
3
|
+
import {derived, signal} from "@e280/strata"
|
|
4
|
+
import {Sample} from "../types.js"
|
|
5
|
+
import {Device} from "../device.js"
|
|
6
|
+
import {splitVector} from "../../../utils/split-axis.js"
|
|
7
|
+
|
|
8
|
+
export class StickDevice extends Device {
|
|
9
|
+
$vector = signal(Vec2.zero())
|
|
10
|
+
$breakdown = derived(() => splitVector(this.$vector.get()))
|
|
11
|
+
|
|
12
|
+
constructor(public channel = "stick") {
|
|
13
|
+
super()
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
samples() {
|
|
17
|
+
const {channel} = this
|
|
18
|
+
const {up, down, left, right} = this.$breakdown.get()
|
|
19
|
+
return [
|
|
20
|
+
[`${channel}.up`, up],
|
|
21
|
+
[`${channel}.down`, down],
|
|
22
|
+
[`${channel}.left`, left],
|
|
23
|
+
[`${channel}.right`, right],
|
|
24
|
+
] as Sample[]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import {StickDevice} from "./stick.js"
|
|
3
|
+
import {SamplerDevice} from "../infra/sampler.js"
|
|
4
4
|
|
|
5
|
-
export class
|
|
6
|
-
stickLeft = new
|
|
7
|
-
stickRight = new
|
|
5
|
+
export class VpadDevice extends SamplerDevice {
|
|
6
|
+
stickLeft = new StickDevice()
|
|
7
|
+
stickRight = new StickDevice()
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
const left = this.stickLeft
|
|
9
|
+
samples() {
|
|
10
|
+
const left = this.stickLeft.$breakdown()
|
|
11
11
|
this.setSample("gamepad.stick.left.up", left.up)
|
|
12
12
|
this.setSample("gamepad.stick.left.down", left.down)
|
|
13
13
|
this.setSample("gamepad.stick.left.left", left.left)
|
|
14
14
|
this.setSample("gamepad.stick.left.right", left.right)
|
|
15
15
|
|
|
16
|
-
const right = this.stickRight
|
|
16
|
+
const right = this.stickRight.$breakdown()
|
|
17
17
|
this.setSample("gamepad.stick.right.up", right.up)
|
|
18
18
|
this.setSample("gamepad.stick.right.down", right.down)
|
|
19
19
|
this.setSample("gamepad.stick.right.left", right.left)
|
|
20
20
|
this.setSample("gamepad.stick.right.right", right.right)
|
|
21
21
|
|
|
22
|
-
return super.
|
|
22
|
+
return super.samples()
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
package/s/core/hub/hub.ts
CHANGED
|
@@ -1,48 +1,40 @@
|
|
|
1
1
|
|
|
2
|
-
import {SetG} from "@e280/stz"
|
|
3
2
|
import {Scalar} from "@benev/math"
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
3
|
+
import {debounce, MapG, sub} from "@e280/stz"
|
|
4
|
+
import {Port} from "./port.js"
|
|
5
|
+
import {Device} from "../devices/device.js"
|
|
6
|
+
import {Bindings} from "../bindings/types.js"
|
|
7
|
+
import {Connected} from "./parts/connected.js"
|
|
8
|
+
import {MetaBindings, metaMode} from "./types.js"
|
|
9
|
+
import {makeMetaBindings} from "./meta-bindings.js"
|
|
8
10
|
|
|
9
|
-
export class Hub<B extends
|
|
10
|
-
static readonly mode = hubMode
|
|
11
|
-
static readonly bindings = hubBindings
|
|
11
|
+
export class Hub<B extends Bindings, MB extends MetaBindings = any> {
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
/** event fires whenever a device changes ports. */
|
|
14
|
+
readonly on = sub()
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
port.modes.add(Hub.mode)
|
|
18
|
-
}
|
|
19
|
-
}
|
|
16
|
+
/** all devices known to this hub */
|
|
17
|
+
#connected = new MapG<Device, Connected>()
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
yield* this.ports.values()
|
|
23
|
-
}
|
|
19
|
+
metaPort: Port<MB>
|
|
24
20
|
|
|
25
|
-
|
|
26
|
-
yield* this.ports.entries()
|
|
27
|
-
}
|
|
21
|
+
constructor(
|
|
28
22
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (actions[hubMode].shimmyNext.down) fn(1)
|
|
38
|
-
if (actions[hubMode].shimmyPrevious.down) fn(-1)
|
|
39
|
-
return actions
|
|
40
|
-
})
|
|
23
|
+
/** available ports that devices can be assigned to. */
|
|
24
|
+
public readonly ports: Port<B>[],
|
|
25
|
+
|
|
26
|
+
/** special bindings for devices to shimmy between ports. */
|
|
27
|
+
public metaBindings = makeMetaBindings() as MB,
|
|
28
|
+
) {
|
|
29
|
+
|
|
30
|
+
this.metaPort = new Port<MB>(metaBindings)
|
|
41
31
|
}
|
|
42
32
|
|
|
43
|
-
/**
|
|
44
|
-
|
|
45
|
-
|
|
33
|
+
/** poll every device, providing actions for each port, and internally handling meta actions. */
|
|
34
|
+
poll(now = Date.now()) {
|
|
35
|
+
this.#resolveMetaPort(now)
|
|
36
|
+
this.#actuateMetaActions(now)
|
|
37
|
+
return this.#resolvePorts(now)
|
|
46
38
|
}
|
|
47
39
|
|
|
48
40
|
portByIndex(index: number) {
|
|
@@ -51,52 +43,76 @@ export class Hub<B extends HubFriendlyBindings> {
|
|
|
51
43
|
return port
|
|
52
44
|
}
|
|
53
45
|
|
|
54
|
-
|
|
46
|
+
portByDevice(device: Device) {
|
|
55
47
|
for (const port of this.ports) {
|
|
56
|
-
if (port.
|
|
48
|
+
if (port.devices.has(device))
|
|
57
49
|
return port
|
|
58
50
|
}
|
|
59
51
|
}
|
|
60
52
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return controller
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** move a player's controller to the next or previous port */
|
|
69
|
-
shimmy(controller: Controller, indexDelta: 1 | -1) {
|
|
70
|
-
const oldIndex = this.ports.findIndex(port => port.controllers.has(controller))
|
|
53
|
+
/** move a player's device to the next or previous port */
|
|
54
|
+
shimmy(device: Device, indexDelta: 1 | -1) {
|
|
55
|
+
const oldIndex = this.ports.findIndex(port => port.devices.has(device))
|
|
71
56
|
const maxIndex = Math.max(0, this.ports.length - 1)
|
|
72
57
|
const newIndex = Scalar.clamp(oldIndex + indexDelta, 0, maxIndex)
|
|
73
58
|
const port = this.portByIndex(newIndex)
|
|
74
|
-
this.
|
|
59
|
+
this.reassign(device, port)
|
|
75
60
|
return port
|
|
76
61
|
}
|
|
77
62
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
this
|
|
82
|
-
|
|
83
|
-
|
|
63
|
+
reassign(device: Device, port = this.getLonelyPort()) {
|
|
64
|
+
this.ports.forEach(port => port.devices.delete(device))
|
|
65
|
+
port.devices.add(device)
|
|
66
|
+
this.#dispatchChange()
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** unplug a device */
|
|
70
|
+
unplug(device: Device) {
|
|
71
|
+
this.ports.forEach(port => port.devices.delete(device))
|
|
72
|
+
this.#connected.delete(device)
|
|
73
|
+
this.#dispatchChange()
|
|
84
74
|
}
|
|
85
75
|
|
|
86
|
-
/**
|
|
87
|
-
|
|
88
|
-
this.
|
|
89
|
-
this.
|
|
76
|
+
/** plug a device into a port */
|
|
77
|
+
plug = (device: Device, port = this.getLonelyPort()) => {
|
|
78
|
+
this.unplug(device)
|
|
79
|
+
this.#connected.set(device, new Connected(device, this.metaBindings))
|
|
80
|
+
port.devices.add(device)
|
|
81
|
+
this.#dispatchChange()
|
|
82
|
+
return () => this.unplug(device)
|
|
90
83
|
}
|
|
91
84
|
|
|
92
85
|
/** returns an unplugged port (otherwise the last one) */
|
|
93
86
|
getLonelyPort() {
|
|
87
|
+
let smallest = this.ports.at(0)!
|
|
94
88
|
for (const port of this.ports) {
|
|
95
|
-
if (
|
|
96
|
-
|
|
89
|
+
if (port.devices.size < smallest.devices.size)
|
|
90
|
+
smallest = port
|
|
91
|
+
}
|
|
92
|
+
return smallest
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
#dispatchChange = debounce(0, () => this.on.publish())
|
|
96
|
+
|
|
97
|
+
#resolveMetaPort(now: number) {
|
|
98
|
+
this.metaPort.devices.clear()
|
|
99
|
+
this.metaPort.devices.adds(...this.#connected.keys())
|
|
100
|
+
this.metaPort.resolve(now)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
#actuateMetaActions(now: number) {
|
|
104
|
+
for (const connected of this.#connected.values()) {
|
|
105
|
+
const actions = connected.metaPort.resolve(now)
|
|
106
|
+
if (actions[metaMode].shimmyNext.down) this.shimmy(connected.device, 1)
|
|
107
|
+
if (actions[metaMode].shimmyPrevious.down) this.shimmy(connected.device, -1)
|
|
97
108
|
}
|
|
98
|
-
|
|
99
|
-
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
#resolvePorts(now: number) {
|
|
112
|
+
return this.ports.map(port => {
|
|
113
|
+
port.resolve(now)
|
|
114
|
+
return port
|
|
115
|
+
})
|
|
100
116
|
}
|
|
101
117
|
}
|
|
102
118
|
|