@antha/input 0.1.3 → 0.3.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.
@@ -58,12 +58,26 @@ export type MenuNavOptions = Readonly<Partial<{
58
58
  * @default {milliseconds: 60}
59
59
  */
60
60
  repeatInterval: Readonly<AnyDuration>;
61
+ /**
62
+ * The minimum input value required to trigger directional menu navigation. Helps prevent
63
+ * unintentional perpendicular navigation with joysticks in 2D menus.
64
+ *
65
+ * @default 0.8
66
+ */
67
+ minimumDirectionalInputValue: number;
61
68
  /**
62
69
  * Allow wrapping when navigating menu items.
63
70
  *
64
71
  * @default true
65
72
  */
66
73
  allowWrapping: boolean;
74
+ /**
75
+ * Prevent a one-dimensional nav tree from using its available axis for perpendicular
76
+ * navigation.
77
+ *
78
+ * @default false
79
+ */
80
+ blockPerpendicularNavigation: boolean;
67
81
  }>>;
68
82
  /**
69
83
  * State for {@link createAnthaMenuNavMod}.
@@ -40,6 +40,12 @@ export var MenuNavBinding;
40
40
  MenuNavBinding["MenuSectionPrevious"] = "menu-section-previous";
41
41
  MenuNavBinding["OpenPauseMenu"] = "open-pause-menu";
42
42
  })(MenuNavBinding || (MenuNavBinding = {}));
43
+ const directionalMenuNavBindings = [
44
+ MenuNavBinding.MenuUp,
45
+ MenuNavBinding.MenuDown,
46
+ MenuNavBinding.MenuLeft,
47
+ MenuNavBinding.MenuRight,
48
+ ];
43
49
  /**
44
50
  * Default menu nav bindings for {@link AnthaMenuNavMod}.
45
51
  *
@@ -223,7 +229,9 @@ export const defaultMenuNavOptions = {
223
229
  repeatInterval: {
224
230
  milliseconds: 60,
225
231
  },
232
+ minimumDirectionalInputValue: 0.8,
226
233
  allowWrapping: true,
234
+ blockPerpendicularNavigation: false,
227
235
  };
228
236
  /**
229
237
  * A pre-built mod that enables menu navigation. Set `isInMenu` on your game state to true to
@@ -257,6 +265,7 @@ export function createAnthaMenuNavMod(options = {}) {
257
265
  const repeatInterval = convertDuration(state.menuNavOptions.repeatInterval, {
258
266
  milliseconds: true,
259
267
  }).milliseconds;
268
+ const minimumDirectionalInputValue = state.menuNavOptions.minimumDirectionalInputValue;
260
269
  const bindingsToAct = {};
261
270
  const activeMenuBindings = {};
262
271
  getObjectTypedValues(state.activeBindings).forEach((playerActiveBindings) => {
@@ -265,11 +274,13 @@ export function createAnthaMenuNavMod(options = {}) {
265
274
  return;
266
275
  }
267
276
  activeMenuBindings[bindingName] = true;
268
- if (!activeBinding.actCount ||
269
- (activeBinding.holdDuration.milliseconds >= repeatThreshold &&
270
- activeBinding.holdDuration.milliseconds -
271
- activeBinding.lastActDuration.milliseconds >
272
- repeatInterval)) {
277
+ if ((!directionalMenuNavBindings.includes(bindingName) ||
278
+ activeBinding.value >= minimumDirectionalInputValue) &&
279
+ (!activeBinding.actCount ||
280
+ (activeBinding.holdDuration.milliseconds >= repeatThreshold &&
281
+ activeBinding.holdDuration.milliseconds -
282
+ activeBinding.lastActDuration.milliseconds >
283
+ repeatInterval))) {
273
284
  bindingsToAct[bindingName] = true;
274
285
  activeBinding.actCount++;
275
286
  activeBinding.lastActDuration = activeBinding.holdDuration;
@@ -300,6 +311,7 @@ export function createAnthaMenuNavMod(options = {}) {
300
311
  if (sectionDirection) {
301
312
  state.navController.navigatePibling({
302
313
  allowWrapping: state.menuNavOptions.allowWrapping,
314
+ blockPerpendicularNavigation: state.menuNavOptions.blockPerpendicularNavigation,
303
315
  direction: sectionDirection,
304
316
  });
305
317
  return;
@@ -319,12 +331,14 @@ export function createAnthaMenuNavMod(options = {}) {
319
331
  if (vertical) {
320
332
  state.navController.navigate({
321
333
  allowWrapping: state.menuNavOptions.allowWrapping,
334
+ blockPerpendicularNavigation: state.menuNavOptions.blockPerpendicularNavigation,
322
335
  direction: vertical,
323
336
  });
324
337
  }
325
338
  if (horizontal) {
326
339
  state.navController.navigate({
327
340
  allowWrapping: state.menuNavOptions.allowWrapping,
341
+ blockPerpendicularNavigation: state.menuNavOptions.blockPerpendicularNavigation,
328
342
  direction: horizontal,
329
343
  });
330
344
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antha/input",
3
- "version": "0.1.3",
3
+ "version": "0.3.0",
4
4
  "description": "An Antha mod for handling inputs.",
5
5
  "keywords": [
6
6
  "vir",
@@ -33,14 +33,14 @@
33
33
  "test:docs": "virmator docs check"
34
34
  },
35
35
  "dependencies": {
36
- "@antha/gamepad-type": "^0.1.3",
36
+ "@antha/gamepad-type": "^0.3.0",
37
37
  "@augment-vir/assert": "^32.2.3",
38
38
  "@augment-vir/common": "^32.2.3",
39
39
  "date-vir": "^9.1.1",
40
- "device-navigation": "^4.7.3",
40
+ "device-navigation": "^4.8.0",
41
41
  "input-device-handler": "^9.0.4",
42
42
  "object-shape-tester": "^6.15.0",
43
- "vira": "^31.31.2"
43
+ "vira": "^31.31.4"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@augment-vir/test": "^32.2.3",
@@ -51,7 +51,7 @@
51
51
  "istanbul-smart-text-reporter": "^1.1.5"
52
52
  },
53
53
  "peerDependencies": {
54
- "@antha/engine": "^0.1.3",
54
+ "@antha/engine": "^0.3.0",
55
55
  "element-vir": ">=26"
56
56
  },
57
57
  "engines": {