@benev/tact 0.1.0-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/LICENSE +23 -0
- package/README.md +299 -0
- package/package.json +60 -0
- package/s/demo/main.bundle.ts +14 -0
- package/s/demo/main.css +57 -0
- package/s/index.html.ts +42 -0
- package/s/index.ts +16 -0
- package/s/nubs/lookpad/styles.ts +21 -0
- package/s/nubs/lookpad/utils/listeners.ts +53 -0
- package/s/nubs/lookpad/view.ts +32 -0
- package/s/nubs/stick/device.ts +30 -0
- package/s/nubs/stick/styles.ts +22 -0
- package/s/nubs/stick/utils/calculate_new_vector_from_pointer_position.ts +27 -0
- package/s/nubs/stick/utils/find_closest_point_on_circle.ts +15 -0
- package/s/nubs/stick/utils/make_pointer_listeners.ts +50 -0
- package/s/nubs/stick/utils/within_radius.ts +6 -0
- package/s/nubs/stick/view.ts +50 -0
- package/s/nubs/stick-graphic/styles.ts +38 -0
- package/s/nubs/stick-graphic/types/basis.ts +5 -0
- package/s/nubs/stick-graphic/utils/calculate_basis.ts +19 -0
- package/s/nubs/stick-graphic/utils/stick_vector_to_pixels.ts +13 -0
- package/s/nubs/stick-graphic/utils/transform.ts +10 -0
- package/s/nubs/stick-graphic/view.ts +43 -0
- package/s/nubs/virtual-gamepad/device.ts +25 -0
- package/s/nubs/virtual-gamepad/styles.css.ts +133 -0
- package/s/nubs/virtual-gamepad/utils/gamepad-inputs.ts +42 -0
- package/s/nubs/virtual-gamepad/utils/prevent-default-touch-shenanigans.ts +12 -0
- package/s/nubs/virtual-gamepad/utils/touch-tracking.ts +75 -0
- package/s/nubs/virtual-gamepad/view.ts +139 -0
- package/s/station/devices/gamepad.ts +81 -0
- package/s/station/devices/infra/device.ts +7 -0
- package/s/station/devices/infra/group.ts +17 -0
- package/s/station/devices/infra/sampler.ts +22 -0
- package/s/station/devices/keyboard.ts +53 -0
- package/s/station/devices/pointer.ts +95 -0
- package/s/station/parts/action.ts +26 -0
- package/s/station/parts/defaults.ts +28 -0
- package/s/station/parts/resolver.ts +73 -0
- package/s/station/parts/routines/aggregate_samples_into_map.ts +20 -0
- package/s/station/parts/routines/build_updatable_actions_structure.ts +29 -0
- package/s/station/parts/routines/lensing_algorithm.ts +74 -0
- package/s/station/parts/switchboard-bindings.ts +21 -0
- package/s/station/station.test.ts +86 -0
- package/s/station/station.ts +47 -0
- package/s/station/switchboard.ts +107 -0
- package/s/station/testing/testing.ts +47 -0
- package/s/station/types.ts +72 -0
- package/s/station/utils/is-pressed.ts +5 -0
- package/s/station/utils/modprefix.ts +16 -0
- package/s/station/utils/tmax.ts +7 -0
- package/s/station/utils/tmin.ts +7 -0
- package/s/tests.test.ts +8 -0
- package/s/utils/evergreen.ts +10 -0
- package/s/utils/gamepads.ts +41 -0
- package/s/utils/split-axis.ts +7 -0
- package/x/demo/main.bundle.d.ts +1 -0
- package/x/demo/main.bundle.js +11 -0
- package/x/demo/main.bundle.js.map +1 -0
- package/x/demo/main.bundle.min.js +139 -0
- package/x/demo/main.bundle.min.js.map +7 -0
- package/x/demo/main.css +57 -0
- package/x/index.d.ts +13 -0
- package/x/index.html +97 -0
- package/x/index.html.d.ts +2 -0
- package/x/index.html.js +37 -0
- package/x/index.html.js.map +1 -0
- package/x/index.js +14 -0
- package/x/index.js.map +1 -0
- package/x/nubs/lookpad/styles.d.ts +1 -0
- package/x/nubs/lookpad/styles.js +21 -0
- package/x/nubs/lookpad/styles.js.map +1 -0
- package/x/nubs/lookpad/utils/listeners.d.ts +19 -0
- package/x/nubs/lookpad/utils/listeners.js +37 -0
- package/x/nubs/lookpad/utils/listeners.js.map +1 -0
- package/x/nubs/lookpad/view.d.ts +1 -0
- package/x/nubs/lookpad/view.js +24 -0
- package/x/nubs/lookpad/view.js.map +1 -0
- package/x/nubs/stick/device.d.ts +15 -0
- package/x/nubs/stick/device.js +27 -0
- package/x/nubs/stick/device.js.map +1 -0
- package/x/nubs/stick/styles.d.ts +1 -0
- package/x/nubs/stick/styles.js +22 -0
- package/x/nubs/stick/styles.js.map +1 -0
- package/x/nubs/stick/utils/calculate_new_vector_from_pointer_position.d.ts +3 -0
- package/x/nubs/stick/utils/calculate_new_vector_from_pointer_position.js +16 -0
- package/x/nubs/stick/utils/calculate_new_vector_from_pointer_position.js.map +1 -0
- package/x/nubs/stick/utils/find_closest_point_on_circle.d.ts +2 -0
- package/x/nubs/stick/utils/find_closest_point_on_circle.js +6 -0
- package/x/nubs/stick/utils/find_closest_point_on_circle.js.map +1 -0
- package/x/nubs/stick/utils/make_pointer_listeners.d.ts +16 -0
- package/x/nubs/stick/utils/make_pointer_listeners.js +34 -0
- package/x/nubs/stick/utils/make_pointer_listeners.js.map +1 -0
- package/x/nubs/stick/utils/within_radius.d.ts +2 -0
- package/x/nubs/stick/utils/within_radius.js +4 -0
- package/x/nubs/stick/utils/within_radius.js.map +1 -0
- package/x/nubs/stick/view.d.ts +2 -0
- package/x/nubs/stick/view.js +38 -0
- package/x/nubs/stick/view.js.map +1 -0
- package/x/nubs/stick-graphic/styles.d.ts +1 -0
- package/x/nubs/stick-graphic/styles.js +38 -0
- package/x/nubs/stick-graphic/styles.js.map +1 -0
- package/x/nubs/stick-graphic/types/basis.d.ts +4 -0
- package/x/nubs/stick-graphic/types/basis.js +2 -0
- package/x/nubs/stick-graphic/types/basis.js.map +1 -0
- package/x/nubs/stick-graphic/utils/calculate_basis.d.ts +2 -0
- package/x/nubs/stick-graphic/utils/calculate_basis.js +10 -0
- package/x/nubs/stick-graphic/utils/calculate_basis.js.map +1 -0
- package/x/nubs/stick-graphic/utils/stick_vector_to_pixels.d.ts +2 -0
- package/x/nubs/stick-graphic/utils/stick_vector_to_pixels.js +7 -0
- package/x/nubs/stick-graphic/utils/stick_vector_to_pixels.js.map +1 -0
- package/x/nubs/stick-graphic/utils/transform.d.ts +2 -0
- package/x/nubs/stick-graphic/utils/transform.js +7 -0
- package/x/nubs/stick-graphic/utils/transform.js.map +1 -0
- package/x/nubs/stick-graphic/view.d.ts +3 -0
- package/x/nubs/stick-graphic/view.js +30 -0
- package/x/nubs/stick-graphic/view.js.map +1 -0
- package/x/nubs/virtual-gamepad/device.d.ts +7 -0
- package/x/nubs/virtual-gamepad/device.js +20 -0
- package/x/nubs/virtual-gamepad/device.js.map +1 -0
- package/x/nubs/virtual-gamepad/styles.css.d.ts +2 -0
- package/x/nubs/virtual-gamepad/styles.css.js +133 -0
- package/x/nubs/virtual-gamepad/styles.css.js.map +1 -0
- package/x/nubs/virtual-gamepad/utils/gamepad-inputs.d.ts +29 -0
- package/x/nubs/virtual-gamepad/utils/gamepad-inputs.js +31 -0
- package/x/nubs/virtual-gamepad/utils/gamepad-inputs.js.map +1 -0
- package/x/nubs/virtual-gamepad/utils/prevent-default-touch-shenanigans.d.ts +1 -0
- package/x/nubs/virtual-gamepad/utils/prevent-default-touch-shenanigans.js +9 -0
- package/x/nubs/virtual-gamepad/utils/prevent-default-touch-shenanigans.js.map +1 -0
- package/x/nubs/virtual-gamepad/utils/touch-tracking.d.ts +6 -0
- package/x/nubs/virtual-gamepad/utils/touch-tracking.js +55 -0
- package/x/nubs/virtual-gamepad/utils/touch-tracking.js.map +1 -0
- package/x/nubs/virtual-gamepad/view.d.ts +2 -0
- package/x/nubs/virtual-gamepad/view.js +120 -0
- package/x/nubs/virtual-gamepad/view.js.map +1 -0
- package/x/station/devices/gamepad.d.ts +10 -0
- package/x/station/devices/gamepad.js +70 -0
- package/x/station/devices/gamepad.js.map +1 -0
- package/x/station/devices/infra/device.d.ts +4 -0
- package/x/station/devices/infra/device.js +3 -0
- package/x/station/devices/infra/device.js.map +1 -0
- package/x/station/devices/infra/group.d.ts +7 -0
- package/x/station/devices/infra/group.js +13 -0
- package/x/station/devices/infra/group.js.map +1 -0
- package/x/station/devices/infra/sampler.d.ts +8 -0
- package/x/station/devices/infra/sampler.js +17 -0
- package/x/station/devices/infra/sampler.js.map +1 -0
- package/x/station/devices/keyboard.d.ts +9 -0
- package/x/station/devices/keyboard.js +42 -0
- package/x/station/devices/keyboard.js.map +1 -0
- package/x/station/devices/pointer.d.ts +11 -0
- package/x/station/devices/pointer.js +79 -0
- package/x/station/devices/pointer.js.map +1 -0
- package/x/station/parts/action.d.ts +12 -0
- package/x/station/parts/action.js +23 -0
- package/x/station/parts/action.js.map +1 -0
- package/x/station/parts/defaults.d.ts +5 -0
- package/x/station/parts/defaults.js +22 -0
- package/x/station/parts/defaults.js.map +1 -0
- package/x/station/parts/resolver.d.ts +10 -0
- package/x/station/parts/resolver.js +63 -0
- package/x/station/parts/resolver.js.map +1 -0
- package/x/station/parts/routines/aggregate_samples_into_map.d.ts +3 -0
- package/x/station/parts/routines/aggregate_samples_into_map.js +11 -0
- package/x/station/parts/routines/aggregate_samples_into_map.js.map +1 -0
- package/x/station/parts/routines/build_updatable_actions_structure.d.ts +5 -0
- package/x/station/parts/routines/build_updatable_actions_structure.js +18 -0
- package/x/station/parts/routines/build_updatable_actions_structure.js.map +1 -0
- package/x/station/parts/routines/lensing_algorithm.d.ts +2 -0
- package/x/station/parts/routines/lensing_algorithm.js +42 -0
- package/x/station/parts/routines/lensing_algorithm.js.map +1 -0
- package/x/station/parts/switchboard-bindings.d.ts +2 -0
- package/x/station/parts/switchboard-bindings.js +19 -0
- package/x/station/parts/switchboard-bindings.js.map +1 -0
- package/x/station/station.d.ts +15 -0
- package/x/station/station.js +35 -0
- package/x/station/station.js.map +1 -0
- package/x/station/station.test.d.ts +11 -0
- package/x/station/station.test.js +80 -0
- package/x/station/station.test.js.map +1 -0
- package/x/station/switchboard.d.ts +30 -0
- package/x/station/switchboard.js +90 -0
- package/x/station/switchboard.js.map +1 -0
- package/x/station/testing/testing.d.ts +58 -0
- package/x/station/testing/testing.js +39 -0
- package/x/station/testing/testing.js.map +1 -0
- package/x/station/types.d.ts +56 -0
- package/x/station/types.js +5 -0
- package/x/station/types.js.map +1 -0
- package/x/station/utils/is-pressed.d.ts +1 -0
- package/x/station/utils/is-pressed.js +4 -0
- package/x/station/utils/is-pressed.js.map +1 -0
- package/x/station/utils/modprefix.d.ts +1 -0
- package/x/station/utils/modprefix.js +16 -0
- package/x/station/utils/modprefix.js.map +1 -0
- package/x/station/utils/tmax.d.ts +1 -0
- package/x/station/utils/tmax.js +6 -0
- package/x/station/utils/tmax.js.map +1 -0
- package/x/station/utils/tmin.d.ts +1 -0
- package/x/station/utils/tmin.js +6 -0
- package/x/station/utils/tmin.js.map +1 -0
- package/x/tests.test.d.ts +1 -0
- package/x/tests.test.js +6 -0
- package/x/tests.test.js.map +1 -0
- package/x/utils/evergreen.d.ts +1 -0
- package/x/utils/evergreen.js +10 -0
- package/x/utils/evergreen.js.map +1 -0
- package/x/utils/gamepads.d.ts +14 -0
- package/x/utils/gamepads.js +40 -0
- package/x/utils/gamepads.js.map +1 -0
- package/x/utils/split-axis.d.ts +1 -0
- package/x/utils/split-axis.js +6 -0
- package/x/utils/split-axis.js.map +1 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
|
|
2
|
+
import {Vec2} from "@benev/math"
|
|
3
|
+
import {within_radius} from "./within_radius.js"
|
|
4
|
+
import {Basis} from "../../stick-graphic/types/basis.js"
|
|
5
|
+
import {find_closest_point_on_circle} from "./find_closest_point_on_circle.js"
|
|
6
|
+
|
|
7
|
+
export function calculate_new_vector_from_pointer_position(
|
|
8
|
+
{radius, rect: {left, top, width, height}}: Basis,
|
|
9
|
+
{x: client_x, y: client_y}: Vec2,
|
|
10
|
+
): Vec2 {
|
|
11
|
+
|
|
12
|
+
const middle_x = left + (width / 2)
|
|
13
|
+
const middle_y = top + (height / 2)
|
|
14
|
+
|
|
15
|
+
let new_vector = Vec2.new((client_x - middle_x), (client_y - middle_y))
|
|
16
|
+
|
|
17
|
+
if (!within_radius(radius, new_vector))
|
|
18
|
+
new_vector = find_closest_point_on_circle(radius, new_vector)
|
|
19
|
+
const [x, y] = new_vector
|
|
20
|
+
|
|
21
|
+
const final = Vec2.new((x / radius), -(y / radius))
|
|
22
|
+
|
|
23
|
+
return [...final].some(isNaN)
|
|
24
|
+
? Vec2.zero()
|
|
25
|
+
: final
|
|
26
|
+
}
|
|
27
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
import {Vec2} from "@benev/math"
|
|
3
|
+
|
|
4
|
+
export function find_closest_point_on_circle(
|
|
5
|
+
radius: number,
|
|
6
|
+
{x, y}: Vec2,
|
|
7
|
+
): Vec2 {
|
|
8
|
+
|
|
9
|
+
const magnitude = Math.sqrt((x ** 2) + (y ** 2))
|
|
10
|
+
|
|
11
|
+
return Vec2.new(
|
|
12
|
+
(x / magnitude) * radius,
|
|
13
|
+
(y / magnitude) * radius,
|
|
14
|
+
)
|
|
15
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
|
|
2
|
+
import {Vec2} from "@benev/math"
|
|
3
|
+
|
|
4
|
+
export function make_pointer_listeners({
|
|
5
|
+
set_vector,
|
|
6
|
+
set_pointer_position,
|
|
7
|
+
}: {
|
|
8
|
+
set_vector: (vector: Vec2) => void
|
|
9
|
+
set_pointer_position: (position: Vec2) => void
|
|
10
|
+
}) {
|
|
11
|
+
|
|
12
|
+
let pointer_id: number | undefined
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
pointerdown: {
|
|
16
|
+
handleEvent: (event: PointerEvent) => {
|
|
17
|
+
event.preventDefault()
|
|
18
|
+
|
|
19
|
+
const element = event.currentTarget as HTMLElement
|
|
20
|
+
|
|
21
|
+
if (pointer_id)
|
|
22
|
+
element.releasePointerCapture(pointer_id)
|
|
23
|
+
|
|
24
|
+
pointer_id = event.pointerId
|
|
25
|
+
element.setPointerCapture(pointer_id)
|
|
26
|
+
set_pointer_position(Vec2.new(event.clientX, event.clientY))
|
|
27
|
+
set_vector(Vec2.zero())
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
pointermove: {
|
|
32
|
+
passive: false,
|
|
33
|
+
handleEvent: (event: PointerEvent) => {
|
|
34
|
+
event.preventDefault()
|
|
35
|
+
|
|
36
|
+
if (event.pointerId === pointer_id)
|
|
37
|
+
set_pointer_position(Vec2.new(event.clientX, event.clientY))
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
pointerup: {
|
|
42
|
+
handleEvent: (event: PointerEvent) => {
|
|
43
|
+
event.preventDefault()
|
|
44
|
+
pointer_id = undefined
|
|
45
|
+
set_vector(Vec2.zero())
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
|
|
2
|
+
import {html} from "lit"
|
|
3
|
+
import {view} from "@e280/sly"
|
|
4
|
+
import {Vec2} from "@benev/math"
|
|
5
|
+
|
|
6
|
+
import {StickDevice} from "./device.js"
|
|
7
|
+
import {styles} from "./styles.js"
|
|
8
|
+
import {Basis} from "../stick-graphic/types/basis.js"
|
|
9
|
+
import {NubStickGraphic} from "../stick-graphic/view.js"
|
|
10
|
+
import {make_pointer_listeners} from "./utils/make_pointer_listeners.js"
|
|
11
|
+
import {calculate_new_vector_from_pointer_position} from "./utils/calculate_new_vector_from_pointer_position.js"
|
|
12
|
+
|
|
13
|
+
export const NubStick = view(use => (stick: StickDevice) => {
|
|
14
|
+
use.name("nub-stick")
|
|
15
|
+
use.styles(styles)
|
|
16
|
+
|
|
17
|
+
let basis: Basis | undefined = undefined
|
|
18
|
+
const updateBasis = (b: Basis) => basis = b
|
|
19
|
+
|
|
20
|
+
const listeners = use.once(() => make_pointer_listeners({
|
|
21
|
+
set_vector: vector => stick.vector.value = vector,
|
|
22
|
+
set_pointer_position: position => {
|
|
23
|
+
if (basis)
|
|
24
|
+
stick.vector.value = calculate_new_vector_from_pointer_position(
|
|
25
|
+
basis,
|
|
26
|
+
position,
|
|
27
|
+
)
|
|
28
|
+
},
|
|
29
|
+
}))
|
|
30
|
+
|
|
31
|
+
use.mount(() => {
|
|
32
|
+
stick.vector.set(Vec2.zero())
|
|
33
|
+
return () => stick.vector.set(Vec2.zero())
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
return html`
|
|
37
|
+
<div
|
|
38
|
+
class=container
|
|
39
|
+
.vector="${stick.vector}"
|
|
40
|
+
@pointerdown="${listeners.pointerdown}"
|
|
41
|
+
@pointermove="${listeners.pointermove}"
|
|
42
|
+
@pointerup="${listeners.pointerup}"
|
|
43
|
+
>
|
|
44
|
+
${NubStickGraphic
|
|
45
|
+
.attr("part", "graphic")
|
|
46
|
+
.props(stick.vector.get(), updateBasis)}
|
|
47
|
+
</div>
|
|
48
|
+
`
|
|
49
|
+
})
|
|
50
|
+
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
|
|
2
|
+
import {css} from "lit"
|
|
3
|
+
export const styles = css`
|
|
4
|
+
|
|
5
|
+
:host {
|
|
6
|
+
display: block;
|
|
7
|
+
width: 8em;
|
|
8
|
+
height: 8em;
|
|
9
|
+
--size: var(--nub-stick-size, 66%);
|
|
10
|
+
--background: var(--nub-stick-background, black);
|
|
11
|
+
--color: var(--nub-stick-color, white);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
[part="base"] {
|
|
15
|
+
position: relative;
|
|
16
|
+
aspect-ratio: 1/1;
|
|
17
|
+
width: 100%;
|
|
18
|
+
height: 100%;
|
|
19
|
+
background: var(--background);
|
|
20
|
+
border-radius: 100%;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
[part="over"], [part="under"] {
|
|
24
|
+
position: absolute;
|
|
25
|
+
inset: 0;
|
|
26
|
+
width: var(--size);
|
|
27
|
+
height: var(--size);
|
|
28
|
+
border-radius: 100%;
|
|
29
|
+
margin: auto;
|
|
30
|
+
pointer-events: none;
|
|
31
|
+
background: var(--color);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
[part="under"] {
|
|
35
|
+
opacity: 0.5;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
`
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
|
|
2
|
+
import {Basis} from "../types/basis.js"
|
|
3
|
+
|
|
4
|
+
export function calculate_basis(
|
|
5
|
+
base: HTMLElement,
|
|
6
|
+
over: HTMLElement,
|
|
7
|
+
): Basis {
|
|
8
|
+
|
|
9
|
+
const rect = base.getBoundingClientRect()
|
|
10
|
+
|
|
11
|
+
const half_base = (rect.width / 2)
|
|
12
|
+
const quarter_stick = (over.getBoundingClientRect().width / 4)
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
rect,
|
|
16
|
+
radius: half_base - quarter_stick,
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
|
|
2
|
+
import {html} from "lit"
|
|
3
|
+
import {view} from "@e280/sly"
|
|
4
|
+
import {Vec2} from "@benev/math"
|
|
5
|
+
|
|
6
|
+
import {styles} from "./styles.js"
|
|
7
|
+
import {Basis} from "./types/basis.js"
|
|
8
|
+
import {transform} from "./utils/transform.js"
|
|
9
|
+
import {calculate_basis} from "./utils/calculate_basis.js"
|
|
10
|
+
import {stick_vector_to_pixels} from "./utils/stick_vector_to_pixels.js"
|
|
11
|
+
|
|
12
|
+
export const NubStickGraphic = view(use => (
|
|
13
|
+
vector: Vec2,
|
|
14
|
+
updateBasis: (basis: Basis) => void,
|
|
15
|
+
) => {
|
|
16
|
+
|
|
17
|
+
use.name("nub-stick-graphic")
|
|
18
|
+
use.styles(styles)
|
|
19
|
+
|
|
20
|
+
const basis = use.signal<Basis | null>(null)
|
|
21
|
+
|
|
22
|
+
use.rendered.then(() => {
|
|
23
|
+
const base = use.shadow.querySelector<HTMLElement>(`[part="base"]`)
|
|
24
|
+
const over = use.shadow.querySelector<HTMLElement>(`[part="over"]`)
|
|
25
|
+
if (base && over) {
|
|
26
|
+
const newBasis = calculate_basis(base, over)
|
|
27
|
+
basis.value = newBasis
|
|
28
|
+
updateBasis(newBasis)
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
const pixels = stick_vector_to_pixels(basis.value?.radius, vector)
|
|
33
|
+
const over_style = transform(pixels)
|
|
34
|
+
const under_style = transform(pixels.clone().half())
|
|
35
|
+
|
|
36
|
+
return html`
|
|
37
|
+
<div part=base>
|
|
38
|
+
<div part=under style="${under_style}"></div>
|
|
39
|
+
<div part=over style="${over_style}"></div>
|
|
40
|
+
</div>
|
|
41
|
+
`
|
|
42
|
+
})
|
|
43
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
import {StickDevice} from "../stick/device.js"
|
|
3
|
+
import {SamplerDevice} from "../../station/devices/infra/sampler.js"
|
|
4
|
+
|
|
5
|
+
export class VirtualGamepadDevice extends SamplerDevice {
|
|
6
|
+
stickLeft = new StickDevice()
|
|
7
|
+
stickRight = new StickDevice()
|
|
8
|
+
|
|
9
|
+
takeSamples() {
|
|
10
|
+
const left = this.stickLeft.breakdown()
|
|
11
|
+
this.setSample("gamepad.stick.left.up", left.up)
|
|
12
|
+
this.setSample("gamepad.stick.left.down", left.down)
|
|
13
|
+
this.setSample("gamepad.stick.left.left", left.left)
|
|
14
|
+
this.setSample("gamepad.stick.left.right", left.right)
|
|
15
|
+
|
|
16
|
+
const right = this.stickRight.breakdown()
|
|
17
|
+
this.setSample("gamepad.stick.right.up", right.up)
|
|
18
|
+
this.setSample("gamepad.stick.right.down", right.down)
|
|
19
|
+
this.setSample("gamepad.stick.right.left", right.left)
|
|
20
|
+
this.setSample("gamepad.stick.right.right", right.right)
|
|
21
|
+
|
|
22
|
+
return super.takeSamples()
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
|
|
2
|
+
import {css} from "lit"
|
|
3
|
+
export default css`
|
|
4
|
+
|
|
5
|
+
:host {
|
|
6
|
+
pointer-events: none;
|
|
7
|
+
|
|
8
|
+
display: flex;
|
|
9
|
+
flex-direction: column;
|
|
10
|
+
container: my-layout / size;
|
|
11
|
+
|
|
12
|
+
width: 100%;
|
|
13
|
+
height: 100%;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
* {
|
|
17
|
+
user-drag: none;
|
|
18
|
+
user-select: none;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
button, [view="nub-stick"] {
|
|
22
|
+
pointer-events: all;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
button {
|
|
26
|
+
font-size: 0.5em;
|
|
27
|
+
color: #fff;
|
|
28
|
+
text-shadow: .1em .2em .1em #000;
|
|
29
|
+
text-transform: uppercase;
|
|
30
|
+
display: inline-flex;
|
|
31
|
+
justify-content: center;
|
|
32
|
+
align-items: center;
|
|
33
|
+
background: #888;
|
|
34
|
+
box-shadow: .2em .4em .1em #000;
|
|
35
|
+
|
|
36
|
+
-webkit-tap-highlight-color: transparent;
|
|
37
|
+
&:is(:focus, :hover) {
|
|
38
|
+
outline: none;
|
|
39
|
+
background: #888;
|
|
40
|
+
filter: none;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.upper {
|
|
45
|
+
flex: 1 1 auto;
|
|
46
|
+
display: flex;
|
|
47
|
+
justify-content: center;
|
|
48
|
+
align-items: start;
|
|
49
|
+
gap: 0.5em;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.lower {
|
|
53
|
+
display: flex;
|
|
54
|
+
justify-content: space-between;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.side {
|
|
58
|
+
display: flex;
|
|
59
|
+
flex-direction: column;
|
|
60
|
+
gap: 1em;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.pad {
|
|
64
|
+
display: flex;
|
|
65
|
+
gap: 0.5em;
|
|
66
|
+
|
|
67
|
+
> div {
|
|
68
|
+
display: flex;
|
|
69
|
+
flex-direction: column;
|
|
70
|
+
justify-content: center;
|
|
71
|
+
gap: 0.5em;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.shoulder {
|
|
76
|
+
display: flex;
|
|
77
|
+
gap: 0.5em;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.right {
|
|
81
|
+
align-items: end;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.right .shoulder {
|
|
85
|
+
flex-direction: row-reverse;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
[x-code^="g.trigger"] {
|
|
89
|
+
width: 6em;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
[x-code^="g.bumper"] {
|
|
93
|
+
width: 4em;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.stick {
|
|
97
|
+
width: 4em;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
@container (min-width: 0px) {
|
|
101
|
+
.upper, .lower {
|
|
102
|
+
padding: 2cqh 2cqw;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
button {
|
|
106
|
+
font-size: min(3cqh, 3cqw);
|
|
107
|
+
width: 7cqw;
|
|
108
|
+
height: 6cqh;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.upper button {
|
|
112
|
+
width: unset;
|
|
113
|
+
height: unset;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.shoulder button {
|
|
117
|
+
height: 9cqh;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.stick {
|
|
121
|
+
width: max(15cqw, 15cqh);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
[x-code^="g.trigger"] {
|
|
125
|
+
width: 9cqw;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
[x-code^="g.bumper"] {
|
|
129
|
+
width: 7cqw;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
`
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
|
|
2
|
+
export type GamepadInputs = ReturnType<typeof gamepadInputs>
|
|
3
|
+
|
|
4
|
+
export function gamepadInputs() {
|
|
5
|
+
return {
|
|
6
|
+
"gamepad.any": 0,
|
|
7
|
+
|
|
8
|
+
"gamepad.stick.left.up": 0,
|
|
9
|
+
"gamepad.stick.left.down": 0,
|
|
10
|
+
"gamepad.stick.left.left": 0,
|
|
11
|
+
"gamepad.stick.left.right": 0,
|
|
12
|
+
|
|
13
|
+
"gamepad.stick.right.up": 0,
|
|
14
|
+
"gamepad.stick.right.down": 0,
|
|
15
|
+
"gamepad.stick.right.left": 0,
|
|
16
|
+
"gamepad.stick.right.right": 0,
|
|
17
|
+
|
|
18
|
+
"gamepad.stick.left.click": 0,
|
|
19
|
+
"gamepad.stick.right.click": 0,
|
|
20
|
+
|
|
21
|
+
"gamepad.a": 0,
|
|
22
|
+
"gamepad.b": 0,
|
|
23
|
+
"gamepad.x": 0,
|
|
24
|
+
"gamepad.y": 0,
|
|
25
|
+
|
|
26
|
+
"gamepad.up": 0,
|
|
27
|
+
"gamepad.down": 0,
|
|
28
|
+
"gamepad.left": 0,
|
|
29
|
+
"gamepad.right": 0,
|
|
30
|
+
|
|
31
|
+
"gamepad.trigger.left": 0,
|
|
32
|
+
"gamepad.trigger.right": 0,
|
|
33
|
+
|
|
34
|
+
"gamepad.bumper.left": 0,
|
|
35
|
+
"gamepad.bumper.right": 0,
|
|
36
|
+
|
|
37
|
+
"gamepad.alpha": 0,
|
|
38
|
+
"gamepad.beta": 0,
|
|
39
|
+
"gamepad.gamma": 0,
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
export function preventDefaultTouchShenanigans() {
|
|
3
|
+
const preventer = (e: TouchEvent) => e.preventDefault()
|
|
4
|
+
const opts = {passive: false}
|
|
5
|
+
|
|
6
|
+
window.addEventListener("touchmove", preventer, opts)
|
|
7
|
+
|
|
8
|
+
return () => {
|
|
9
|
+
window.removeEventListener("touchmove", preventer)
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
|
|
2
|
+
import {ev, MapG} from "@e280/stz"
|
|
3
|
+
|
|
4
|
+
export function touchTracking({target, buttons, touchdown, touchup}: {
|
|
5
|
+
target: Document | ShadowRoot
|
|
6
|
+
buttons: Set<HTMLButtonElement>
|
|
7
|
+
touchdown: (button: HTMLButtonElement) => void
|
|
8
|
+
touchup: (button: HTMLButtonElement) => void
|
|
9
|
+
}) {
|
|
10
|
+
|
|
11
|
+
const tracks = new MapG<number, Track>
|
|
12
|
+
|
|
13
|
+
function grabTrack(touch: Touch) {
|
|
14
|
+
return tracks.guarantee(touch.identifier, () => new Track(
|
|
15
|
+
touchdown,
|
|
16
|
+
touchup,
|
|
17
|
+
))
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function underTouch(touch: Touch) {
|
|
21
|
+
const element = target.elementFromPoint(touch.clientX, touch.clientY)
|
|
22
|
+
return (element && element instanceof HTMLButtonElement && buttons.has(element))
|
|
23
|
+
? element
|
|
24
|
+
: undefined
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function additive(event: TouchEvent) {
|
|
28
|
+
for (const touch of Array.from(event.touches)) {
|
|
29
|
+
const track = grabTrack(touch)
|
|
30
|
+
track.button = underTouch(touch)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function subtractive(event: TouchEvent) {
|
|
35
|
+
for (const touch of Array.from(event.changedTouches)) {
|
|
36
|
+
const track = grabTrack(touch)
|
|
37
|
+
track.button = undefined
|
|
38
|
+
tracks.delete(touch.identifier)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return ev(window, {
|
|
43
|
+
touchstart: additive,
|
|
44
|
+
touchmove: additive,
|
|
45
|
+
touchcancel: subtractive,
|
|
46
|
+
touchend: subtractive,
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
class Track {
|
|
51
|
+
#button: HTMLButtonElement | undefined = undefined
|
|
52
|
+
|
|
53
|
+
constructor(
|
|
54
|
+
public touchdown: (button: HTMLButtonElement) => void,
|
|
55
|
+
public touchup: (button: HTMLButtonElement) => void,
|
|
56
|
+
) {}
|
|
57
|
+
|
|
58
|
+
get button() {
|
|
59
|
+
return this.#button
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
set button(next: HTMLButtonElement | undefined) {
|
|
63
|
+
const previous = this.#button
|
|
64
|
+
const changed = next !== previous
|
|
65
|
+
|
|
66
|
+
this.#button = next
|
|
67
|
+
|
|
68
|
+
if (changed && previous) {
|
|
69
|
+
this.touchup(previous)
|
|
70
|
+
}
|
|
71
|
+
if (changed && next)
|
|
72
|
+
this.touchdown(next)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|