@typeonce/ritmo-browser 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +106 -0
- package/README.md +6 -1
- package/dist/Controls.d.ts +496 -0
- package/dist/Controls.d.ts.map +1 -0
- package/dist/Controls.js +343 -0
- package/dist/Controls.js.map +1 -0
- package/dist/Gamepad.d.ts +376 -0
- package/dist/Gamepad.d.ts.map +1 -0
- package/dist/Gamepad.js +459 -0
- package/dist/Gamepad.js.map +1 -0
- package/dist/InputCapture.d.ts +46 -16
- package/dist/InputCapture.d.ts.map +1 -1
- package/dist/InputCapture.js +1 -1
- package/dist/InputCapture.js.map +1 -1
- package/dist/Keyboard.d.ts +177 -25
- package/dist/Keyboard.d.ts.map +1 -1
- package/dist/Keyboard.js +257 -91
- package/dist/Keyboard.js.map +1 -1
- package/dist/Pointer.d.ts +233 -64
- package/dist/Pointer.d.ts.map +1 -1
- package/dist/Pointer.js +205 -145
- package/dist/Pointer.js.map +1 -1
- package/dist/Touch.d.ts +75 -33
- package/dist/Touch.d.ts.map +1 -1
- package/dist/Touch.js +25 -30
- package/dist/Touch.js.map +1 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/buttons.d.ts +52 -0
- package/dist/internal/buttons.d.ts.map +1 -0
- package/dist/internal/buttons.js +211 -0
- package/dist/internal/buttons.js.map +1 -0
- package/dist/internal/introspect.d.ts +14 -0
- package/dist/internal/introspect.d.ts.map +1 -0
- package/dist/internal/introspect.js +19 -0
- package/dist/internal/introspect.js.map +1 -0
- package/dist/internal/state.d.ts +13 -0
- package/dist/internal/state.d.ts.map +1 -0
- package/dist/internal/state.js +2 -0
- package/dist/internal/state.js.map +1 -0
- package/dist/internal/used.d.ts +8 -0
- package/dist/internal/used.d.ts.map +1 -0
- package/dist/internal/used.js +14 -0
- package/dist/internal/used.js.map +1 -0
- package/dist/internal/vectors.d.ts +29 -0
- package/dist/internal/vectors.d.ts.map +1 -0
- package/dist/internal/vectors.js +22 -0
- package/dist/internal/vectors.js.map +1 -0
- package/package.json +4 -3
- package/src/Controls.ts +800 -0
- package/src/Gamepad.ts +752 -0
- package/src/InputCapture.ts +43 -24
- package/src/Keyboard.ts +387 -72
- package/src/Pointer.ts +392 -166
- package/src/Touch.ts +113 -61
- package/src/index.ts +10 -1
- package/src/internal/buttons.ts +222 -0
- package/src/internal/introspect.ts +23 -0
- package/src/internal/state.ts +12 -0
- package/src/internal/used.ts +14 -0
- package/src/internal/vectors.ts +41 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A direction and strength, length at most 1, `y` growing down as on
|
|
3
|
+
* screen, the same on every device and in `Controls`: a vector action, a
|
|
4
|
+
* stick's tilt (dead zone removed, zero at rest, 1 at full tilt), or a
|
|
5
|
+
* touch stick, swipe or aim.
|
|
6
|
+
*/
|
|
7
|
+
export interface Vector {
|
|
8
|
+
readonly x: number
|
|
9
|
+
readonly y: number
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** The four directions a digital vector binding names. */
|
|
13
|
+
export const directions = ["up", "down", "left", "right"] as const
|
|
14
|
+
|
|
15
|
+
/** One direction of a vector action; a keyboard timeline names it as `"move.right"`. */
|
|
16
|
+
export type Direction = (typeof directions)[number]
|
|
17
|
+
|
|
18
|
+
export const zero: Vector = { x: 0, y: 0 }
|
|
19
|
+
|
|
20
|
+
/** The internal action name of one direction of a vector, for timelines and the button trackers. */
|
|
21
|
+
export const directionName = (vector: string, direction: Direction): string => `${vector}.${direction}`
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The vector four held directions give: opposite directions cancel and a
|
|
25
|
+
* diagonal has length 1, so it is not faster than a straight line.
|
|
26
|
+
*/
|
|
27
|
+
export const digital = (up: boolean, down: boolean, left: boolean, right: boolean): Vector => {
|
|
28
|
+
const x = (right ? 1 : 0) - (left ? 1 : 0)
|
|
29
|
+
const y = (down ? 1 : 0) - (up ? 1 : 0)
|
|
30
|
+
if (x === 0 && y === 0) return zero
|
|
31
|
+
return x !== 0 && y !== 0 ? { x: x * Math.SQRT1_2, y: y * Math.SQRT1_2 } : { x, y }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const lengthSquared = (vector: Vector): number => vector.x * vector.x + vector.y * vector.y
|
|
35
|
+
|
|
36
|
+
/** The longer of two vectors, the first on a tie: how vectors from several sources combine. */
|
|
37
|
+
export const longer = (a: Vector, b: Vector): Vector => lengthSquared(b) > lengthSquared(a) ? b : a
|
|
38
|
+
|
|
39
|
+
/** Whether a binding entry is a vector binding (`Keyboard.vector`, `Gamepad.vector`). */
|
|
40
|
+
export const isVectorBinding = (entry: unknown): entry is { readonly _tag: "Vector" } =>
|
|
41
|
+
typeof entry === "object" && entry !== null && !Array.isArray(entry) && (entry as { readonly _tag?: unknown })._tag === "Vector"
|