@woosh/meep-engine 2.46.30 → 2.46.33

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.
@@ -8,6 +8,8 @@ import EmptyView from "../../../src/view/elements/EmptyView.js";
8
8
  import { downloadAsFile } from "../../../src/core/binary/ByteArrayTools.js";
9
9
 
10
10
  export async function obtainClipBoard() {
11
+ const navigator = globalThis.navigator;
12
+
11
13
  if (navigator.clipboard === undefined) {
12
14
  const queries = [{
13
15
  name: "clipboard-read"
@@ -41,6 +43,7 @@ export async function safeClipboardWriteText(text, data_name = "data") {
41
43
 
42
44
  return obtainClipBoard().then(
43
45
  () => {
46
+ const navigator = globalThis.navigator;
44
47
  return navigator.clipboard.writeText(text);
45
48
  },
46
49
  () => {
@@ -55,6 +58,7 @@ export async function safeClipboardReadText() {
55
58
 
56
59
  return obtainClipBoard().then(() => {
57
60
 
61
+ const navigator = globalThis.navigator;
58
62
  return navigator.clipboard.readText();
59
63
  }, () => {
60
64
  // clipboard not available
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.33",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -9,6 +9,12 @@ function browserInfo() {
9
9
  return cached;
10
10
  }
11
11
 
12
+ const navigator = globalThis.navigator;
13
+
14
+ if(navigator === undefined){
15
+ throw new Error('Not a browser, globalThis.navigator is undefined');
16
+ }
17
+
12
18
  let ua = navigator.userAgent, tem,
13
19
  M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
14
20
 
@@ -990,6 +990,7 @@ function make_box_editor(engine, transform = new Transform()) {
990
990
  const code_snippet = `TransformedShape3D.from_m4(new UnitCubeShape3D(), ${JSON.stringify(cachedObject.matrix.elements)})`;
991
991
  console.warn(code_snippet);
992
992
 
993
+ const navigator = globalThis.navigator;
993
994
  navigator.clipboard.writeText(code_snippet);
994
995
  }
995
996
  },
@@ -53,6 +53,7 @@ const init = async ({ canvasRef, gui }) => {
53
53
  // const mesh = await load_geometry("data/models/stanford/dragon_recon/dragon_vrip.ply");
54
54
  const mesh = await load_geometry_gltf("data/models/stanford/DragonAttenuation.glb");
55
55
 
56
+ const navigator = globalThis.navigator;
56
57
 
57
58
  const adapter = await navigator.gpu.requestAdapter();
58
59
  const device = await adapter.requestDevice();
@@ -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
 
@@ -649,6 +649,8 @@ function getRandomString() {
649
649
 
650
650
  window.userid = getRandomString();
651
651
 
652
+ const navigator = globalThis.navigator;
653
+
652
654
  const isMobileDevice = navigator.userAgent.match(/Android|iPhone|iPad|iPod|BlackBerry|IEMobile/i);
653
655
  const isChrome = !!navigator.webkitGetUserMedia;
654
656
  const isFirefox = !!navigator.mozGetUserMedia;
@@ -1205,4 +1207,4 @@ function RTCPeerConnection(options) {
1205
1207
  };
1206
1208
  }
1207
1209
 
1208
- export default DataChannel;
1210
+ export default DataChannel;
@@ -196,7 +196,7 @@ function setListenerPositionNOOP(listener, position) {
196
196
 
197
197
  let setListenerPosition = setListenerPositionNOOP;
198
198
 
199
- if (navigator !== undefined) {
199
+ if (globalThis.navigator !== undefined) {
200
200
  const info = browserInfo();
201
201
  if (info.name === "Chrome") {
202
202
  if (info.version >= 64) {
@@ -248,7 +248,7 @@ function setListenerOrientation2(listener, forward, up) {
248
248
 
249
249
  let setListenerOrientation = noop;
250
250
 
251
- if (navigator !== undefined) {
251
+ if (globalThis.navigator !== undefined) {
252
252
  const info = browserInfo();
253
253
  if (info.name === "Chrome") {
254
254
  setListenerOrientation = setListenerOrientation1;