@woosh/meep-engine 2.46.30 → 2.46.31

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/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.46.30",
8
+ "version": "2.46.31",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -1,6 +1,9 @@
1
1
  import { Behavior } from "../Behavior.js";
2
2
  import { assert } from "../../../../core/assert.js";
3
3
 
4
+ /**
5
+ * Abstract class
6
+ */
4
7
  export class CompositeBehavior extends Behavior {
5
8
  constructor() {
6
9
  super();
@@ -18,12 +21,25 @@ export class CompositeBehavior extends Behavior {
18
21
  * @param {Behavior} child
19
22
  */
20
23
  addChild(child) {
21
- assert.defined(child);
22
- assert.ok(child.isBehavior, 'child is not a Behavior');
24
+ assert.defined(child, 'child');
25
+ assert.notNull(child, 'child');
26
+ assert.equal(child.isBehavior, true, 'child is not a Behavior');
23
27
 
24
28
  this.__children.push(child);
25
29
  }
26
30
 
31
+ /**
32
+ *
33
+ * @param {Behavior[]} many
34
+ */
35
+ addChildren(many) {
36
+ const n = many.length;
37
+ for (let i = 0; i < n; i++) {
38
+ const e = many[i];
39
+ r.addChild(e);
40
+ }
41
+ }
42
+
27
43
  /**
28
44
  * NOTE: do not modify obtained value
29
45
  * @return {Behavior[]}
@@ -1,6 +1,7 @@
1
1
  import { CompositeBehavior } from "./CompositeBehavior.js";
2
2
  import { BehaviorStatus } from "../BehaviorStatus.js";
3
3
  import { BitSet } from "../../../../core/binary/BitSet.js";
4
+ import { assert } from "../../../../core/assert.js";
4
5
 
5
6
  /**
6
7
  *
@@ -11,6 +12,9 @@ export const ParallelBehaviorPolicy = {
11
12
  RequireAll: 1
12
13
  };
13
14
 
15
+ /**
16
+ * Executes all contained behaviors in parallel
17
+ */
14
18
  export class ParallelBehavior extends CompositeBehavior {
15
19
  /**
16
20
  *
@@ -20,6 +24,9 @@ export class ParallelBehavior extends CompositeBehavior {
20
24
  constructor(successPolicy, failurePolicy) {
21
25
  super();
22
26
 
27
+ assert.enum(successPolicy, ParallelBehaviorPolicy, 'successPolicy');
28
+ assert.enum(failurePolicy, ParallelBehaviorPolicy, 'failurePolicy');
29
+
23
30
  /**
24
31
  * @private
25
32
  * @type {ParallelBehaviorPolicy}
@@ -33,6 +40,7 @@ export class ParallelBehavior extends CompositeBehavior {
33
40
  this.failurePolicy = failurePolicy;
34
41
 
35
42
  /**
43
+ * @readonly
36
44
  * @private
37
45
  * @type {BitSet}
38
46
  */
@@ -60,10 +68,11 @@ export class ParallelBehavior extends CompositeBehavior {
60
68
 
61
69
  /**
62
70
  *
63
- * @param {ParallelBehaviorPolicy|number} v
71
+ * @param {ParallelBehaviorPolicy|number} policy
64
72
  */
65
- setSuccessPolicy(v) {
66
- this.successPolicy = v;
73
+ setSuccessPolicy(policy) {
74
+ assert.enum(policy, ParallelBehaviorPolicy, 'policy');
75
+ this.successPolicy = policy;
67
76
  }
68
77
 
69
78
  /**
@@ -76,10 +85,11 @@ export class ParallelBehavior extends CompositeBehavior {
76
85
 
77
86
  /**
78
87
  *
79
- * @param {ParallelBehaviorPolicy|number} v
88
+ * @param {ParallelBehaviorPolicy|number} policy
80
89
  */
81
- setFailurePolicy(v) {
82
- this.failurePolicy = v;
90
+ setFailurePolicy(policy) {
91
+ assert.enum(policy, ParallelBehaviorPolicy, 'policy');
92
+ this.failurePolicy = policy;
83
93
  }
84
94
 
85
95
  /**
@@ -213,14 +223,16 @@ export class ParallelBehavior extends CompositeBehavior {
213
223
  /**
214
224
  *
215
225
  * @param {Behavior[]} elements
216
- * @param {ParallelBehaviorPolicy} success
217
- * @param {ParallelBehaviorPolicy} failure
226
+ * @param {ParallelBehaviorPolicy} success how should successful completion be determined?
227
+ * @param {ParallelBehaviorPolicy} failure how should failing completion be determined
218
228
  * @returns {ParallelBehavior}
219
229
  */
220
230
  static from(elements, success = ParallelBehaviorPolicy.RequireAll, failure = ParallelBehaviorPolicy.RequireOne) {
231
+ assert.isArray(elements, 'elements');
232
+
221
233
  const r = new ParallelBehavior(success, failure);
222
234
 
223
- elements.forEach(e => r.addChild(e));
235
+ r.addChildren(elements);
224
236
 
225
237
  return r;
226
238
  }
@@ -3,6 +3,10 @@ import { CompositeBehavior } from "./CompositeBehavior.js";
3
3
  import { BehaviorStatus } from "../BehaviorStatus.js";
4
4
  import { assert } from "../../../../core/assert.js";
5
5
 
6
+ /**
7
+ * Executes all contained behaviors one after another in a sequence, next behaviour in the sequence will not be started until the previous one signal success
8
+ * If any of the contained behaviours fail - the whole sequence fails
9
+ */
6
10
  export class SequenceBehavior extends CompositeBehavior {
7
11
  constructor() {
8
12
  super();
@@ -106,7 +110,7 @@ export class SequenceBehavior extends CompositeBehavior {
106
110
  static from(list) {
107
111
  const r = new SequenceBehavior();
108
112
 
109
- list.forEach(b => r.addChild(b));
113
+ r.addChildren(list);
110
114
 
111
115
  return r;
112
116
  }
@@ -2,12 +2,15 @@ import { Behavior } from "../Behavior.js";
2
2
  import { BehaviorStatus } from "../BehaviorStatus.js";
3
3
  import { assert } from "../../../../core/assert.js";
4
4
 
5
+ /**
6
+ * Wait for a certain amount of time
7
+ */
5
8
  export class DelayBehavior extends Behavior {
6
9
  constructor() {
7
10
  super();
8
11
 
9
12
  /**
10
- * Delay value
13
+ * Delay value in seconds
11
14
  * @type {number}
12
15
  */
13
16
  this.value = 0;
@@ -38,11 +41,13 @@ export class DelayBehavior extends Behavior {
38
41
 
39
42
  /**
40
43
  *
41
- * @param {number} value
44
+ * @param {number} value in seconds
42
45
  * @return {DelayBehavior}
43
46
  */
44
47
  static from(value) {
45
- assert.typeOf(value, 'number', 'value');
48
+ assert.isNumber(value, 'value');
49
+ assert.notNaN(value,'value');
50
+ assert.isFiniteNumber(value,'value');
46
51
 
47
52
  const r = new DelayBehavior();
48
53