@woosh/meep-engine 2.100.0 → 2.100.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/build/meep.cjs +553 -17
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +553 -17
- package/package.json +1 -1
- package/src/core/color/Color.d.ts.map +1 -1
- package/src/core/color/Color.js +39 -8
- package/src/engine/animation/async/prototypeAsyncAnimation.d.ts +2 -0
- package/src/engine/animation/async/prototypeAsyncAnimation.d.ts.map +1 -0
- package/src/engine/animation/async/prototypeAsyncAnimation.js +344 -0
- package/src/engine/asset/AssetManager.d.ts.map +1 -1
- package/src/engine/asset/AssetManager.js +17 -0
- package/src/engine/ecs/Entity.d.ts.map +1 -1
- package/src/engine/ecs/Entity.js +1 -0
- package/src/engine/ecs/terrain/ecs/TerrainSystem.d.ts.map +1 -1
- package/src/engine/ecs/terrain/ecs/TerrainSystem.js +3 -3
- package/src/engine/input/ecs/systems/InputControllerSystem.d.ts.map +1 -1
- package/src/engine/input/ecs/systems/InputControllerSystem.js +4 -8
- package/src/engine/intelligence/behavior/util/RandomDelayBehavior.d.ts +46 -0
- package/src/engine/intelligence/behavior/util/RandomDelayBehavior.d.ts.map +1 -0
- package/src/engine/intelligence/behavior/util/RandomDelayBehavior.js +85 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { UINT32_MAX } from "../../../../core/binary/UINT32_MAX.js";
|
|
2
|
+
import { NumericInterval } from "../../../../core/math/interval/NumericInterval.js";
|
|
3
|
+
import { seededRandom } from "../../../../core/math/random/seededRandom.js";
|
|
4
|
+
import { Behavior } from "../Behavior.js";
|
|
5
|
+
import { BehaviorStatus } from "../BehaviorStatus.js";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
function nextSeed() {
|
|
9
|
+
return Date.now() ^ (Math.random() * UINT32_MAX);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Wait for a certain amount of time
|
|
14
|
+
*/
|
|
15
|
+
export class RandomDelayBehavior extends Behavior {
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Delay value in seconds
|
|
19
|
+
* @type {number}
|
|
20
|
+
*/
|
|
21
|
+
value = 0;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @type {NumericInterval}
|
|
26
|
+
*/
|
|
27
|
+
limits = new NumericInterval(1, 1);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Time elapsed
|
|
31
|
+
* @private
|
|
32
|
+
* @type {number}
|
|
33
|
+
*/
|
|
34
|
+
elapsed = 0;
|
|
35
|
+
|
|
36
|
+
random = seededRandom(nextSeed())
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
fromJSON({ limits, elapsed = 0 }) {
|
|
40
|
+
this.limits.fromJSON(limits);
|
|
41
|
+
this.elapsed = elapsed;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
*
|
|
46
|
+
* @param json
|
|
47
|
+
* @return {RandomDelayBehavior}
|
|
48
|
+
*/
|
|
49
|
+
static fromJSON(json) {
|
|
50
|
+
const r = new RandomDelayBehavior();
|
|
51
|
+
r.fromJSON(json);
|
|
52
|
+
return r;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
*
|
|
57
|
+
* @return {RandomDelayBehavior}
|
|
58
|
+
* @param min
|
|
59
|
+
* @param max
|
|
60
|
+
*/
|
|
61
|
+
static from(min, max) {
|
|
62
|
+
const r = new RandomDelayBehavior();
|
|
63
|
+
|
|
64
|
+
r.limits.set(min, max);
|
|
65
|
+
|
|
66
|
+
return r;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
initialize(ctx) {
|
|
70
|
+
super.initialize(ctx);
|
|
71
|
+
|
|
72
|
+
this.elapsed = 0;
|
|
73
|
+
this.value = this.limits.sampleRandom(this.random)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
tick(timeDelta) {
|
|
77
|
+
this.elapsed += timeDelta;
|
|
78
|
+
|
|
79
|
+
if (this.elapsed >= this.value) {
|
|
80
|
+
return BehaviorStatus.Succeeded;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return BehaviorStatus.Running;
|
|
84
|
+
}
|
|
85
|
+
}
|