@vived/app 2.4.0 → 2.7.0

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.
Files changed (80) hide show
  1. package/lib/Core/BaseApp/Boundary.d.ts +8 -2
  2. package/lib/Core/BaseApp/Entity.d.ts +2 -0
  3. package/lib/Core/BaseApp/UseCase.d.ts +29 -19
  4. package/lib/Core/BaseApp/UseCase.js +211 -135
  5. package/lib/Entities/Babylon.d.ts +17 -0
  6. package/lib/Entities/Babylon.js +81 -0
  7. package/lib/Entities/BaseApp.d.ts +7 -0
  8. package/lib/Entities/BaseApp.js +27 -0
  9. package/lib/Entities/Color.d.ts +20 -0
  10. package/lib/Entities/Color.js +59 -0
  11. package/lib/Entities/DevicePreview.d.ts +11 -0
  12. package/lib/Entities/DevicePreview.js +44 -0
  13. package/lib/Entities/KeyboardInput.d.ts +14 -0
  14. package/lib/Entities/KeyboardInput.js +76 -0
  15. package/lib/Entities/LineSegment2D.d.ts +11 -0
  16. package/lib/Entities/LineSegment2D.js +70 -0
  17. package/lib/Entities/MemoizedBoolean.d.ts +7 -0
  18. package/lib/Entities/MemoizedBoolean.js +19 -0
  19. package/lib/Entities/MemoizedNumber.d.ts +7 -0
  20. package/lib/Entities/MemoizedNumber.js +19 -0
  21. package/lib/Entities/MemoizedString.d.ts +7 -0
  22. package/lib/Entities/MemoizedString.js +19 -0
  23. package/lib/Entities/MemoizedVector2.d.ts +12 -0
  24. package/lib/Entities/MemoizedVector2.js +37 -0
  25. package/lib/Entities/MemoizedVector3.d.ts +14 -0
  26. package/lib/Entities/MemoizedVector3.js +46 -0
  27. package/lib/Entities/ObserverList.d.ts +6 -0
  28. package/lib/Entities/ObserverList.js +23 -0
  29. package/lib/Entities/OrbitCamera.d.ts +17 -0
  30. package/lib/Entities/OrbitCamera.js +74 -0
  31. package/lib/Entities/ParametricLine.d.ts +29 -0
  32. package/lib/Entities/ParametricLine.js +79 -0
  33. package/lib/Entities/ParametricPlane.d.ts +20 -0
  34. package/lib/Entities/ParametricPlane.js +63 -0
  35. package/lib/Entities/StateMachine.d.ts +25 -0
  36. package/lib/Entities/StateMachine.js +81 -0
  37. package/lib/Entities/UndoRedo.d.ts +22 -0
  38. package/lib/Entities/UndoRedo.js +61 -0
  39. package/lib/Entities/Vector2.d.ts +21 -0
  40. package/lib/Entities/Vector2.js +83 -0
  41. package/lib/Entities/Vector3.d.ts +19 -0
  42. package/lib/Entities/Vector3.js +75 -0
  43. package/lib/Entities/index.d.ts +19 -0
  44. package/lib/Entities/index.js +31 -0
  45. package/lib/Interface/Controllers/setState.d.ts +1 -1
  46. package/lib/Interface/Controllers/setState.js +14 -3
  47. package/lib/PresentationManagers/DevicePreviewPM.d.ts +13 -0
  48. package/lib/PresentationManagers/DevicePreviewPM.js +25 -0
  49. package/lib/PresentationManagers/HasRedoPM.d.ts +9 -0
  50. package/lib/PresentationManagers/HasRedoPM.js +22 -0
  51. package/lib/PresentationManagers/HasUndoPM.d.ts +9 -0
  52. package/lib/PresentationManagers/HasUndoPM.js +22 -0
  53. package/lib/PresentationManagers/IsAuthoringPM.d.ts +9 -0
  54. package/lib/PresentationManagers/IsAuthoringPM.js +22 -0
  55. package/lib/PresentationManagers/OrbitCameraPM.d.ts +14 -0
  56. package/lib/PresentationManagers/OrbitCameraPM.js +31 -0
  57. package/lib/PresentationManagers/ShowBabylonInspectorPM.d.ts +9 -0
  58. package/lib/PresentationManagers/ShowBabylonInspectorPM.js +22 -0
  59. package/lib/PresentationManagers/index.d.ts +6 -0
  60. package/lib/PresentationManagers/index.js +18 -0
  61. package/lib/UseCases/LerpOrbitCamera.d.ts +36 -0
  62. package/lib/UseCases/LerpOrbitCamera.js +71 -0
  63. package/lib/UseCases/SerializeCamera.d.ts +21 -0
  64. package/lib/UseCases/SerializeCamera.js +59 -0
  65. package/lib/UseCases/SerializeOrbitCamera.d.ts +21 -0
  66. package/lib/UseCases/SerializeOrbitCamera.js +59 -0
  67. package/lib/UseCases/SerializedCamDemo.d.ts +0 -0
  68. package/lib/UseCases/SerializedCamDemo.js +1 -0
  69. package/lib/UseCases/index.d.ts +3 -0
  70. package/lib/UseCases/index.js +15 -0
  71. package/lib/UseCases/setDevicePreview.d.ts +2 -0
  72. package/lib/UseCases/setDevicePreview.js +14 -0
  73. package/lib/Utilities/degreesToRadians.d.ts +1 -0
  74. package/lib/Utilities/degreesToRadians.js +7 -0
  75. package/lib/Utilities/index.d.ts +1 -0
  76. package/lib/Utilities/index.js +13 -0
  77. package/lib/index.d.ts +7 -2
  78. package/lib/index.js +8 -2
  79. package/package.json +1 -2
  80. package/CHANGELOG.md +0 -51
