@vived/app 2.15.4 → 2.15.7

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.
@@ -13,12 +13,17 @@ class DevicePreviewImp {
13
13
  this._usePreview = false;
14
14
  this._previewSize = ValueObjects_1.Vector2.Zero();
15
15
  this.setDevicePreview = (x, y) => {
16
- if (this._usePreview &&
17
- this._previewSize.x === x &&
16
+ if (this._previewSize.x === x &&
18
17
  this._previewSize.y === y)
19
18
  return;
20
19
  this._usePreview = true;
21
20
  this._previewSize = new ValueObjects_1.Vector2(x, y);
21
+ if (x > 0 && y > 0) {
22
+ this._usePreview = true;
23
+ }
24
+ else {
25
+ this._usePreview = false;
26
+ }
22
27
  this.observers.notify();
23
28
  };
24
29
  this.clearDevicePreview = () => {
@@ -33,14 +33,18 @@ class FocusCameraImp {
33
33
  this.memoizedRadius = new _1.MemoizedNumber(1, this.observers.notify);
34
34
  this.memoizedTarget = new _1.MemoizedVector3(ValueObjects_1.Vector3.Zero(), this.observers.notify);
35
35
  this.setRadiusLimits = (min, max) => {
36
+ let minToUse = min;
37
+ let maxToUse = max;
36
38
  if (min < 0) {
37
- throw new Error("[Orbit Camera] Mininum Radius must be greater >= 0");
39
+ console.warn("[Orbit Camera Entity] Mininum Radius must be greater >= 0, forcing to 0");
40
+ minToUse = 0;
38
41
  }
39
- if (max < min) {
40
- throw new Error("[Orbit Camera] Max radius must be >= min radius");
42
+ if (max < minToUse) {
43
+ console.warn(`[Orbit Camera] Max radius must be >= min radius. Forcing to ${minToUse}`);
44
+ maxToUse = minToUse;
41
45
  }
42
- this.maxRadius = max;
43
- this.minRadius = min;
46
+ this.maxRadius = maxToUse;
47
+ this.minRadius = minToUse;
44
48
  this.limitRadius = true;
45
49
  this.radius = this.radius;
46
50
  };
@@ -50,17 +54,26 @@ class FocusCameraImp {
50
54
  this.limitRadius = false;
51
55
  };
52
56
  this.setAlphaLimits = (min, max) => {
53
- if (min > max) {
54
- throw new Error("[Orbit Camera] Max alpha must be >= min alpha");
55
- }
57
+ let minToUse = min;
58
+ let maxToUse = max;
56
59
  if (min < -180) {
57
- throw new Error("[Orbit Camera] Min alpha must be >= -180");
60
+ minToUse = -180;
61
+ console.warn("[Orbit Camera] Min alpha must be >= -180. Forcing to -180");
58
62
  }
59
63
  if (max > 180) {
60
- throw new Error("[Orbit Camera] Max alpha must be <= 180");
64
+ maxToUse = 180;
65
+ console.warn("[Orbit Camera] Max alpha must be <= 180. Forcing to 180");
66
+ }
67
+ if (minToUse > maxToUse) {
68
+ const absMin = Math.abs(minToUse);
69
+ const absMax = Math.abs(maxToUse);
70
+ const closestToZero = absMin < absMax ? minToUse : maxToUse;
71
+ minToUse = closestToZero;
72
+ maxToUse = closestToZero;
73
+ console.warn(`[Orbit Camera] Max alpha must be <= Min Alpha. Forcing to ${closestToZero}`);
61
74
  }
62
- this.maxAlpha = max;
63
- this.minAlpha = min;
75
+ this.maxAlpha = maxToUse;
76
+ this.minAlpha = minToUse;
64
77
  this.limitAlpha = true;
65
78
  this.alpha = this.alpha;
66
79
  };
@@ -70,17 +83,26 @@ class FocusCameraImp {
70
83
  this.limitAlpha = false;
71
84
  };
72
85
  this.setBetaLimits = (min, max) => {
73
- if (min > max) {
74
- throw new Error("[Orbit Camera] Max beta must be >= min beta");
75
- }
86
+ let minToUse = min;
87
+ let maxToUse = max;
76
88
  if (min < -180) {
77
- throw new Error("[Orbit Camera] Min beta must be >= -180");
89
+ minToUse = -180;
90
+ console.warn("[Orbit Camera] Min beta must be >= -180. Forcing to -180");
78
91
  }
79
92
  if (max > 180) {
80
- throw new Error("[Orbit Camera] Max beta must be <= 180");
93
+ maxToUse = 180;
94
+ console.warn("[Orbit Camera] Max beta must be <= 180. Forcing to 180");
81
95
  }
82
- this.maxBeta = max;
83
- this.minBeta = min;
96
+ if (minToUse > maxToUse) {
97
+ const absMin = Math.abs(minToUse);
98
+ const absMax = Math.abs(maxToUse);
99
+ const closestToZero = absMin < absMax ? minToUse : maxToUse;
100
+ minToUse = closestToZero;
101
+ maxToUse = closestToZero;
102
+ console.warn(`[Orbit Camera] Max beta must be <= Min beta. Forcing to ${closestToZero}`);
103
+ }
104
+ this.maxBeta = maxToUse;
105
+ this.minBeta = minToUse;
84
106
  this.limitBeta = true;
85
107
  this.beta = this.beta;
86
108
  };
@@ -94,7 +116,8 @@ class FocusCameraImp {
94
116
  const maxArray = max.array;
95
117
  for (let i = 0; i < 3; i++) {
96
118
  if (minArray[i] > maxArray[i]) {
97
- throw new Error("[Orbit Camera] Min target must be less than the max target");
119
+ console.warn("[Orbit Camera] Target limit min's components must all be <= the max. Limits not set");
120
+ return;
98
121
  }
99
122
  }
100
123
  this.maxTargetPosition = max;
@@ -166,23 +189,29 @@ class FocusCameraImp {
166
189
  return this.memoizedAlpha.val;
167
190
  }
168
191
  set alpha(val) {
169
- let clampedVal = this.clampAngle(val);
192
+ let valToUse = val;
170
193
  if (this.limitAlpha) {
171
- clampedVal = Math.min(clampedVal, this.maxAlpha);
172
- clampedVal = Math.max(clampedVal, this.minAlpha);
194
+ valToUse = Math.min(valToUse, this.maxAlpha);
195
+ valToUse = Math.max(valToUse, this.minAlpha);
196
+ }
197
+ else {
198
+ valToUse = this.clampAngle(val);
173
199
  }
174
- this.memoizedAlpha.val = clampedVal;
200
+ this.memoizedAlpha.val = valToUse;
175
201
  }
176
202
  get beta() {
177
203
  return this.memoizedBeta.val;
178
204
  }
179
205
  set beta(val) {
180
- let clampedVal = this.clampAngle(val);
206
+ let valToUse = val;
181
207
  if (this.limitBeta) {
182
- clampedVal = Math.min(clampedVal, this.maxBeta);
183
- clampedVal = Math.max(clampedVal, this.minBeta);
208
+ valToUse = Math.min(valToUse, this.maxBeta);
209
+ valToUse = Math.max(valToUse, this.minBeta);
210
+ }
211
+ else {
212
+ valToUse = this.clampAngle(val);
184
213
  }
185
- this.memoizedBeta.val = clampedVal;
214
+ this.memoizedBeta.val = valToUse;
186
215
  }
187
216
  get radius() {
188
217
  return this.memoizedRadius.val;
@@ -26,7 +26,7 @@ class QuestionChallengeImp {
26
26
  };
27
27
  this.addAnswer = (answer) => {
28
28
  if (this.answerLookup.has(answer.id)) {
29
- throw new Error(`Answer with ID ${answer.id} already exists`);
29
+ console.warn(`Answer with ID ${answer.id} already exists. Overwriting`);
30
30
  }
31
31
  this.answerLookup.set(answer.id, answer);
32
32
  this.reset();
@@ -1,3 +1,4 @@
1
+ import { Result } from "../ValueObjects";
1
2
  export interface SerializedStates {
2
3
  version: number;
3
4
  systems: SystemState[];
@@ -17,9 +18,9 @@ export interface SerializedSystem {
17
18
  export interface StateMachine {
18
19
  transitionEaseFunction: (normalizedTime: number) => number;
19
20
  getSerializedStates(): SerializedStates;
20
- setSerializedStates(state: SerializedStates, transitionTime: number): void;
21
+ setSerializedStates(state: SerializedStates, transitionTime: number): Result<null, Error>;
21
22
  applySerializedStatesString: (state: string, duration?: number) => void;
22
23
  setDefaultState(transitionTime: number): void;
23
- registerSerializedSystem(serializedSystem: SerializedSystem): void;
24
+ registerSerializedSystem(serializedSystem: SerializedSystem): Result<null, Error>;
24
25
  }
25
26
  export declare function makeStateMachine(): StateMachine;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeStateMachine = void 0;
4
+ const ValueObjects_1 = require("../ValueObjects");
4
5
  function makeStateMachine() {
5
6
  return new StateMachineImp();
6
7
  }
@@ -29,9 +30,12 @@ class StateMachineImp {
29
30
  };
30
31
  this.registerSerializedSystem = (serializedSystem) => {
31
32
  if (this.serializedSystems.has(serializedSystem.name)) {
32
- throw new Error(`[StateMachine] Duplicate stateable systems encountered: ${serializedSystem.name}`);
33
+ const err = new Error(`[StateMachine] Duplicate stateable systems encountered: ${serializedSystem.name}`);
34
+ console.error(err.message);
35
+ return ValueObjects_1.reject(err);
33
36
  }
34
37
  this.serializedSystems.set(serializedSystem.name, serializedSystem);
38
+ return ValueObjects_1.resolve(null);
35
39
  };
36
40
  this.getSerializedStates = () => {
37
41
  const systems = Array.from(this.serializedSystems.values());
@@ -66,10 +70,13 @@ class StateMachineImp {
66
70
  system.applyDefaultState(duration);
67
71
  }
68
72
  });
73
+ return ValueObjects_1.resolve(null);
69
74
  }
70
75
  // Here is where we will add support for future versions
71
76
  else {
72
- throw new Error(`[StateMachine] Unsupported sereialized state encountered: ${state.version}`);
77
+ const err = new Error(`[StateMachine] Unsupported sereialized state encountered: ${state.version}`);
78
+ console.error(err.message);
79
+ return ValueObjects_1.reject(err);
73
80
  }
74
81
  };
75
82
  this.setDefaultState = (duration) => {
@@ -11,3 +11,4 @@ export declare class DevicePreviewPM {
11
11
  dispose(): void;
12
12
  constructor(devicePreview: DevicePreview, updateView: (vm: DevicePreviewVM) => void);
13
13
  }
14
+ export declare const defaultDevicePreviewVM: DevicePreviewVM;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DevicePreviewPM = void 0;
3
+ exports.defaultDevicePreviewVM = exports.DevicePreviewPM = void 0;
4
4
  class DevicePreviewPM {
5
5
  constructor(devicePreview, updateView) {
6
6
  this.doUpdateView = () => {
@@ -23,3 +23,8 @@ class DevicePreviewPM {
23
23
  }
24
24
  }
25
25
  exports.DevicePreviewPM = DevicePreviewPM;
26
+ exports.defaultDevicePreviewVM = {
27
+ x: 0,
28
+ y: 0,
29
+ useDevicePreview: false,
30
+ };
@@ -5,10 +5,12 @@ class ShowBabylonInspectorPM {
5
5
  constructor(babylon, updateView) {
6
6
  this.doUpdateView = () => {
7
7
  const showInspector = this.babylon.showInspector;
8
- if (showInspector === this.lastSetState)
8
+ const hasCanvas = this.babylon.renderCanvas === undefined ? false : true;
9
+ const showBeShown = hasCanvas && showInspector;
10
+ if (showBeShown === this.lastSetState)
9
11
  return;
10
- this.updateView(showInspector);
11
- this.lastSetState = showInspector;
12
+ this.updateView(showBeShown);
13
+ this.lastSetState = showBeShown;
12
14
  };
13
15
  this.babylon = babylon;
14
16
  this.updateView = updateView;
@@ -8,7 +8,8 @@ class PixelOrbitFocusCamera {
8
8
  this.sensitivity = 0.5;
9
9
  this.doOrbit = (pixelPosition) => {
10
10
  if (!this.previousPixelPos) {
11
- throw new Error("[PixelOrbitFocusCamera] You must initialize first!");
11
+ console.error("[PixelOrbitFocusCamera] You must initialize first!");
12
+ return;
12
13
  }
13
14
  const pixelChange = ValueObjects_1.Vector2.Subtract(pixelPosition, this.previousPixelPos);
14
15
  this.focusCamera.alpha += pixelChange.x * this.sensitivity;
@@ -8,7 +8,8 @@ class PixelPlanePanFocusCamera {
8
8
  this.babylon = babylon;
9
9
  this.doPan = (pixelPosition) => {
10
10
  if (!this.plane || !this.previousPixelPos) {
11
- throw new Error("[PixelPlanePan_OrbitCamera] You must initialize first!");
11
+ console.error("[PixelPlanePan_OrbitCamera] You must initialize first!");
12
+ return;
12
13
  }
13
14
  const initialRay = this.babylon.sceneRay(this.previousPixelPos);
14
15
  const finalRay = this.babylon.sceneRay(pixelPosition);
@@ -0,0 +1,30 @@
1
+ export declare type Result<T, E> = Resolved<T, E> | Rejected<T, E>;
2
+ export declare const resolve: <T, E = never>(value: T) => Resolved<T, E>;
3
+ export declare const reject: <T = never, E = unknown>(err: E) => Rejected<T, E>;
4
+ interface IResult<T, E> {
5
+ isResolved: boolean;
6
+ isRejected: boolean;
7
+ value?: T;
8
+ error?: E;
9
+ then<A>(f: (t: T) => A): Result<A, E>;
10
+ catch<U>(f: (e: E) => U): Result<T, U>;
11
+ }
12
+ export declare class Rejected<T, E> implements IResult<T, E> {
13
+ readonly error: E;
14
+ readonly value: undefined;
15
+ get isResolved(): boolean;
16
+ get isRejected(): boolean;
17
+ then<A>(_f: (t: T) => A): Result<A, E>;
18
+ catch<U>(f: (e: E) => U): Result<T, U>;
19
+ constructor(error: E);
20
+ }
21
+ export declare class Resolved<T, E> implements IResult<T, E> {
22
+ readonly value: T;
23
+ readonly error: undefined;
24
+ get isResolved(): boolean;
25
+ get isRejected(): boolean;
26
+ then<A>(f: (t: T) => A): Result<A, E>;
27
+ catch<U>(_f: (e: E) => U): Result<T, U>;
28
+ constructor(value: T);
29
+ }
30
+ export {};
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Resolved = exports.Rejected = exports.reject = exports.resolve = void 0;
4
+ const resolve = (value) => new Resolved(value);
5
+ exports.resolve = resolve;
6
+ const reject = (err) => new Rejected(err);
7
+ exports.reject = reject;
8
+ class Rejected {
9
+ constructor(error) {
10
+ this.value = undefined;
11
+ this.error = error;
12
+ }
13
+ get isResolved() {
14
+ return false;
15
+ }
16
+ get isRejected() {
17
+ return true;
18
+ }
19
+ then(_f) {
20
+ return exports.reject(this.error);
21
+ }
22
+ catch(f) {
23
+ return exports.reject(f(this.error));
24
+ }
25
+ }
26
+ exports.Rejected = Rejected;
27
+ class Resolved {
28
+ constructor(value) {
29
+ this.error = undefined;
30
+ this.value = value;
31
+ }
32
+ get isResolved() {
33
+ return true;
34
+ }
35
+ get isRejected() {
36
+ return false;
37
+ }
38
+ then(f) {
39
+ return exports.resolve(f(this.value));
40
+ }
41
+ catch(_f) {
42
+ return exports.resolve(this.value);
43
+ }
44
+ }
45
+ exports.Resolved = Resolved;
@@ -5,3 +5,4 @@ export * from "./Angle";
5
5
  export * from "./Vector3";
6
6
  export * from "./ParametricLine";
7
7
  export * from "./ParametricPlane";
8
+ export * from "./Result";
@@ -17,3 +17,4 @@ __exportStar(require("./Angle"), exports);
17
17
  __exportStar(require("./Vector3"), exports);
18
18
  __exportStar(require("./ParametricLine"), exports);
19
19
  __exportStar(require("./ParametricPlane"), exports);
20
+ __exportStar(require("./Result"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vived/app",
3
- "version": "2.15.4",
3
+ "version": "2.15.7",
4
4
  "description": "Public package for the VIVED Learning App system",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",