@waica/behaviors 0.5.0 → 0.6.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/health.d.ts +4 -3
- package/dist/health.js +12 -15
- package/dist/out-of-bounds.d.ts +1 -0
- package/dist/out-of-bounds.js +1 -0
- package/package.json +2 -2
package/dist/health.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare function deathTargets(states: Record<string, StateJson>, current:
|
|
|
14
14
|
* Declaring an edge is not the same as taking it: nextTransition returns the
|
|
15
15
|
* FIRST firing edge, so a death edge listed after another edge that also
|
|
16
16
|
* fires loses the race and the signal is dropped. That is why signalling is
|
|
17
|
-
* followed by
|
|
17
|
+
* followed by a check on Health's first eligible update after StateMachine.
|
|
18
18
|
*/
|
|
19
19
|
export declare function declaresDeathHandling(states: Record<string, StateJson>, current: string): boolean;
|
|
20
20
|
/**
|
|
@@ -27,6 +27,7 @@ export declare function declaresDeathHandling(states: Record<string, StateJson>,
|
|
|
27
27
|
*/
|
|
28
28
|
export declare class Health extends Component {
|
|
29
29
|
static componentName: string;
|
|
30
|
+
static updateAfter: readonly string[];
|
|
30
31
|
static params: {
|
|
31
32
|
max: {
|
|
32
33
|
label: string;
|
|
@@ -49,8 +50,8 @@ export declare class Health extends Component {
|
|
|
49
50
|
current: number;
|
|
50
51
|
/** Seconds left in the invulnerability window. */
|
|
51
52
|
private invulnerable;
|
|
52
|
-
/**
|
|
53
|
-
private
|
|
53
|
+
/** Whether the signalled death must be checked on this component's next update. */
|
|
54
|
+
private deathPending;
|
|
54
55
|
/** States the death signal was supposed to reach. */
|
|
55
56
|
private expectedStates;
|
|
56
57
|
onReady(): void;
|
package/dist/health.js
CHANGED
|
@@ -25,18 +25,11 @@ export function deathTargets(states, current) {
|
|
|
25
25
|
* Declaring an edge is not the same as taking it: nextTransition returns the
|
|
26
26
|
* FIRST firing edge, so a death edge listed after another edge that also
|
|
27
27
|
* fires loses the race and the signal is dropped. That is why signalling is
|
|
28
|
-
* followed by
|
|
28
|
+
* followed by a check on Health's first eligible update after StateMachine.
|
|
29
29
|
*/
|
|
30
30
|
export function declaresDeathHandling(states, current) {
|
|
31
31
|
return deathTargets(states, current).length > 0;
|
|
32
32
|
}
|
|
33
|
-
/**
|
|
34
|
-
* Frames to wait before deciding the graph ignored the death signal. Two,
|
|
35
|
-
* not one, because component update order is prefab-authored: with Health
|
|
36
|
-
* listed before its StateMachine, one frame would check before the machine
|
|
37
|
-
* ever ran. Two guarantees the machine got a full tick either way.
|
|
38
|
-
*/
|
|
39
|
-
const DEATH_GRACE_FRAMES = 2;
|
|
40
33
|
/**
|
|
41
34
|
* How much punishment an entity takes before it dies. Deliberately separate
|
|
42
35
|
* from Hazard's "hurts on touch": an enemy is both, a spike is only the
|
|
@@ -47,11 +40,12 @@ const DEATH_GRACE_FRAMES = 2;
|
|
|
47
40
|
*/
|
|
48
41
|
export class Health extends Component {
|
|
49
42
|
static componentName = 'Health';
|
|
43
|
+
static updateAfter = ['StateMachine'];
|
|
50
44
|
static params = {
|
|
51
45
|
max: { label: 'Max health', min: 1, max: 20, step: 1 },
|
|
52
46
|
invulnerability: { label: 'Invulnerability', min: 0, max: 5, step: 0.1 },
|
|
53
47
|
};
|
|
54
|
-
static transient = ['current', 'invulnerable', '
|
|
48
|
+
static transient = ['current', 'invulnerable', 'deathPending', 'expectedStates'];
|
|
55
49
|
max = 3;
|
|
56
50
|
/** Seconds of immunity granted by taking a hit. 0 disables i-frames. */
|
|
57
51
|
invulnerability = 0;
|
|
@@ -59,8 +53,8 @@ export class Health extends Component {
|
|
|
59
53
|
current = 0;
|
|
60
54
|
/** Seconds left in the invulnerability window. */
|
|
61
55
|
invulnerable = 0;
|
|
62
|
-
/**
|
|
63
|
-
|
|
56
|
+
/** Whether the signalled death must be checked on this component's next update. */
|
|
57
|
+
deathPending = false;
|
|
64
58
|
/** States the death signal was supposed to reach. */
|
|
65
59
|
expectedStates = [];
|
|
66
60
|
onReady() {
|
|
@@ -76,8 +70,10 @@ export class Health extends Component {
|
|
|
76
70
|
onUpdate(dt) {
|
|
77
71
|
if (this.invulnerable > 0)
|
|
78
72
|
this.invulnerable = Math.max(0, this.invulnerable - dt);
|
|
79
|
-
if (this.
|
|
73
|
+
if (this.deathPending) {
|
|
74
|
+
this.deathPending = false;
|
|
80
75
|
this.settleDeath();
|
|
76
|
+
}
|
|
81
77
|
}
|
|
82
78
|
/**
|
|
83
79
|
* Makes good on a death the graph said it would handle. Signalling is
|
|
@@ -139,10 +135,11 @@ export class Health extends Component {
|
|
|
139
135
|
const targets = machine ? deathTargets(machine.states, machine.current) : [];
|
|
140
136
|
if (machine && targets.length > 0) {
|
|
141
137
|
machine.signal('death');
|
|
142
|
-
// Trust, then verify:
|
|
143
|
-
//
|
|
138
|
+
// Trust, then verify: the deterministic schedule puts Health after the
|
|
139
|
+
// machine, so its first eligible update can settle this without an
|
|
140
|
+
// authored-order grace period.
|
|
144
141
|
this.expectedStates = targets;
|
|
145
|
-
this.
|
|
142
|
+
this.deathPending = true;
|
|
146
143
|
return;
|
|
147
144
|
}
|
|
148
145
|
this.entity.destroy();
|
package/dist/out-of-bounds.d.ts
CHANGED
package/dist/out-of-bounds.js
CHANGED
|
@@ -15,6 +15,7 @@ import { Health } from './health.js';
|
|
|
15
15
|
*/
|
|
16
16
|
export class OutOfBounds extends Component {
|
|
17
17
|
static componentName = 'OutOfBounds';
|
|
18
|
+
static updateAfter = ['DynamicBody', 'Health', 'StateMachine'];
|
|
18
19
|
static displayName = 'Out of bounds';
|
|
19
20
|
static params = {
|
|
20
21
|
minY: { label: 'Floor height', min: -50, max: 0, step: 1 },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@waica/behaviors",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
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.6.1"
|
|
23
23
|
}
|
|
24
24
|
}
|