@waica/behaviors 0.21.0 → 0.23.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/dist/facing.d.ts CHANGED
@@ -3,9 +3,10 @@ import { type ProjectedPoint } from '@waica/engine';
3
3
  export type ScreenFacing = 'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w' | 'nw';
4
4
  export declare const SCREEN_FACINGS: readonly ScreenFacing[];
5
5
  /**
6
- * The eight-way facing a screen-relative input reads as — signs only, so a
7
- * tiny diagonal component still counts. Undefined for no input, which lets
8
- * the caller keep whatever it was facing.
6
+ * The eight-way facing a screen-relative input reads as: the 45° sector its
7
+ * angle falls in, so an almost-vertical stick faces `n`, not `ne`; every
8
+ * keyboard input (components in {-1, 0, 1}) lands on its sign pair exactly.
9
+ * Undefined for no input, which lets the caller keep whatever it was facing.
9
10
  */
10
11
  export declare function facingForInput(inputX: number, inputY: number): ScreenFacing | undefined;
11
12
  /** The screen sign pair behind a facing; undefined for a name the table lacks. */
package/dist/facing.js CHANGED
@@ -11,29 +11,19 @@ const FACING_VECTORS = {
11
11
  w: { x: -1, y: 0 },
12
12
  nw: { x: -1, y: 1 },
13
13
  };
14
+ /** Counter-clockwise from east, one per 45° sector of the input angle. */
15
+ const FACINGS_BY_SECTOR = ['e', 'ne', 'n', 'nw', 'w', 'sw', 's', 'se'];
14
16
  /**
15
- * The eight-way facing a screen-relative input reads as — signs only, so a
16
- * tiny diagonal component still counts. Undefined for no input, which lets
17
- * the caller keep whatever it was facing.
17
+ * The eight-way facing a screen-relative input reads as: the 45° sector its
18
+ * angle falls in, so an almost-vertical stick faces `n`, not `ne`; every
19
+ * keyboard input (components in {-1, 0, 1}) lands on its sign pair exactly.
20
+ * Undefined for no input, which lets the caller keep whatever it was facing.
18
21
  */
19
22
  export function facingForInput(inputX, inputY) {
20
23
  if (inputX === 0 && inputY === 0)
21
24
  return undefined;
22
- if (inputY > 0) {
23
- if (inputX > 0)
24
- return 'ne';
25
- if (inputX < 0)
26
- return 'nw';
27
- return 'n';
28
- }
29
- if (inputY < 0) {
30
- if (inputX > 0)
31
- return 'se';
32
- if (inputX < 0)
33
- return 'sw';
34
- return 's';
35
- }
36
- return inputX > 0 ? 'e' : 'w';
25
+ const sector = Math.round(Math.atan2(inputY, inputX) / (Math.PI / 4));
26
+ return FACINGS_BY_SECTOR[(sector + 8) % 8];
37
27
  }
38
28
  /** The screen sign pair behind a facing; undefined for a name the table lacks. */
39
29
  export function facingVector(facing) {
@@ -51,25 +51,25 @@ function gridPlayerGraph() {
51
51
  },
52
52
  };
53
53
  }
54
- /** The body update: keyboard input, else a live Move Order, then the motor step and move/stop signal. */
54
+ /** The body update: directional input (keys or stick), else a live Move Order, then the motor step and move/stop signal. */
55
55
  function gridPlayerUpdate(Motor) {
56
56
  return (ctx, dt) => {
57
57
  const { entity, game, fsm } = ctx;
58
58
  const motor = entity.get(Motor);
59
59
  if (!motor)
60
60
  return;
61
- const keyboardX = game.input.axis('left', 'right');
62
- const keyboardY = game.input.axis('down', 'up');
63
- if (keyboardX !== 0 || keyboardY !== 0) {
64
- // Keyboard movement always wins and cancels a live Move Order (CA-4).
61
+ const inputX = game.input.axis('left', 'right');
62
+ const inputY = game.input.axis('down', 'up');
63
+ if (inputX !== 0 || inputY !== 0) {
64
+ // Any directional input — keys or stick — wins and cancels a live Move Order (CA-4).
65
65
  entity.get(ClickToMove)?.cancel();
66
- motor.run(keyboardX, keyboardY, dt);
66
+ motor.run(inputX, inputY, dt);
67
67
  }
68
68
  else {
69
69
  const driven = driveClickToMove(ctx, motor);
70
70
  if (driven) {
71
71
  // driveClickToMove answers in logical space; motor.run expects the
72
- // same screen-relative input keyboard axes already are (IsoMotor
72
+ // same screen-relative input the directional axes already are (IsoMotor
73
73
  // converts internally, TopDownMotor's screen space is logical).
74
74
  const screenInput = game.projection === 'isometric' ? screenInputToLogical(driven.x, driven.y) : driven;
75
75
  motor.run(screenInput.x, screenInput.y, dt);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waica/behaviors",
3
- "version": "0.21.0",
3
+ "version": "0.23.0",
4
4
  "description": "Waica built-in behaviors — the curated game-feel library",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -19,6 +19,6 @@
19
19
  }
20
20
  },
21
21
  "dependencies": {
22
- "@waica/engine": "^0.21.0"
22
+ "@waica/engine": "^0.23.0"
23
23
  }
24
24
  }