@antha/input 0.10.0 → 0.11.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/dist/bindings/antha-input-bindings.mod.d.ts +3 -0
- package/dist/bindings/antha-input-bindings.mod.js +12 -3
- package/dist/bindings/player-bindings.d.ts +9 -0
- package/dist/bindings/player-bindings.js +14 -0
- package/dist/raw-inputs/antha-read-raw-input.mod.d.ts +0 -3
- package/dist/raw-inputs/antha-read-raw-input.mod.js +10 -18
- package/package.json +6 -4
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type EngineTime } from '@antha/engine';
|
|
1
2
|
import { type SelectFrom } from '@augment-vir/common';
|
|
2
3
|
import { type AnthaReadRawInputModState } from '../raw-inputs/antha-read-raw-input.mod.js';
|
|
3
4
|
import { type GamepadKeyMap, type PlayersActiveBindings, type PlayersBindingAssignments } from './player-bindings.js';
|
|
@@ -18,6 +19,8 @@ export type AnthaInputBindingsModOptions<BindingNames extends string = string> =
|
|
|
18
19
|
* @category Internal
|
|
19
20
|
*/
|
|
20
21
|
export type AnthaInputBindingsModState<BindingNames extends string = string> = Pick<AnthaReadRawInputModState, 'rawInputs'> & {
|
|
22
|
+
/** The engine time when active bindings become available again. */
|
|
23
|
+
inputDisableEndsAt: EngineTime | undefined;
|
|
21
24
|
/** Maps gamepads to different gamepad slots. See `GamepadKeyMap` for more information. */
|
|
22
25
|
gamepadKeyMap: GamepadKeyMap;
|
|
23
26
|
/** Bindings for all players. */
|
|
@@ -18,9 +18,18 @@ import { AnyGamepad, } from './player-bindings.js';
|
|
|
18
18
|
export function createAnthaInputBindingsMod(options = {}) {
|
|
19
19
|
return defineAnthaMod({
|
|
20
20
|
modName: 'antha-input-bindings',
|
|
21
|
-
initState:
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
initState: {
|
|
22
|
+
inputDisableEndsAt: undefined,
|
|
23
|
+
...options,
|
|
24
|
+
},
|
|
25
|
+
execute({ engine, state, msSinceLastExecute }) {
|
|
26
|
+
if (state.inputDisableEndsAt != undefined &&
|
|
27
|
+
state.inputDisableEndsAt <= engine.totalMs) {
|
|
28
|
+
state.inputDisableEndsAt = undefined;
|
|
29
|
+
}
|
|
30
|
+
if (state.inputDisableEndsAt != undefined ||
|
|
31
|
+
!state.bindingAssignments ||
|
|
32
|
+
!state.rawInputs) {
|
|
24
33
|
/** Nothing to do if there are no bindings or inputs. */
|
|
25
34
|
state.activeBindings = {};
|
|
26
35
|
}
|
|
@@ -85,6 +85,15 @@ export type BindingAssignments<BindingNames extends string = string> = Partial<R
|
|
|
85
85
|
* @category Internal
|
|
86
86
|
*/
|
|
87
87
|
export type PlayersBindingAssignments<BindingNames extends string = string> = Record<PlayerPosition, BindingAssignments<BindingNames>>;
|
|
88
|
+
/**
|
|
89
|
+
* Returns assignments limited to the binding names supported by the consuming game.
|
|
90
|
+
*
|
|
91
|
+
* @category Internal
|
|
92
|
+
*/
|
|
93
|
+
export declare function filterToAllowedActions<BindingNames extends string>({ allowedBindingNames, bindingAssignments, }: Readonly<{
|
|
94
|
+
allowedBindingNames: ReadonlyArray<BindingNames>;
|
|
95
|
+
bindingAssignments: Readonly<Partial<Record<PlayerPosition, Readonly<BindingAssignments>>>>;
|
|
96
|
+
}>): PlayersBindingAssignments<BindingNames>;
|
|
88
97
|
/**
|
|
89
98
|
* An individual active binding. Used in `createAnthaReadBindingsMod` and {@link ActiveBindings}.
|
|
90
99
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getObjectTypedEntries, pickObjectKeys } from '@augment-vir/common';
|
|
1
2
|
import { InputDeviceKey } from 'input-device-handler';
|
|
2
3
|
import { defineShape, enumShape, nonEmptyStringShape, optionalShape, recordShape, typedStringShape, } from 'object-shape-tester';
|
|
3
4
|
import { InputDirection } from '../raw-inputs/raw-input.js';
|
|
@@ -35,3 +36,16 @@ export const playersBindingAssignmentsShape = recordShape({
|
|
|
35
36
|
values: [bindingAssignmentShape],
|
|
36
37
|
}),
|
|
37
38
|
});
|
|
39
|
+
/**
|
|
40
|
+
* Returns assignments limited to the binding names supported by the consuming game.
|
|
41
|
+
*
|
|
42
|
+
* @category Internal
|
|
43
|
+
*/
|
|
44
|
+
export function filterToAllowedActions({ allowedBindingNames, bindingAssignments, }) {
|
|
45
|
+
return getObjectTypedEntries(bindingAssignments).reduce((filteredBindingAssignments, [playerPosition, playerBindingAssignments,]) => {
|
|
46
|
+
return {
|
|
47
|
+
...filteredBindingAssignments,
|
|
48
|
+
[playerPosition]: pickObjectKeys(playerBindingAssignments, allowedBindingNames),
|
|
49
|
+
};
|
|
50
|
+
}, {});
|
|
51
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type EngineTime } from '@antha/engine';
|
|
2
1
|
import { type GamepadBrandMap, type GamepadLayout, type GamepadModelMap } from '@antha/gamepad-type';
|
|
3
2
|
import { type PartialWithUndefined, type SelectFrom, type SetRequired } from '@augment-vir/common';
|
|
4
3
|
import { InputDeviceHandler, type InputDeviceHandlerOptions, type InputDeviceKey } from 'input-device-handler';
|
|
@@ -33,8 +32,6 @@ export type AnthaReadRawInputModState = {
|
|
|
33
32
|
/** Identifies the part of the game that owns newly started raw inputs. */
|
|
34
33
|
rawInputConsumer: string | undefined;
|
|
35
34
|
currentInputDevices: SimpleInputDevicesMap;
|
|
36
|
-
/** The engine time when a timed input lock expires. */
|
|
37
|
-
inputDisableEndsAt: EngineTime | undefined;
|
|
38
35
|
/**
|
|
39
36
|
* If no model map is provided, the built-in defaults from
|
|
40
37
|
* [gamepad-type](https://www.npmjs.com/package/gamepad-type) are used. If a model map is
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineAnthaMod } from '@antha/engine';
|
|
2
2
|
import { defaultGamepadLayouts, defaultGamepadModelMap, findMatchingGamepadLayout, findMatchingGamepadModel, modelInputNameOverrides, } from '@antha/gamepad-type';
|
|
3
|
-
import { check } from '@augment-vir/assert';
|
|
3
|
+
import { assertWrap, check } from '@augment-vir/assert';
|
|
4
4
|
import { mapObject, } from '@augment-vir/common';
|
|
5
5
|
import { html } from 'element-vir';
|
|
6
6
|
import { InputDeviceHandler, isGamepadDeviceKey, } from 'input-device-handler';
|
|
@@ -16,14 +16,9 @@ export function createAnthaReadRawInputMod(options = {}) {
|
|
|
16
16
|
modName: 'antha-read-raw-input',
|
|
17
17
|
initState: {
|
|
18
18
|
debugRawInputs: !!options.debugRawInputs,
|
|
19
|
-
inputDisableEndsAt: undefined,
|
|
20
19
|
rawInputConsumer: options.startRawInputConsumer,
|
|
21
20
|
},
|
|
22
|
-
execute({
|
|
23
|
-
if (state.inputDisableEndsAt != undefined &&
|
|
24
|
-
state.inputDisableEndsAt <= engine.totalMs) {
|
|
25
|
-
state.inputDisableEndsAt = undefined;
|
|
26
|
-
}
|
|
21
|
+
execute({ state, msSinceLastExecute }) {
|
|
27
22
|
if (!state.deviceHandler) {
|
|
28
23
|
state.deviceHandler =
|
|
29
24
|
options.deviceHandler ||
|
|
@@ -32,17 +27,14 @@ export function createAnthaReadRawInputMod(options = {}) {
|
|
|
32
27
|
startLoopImmediately: false,
|
|
33
28
|
});
|
|
34
29
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
state.rawInputs = {};
|
|
44
|
-
state.currentInputDevices = {};
|
|
45
|
-
}
|
|
30
|
+
const { currentDevices, rawInputs } = readRawInputs({
|
|
31
|
+
...state,
|
|
32
|
+
deviceHandler: assertWrap.isDefined(state.deviceHandler),
|
|
33
|
+
}, {
|
|
34
|
+
msSinceLastExecute,
|
|
35
|
+
});
|
|
36
|
+
state.rawInputs = rawInputs;
|
|
37
|
+
state.currentInputDevices = currentDevices;
|
|
46
38
|
if (state.debugRawInputs) {
|
|
47
39
|
return html `
|
|
48
40
|
<${AnthaRawInputDebug.assign({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antha/input",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "An Antha mod for handling inputs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vir",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"test:docs": "virmator docs check"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@antha/gamepad-type": "^0.
|
|
36
|
+
"@antha/gamepad-type": "^0.11.1",
|
|
37
37
|
"@augment-vir/assert": "^32.2.3",
|
|
38
38
|
"@augment-vir/common": "^32.2.3",
|
|
39
39
|
"date-vir": "^9.1.1",
|
|
@@ -48,10 +48,12 @@
|
|
|
48
48
|
"@web/test-runner": "^1.0.0",
|
|
49
49
|
"@web/test-runner-playwright": "^1.0.0",
|
|
50
50
|
"element-vir": "^26.17.3",
|
|
51
|
-
"istanbul-smart-text-reporter": "^1.1.5"
|
|
51
|
+
"istanbul-smart-text-reporter": "^1.1.5",
|
|
52
|
+
"markdown-code-example-inserter": "^3.0.6",
|
|
53
|
+
"typedoc": "^0.28.20"
|
|
52
54
|
},
|
|
53
55
|
"peerDependencies": {
|
|
54
|
-
"@antha/engine": "^0.
|
|
56
|
+
"@antha/engine": "^0.11.1",
|
|
55
57
|
"element-vir": ">=26"
|
|
56
58
|
},
|
|
57
59
|
"engines": {
|