@@ -6,9 +6,14 @@ export interface BaseAppUC {
6
6
  setShowBabylonInspector(showInspector: boolean): void;
7
7
  addObserver(observer: BaseAppStateObserver): void;
8
8
  removeObserver(observer: BaseAppStateObserver): void;
9
+ setVerbose(verbose: boolean): void;
9
10
  getSerializedState(): SerializedStates;
10
- setSerializedState(state: SerializedStates): void;
11
+ setSerializedState(state: SerializedStates, transitionTime: number): void;
12
+ setDefaultState(transitionTime: number): void;
11
13
  registerSerializableSystem(serializedSystem: SerializableSystem): void;
14
+ getIsTransitioning(): boolean;
15
+ abortTransition(): void;
16
+ setTransitionEaseFn: (easeFn: (normalizedTime: number) => number) => void;
12
17
  setHostHandler(handler: Handler): void;
13
18
  hasHostHandler(): boolean;
14
19
  dispatchOnStateChange(stateObject: object): void;
@@ -39,5 +44,6 @@ export interface SerializableSystem {
39
44
  name: string;
40
45
  seriliziationVersion: number;
41
46
  getSerializedObject(): object;
42
- applySerailizedObject(state: object, version: number): void;
47
+ intializeStateForTransition(serializedState: object | null, version: number): void;
48
+ applyTransition(percent: number): void;
43
49
  }
@@ -6,4 +6,6 @@ export interface BaseAppState {
6
6
  useDevicePreview: boolean;
7
7
  x: number;
8
8
  y: number;
9
+ isTransitioning: boolean;
10
+ verbose: boolean;
9
11
  }
@@ -5,29 +5,39 @@ export declare class BaseAppUCImp implements BaseAppUC {
5
5
  private observers;
6
6
  private systems;
7
7
  private serilizationVersion;
8
+ private currentInterval?;
9
+ private easeFunction;
8
10
  constructor();
9
- setDevicePreview(x: number, y: number): void;
10
- clearDevicePreview(): void;
11
- getUseDevicePreview(): boolean;
12
- getDevicePreviewSize(): {
11
+ setVerbose(verbose: boolean): void;
12
+ abortTransition: () => void;
13
+ setTransitionEaseFn: (easeFn: (normalizedTime: number) => number) => void;
14
+ getIsTransitioning: () => boolean;
15
+ setDevicePreview: (x: number, y: number) => void;
16
+ clearDevicePreview: () => void;
17
+ getUseDevicePreview: () => boolean;
18
+ getDevicePreviewSize: () => {
13
19
  x: number;
14
20
  y: number;
15
21
  };
16
- setHostHandler(handler: Handler): void;
17
- hasHostHandler(): boolean;
18
- dispatchOnStateChange(stateObject: object): void;
19
- dispatchOnStateComplete(): void;
20
- dispatchSubmitResults(results: object): void;
21
- dispatchGetAppAssetsURL(): string;
22
- registerSerializableSystem(serializedSystem: SerializableSystem): void;
23
- getSerializedState(): SerializedStates;
24
- setSerializedState(state: SerializedStates): void;
25
- getShowBabylonInspector(): boolean;
26
- setShowBabylonInspector(showInspector: boolean): void;
27
- getIsAuthoring(): boolean;
28
- setIsAuthoring(isAuthoring: boolean): void;
29
- addObserver(observer: BaseAppStateObserver): void;
30
- removeObserver(observer: BaseAppStateObserver): void;
22
+ setHostHandler: (handler: Handler) => void;
23
+ hasHostHandler: () => boolean;
24
+ dispatchOnStateChange: (stateObject: object) => void;
25
+ dispatchOnStateComplete: () => void;
26
+ dispatchSubmitResults: (results: object) => void;
27
+ dispatchGetAppAssetsURL: () => string;
28
+ registerSerializableSystem: (serializedSystem: SerializableSystem) => void;
29
+ getSerializedState: () => SerializedStates;
30
+ setSerializedState: (state: SerializedStates, duration: number) => void;
31
+ setDefaultState: (duration: number) => void;
32
+ getShowBabylonInspector: () => boolean;
33
+ setShowBabylonInspector: (showInspector: boolean) => void;
34
+ getIsAuthoring: () => boolean;
35
+ setIsAuthoring: (isAuthoring: boolean) => void;
36
+ addObserver: (observer: BaseAppStateObserver) => void;
37
+ removeObserver: (observer: BaseAppStateObserver) => void;
38
+ private logToConsole;
39
+ private startTransition;
40
+ private applyTransitionToSystems;
31
41
  private notify;
32
42
  private dispatch;
33
43
  }
@@ -8,157 +8,232 @@ class BaseAppUCImp {
8
8
  this.observers = [];
9
9
  this.systems = new Map();
10
10
  this.serilizationVersion = 2;
11
+ this.easeFunction = (normalizedTime) => {
12
+ return normalizedTime; // default to a linear function
13
+ };
14
+ this.abortTransition = () => {
15
+ if (this.currentInterval) {
16
+ clearInterval(this.currentInterval);
17
+ }
18
+ this.appState.isTransitioning = false;
19
+ };
20
+ this.setTransitionEaseFn = (easeFn) => {
21
+ this.easeFunction = easeFn;
22
+ };
23
+ this.getIsTransitioning = () => {
24
+ return this.appState.isTransitioning;
25
+ };
26
+ this.setDevicePreview = (x, y) => {
27
+ if (this.appState.useDevicePreview &&
28
+ x === this.appState.x &&
29
+ y === this.appState.y) {
30
+ return;
31
+ }
32
+ this.appState.useDevicePreview = true;
33
+ this.appState.x = x;
34
+ this.appState.y = y;
35
+ this.notify();
36
+ this.logToConsole(`Device Preview set to ${x}, ${y}`);
37
+ };
38
+ this.clearDevicePreview = () => {
39
+ if (!this.appState.useDevicePreview)
40
+ return;
41
+ this.appState.useDevicePreview = false;
42
+ this.appState.x = -1;
43
+ this.appState.y = -1;
44
+ this.notify();
45
+ this.logToConsole(`Device Preview cleared`);
46
+ };
47
+ this.getUseDevicePreview = () => {
48
+ return this.appState.useDevicePreview;
49
+ };
50
+ this.getDevicePreviewSize = () => {
51
+ const { x, y } = this.appState;
52
+ return { x, y };
53
+ };
54
+ this.setHostHandler = (handler) => {
55
+ this.appState.handler = handler;
56
+ this.logToConsole("Handler set");
57
+ };
58
+ this.hasHostHandler = () => {
59
+ if (this.appState.handler) {
60
+ return true;
61
+ }
62
+ else {
63
+ return false;
64
+ }
65
+ };
66
+ this.dispatchOnStateChange = (stateObject) => {
67
+ const request = {
68
+ type: app_host_boundary_1.ON_STATE_CHANGE,
69
+ version: 1,
70
+ payload: {
71
+ stateObject,
72
+ },
73
+ };
74
+ this.dispatch(request);
75
+ };
76
+ this.dispatchOnStateComplete = () => {
77
+ const request = {
78
+ type: app_host_boundary_1.ON_STATE_COMPLETED,
79
+ version: 1,
80
+ };
81
+ this.dispatch(request);
82
+ };
83
+ this.dispatchSubmitResults = (results) => {
84
+ const request = {
85
+ type: app_host_boundary_1.SUBMIT_RESULTS,
86
+ version: 1,
87
+ payload: {
88
+ results,
89
+ },
90
+ };
91
+ this.dispatch(request);
92
+ };
93
+ this.dispatchGetAppAssetsURL = () => {
94
+ var _a;
95
+ const callback = (url) => {
96
+ this.appState.appAssetsURL = url;
97
+ };
98
+ const request = {
99
+ type: app_host_boundary_1.GET_APP_ASSET_URL,
100
+ version: 1,
101
+ payload: {
102
+ callback,
103
+ },
104
+ };
105
+ this.dispatch(request);
106
+ return (_a = this.appState.appAssetsURL) !== null && _a !== void 0 ? _a : "";
107
+ };
108
+ this.registerSerializableSystem = (serializedSystem) => {
109
+ if (this.systems.has(serializedSystem.name)) {
110
+ throw new Errors_1.DuplicateSystemNameError(serializedSystem.name);
111
+ }
112
+ this.systems.set(serializedSystem.name, serializedSystem);
113
+ };
114
+ this.getSerializedState = () => {
115
+ const systems = Array.from(this.systems.values());
116
+ const serializedStates = systems.map((system) => {
117
+ const state = system.getSerializedObject();
118
+ return {
119
+ seriliziationVersion: system.seriliziationVersion,
120
+ name: system.name,
121
+ state,
122
+ };
123
+ });
124
+ return {
125
+ version: this.serilizationVersion,
126
+ systems: serializedStates,
127
+ };
128
+ };
129
+ this.setSerializedState = (state, duration) => {
130
+ if (state.version === 2) {
131
+ state.systems.forEach((systemState) => {
132
+ const seriliazableSystem = this.systems.get(systemState.name);
133
+ if (seriliazableSystem) {
134
+ seriliazableSystem.intializeStateForTransition(systemState.state, systemState.seriliziationVersion);
135
+ }
136
+ else {
137
+ console.warn("Unable to find seriarializedSystem " + systemState.name);
138
+ }
139
+ });
140
+ }
141
+ // Here is where we will add support for future versions
142
+ else {
143
+ throw new Errors_1.UnsupportedVersionNumber(state.version);
144
+ }
145
+ this.startTransition(duration);
146
+ this.logToConsole(`State set to ${JSON.stringify(state)} with a ${duration} second duration`);
147
+ };
148
+ this.setDefaultState = (duration) => {
149
+ this.systems.forEach((system) => {
150
+ system.intializeStateForTransition(null, -1);
151
+ });
152
+ this.startTransition(duration);
153
+ this.logToConsole(`State has been set to transition to default over ${duration} seconds`);
154
+ };
155
+ this.getShowBabylonInspector = () => {
156
+ return this.appState.showBabyonInspector;
157
+ };
158
+ this.setShowBabylonInspector = (showInspector) => {
159
+ if (this.appState.showBabyonInspector === showInspector)
160
+ return;
161
+ this.appState.showBabyonInspector = showInspector;
162
+ this.notify();
163
+ this.logToConsole(`Show Babylon Inspector set to ${showInspector}`);
164
+ };
165
+ this.getIsAuthoring = () => {
166
+ return this.appState.isAuthoring;
167
+ };
168
+ this.setIsAuthoring = (isAuthoring) => {
169
+ if (isAuthoring === this.appState.isAuthoring)
170
+ return;
171
+ this.appState.isAuthoring = isAuthoring;
172
+ this.notify();
173
+ this.logToConsole(`Is Authoring set to ${isAuthoring}`);
174
+ };
175
+ this.addObserver = (observer) => {
176
+ this.observers.push(observer);
177
+ };
178
+ this.removeObserver = (observer) => {
179
+ const index = this.observers.indexOf(observer);
180
+ if (index >= 0) {
181
+ this.observers.splice(index, 1);
182
+ }
183
+ };
11
184
  this.appState = {
12
185
  isAuthoring: false,
13
186
  showBabyonInspector: false,
14
187
  useDevicePreview: false,
15
188
  x: -1,
16
189
  y: -1,
190
+ isTransitioning: false,
191
+ verbose: false,
17
192
  };
18
193
  }
19
- setDevicePreview(x, y) {
20
- if (this.appState.useDevicePreview &&
21
- x === this.appState.x &&
22
- y === this.appState.y) {
23
- return;
24
- }
25
- this.appState.useDevicePreview = true;
26
- this.appState.x = x;
27
- this.appState.y = y;
28
- this.notify();
194
+ setVerbose(verbose) {
195
+ this.appState.verbose = verbose;
29
196
  }
30
- clearDevicePreview() {
31
- if (!this.appState.useDevicePreview)
197
+ logToConsole(message) {
198
+ if (!this.appState.verbose)
32
199
  return;
33
- this.appState.useDevicePreview = false;
34
- this.appState.x = -1;
35
- this.appState.y = -1;
36
- this.notify();
37
- }
38
- getUseDevicePreview() {
39
- return this.appState.useDevicePreview;
40
- }
41
- getDevicePreviewSize() {
42
- const { x, y } = this.appState;
43
- return { x, y };
44
- }
45
- setHostHandler(handler) {
46
- this.appState.handler = handler;
47
- }
48
- hasHostHandler() {
49
- if (this.appState.handler) {
50
- return true;
200
+ console.log("[Base App UC] " + message);
201
+ }
202
+ startTransition(duration) {
203
+ if (duration === 0) {
204
+ if (this.currentInterval) {
205
+ clearInterval(this.currentInterval);
206
+ this.appState.isTransitioning = false;
207
+ }
208
+ this.applyTransitionToSystems(1);
51
209
  }
52
210
  else {
53
- return false;
54
- }
55
- }
56
- dispatchOnStateChange(stateObject) {
57
- const request = {
58
- type: app_host_boundary_1.ON_STATE_CHANGE,
59
- version: 1,
60
- payload: {
61
- stateObject,
62
- },
63
- };
64
- this.dispatch(request);
65
- }
66
- dispatchOnStateComplete() {
67
- const request = {
68
- type: app_host_boundary_1.ON_STATE_COMPLETED,
69
- version: 1,
70
- };
71
- this.dispatch(request);
72
- }
73
- dispatchSubmitResults(results) {
74
- const request = {
75
- type: app_host_boundary_1.SUBMIT_RESULTS,
76
- version: 1,
77
- payload: {
78
- results,
79
- },
80
- };
81
- this.dispatch(request);
82
- }
83
- dispatchGetAppAssetsURL() {
84
- var _a;
85
- const callback = (url) => {
86
- this.appState.appAssetsURL = url;
87
- };
88
- const request = {
89
- type: app_host_boundary_1.GET_APP_ASSET_URL,
90
- version: 1,
91
- payload: {
92
- callback,
93
- },
94
- };
95
- this.dispatch(request);
96
- return (_a = this.appState.appAssetsURL) !== null && _a !== void 0 ? _a : "";
97
- }
98
- registerSerializableSystem(serializedSystem) {
99
- if (this.systems.has(serializedSystem.name)) {
100
- throw new Errors_1.DuplicateSystemNameError(serializedSystem.name);
101
- }
102
- this.systems.set(serializedSystem.name, serializedSystem);
103
- }
104
- getSerializedState() {
105
- const systems = Array.from(this.systems.values());
106
- const serializedStates = systems.map((system) => {
107
- const state = system.getSerializedObject();
108
- return {
109
- seriliziationVersion: system.seriliziationVersion,
110
- name: system.name,
111
- state,
112
- };
113
- });
114
- return {
115
- version: this.serilizationVersion,
116
- systems: serializedStates,
117
- };
118
- }
119
- setSerializedState(state) {
120
- if (state.version === 2) {
121
- state.systems.forEach((systemState) => {
122
- const seriliazableSystem = this.systems.get(systemState.name);
123
- if (seriliazableSystem) {
124
- seriliazableSystem.applySerailizedObject(systemState.state, systemState.seriliziationVersion);
211
+ if (this.currentInterval) {
212
+ clearInterval(this.currentInterval);
213
+ }
214
+ this.appState.isTransitioning = true;
215
+ const durationInMS = duration * 1000;
216
+ let chrono = 0;
217
+ const transitionDelta = 10;
218
+ this.currentInterval = setInterval(() => {
219
+ chrono = chrono + transitionDelta;
220
+ let normalizedTime = chrono / durationInMS;
221
+ if (normalizedTime > 1) {
222
+ normalizedTime = 1;
125
223
  }
126
- else {
127
- console.warn("Unable to find seriarializedSystem " + systemState.name);
224
+ const percent = this.easeFunction(normalizedTime);
225
+ this.applyTransitionToSystems(percent);
226
+ if (normalizedTime >= 1 && this.currentInterval) {
227
+ clearInterval(this.currentInterval);
228
+ this.appState.isTransitioning = false;
128
229
  }
129
- });
130
- }
131
- // Here is where we will add support for future versions
132
- else {
133
- throw new Errors_1.UnsupportedVersionNumber(state.version);
230
+ }, transitionDelta);
134
231
  }
135
232
  }
136
- getShowBabylonInspector() {
137
- return this.appState.showBabyonInspector;
138
- }
139
- setShowBabylonInspector(showInspector) {
140
- if (this.appState.showBabyonInspector === showInspector)
141
- return;
142
- this.appState.showBabyonInspector = showInspector;
143
- this.notify();
144
- }
145
- getIsAuthoring() {
146
- return this.appState.isAuthoring;
147
- }
148
- setIsAuthoring(isAuthoring) {
149
- if (isAuthoring === this.appState.isAuthoring)
150
- return;
151
- this.appState.isAuthoring = isAuthoring;
152
- this.notify();
153
- }
154
- addObserver(observer) {
155
- this.observers.push(observer);
156
- }
157
- removeObserver(observer) {
158
- const index = this.observers.indexOf(observer);
159
- if (index >= 0) {
160
- this.observers.splice(index, 1);
161
- }
233
+ applyTransitionToSystems(percent) {
234
+ this.systems.forEach((system) => {
235
+ system.applyTransition(percent);
236
+ });
162
237
  }
163
238
  notify() {
164
239
  this.observers.forEach((observer) => observer.onBaseAppChange());
@@ -169,6 +244,7 @@ class BaseAppUCImp {
169
244
  }
170
245
  const handler = this.appState.handler;
171
246
  handler(request);
247
+ this.logToConsole(`Dispatched request: ${JSON.stringify(request)}`);
172
248
  }
173
249
  }
174
250
  exports.BaseAppUCImp = BaseAppUCImp;
@@ -0,0 +1,17 @@
1
+ export declare type OnBabylonChange = () => void;
2
+ export interface Babylon {
3
+ engine: unknown;
4
+ scene: unknown;
5
+ workingCanvas?: HTMLCanvasElement;
6
+ showInspector: boolean;
7
+ renderCanvas?: HTMLCanvasElement;
8
+ updateCanvasSize: () => void;
9
+ submitRenderCanvas: (canvas: HTMLCanvasElement) => void;
10
+ clearRenderCanvas: () => void;
11
+ registerResizeEnging: (resizeEngine: () => void) => void;
12
+ registerStartRendering: (startRendering: (canvas: HTMLCanvasElement) => void) => void;
13
+ registerStopRendering: (stopRendering: (canvas: HTMLCanvasElement) => void) => void;
14
+ addObserver: (observer: OnBabylonChange) => void;
15
+ removeObserver: (observer: OnBabylonChange) => void;
16
+ }
17
+ export declare function makeBabylon(): Babylon;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeBabylon = void 0;
4
+ const MemoizedBoolean_1 = require("./MemoizedBoolean");
5
+ const MemoizedVector2_1 = require("./MemoizedVector2");
6
+ const ObserverList_1 = require("./ObserverList");
7
+ const Vector2_1 = require("./Vector2");
8
+ function makeBabylon() {
9
+ return new BabylonImp();
10
+ }
11
+ exports.makeBabylon = makeBabylon;
12
+ class BabylonImp {
13
+ constructor() {
14
+ this.observers = new ObserverList_1.ObserverList();
15
+ this.updateCanvasSize = () => {
16
+ if (!this.workingCanvas)
17
+ return;
18
+ if (!this._renderCanvas)
19
+ return;
20
+ if (this.resizeEngine) {
21
+ this.resizeEngine();
22
+ }
23
+ this.workingCanvas.height = this._renderCanvas.height;
24
+ this.workingCanvas.width = this._renderCanvas.width;
25
+ };
26
+ this.submitRenderCanvas = (canvas) => {
27
+ if (canvas === this._renderCanvas)
28
+ return;
29
+ if (this._renderCanvas && this.stopRendering) {
30
+ this.stopRendering(this._renderCanvas);
31
+ }
32
+ this._renderCanvas = canvas;
33
+ this.updateCanvasSize();
34
+ if (this.startRendering) {
35
+ this.startRendering(canvas);
36
+ }
37
+ this.observers.notify();
38
+ };
39
+ this.clearRenderCanvas = () => {
40
+ if (!this._renderCanvas)
41
+ return;
42
+ if (this.stopRendering) {
43
+ this.stopRendering(this._renderCanvas);
44
+ }
45
+ this._renderCanvas = undefined;
46
+ this.observers.notify();
47
+ };
48
+ this.registerResizeEnging = (resizeEngine) => {
49
+ this.resizeEngine = resizeEngine;
50
+ };
51
+ this.registerStartRendering = (startRendering) => {
52
+ this.startRendering = startRendering;
53
+ };
54
+ this.registerStopRendering = (stopRendering) => {
55
+ this.stopRendering = stopRendering;
56
+ };
57
+ this.addObserver = (observer) => {
58
+ this.observers.add(observer);
59
+ };
60
+ this.removeObserver = (observer) => {
61
+ this.observers.remove(observer);
62
+ };
63
+ this.memoizedShowInspector = new MemoizedBoolean_1.MemoizedBoolean(false, this.observers.notify);
64
+ this.memoizedCanvasSize = new MemoizedVector2_1.MemoizedVector2(Vector2_1.Vector2.One(), this.observers.notify);
65
+ }
66
+ get showInspector() {
67
+ return this.memoizedShowInspector.val;
68
+ }
69
+ set showInspector(val) {
70
+ this.memoizedShowInspector.val = val;
71
+ }
72
+ get renderCanvas() {
73
+ return this._renderCanvas;
74
+ }
75
+ get canvasSize() {
76
+ return this.memoizedCanvasSize.getVector();
77
+ }
78
+ set canvasSize(val) {
79
+ this.memoizedCanvasSize.setVector(val);
80
+ }
81
+ }
@@ -0,0 +1,7 @@
1
+ export declare type OnBaseAppChange = () => void;
2
+ export interface BaseApp {
3
+ isAuthoring: boolean;
4
+ addObserver(observer: OnBaseAppChange): void;
5
+ removeObserver(observer: OnBaseAppChange): void;
6
+ }
7
+ export declare function makeBaseApp(): BaseApp;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeBaseApp = void 0;
4
+ const MemoizedBoolean_1 = require("./MemoizedBoolean");
5
+ const ObserverList_1 = require("./ObserverList");
6
+ function makeBaseApp() {
7
+ return new BaseAppImp();
8
+ }
9
+ exports.makeBaseApp = makeBaseApp;
10
+ class BaseAppImp {
11
+ constructor() {
12
+ this.observers = new ObserverList_1.ObserverList();
13
+ this.memoizedIsAuthoring = new MemoizedBoolean_1.MemoizedBoolean(false, this.observers.notify);
14
+ this.addObserver = (observer) => {
15
+ this.observers.add(observer);
16
+ };
17
+ this.removeObserver = (observer) => {
18
+ this.observers.remove(observer);
19
+ };
20
+ }
21
+ get isAuthoring() {
22
+ return this.memoizedIsAuthoring.val;
23
+ }
24
+ set isAuthoring(val) {
25
+ this.memoizedIsAuthoring.val = val;
26
+ }
27
+ }
@@ -0,0 +1,20 @@
1
+ export declare class Color {
2
+ static White(): Color;
3
+ static Black(): Color;
4
+ static Red(): Color;
5
+ static Green(): Color;
6
+ static Blue(): Color;
7
+ static Yellow(): Color;
8
+ static Gray(): Color;
9
+ r: number;
10
+ g: number;
11
+ b: number;
12
+ a: number;
13
+ get rPercent(): number;
14
+ get gPercent(): number;
15
+ get bPercent(): number;
16
+ get aPercent(): number;
17
+ equal: (otherColor: Color) => boolean;
18
+ copy: () => Color;
19
+ constructor(r: number, g: number, b: number, a?: number);
20
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Color = void 0;
4
+ class Color {
5
+ constructor(r, g, b, a = 255) {
6
+ this.equal = (otherColor) => {
7
+ if (otherColor.r === this.r &&
8
+ otherColor.g === this.g &&
9
+ otherColor.b === this.b &&
10
+ otherColor.a === this.a) {
11
+ return true;
12
+ }
13
+ else {
14
+ return false;
15
+ }
16
+ };
17
+ this.copy = () => {
18
+ return new Color(this.r, this.g, this.b, this.a);
19
+ };
20
+ this.r = r;
21
+ this.g = g;
22
+ this.b = b;
23
+ this.a = a;
24
+ }
25
+ static White() {
26
+ return new Color(255, 255, 255, 255);
27
+ }
28
+ static Black() {
29
+ return new Color(0, 0, 0, 255);
30
+ }
31
+ static Red() {
32
+ return new Color(255, 0, 0, 255);
33
+ }
34
+ static Green() {
35
+ return new Color(0, 255, 0, 255);
36
+ }
37
+ static Blue() {
38
+ return new Color(0, 0, 255, 255);
39
+ }
40
+ static Yellow() {
41
+ return new Color(255, 0, 255, 255);
42
+ }
43
+ static Gray() {
44
+ return new Color(192, 192, 192, 255);
45
+ }
46
+ get rPercent() {
47
+ return this.r / 255;
48
+ }
49
+ get gPercent() {
50
+ return this.g / 255;
51
+ }
52
+ get bPercent() {
53
+ return this.b / 255;
54
+ }
55
+ get aPercent() {
56
+ return this.a / 255;
57
+ }
58
+ }
59
+ exports.Color = Color;