@antha/input 0.9.0 → 0.11.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.
@@ -65,6 +65,7 @@ export function createAnthaInputBindingsMod(options = {}) {
65
65
  const gamepadInputDeviceKeys = getEnumValues(GamepadInputDeviceKey);
66
66
  function filterRawInput(entry, binding) {
67
67
  return (entry?.direction === binding.direction &&
68
+ !entry.isIgnoredByConsumer &&
68
69
  (binding.gamepadBrand ? binding.gamepadBrand === entry.mapped.gamepadBrand : true));
69
70
  }
70
71
  function readPlayerBindings({ bindingsMap, activeBindingsMap, rawInputs, msSinceLastExecute, gamepadKeyMap, }) {
@@ -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
+ }
@@ -20,6 +20,7 @@ export type AnthaReadRawInputModOptions = PartialWithUndefined<{
20
20
  */
21
21
  deviceHandlerOptions: Omit<InputDeviceHandlerOptions, 'startLoopImmediately'>;
22
22
  debugRawInputs: AnthaReadRawInputModState['debugRawInputs'];
23
+ startRawInputConsumer: AnthaReadRawInputModState['rawInputConsumer'];
23
24
  }>;
24
25
  /**
25
26
  * All state used by and set by `createAnthaReadRawInputMod`.
@@ -29,6 +30,8 @@ export type AnthaReadRawInputModOptions = PartialWithUndefined<{
29
30
  export type AnthaReadRawInputModState = {
30
31
  deviceHandler: Pick<InputDeviceHandler, 'readAllDevices'>;
31
32
  rawInputs: RawInputs;
33
+ /** Identifies the part of the game that owns newly started raw inputs. */
34
+ rawInputConsumer: string | undefined;
32
35
  currentInputDevices: SimpleInputDevicesMap;
33
36
  /** The engine time when a timed input lock expires. */
34
37
  inputDisableEndsAt: EngineTime | undefined;
@@ -78,6 +81,7 @@ export type AnthaReadRawInputMod = ReturnType<typeof createAnthaReadRawInputMod>
78
81
  */
79
82
  export declare function readRawInputs(state: SetRequired<SelectFrom<Partial<AnthaReadRawInputModState>, {
80
83
  rawInputs: true;
84
+ rawInputConsumer: true;
81
85
  deviceHandler: true;
82
86
  gamepadLayouts: true;
83
87
  gamepadBrandMap: true;
@@ -17,6 +17,7 @@ export function createAnthaReadRawInputMod(options = {}) {
17
17
  initState: {
18
18
  debugRawInputs: !!options.debugRawInputs,
19
19
  inputDisableEndsAt: undefined,
20
+ rawInputConsumer: options.startRawInputConsumer,
20
21
  },
21
22
  execute({ engine, state, msSinceLastExecute }) {
22
23
  if (state.inputDisableEndsAt != undefined &&
@@ -71,6 +72,9 @@ export function readRawInputs(state, { msSinceLastExecute, }) {
71
72
  const previousRawInput = potentialPreviousRawInput?.direction === direction
72
73
  ? potentialPreviousRawInput
73
74
  : undefined;
75
+ const consumedBy = previousRawInput
76
+ ? previousRawInput.consumedBy
77
+ : state.rawInputConsumer;
74
78
  const duration = {
75
79
  milliseconds: previousRawInput
76
80
  ? Math.round(previousRawInput.duration.milliseconds + msSinceLastExecute)
@@ -100,7 +104,7 @@ export function readRawInputs(state, { msSinceLastExecute, }) {
100
104
  gamepadModel: model?.gamepadModel,
101
105
  });
102
106
  const rawInput = {
103
- consumedBy: previousRawInput?.consumedBy,
107
+ consumedBy,
104
108
  mapped: {
105
109
  deviceName: model?.gamepadModel || device.deviceName,
106
110
  gamepadBrand: model?.gamepadBrand,
@@ -113,6 +117,9 @@ export function readRawInputs(state, { msSinceLastExecute, }) {
113
117
  duration,
114
118
  inputName: currentInput.inputName,
115
119
  inputValue: currentInput.inputValue,
120
+ isIgnoredByConsumer: !!state.rawInputConsumer &&
121
+ !!consumedBy &&
122
+ consumedBy !== state.rawInputConsumer,
116
123
  };
117
124
  if (mappedInputName) {
118
125
  deviceInputs[mappedInputName] = rawInput;
@@ -26,6 +26,8 @@ export declare function calculateInputDirection(inputValue: number): InputDirect
26
26
  export type RawInput = Omit<InputValueWrapper<InputDeviceKey, any>, 'details'> & {
27
27
  /** An identifier set by a game when it claims this input. */
28
28
  consumedBy: string | undefined;
29
+ /** True when this input belongs to a different raw input consumer. */
30
+ isIgnoredByConsumer: boolean;
29
31
  mapped: SelectFrom<InputValueWrapper<InputDeviceKey, any>, {
30
32
  /**
31
33
  * `deviceName` is mapped by `gamepadModelMap`. If no mapping exists, this will always
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antha/input",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
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.9.0",
36
+ "@antha/gamepad-type": "^0.11.0",
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.9.0",
56
+ "@antha/engine": "^0.11.0",
55
57
  "element-vir": ">=26"
56
58
  },
57
59
  "engines": {