@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 @@
|
|
|
1
|
+
{"version":3,"file":"basis.js","sourceRoot":"","sources":["../../../../s/nubs/stick-graphic/types/basis.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function calculate_basis(base, over) {
|
|
2
|
+
const rect = base.getBoundingClientRect();
|
|
3
|
+
const half_base = (rect.width / 2);
|
|
4
|
+
const quarter_stick = (over.getBoundingClientRect().width / 4);
|
|
5
|
+
return {
|
|
6
|
+
rect,
|
|
7
|
+
radius: half_base - quarter_stick,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=calculate_basis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculate_basis.js","sourceRoot":"","sources":["../../../../s/nubs/stick-graphic/utils/calculate_basis.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,eAAe,CAC7B,IAAiB,EACjB,IAAiB;IAGlB,MAAM,IAAI,GAAG,IAAI,CAAC,qBAAqB,EAAE,CAAA;IAEzC,MAAM,SAAS,GAAG,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAA;IAClC,MAAM,aAAa,GAAG,CAAC,IAAI,CAAC,qBAAqB,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC,CAAA;IAE9D,OAAO;QACN,IAAI;QACJ,MAAM,EAAE,SAAS,GAAG,aAAa;KACjC,CAAA;AACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stick_vector_to_pixels.js","sourceRoot":"","sources":["../../../../s/nubs/stick-graphic/utils/stick_vector_to_pixels.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,IAAI,EAAC,MAAM,aAAa,CAAA;AAEhC,MAAM,UAAU,sBAAsB,CACpC,MAA0B,EAC1B,MAAY;IAGb,OAAO,MAAM,KAAK,SAAS;QAC1B,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC;QAC3C,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../../../s/nubs/stick-graphic/utils/transform.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,EAAC,CAAC,EAAE,CAAC,EAAO,EAAE,EAAE,CAAC;;IAEvC,CAAC;IACD,CAAC;;CAEJ,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { html } from "lit";
|
|
2
|
+
import { view } from "@e280/sly";
|
|
3
|
+
import { styles } from "./styles.js";
|
|
4
|
+
import { transform } from "./utils/transform.js";
|
|
5
|
+
import { calculate_basis } from "./utils/calculate_basis.js";
|
|
6
|
+
import { stick_vector_to_pixels } from "./utils/stick_vector_to_pixels.js";
|
|
7
|
+
export const NubStickGraphic = view(use => (vector, updateBasis) => {
|
|
8
|
+
use.name("nub-stick-graphic");
|
|
9
|
+
use.styles(styles);
|
|
10
|
+
const basis = use.signal(null);
|
|
11
|
+
use.rendered.then(() => {
|
|
12
|
+
const base = use.shadow.querySelector(`[part="base"]`);
|
|
13
|
+
const over = use.shadow.querySelector(`[part="over"]`);
|
|
14
|
+
if (base && over) {
|
|
15
|
+
const newBasis = calculate_basis(base, over);
|
|
16
|
+
basis.value = newBasis;
|
|
17
|
+
updateBasis(newBasis);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
const pixels = stick_vector_to_pixels(basis.value?.radius, vector);
|
|
21
|
+
const over_style = transform(pixels);
|
|
22
|
+
const under_style = transform(pixels.clone().half());
|
|
23
|
+
return html `
|
|
24
|
+
<div part=base>
|
|
25
|
+
<div part=under style="${under_style}"></div>
|
|
26
|
+
<div part=over style="${over_style}"></div>
|
|
27
|
+
</div>
|
|
28
|
+
`;
|
|
29
|
+
});
|
|
30
|
+
//# sourceMappingURL=view.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view.js","sourceRoot":"","sources":["../../../s/nubs/stick-graphic/view.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,IAAI,EAAC,MAAM,KAAK,CAAA;AACxB,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAG9B,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAA;AAElC,OAAO,EAAC,SAAS,EAAC,MAAM,sBAAsB,CAAA;AAC9C,OAAO,EAAC,eAAe,EAAC,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAC,sBAAsB,EAAC,MAAM,mCAAmC,CAAA;AAExE,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CACzC,MAAY,EACZ,WAAmC,EAClC,EAAE;IAEJ,GAAG,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAA;IAC7B,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAElB,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,CAAe,IAAI,CAAC,CAAA;IAE5C,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE;QACtB,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,aAAa,CAAc,eAAe,CAAC,CAAA;QACnE,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,aAAa,CAAc,eAAe,CAAC,CAAA;QACnE,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;YAClB,MAAM,QAAQ,GAAG,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;YAC5C,KAAK,CAAC,KAAK,GAAG,QAAQ,CAAA;YACtB,WAAW,CAAC,QAAQ,CAAC,CAAA;QACtB,CAAC;IACF,CAAC,CAAC,CAAA;IAEF,MAAM,MAAM,GAAG,sBAAsB,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;IAClE,MAAM,UAAU,GAAG,SAAS,CAAC,MAAM,CAAC,CAAA;IACpC,MAAM,WAAW,GAAG,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,CAAA;IAEpD,OAAO,IAAI,CAAA;;4BAEgB,WAAW;2BACZ,UAAU;;EAEnC,CAAA;AACF,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { StickDevice } from "../stick/device.js";
|
|
2
|
+
import { SamplerDevice } from "../../station/devices/infra/sampler.js";
|
|
3
|
+
export declare class VirtualGamepadDevice extends SamplerDevice {
|
|
4
|
+
stickLeft: StickDevice;
|
|
5
|
+
stickRight: StickDevice;
|
|
6
|
+
takeSamples(): import("../../index.js").Sample[];
|
|
7
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { StickDevice } from "../stick/device.js";
|
|
2
|
+
import { SamplerDevice } from "../../station/devices/infra/sampler.js";
|
|
3
|
+
export class VirtualGamepadDevice extends SamplerDevice {
|
|
4
|
+
stickLeft = new StickDevice();
|
|
5
|
+
stickRight = new StickDevice();
|
|
6
|
+
takeSamples() {
|
|
7
|
+
const left = this.stickLeft.breakdown();
|
|
8
|
+
this.setSample("gamepad.stick.left.up", left.up);
|
|
9
|
+
this.setSample("gamepad.stick.left.down", left.down);
|
|
10
|
+
this.setSample("gamepad.stick.left.left", left.left);
|
|
11
|
+
this.setSample("gamepad.stick.left.right", left.right);
|
|
12
|
+
const right = this.stickRight.breakdown();
|
|
13
|
+
this.setSample("gamepad.stick.right.up", right.up);
|
|
14
|
+
this.setSample("gamepad.stick.right.down", right.down);
|
|
15
|
+
this.setSample("gamepad.stick.right.left", right.left);
|
|
16
|
+
this.setSample("gamepad.stick.right.right", right.right);
|
|
17
|
+
return super.takeSamples();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=device.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device.js","sourceRoot":"","sources":["../../../s/nubs/virtual-gamepad/device.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAC,aAAa,EAAC,MAAM,wCAAwC,CAAA;AAEpE,MAAM,OAAO,oBAAqB,SAAQ,aAAa;IACtD,SAAS,GAAG,IAAI,WAAW,EAAE,CAAA;IAC7B,UAAU,GAAG,IAAI,WAAW,EAAE,CAAA;IAE9B,WAAW;QACV,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,CAAA;QACvC,IAAI,CAAC,SAAS,CAAC,uBAAuB,EAAE,IAAI,CAAC,EAAE,CAAC,CAAA;QAChD,IAAI,CAAC,SAAS,CAAC,yBAAyB,EAAE,IAAI,CAAC,IAAI,CAAC,CAAA;QACpD,IAAI,CAAC,SAAS,CAAC,yBAAyB,EAAE,IAAI,CAAC,IAAI,CAAC,CAAA;QACpD,IAAI,CAAC,SAAS,CAAC,0BAA0B,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;QAEtD,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,CAAA;QACzC,IAAI,CAAC,SAAS,CAAC,wBAAwB,EAAE,KAAK,CAAC,EAAE,CAAC,CAAA;QAClD,IAAI,CAAC,SAAS,CAAC,0BAA0B,EAAE,KAAK,CAAC,IAAI,CAAC,CAAA;QACtD,IAAI,CAAC,SAAS,CAAC,0BAA0B,EAAE,KAAK,CAAC,IAAI,CAAC,CAAA;QACtD,IAAI,CAAC,SAAS,CAAC,2BAA2B,EAAE,KAAK,CAAC,KAAK,CAAC,CAAA;QAExD,OAAO,KAAK,CAAC,WAAW,EAAE,CAAA;IAC3B,CAAC;CACD"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { css } from "lit";
|
|
2
|
+
export default css `
|
|
3
|
+
|
|
4
|
+
:host {
|
|
5
|
+
pointer-events: none;
|
|
6
|
+
|
|
7
|
+
display: flex;
|
|
8
|
+
flex-direction: column;
|
|
9
|
+
container: my-layout / size;
|
|
10
|
+
|
|
11
|
+
width: 100%;
|
|
12
|
+
height: 100%;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
* {
|
|
16
|
+
user-drag: none;
|
|
17
|
+
user-select: none;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
button, [view="nub-stick"] {
|
|
21
|
+
pointer-events: all;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
button {
|
|
25
|
+
font-size: 0.5em;
|
|
26
|
+
color: #fff;
|
|
27
|
+
text-shadow: .1em .2em .1em #000;
|
|
28
|
+
text-transform: uppercase;
|
|
29
|
+
display: inline-flex;
|
|
30
|
+
justify-content: center;
|
|
31
|
+
align-items: center;
|
|
32
|
+
background: #888;
|
|
33
|
+
box-shadow: .2em .4em .1em #000;
|
|
34
|
+
|
|
35
|
+
-webkit-tap-highlight-color: transparent;
|
|
36
|
+
&:is(:focus, :hover) {
|
|
37
|
+
outline: none;
|
|
38
|
+
background: #888;
|
|
39
|
+
filter: none;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.upper {
|
|
44
|
+
flex: 1 1 auto;
|
|
45
|
+
display: flex;
|
|
46
|
+
justify-content: center;
|
|
47
|
+
align-items: start;
|
|
48
|
+
gap: 0.5em;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.lower {
|
|
52
|
+
display: flex;
|
|
53
|
+
justify-content: space-between;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.side {
|
|
57
|
+
display: flex;
|
|
58
|
+
flex-direction: column;
|
|
59
|
+
gap: 1em;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.pad {
|
|
63
|
+
display: flex;
|
|
64
|
+
gap: 0.5em;
|
|
65
|
+
|
|
66
|
+
> div {
|
|
67
|
+
display: flex;
|
|
68
|
+
flex-direction: column;
|
|
69
|
+
justify-content: center;
|
|
70
|
+
gap: 0.5em;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.shoulder {
|
|
75
|
+
display: flex;
|
|
76
|
+
gap: 0.5em;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.right {
|
|
80
|
+
align-items: end;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.right .shoulder {
|
|
84
|
+
flex-direction: row-reverse;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
[x-code^="g.trigger"] {
|
|
88
|
+
width: 6em;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
[x-code^="g.bumper"] {
|
|
92
|
+
width: 4em;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.stick {
|
|
96
|
+
width: 4em;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@container (min-width: 0px) {
|
|
100
|
+
.upper, .lower {
|
|
101
|
+
padding: 2cqh 2cqw;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
button {
|
|
105
|
+
font-size: min(3cqh, 3cqw);
|
|
106
|
+
width: 7cqw;
|
|
107
|
+
height: 6cqh;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.upper button {
|
|
111
|
+
width: unset;
|
|
112
|
+
height: unset;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.shoulder button {
|
|
116
|
+
height: 9cqh;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.stick {
|
|
120
|
+
width: max(15cqw, 15cqh);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
[x-code^="g.trigger"] {
|
|
124
|
+
width: 9cqw;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
[x-code^="g.bumper"] {
|
|
128
|
+
width: 7cqw;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
`;
|
|
133
|
+
//# sourceMappingURL=styles.css.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.css.js","sourceRoot":"","sources":["../../../s/nubs/virtual-gamepad/styles.css.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,GAAG,EAAC,MAAM,KAAK,CAAA;AACvB,eAAe,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkIjB,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type GamepadInputs = ReturnType<typeof gamepadInputs>;
|
|
2
|
+
export declare function gamepadInputs(): {
|
|
3
|
+
"gamepad.any": number;
|
|
4
|
+
"gamepad.stick.left.up": number;
|
|
5
|
+
"gamepad.stick.left.down": number;
|
|
6
|
+
"gamepad.stick.left.left": number;
|
|
7
|
+
"gamepad.stick.left.right": number;
|
|
8
|
+
"gamepad.stick.right.up": number;
|
|
9
|
+
"gamepad.stick.right.down": number;
|
|
10
|
+
"gamepad.stick.right.left": number;
|
|
11
|
+
"gamepad.stick.right.right": number;
|
|
12
|
+
"gamepad.stick.left.click": number;
|
|
13
|
+
"gamepad.stick.right.click": number;
|
|
14
|
+
"gamepad.a": number;
|
|
15
|
+
"gamepad.b": number;
|
|
16
|
+
"gamepad.x": number;
|
|
17
|
+
"gamepad.y": number;
|
|
18
|
+
"gamepad.up": number;
|
|
19
|
+
"gamepad.down": number;
|
|
20
|
+
"gamepad.left": number;
|
|
21
|
+
"gamepad.right": number;
|
|
22
|
+
"gamepad.trigger.left": number;
|
|
23
|
+
"gamepad.trigger.right": number;
|
|
24
|
+
"gamepad.bumper.left": number;
|
|
25
|
+
"gamepad.bumper.right": number;
|
|
26
|
+
"gamepad.alpha": number;
|
|
27
|
+
"gamepad.beta": number;
|
|
28
|
+
"gamepad.gamma": number;
|
|
29
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export function gamepadInputs() {
|
|
2
|
+
return {
|
|
3
|
+
"gamepad.any": 0,
|
|
4
|
+
"gamepad.stick.left.up": 0,
|
|
5
|
+
"gamepad.stick.left.down": 0,
|
|
6
|
+
"gamepad.stick.left.left": 0,
|
|
7
|
+
"gamepad.stick.left.right": 0,
|
|
8
|
+
"gamepad.stick.right.up": 0,
|
|
9
|
+
"gamepad.stick.right.down": 0,
|
|
10
|
+
"gamepad.stick.right.left": 0,
|
|
11
|
+
"gamepad.stick.right.right": 0,
|
|
12
|
+
"gamepad.stick.left.click": 0,
|
|
13
|
+
"gamepad.stick.right.click": 0,
|
|
14
|
+
"gamepad.a": 0,
|
|
15
|
+
"gamepad.b": 0,
|
|
16
|
+
"gamepad.x": 0,
|
|
17
|
+
"gamepad.y": 0,
|
|
18
|
+
"gamepad.up": 0,
|
|
19
|
+
"gamepad.down": 0,
|
|
20
|
+
"gamepad.left": 0,
|
|
21
|
+
"gamepad.right": 0,
|
|
22
|
+
"gamepad.trigger.left": 0,
|
|
23
|
+
"gamepad.trigger.right": 0,
|
|
24
|
+
"gamepad.bumper.left": 0,
|
|
25
|
+
"gamepad.bumper.right": 0,
|
|
26
|
+
"gamepad.alpha": 0,
|
|
27
|
+
"gamepad.beta": 0,
|
|
28
|
+
"gamepad.gamma": 0,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=gamepad-inputs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gamepad-inputs.js","sourceRoot":"","sources":["../../../../s/nubs/virtual-gamepad/utils/gamepad-inputs.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,aAAa;IAC5B,OAAO;QACN,aAAa,EAAE,CAAC;QAEhB,uBAAuB,EAAE,CAAC;QAC1B,yBAAyB,EAAE,CAAC;QAC5B,yBAAyB,EAAE,CAAC;QAC5B,0BAA0B,EAAE,CAAC;QAE7B,wBAAwB,EAAE,CAAC;QAC3B,0BAA0B,EAAE,CAAC;QAC7B,0BAA0B,EAAE,CAAC;QAC7B,2BAA2B,EAAE,CAAC;QAE9B,0BAA0B,EAAE,CAAC;QAC7B,2BAA2B,EAAE,CAAC;QAE9B,WAAW,EAAE,CAAC;QACd,WAAW,EAAE,CAAC;QACd,WAAW,EAAE,CAAC;QACd,WAAW,EAAE,CAAC;QAEd,YAAY,EAAE,CAAC;QACf,cAAc,EAAE,CAAC;QACjB,cAAc,EAAE,CAAC;QACjB,eAAe,EAAE,CAAC;QAElB,sBAAsB,EAAE,CAAC;QACzB,uBAAuB,EAAE,CAAC;QAE1B,qBAAqB,EAAE,CAAC;QACxB,sBAAsB,EAAE,CAAC;QAEzB,eAAe,EAAE,CAAC;QAClB,cAAc,EAAE,CAAC;QACjB,eAAe,EAAE,CAAC;KAClB,CAAA;AACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function preventDefaultTouchShenanigans(): () => void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function preventDefaultTouchShenanigans() {
|
|
2
|
+
const preventer = (e) => e.preventDefault();
|
|
3
|
+
const opts = { passive: false };
|
|
4
|
+
window.addEventListener("touchmove", preventer, opts);
|
|
5
|
+
return () => {
|
|
6
|
+
window.removeEventListener("touchmove", preventer);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=prevent-default-touch-shenanigans.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prevent-default-touch-shenanigans.js","sourceRoot":"","sources":["../../../../s/nubs/virtual-gamepad/utils/prevent-default-touch-shenanigans.ts"],"names":[],"mappings":"AACA,MAAM,UAAU,8BAA8B;IAC7C,MAAM,SAAS,GAAG,CAAC,CAAa,EAAE,EAAE,CAAC,CAAC,CAAC,cAAc,EAAE,CAAA;IACvD,MAAM,IAAI,GAAG,EAAC,OAAO,EAAE,KAAK,EAAC,CAAA;IAE7B,MAAM,CAAC,gBAAgB,CAAC,WAAW,EAAE,SAAS,EAAE,IAAI,CAAC,CAAA;IAErD,OAAO,GAAG,EAAE;QACX,MAAM,CAAC,mBAAmB,CAAC,WAAW,EAAE,SAAS,CAAC,CAAA;IACnD,CAAC,CAAA;AACF,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ev, MapG } from "@e280/stz";
|
|
2
|
+
export function touchTracking({ target, buttons, touchdown, touchup }) {
|
|
3
|
+
const tracks = new MapG;
|
|
4
|
+
function grabTrack(touch) {
|
|
5
|
+
return tracks.guarantee(touch.identifier, () => new Track(touchdown, touchup));
|
|
6
|
+
}
|
|
7
|
+
function underTouch(touch) {
|
|
8
|
+
const element = target.elementFromPoint(touch.clientX, touch.clientY);
|
|
9
|
+
return (element && element instanceof HTMLButtonElement && buttons.has(element))
|
|
10
|
+
? element
|
|
11
|
+
: undefined;
|
|
12
|
+
}
|
|
13
|
+
function additive(event) {
|
|
14
|
+
for (const touch of Array.from(event.touches)) {
|
|
15
|
+
const track = grabTrack(touch);
|
|
16
|
+
track.button = underTouch(touch);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function subtractive(event) {
|
|
20
|
+
for (const touch of Array.from(event.changedTouches)) {
|
|
21
|
+
const track = grabTrack(touch);
|
|
22
|
+
track.button = undefined;
|
|
23
|
+
tracks.delete(touch.identifier);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return ev(window, {
|
|
27
|
+
touchstart: additive,
|
|
28
|
+
touchmove: additive,
|
|
29
|
+
touchcancel: subtractive,
|
|
30
|
+
touchend: subtractive,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
class Track {
|
|
34
|
+
touchdown;
|
|
35
|
+
touchup;
|
|
36
|
+
#button = undefined;
|
|
37
|
+
constructor(touchdown, touchup) {
|
|
38
|
+
this.touchdown = touchdown;
|
|
39
|
+
this.touchup = touchup;
|
|
40
|
+
}
|
|
41
|
+
get button() {
|
|
42
|
+
return this.#button;
|
|
43
|
+
}
|
|
44
|
+
set button(next) {
|
|
45
|
+
const previous = this.#button;
|
|
46
|
+
const changed = next !== previous;
|
|
47
|
+
this.#button = next;
|
|
48
|
+
if (changed && previous) {
|
|
49
|
+
this.touchup(previous);
|
|
50
|
+
}
|
|
51
|
+
if (changed && next)
|
|
52
|
+
this.touchdown(next);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=touch-tracking.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"touch-tracking.js","sourceRoot":"","sources":["../../../../s/nubs/virtual-gamepad/utils/touch-tracking.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,EAAE,EAAE,IAAI,EAAC,MAAM,WAAW,CAAA;AAElC,MAAM,UAAU,aAAa,CAAC,EAAC,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAKhE;IAED,MAAM,MAAM,GAAG,IAAI,IAAmB,CAAA;IAEtC,SAAS,SAAS,CAAC,KAAY;QAC9B,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI,KAAK,CACxD,S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AAC;IAEJ,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,OAAO,CAAA;IACpB,CAAC;IAED,IAAI,MAAM,CAAC,IAAmC;QAC7C,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAA;QAC7B,MAAM,OAAO,GAAG,IAAI,KAAK,QAAQ,CAAA;QAEjC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;QAEnB,IAAI,OAAO,IAAI,QAAQ,EAAE,CAAC;YACzB,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;QACvB,CAAC;QACD,IAAI,OAAO,IAAI,IAAI;YAClB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IACtB,CAAC;CACD"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { html } from "lit";
|
|
2
|
+
import { view } from "@e280/sly";
|
|
3
|
+
import { ev, MapG } from "@e280/stz";
|
|
4
|
+
import stylesCss from "./styles.css.js";
|
|
5
|
+
import { NubStick } from "../stick/view.js";
|
|
6
|
+
import { touchTracking } from "./utils/touch-tracking.js";
|
|
7
|
+
import { preventDefaultTouchShenanigans } from "./utils/prevent-default-touch-shenanigans.js";
|
|
8
|
+
export const VirtualGamepad = view(use => (device) => {
|
|
9
|
+
use.name("virtual-gamepad");
|
|
10
|
+
use.css(stylesCss);
|
|
11
|
+
const buttons = use.once(() => new Set());
|
|
12
|
+
const codes = use.once(() => new MapG());
|
|
13
|
+
use.rendered.then(() => {
|
|
14
|
+
const elements = Array.from(use.shadow.querySelectorAll("button[x-code]"));
|
|
15
|
+
for (const button of elements) {
|
|
16
|
+
const code = button.getAttribute("x-code");
|
|
17
|
+
if (code) {
|
|
18
|
+
buttons.add(button);
|
|
19
|
+
codes.set(button, code);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
use.mount(() => preventDefaultTouchShenanigans());
|
|
24
|
+
use.mount(() => touchTracking({
|
|
25
|
+
target: use.shadow,
|
|
26
|
+
buttons,
|
|
27
|
+
touchdown: button => {
|
|
28
|
+
const code = codes.require(button);
|
|
29
|
+
device.setSample(code, 1);
|
|
30
|
+
},
|
|
31
|
+
touchup: button => {
|
|
32
|
+
const code = codes.require(button);
|
|
33
|
+
device.setSample(code, 0);
|
|
34
|
+
},
|
|
35
|
+
}));
|
|
36
|
+
use.mount(() => ev(use.shadow, {
|
|
37
|
+
contextmenu: (e) => e.preventDefault(),
|
|
38
|
+
}));
|
|
39
|
+
function button(code, label) {
|
|
40
|
+
return html `
|
|
41
|
+
<button x-code="${code}">${label}</button>
|
|
42
|
+
`;
|
|
43
|
+
}
|
|
44
|
+
function renderDPad() {
|
|
45
|
+
return html `
|
|
46
|
+
<div class=pad>
|
|
47
|
+
<div>
|
|
48
|
+
${button("gamepad.left", "w")}
|
|
49
|
+
</div>
|
|
50
|
+
<div>
|
|
51
|
+
${button("gamepad.up", "n")}
|
|
52
|
+
${button("gamepad.down", "s")}
|
|
53
|
+
</div>
|
|
54
|
+
<div>
|
|
55
|
+
${button("gamepad.right", "e")}
|
|
56
|
+
</div>
|
|
57
|
+
</div>
|
|
58
|
+
`;
|
|
59
|
+
}
|
|
60
|
+
function renderButtonPad() {
|
|
61
|
+
return html `
|
|
62
|
+
<div class=pad>
|
|
63
|
+
<div>
|
|
64
|
+
${button("gamepad.x", "x")}
|
|
65
|
+
</div>
|
|
66
|
+
<div>
|
|
67
|
+
${button("gamepad.y", "y")}
|
|
68
|
+
${button("gamepad.a", "a")}
|
|
69
|
+
</div>
|
|
70
|
+
<div>
|
|
71
|
+
${button("gamepad.b", "b")}
|
|
72
|
+
</div>
|
|
73
|
+
</div>
|
|
74
|
+
`;
|
|
75
|
+
}
|
|
76
|
+
function renderLeftShoulder() {
|
|
77
|
+
return html `
|
|
78
|
+
<div class=shoulder>
|
|
79
|
+
${button("gamepad.trigger.left", "lt")}
|
|
80
|
+
${button("gamepad.bumper.left", "lb")}
|
|
81
|
+
${button("gamepad.stick.left.click", "lc")}
|
|
82
|
+
</div>
|
|
83
|
+
`;
|
|
84
|
+
}
|
|
85
|
+
function renderRightShoulder() {
|
|
86
|
+
return html `
|
|
87
|
+
<div class=shoulder>
|
|
88
|
+
${button("gamepad.trigger.right", "rt")}
|
|
89
|
+
${button("gamepad.bumper.right", "rb")}
|
|
90
|
+
${button("gamepad.stick.right.click", "rc")}
|
|
91
|
+
</div>
|
|
92
|
+
`;
|
|
93
|
+
}
|
|
94
|
+
return html `
|
|
95
|
+
<div class=upper>
|
|
96
|
+
${button("gamepad.alpha", "alpha")}
|
|
97
|
+
${button("gamepad.beta", "beta")}
|
|
98
|
+
${button("gamepad.gamma", "gamma")}
|
|
99
|
+
</div>
|
|
100
|
+
|
|
101
|
+
<div class=lower>
|
|
102
|
+
<div class="left side">
|
|
103
|
+
${renderLeftShoulder()}
|
|
104
|
+
${renderDPad()}
|
|
105
|
+
${NubStick
|
|
106
|
+
.attr("class", "stick")
|
|
107
|
+
.props(device.stickLeft)}
|
|
108
|
+
</div>
|
|
109
|
+
|
|
110
|
+
<div class="right side">
|
|
111
|
+
${renderRightShoulder()}
|
|
112
|
+
${renderButtonPad()}
|
|
113
|
+
${NubStick
|
|
114
|
+
.attr("class", "stick")
|
|
115
|
+
.props(device.stickRight)}
|
|
116
|
+
</div>
|
|
117
|
+
</div>
|
|
118
|
+
`;
|
|
119
|
+
});
|
|
120
|
+
//# sourceMappingURL=view.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view.js","sourceRoot":"","sources":["../../../s/nubs/virtual-gamepad/view.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,IAAI,EAAC,MAAM,KAAK,CAAA;AACxB,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAC9B,OAAO,EAAC,EAAE,EAAE,IAAI,EAAC,MAAM,WAAW,CAAA;AAElC,OAAO,SAAS,MAAM,iBAAiB,CAAA;AAEvC,OAAO,EAAC,QAAQ,EAAC,MAAM,kBAAkB,CAAA;AAGzC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AM,CAAC,0BAA0B,EAAE,IAAI,CAAC;;GAE3C,CAAA;IACF,CAAC;IAED,SAAS,mBAAmB;QAC3B,OAAO,IAAI,CAAA;;MAEP,MAAM,CAAC,uBAAuB,EAAE,IAAI,CAAC;MACrC,MAAM,CAAC,sBAAsB,EAAE,IAAI,CAAC;MACpC,MAAM,CAAC,2BAA2B,EAAE,IAAI,CAAC;;GAE5C,CAAA;IACF,CAAC;IAED,OAAO,IAAI,CAAA;;KAEP,MAAM,CAAC,eAAe,EAAE,OAAO,CAAC;KAChC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC;KAC9B,MAAM,CAAC,eAAe,EAAE,OAAO,CAAC;;;;;MAK/B,kBAAkB,EAAE;MACpB,UAAU,EAAE;MACZ,QAAQ;SACR,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC;SACtB,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC;;;;MAIvB,mBAAmB,EAAE;MACrB,eAAe,EAAE;MACjB,QAAQ;SACR,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC;SACtB,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC;;;EAG5B,CAAA;AACF,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SamplerDevice } from "./infra/sampler.js";
|
|
2
|
+
import { Pad } from "../../utils/gamepads.js";
|
|
3
|
+
export declare class GamepadDevice extends SamplerDevice {
|
|
4
|
+
#private;
|
|
5
|
+
pad: Pad;
|
|
6
|
+
static on(fn: (device: GamepadDevice) => () => void): () => void;
|
|
7
|
+
constructor(pad: Pad);
|
|
8
|
+
get gamepad(): Gamepad;
|
|
9
|
+
takeSamples(): import("../types.js").Sample[];
|
|
10
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { tmax } from "../utils/tmax.js";
|
|
2
|
+
import { SamplerDevice } from "./infra/sampler.js";
|
|
3
|
+
import { splitAxis } from "../../utils/split-axis.js";
|
|
4
|
+
import { gamepads } from "../../utils/gamepads.js";
|
|
5
|
+
const gamepadButtonCodes = [
|
|
6
|
+
"gamepad.a",
|
|
7
|
+
"gamepad.b",
|
|
8
|
+
"gamepad.x",
|
|
9
|
+
"gamepad.y",
|
|
10
|
+
"gamepad.bumper.left",
|
|
11
|
+
"gamepad.bumper.right",
|
|
12
|
+
"gamepad.trigger.left",
|
|
13
|
+
"gamepad.trigger.right",
|
|
14
|
+
"gamepad.alpha",
|
|
15
|
+
"gamepad.beta",
|
|
16
|
+
"gamepad.stick.left.click",
|
|
17
|
+
"gamepad.stick.right.click",
|
|
18
|
+
"gamepad.up",
|
|
19
|
+
"gamepad.down",
|
|
20
|
+
"gamepad.left",
|
|
21
|
+
"gamepad.right",
|
|
22
|
+
"gamepad.gamma",
|
|
23
|
+
];
|
|
24
|
+
export class GamepadDevice extends SamplerDevice {
|
|
25
|
+
pad;
|
|
26
|
+
static on(fn) {
|
|
27
|
+
return gamepads(pad => fn(new this(pad)));
|
|
28
|
+
}
|
|
29
|
+
constructor(pad) {
|
|
30
|
+
super();
|
|
31
|
+
this.pad = pad;
|
|
32
|
+
}
|
|
33
|
+
get gamepad() {
|
|
34
|
+
return this.pad.gamepad;
|
|
35
|
+
}
|
|
36
|
+
takeSamples() {
|
|
37
|
+
const { gamepad } = this.pad;
|
|
38
|
+
this.#pollButtons(gamepad);
|
|
39
|
+
this.#pollSticks(gamepad);
|
|
40
|
+
return super.takeSamples();
|
|
41
|
+
}
|
|
42
|
+
#pollButtons(gamepad) {
|
|
43
|
+
let anyButtonValue = 0;
|
|
44
|
+
const recordAny = (value) => {
|
|
45
|
+
anyButtonValue = tmax([anyButtonValue, value]);
|
|
46
|
+
};
|
|
47
|
+
for (const [index, code] of gamepadButtonCodes.entries()) {
|
|
48
|
+
const value = gamepad.buttons.at(index)?.value ?? 0;
|
|
49
|
+
recordAny(value);
|
|
50
|
+
this.setSample(code, value);
|
|
51
|
+
}
|
|
52
|
+
this.setSample("gamepad.any", anyButtonValue);
|
|
53
|
+
}
|
|
54
|
+
#pollSticks(gamepad) {
|
|
55
|
+
const [leftY, leftX, rightY, rightX] = gamepad.axes;
|
|
56
|
+
const [leftUp, leftDown] = splitAxis(leftX);
|
|
57
|
+
const [leftLeft, leftRight] = splitAxis(leftY);
|
|
58
|
+
this.setSample("gamepad.stick.left.up", leftUp);
|
|
59
|
+
this.setSample("gamepad.stick.left.down", leftDown);
|
|
60
|
+
this.setSample("gamepad.stick.left.left", leftLeft);
|
|
61
|
+
this.setSample("gamepad.stick.left.right", leftRight);
|
|
62
|
+
const [rightUp, rightDown] = splitAxis(rightX);
|
|
63
|
+
const [rightLeft, rightRight] = splitAxis(rightY);
|
|
64
|
+
this.setSample("gamepad.stick.right.up", rightUp);
|
|
65
|
+
this.setSample("gamepad.stick.right.down", rightDown);
|
|
66
|
+
this.setSample("gamepad.stick.right.left", rightLeft);
|
|
67
|
+
this.setSample("gamepad.stick.right.right", rightRight);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=gamepad.js.map
|