@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 +4 -3
- package/dist/facing.js +8 -18
- package/dist/grid-player-role.js +7 -7
- package/package.json +2 -2
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
|
|
7
|
-
*
|
|
8
|
-
*
|
|
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
|
|
16
|
-
*
|
|
17
|
-
*
|
|
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
|
-
|
|
23
|
-
|
|
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) {
|
package/dist/grid-player-role.js
CHANGED
|
@@ -51,25 +51,25 @@ function gridPlayerGraph() {
|
|
|
51
51
|
},
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
|
-
/** The body update:
|
|
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
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
64
|
-
//
|
|
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(
|
|
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
|
|
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.
|
|
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.
|
|
22
|
+
"@waica/engine": "^0.23.0"
|
|
23
23
|
}
|
|
24
24
|
}
|