@vived/app 2.6.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.
Files changed (89) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/README.md +151 -0
  3. package/lib/Core/BaseApp/Boundary.d.ts +49 -0
  4. package/lib/Core/BaseApp/Boundary.js +2 -0
  5. package/lib/Core/BaseApp/Entity.d.ts +11 -0
  6. package/lib/Core/BaseApp/Entity.js +2 -0
  7. package/lib/Core/BaseApp/Errors/ErrorDuplicateSystemName.d.ts +3 -0
  8. package/lib/Core/BaseApp/Errors/ErrorDuplicateSystemName.js +12 -0
  9. package/lib/Core/BaseApp/Errors/ErrorNoHostHandler.d.ts +3 -0
  10. package/lib/Core/BaseApp/Errors/ErrorNoHostHandler.js +10 -0
  11. package/lib/Core/BaseApp/Errors/ErrorUnsupportedVersionNumber.d.ts +3 -0
  12. package/lib/Core/BaseApp/Errors/ErrorUnsupportedVersionNumber.js +10 -0
  13. package/lib/Core/BaseApp/Errors/index.d.ts +3 -0
  14. package/lib/Core/BaseApp/Errors/index.js +15 -0
  15. package/lib/Core/BaseApp/UseCase.d.ts +43 -0
  16. package/lib/Core/BaseApp/UseCase.js +250 -0
  17. package/lib/Core/BaseAppState/Boundary.d.ts +14 -0
  18. package/lib/Core/BaseAppState/Boundary.js +2 -0
  19. package/lib/Core/BaseAppState/Entity.d.ts +5 -0
  20. package/lib/Core/BaseAppState/Entity.js +2 -0
  21. package/lib/Core/BaseAppState/UseCase.d.ts +16 -0
  22. package/lib/Core/BaseAppState/UseCase.js +54 -0
  23. package/lib/Core/BaseAppState/UseCase_Imp.d.ts +16 -0
  24. package/lib/Core/BaseAppState/UseCase_Imp.js +54 -0
  25. package/lib/Core/DevicePreview/DevicePreviewUC_Imp.d.ts +16 -0
  26. package/lib/Core/DevicePreview/DevicePreviewUC_Imp.js +56 -0
  27. package/lib/Core/DevicePreview/boundary.d.ts +14 -0
  28. package/lib/Core/DevicePreview/boundary.js +2 -0
  29. package/lib/Core/DevicePreview/entity.d.ts +5 -0
  30. package/lib/Core/DevicePreview/entity.js +2 -0
  31. package/lib/Core/DispatchToHost/Entity.d.ts +4 -0
  32. package/lib/Core/DispatchToHost/Entity.js +2 -0
  33. package/lib/Core/DispatchToHost/UseCase.d.ts +12 -0
  34. package/lib/Core/DispatchToHost/UseCase.js +70 -0
  35. package/lib/Core/DispatchToHost/boundary.d.ts +9 -0
  36. package/lib/Core/DispatchToHost/boundary.js +2 -0
  37. package/lib/Core/Serilization/Boundary.d.ts +20 -0
  38. package/lib/Core/Serilization/Boundary.js +2 -0
  39. package/lib/Core/Serilization/Entity.d.ts +3 -0
  40. package/lib/Core/Serilization/Entity.js +2 -0
  41. package/lib/Core/Serilization/ErrorDuplicateSystemName.d.ts +3 -0
  42. package/lib/Core/Serilization/ErrorDuplicateSystemName.js +12 -0
  43. package/lib/Core/Serilization/ErrorUnsupportedVersionNumber.d.ts +3 -0
  44. package/lib/Core/Serilization/ErrorUnsupportedVersionNumber.js +10 -0
  45. package/lib/Core/Serilization/Errors.d.ts +6 -0
  46. package/lib/Core/Serilization/Errors.js +19 -0
  47. package/lib/Core/Serilization/UseCase.d.ts +10 -0
  48. package/lib/Core/Serilization/UseCase.js +52 -0
  49. package/lib/Core/Serilization/UseCase_Imp.d.ts +10 -0
  50. package/lib/Core/Serilization/UseCase_Imp.js +51 -0
  51. package/lib/Core/index.d.ts +3 -0
  52. package/lib/Core/index.js +19 -0
  53. package/lib/Interface/Controllers/appHandler.d.ts +12 -0
  54. package/lib/Interface/Controllers/appHandler.js +94 -0
  55. package/lib/Interface/Controllers/defaultAppHanlderFunctions.d.ts +3 -0
  56. package/lib/Interface/Controllers/defaultAppHanlderFunctions.js +31 -0
  57. package/lib/Interface/Controllers/dispatchStateChange.d.ts +2 -0
  58. package/lib/Interface/Controllers/dispatchStateChange.js +10 -0
  59. package/lib/Interface/Controllers/index.d.ts +9 -0
  60. package/lib/Interface/Controllers/index.js +21 -0
  61. package/lib/Interface/Controllers/makeAppHandler.d.ts +12 -0
  62. package/lib/Interface/Controllers/makeAppHandler.js +94 -0
  63. package/lib/Interface/Controllers/setDevicePreview.d.ts +2 -0
  64. package/lib/Interface/Controllers/setDevicePreview.js +14 -0
  65. package/lib/Interface/Controllers/setIsAuthoring.d.ts +2 -0
  66. package/lib/Interface/Controllers/setIsAuthoring.js +14 -0
  67. package/lib/Interface/Controllers/setState.d.ts +2 -0
  68. package/lib/Interface/Controllers/setState.js +21 -0
  69. package/lib/Interface/Controllers/showBabylonInspector.d.ts +2 -0
  70. package/lib/Interface/Controllers/showBabylonInspector.js +9 -0
  71. package/lib/Interface/Controllers/startApp.d.ts +1 -0
  72. package/lib/Interface/Controllers/startApp.js +9 -0
  73. package/lib/Interface/Controllers/stopApp.d.ts +2 -0
  74. package/lib/Interface/Controllers/stopApp.js +10 -0
  75. package/lib/Interface/PresentationManagers/DevicePreviewPM.d.ts +13 -0
  76. package/lib/Interface/PresentationManagers/DevicePreviewPM.js +25 -0
  77. package/lib/Interface/PresentationManagers/IsAuthoringPM.d.ts +10 -0
  78. package/lib/Interface/PresentationManagers/IsAuthoringPM.js +23 -0
  79. package/lib/Interface/PresentationManagers/ShowBabylonInspectorPM.d.ts +10 -0
  80. package/lib/Interface/PresentationManagers/ShowBabylonInspectorPM.js +23 -0
  81. package/lib/Interface/PresentationManagers/index.d.ts +3 -0
  82. package/lib/Interface/PresentationManagers/index.js +15 -0
  83. package/lib/Interface/appHandler.d.ts +12 -0
  84. package/lib/Interface/appHandler.js +94 -0
  85. package/lib/Interface/index.d.ts +2 -0
  86. package/lib/Interface/index.js +14 -0
  87. package/lib/index.d.ts +2 -0
  88. package/lib/index.js +14 -0
  89. package/package.json +45 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,58 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+ ## [2.6.0] - 2021-7-29
7
+ ### Added
8
+ - Transition capability to the serailized states
9
+ - Verbose flag to the base use case
10
+ ### Fixed
11
+ - The serilization system did not like having an empty state passed in. Fixed it
12
+ - Changed the base app use case to arrow functions
13
+ ## [2.5.0] - 2021-7-9
14
+ ### Changed
15
+ - Change the Device Peview PM to return a view model
16
+ - Changed system name BaseAppState to BaseApp
17
+ - Merged Serilization into Base App
18
+ - Merged Dispatch to Host into Base App
19
+ - Merged Device Preview into Base App
20
+ ## [2.3.0] - 2021-7-7
21
+ ### Changed
22
+ - Converted the App Handler into a factory
23
+ ### Added
24
+ - Serilization system
25
+ - A lot of app systems controlles and PMs
26
+ ## [2.2.0] - 2021-07-1
27
+ ### Changed
28
+ - Start to payload version 2
29
+ - Set state to payload version 2
30
+ ## [2.1.0] - 2021-06-28
31
+ ### Added
32
+ - Support for responding to requsting app response payload versions
33
+ ## [2.0.0] - 2021-06-28
34
+ ### Removed
35
+ - React and the hook
36
+ ## [1.2.0] - 2021-06-28
37
+ ### Added
38
+ - Support for host communication via the 3rd gen boundary
39
+ ## [1.1.0] - 2021-04-26
40
+ ### Changed
41
+ - General refactor on project structure
42
+ - Renamed the package to @VIVED
43
+ ### Added
44
+ - A Set Device Preview controller
45
+
46
+ ## [1.0.0] - 2021-04-20
47
+ ### Changed
48
+ - Setup the readme file
49
+ ### Removed
50
+ - All the boundary interfaces. These were moved to a seperate package.
51
+
52
+ ## [0.0.2] - 2021-04-06
53
+ ### Added
54
+ - Old version of the App Interface
55
+
56
+ ## [0.0.1] - 2021-04-06
57
+ ### Added
58
+ - Initial setup
package/README.md ADDED
@@ -0,0 +1,151 @@
1
+ # VIVED App
2
+ This package is intended to hold all the common logic used by VIVED Slide Apps.
3
+
4
+ ## Use Case
5
+ You will need to instantiate the baseAppUC by calling makeBaseAppUC(). Typically this is done in your Main script when everything is starting up.
6
+
7
+ ### Functions
8
+ #### getIsAuthoring():boolean
9
+ Gets the flag to see if the app is currently in an authoring state
10
+
11
+ #### setIsAuthoring(isAuthoring:boolean):void
12
+ Sets the is authoring flag. If there is a change this will notify all observers
13
+
14
+ #### getShowBabylonInspector():boolean
15
+ Gets the flag to see if the babylon inspector should be show
16
+
17
+ #### setShowBabylonInspector(showInspector: boolean):void
18
+ Sets if the Babylon Inspector should be shown. If there is a change this will notify all observers.
19
+
20
+ #### addObserver(observer: BaseAppStateObserver): void;
21
+ Adds an observer to the Use Case. The observer will be notified if anything in the use case changes
22
+
23
+ #### removeObserver(observer: BaseAppStateObserver): void;
24
+ Removes an observer so it will no longer be notified of changes in the Use Case
25
+
26
+ #### getSerializedState(): SerializedStates;
27
+ Get the current serialized state of the App. See the Serilization section below
28
+
29
+ #### setSerializedState(state: SerializedStates): void;
30
+ Sets the state of the app to a Serialized State. See the Serilization section below
31
+
32
+ #### registerSerializableSystem(serializedSystem: SerializableSystem):void;
33
+ Registers a Serializable System. This is likely a system in your App which has states that need to be saved and applied. See the Serilization section below
34
+
35
+ #### setHostHandler(handler: Handler):void;
36
+ When an App is mounted it is passed the Host Handler. This is the Handler to which the Use Case will dispatch all requests. This needs to be set when the app Main is constructed. See the App - Host Communication section below
37
+
38
+ #### hasHostHandler():boolean;
39
+ This checks to see if a host handler has been set. This is useful for avoiding nasty errors
40
+
41
+ #### dispatchOnStateChange(stateObject: object):void;
42
+ When authoring the Host should be notified whenever something in the serializable state has changed. Calling this will let the host know that the state has changed and pass along the new state.
43
+
44
+ #### dispatchOnStateComplete():void
45
+ Calling this will let the Host know that the user has completed their required task and the Host can move on to the next state.
46
+
47
+ #### dispatchSubmitResults(results:object):void;
48
+ If a user has completed a task and there are results to submit the app can pass these results to the Host via this call.
49
+
50
+ #### dispatchGetAppAssetsURL():string
51
+ Many Apps require Assets such as GLBs or images. These are expected to be stored in the public/assets folder (assuming the app was built with Create React App). However once the App has been published, the path to this folder will be different. The Host should know this path so calling this will ask the host for the path to the assets folder.
52
+
53
+ #### setDevicePreview(x: number, y: number): void;
54
+ At some point the User may opt to view the Activity in a way the previews a specific hardware device. This decision is handled by the host but the App will be notified. This function is used to set the desired x and y resolution
55
+
56
+ #### clearDevicePreview():void;
57
+ Calling this will clear any preview device resoltions.
58
+
59
+ #### getUseDevicePreview(): boolean;
60
+ This will return a true if the Host has set a device resolution to preview. Otherwise it will return false
61
+
62
+ #### getDevicePreviewSize(): {x: number, y:number}
63
+ This will return the requested preview device x and y resolution. If no device has been set or the previewed device has been cleared, these will both be -1.
64
+
65
+ ### Observers
66
+ If you want to be notified when something changes in the Use Case you will need to create an observer class the implements BaseAppStateObserver and then registers itself with the use case via addObserver. If you observer is getting destroyed it needs to call removeObserver on the Use Case
67
+
68
+ ### Serilization
69
+ The Serilization system is designed to handle all the heavy lifting of serializing and desrializing the state of your app.
70
+
71
+ #### Serializable System
72
+ You app will likey have one or my systems that have data which needs to be stored in the state. For each of these systems you are expected to write a class that implements SerializableSystem and then register this class with the Base App Use Case by calling registerSerializableSystem.
73
+
74
+ This implementation requires your class to setup four items:
75
+ ##### Name
76
+ This is the name of your system. Not this name must be unique across all the serialized systems in your App. In other words you cannot register two different Serializable Systems with the same name. Also, this name should not be modified down the road is it is how the Use Case will determine what Class to send stored activity data to. This name will never be seen by a user.
77
+
78
+ ##### Serilization Version
79
+ This is an integer that is stored with the data and written into an activity file. This is intended to allow the system state data to be changed over time while giving developers the opportunity to be backwards compatable. For example, lets say after a few months the system is improved to include another statable variable. The devloper would iterate the serilizationVersion from 1 to 2. From now on, any new saved states will be saved with version number 2. When the System is asked to apply some saved state data it can check to see if this state data was version 1 or 2 and handle it appropriatetly.
80
+
81
+ ##### getSerializedObject():object
82
+ The Serilization Use Case will trigger this function when it needs to store the current state. The Class is expected to form up an object however they see fit and return it as a vanilla object.
83
+
84
+ ##### applySerializedObject(state: object, version: number):void
85
+ This function will be called when the Serilization Use Case want to apply a state to a system. It will pass in a vanilla object as well as the serilization version that was set when this object was formed. The Class is expected to handle the versions and apply the object appropriatetly.
86
+
87
+ ### App - Host Communication
88
+ The boundary between the Host and the App has been intentionally designed to allow the the host and the apps to be completely independent of each other while allowing communication between the two.
89
+
90
+ #### Request
91
+ All messages passed between the Host and the App are called requests. All Requests are strongly typed and versioned in the @vived/app-host-boundary package.
92
+
93
+ #### Dispatcher
94
+ When an App needs to send a request to the Host all it needs to do is trigger a dispatch action in the Use Case. This package will take care of correctly forming the Request and sending it to the Host.
95
+
96
+ #### Handler
97
+ When the Host sends a request to the App it must be handled, which is the responsibility of the App Handler. You app is expected to provide a list of AppHandlerFunctions when it creates the App Handler during the construction of the App. This allows allows the App to unpack the request and then call one of these functions, allowing your App to handle it however it wants.
98
+
99
+ ## Presenter Models
100
+ Presenter Models are intented to update a view whenenver a something specific changes in the Use Case. The Presenter Model will either pass the View a specific parameter or a View Model of parameters. Ideally the View will be able to just consume the View Model or the parameter without needing any logic or refactoring.
101
+
102
+ To use Presenter Model your View (or Hook) will need to instantiate the Presenter Model, passing in the baseAppUC and a callback function. The callback function will be triggered when the Presenter Moder is initiated and then whenever an update is available. It is important to call Dispose on the Presetner Model if your view or hook is being destroyed in order to remove it's observer from the Use Case.
103
+
104
+ ### DevicePreviewPM
105
+ This PM will update it's view whenever something with the Device Preview changes. It returns a View Model with the following parameters
106
+ - isPreviewingDevice: a boolean letting you know if the render canvas should be scaled
107
+ - x: is the pixel width to scale to if isPreviewingDevice. This will be -1 if there is no device to preview
108
+ - y: is the pixel height to scale to if isPreviewingDevice. This will be -1 if there is no device
109
+
110
+ ### IsAuthoringPM
111
+ This PM will update the view whenever the Is Authoring flag changes, passing back the current isAuthor value.
112
+
113
+ ### ShowBabylonInspectorPM
114
+ This PM will update the view whenever the Show Babylon Inspector flag changes, passing back the current value.
115
+
116
+ ## Controllers
117
+ ### defaultAppHandlerFunctions
118
+ The function creates all the default app handler functions. These include:
119
+ - showBabylonInspector: (show: boolean) => void;
120
+ - setIsAuthoring: (isAuthoring: boolean) => void;
121
+ - disposeApp: () => void;
122
+ - stopApp: () => void;
123
+ - startApp: (container: HTMLElement) => void;
124
+ - setState: (finalState: string, duration?: number) => void;
125
+ - setDevicePreview: (x: number, y: number) => void;
126
+
127
+ Your App will likely need to handle one or more of these functions differently so the intent is that you use this function to create all the default functions and then replace the appropriate functions with your custom function before creating the App Handler
128
+
129
+ ### dispatchStateChange()
130
+ This function is created with the factory makeDispatchStateChange. It first gets the latest serialized state and then dispatches that state to the Host
131
+
132
+ ### makeAppHandler(functions: AppHandlerFunctions): Handler
133
+ This function is used to create the App Handler. It takes in the App Handler Functions and returns a generic Handler, which is passed to the Host. The host can then dispatch a request to this Handler. The App Handler is responsible for reading the request and triggering the appropriate App Handler Function
134
+
135
+ ### setDevicePreview(x: number, y: number)
136
+ This function is created with the makeSetDevicePreview factory. If either x or y are negative this function will clear the selected device in the baseAppUC. Otherwise it will set the x and y value of the selected device in the Use Case.
137
+
138
+ ### setIsAuthoring(isAuthoring: boolean)
139
+ This function is created with the makeSetIsAuthoring factory and will apply the isAuthoring flag to the use case. It will also dispatch a state change if the is Authorin is set to true. This allows the Host to know the initial state when the user start authoring.
140
+
141
+ ### setState(state: string, duration?: number)
142
+ This function is created with the makeSetState facory. It is responsible for recieving a desired state from the Host and applying it locally. You will note that the setState function in this package does not use the duration parameter. This function simply sets the state hard, without any transition. You App will probably what to implement it's own setState function that support nice interpolations for your systems.
143
+
144
+ ### showBabylonInspector(showInspector:boolean)
145
+ This function is created with the makeShowBabylonInspector factory. It will set the show babylon inspector flag in the Use Case.
146
+
147
+ ### startApp(container: HTMLElement)
148
+ This function is created with the makeStartApp factory. It is reponsible for starting up all the renderings of the App. This could include the App's react components as well as the Babylon Engine.
149
+
150
+ ### stopApp()
151
+ This function is created with the makeStopApp factory. It is reponsible for stopping up all the renderings of the App. This could include the App's react components as well as the Babylon Engine. It also ensures that the isAuthoring flag is set to false.
@@ -0,0 +1,49 @@
1
+ import { Handler } from "@vived/app-host-boundary";
2
+ export interface BaseAppUC {
3
+ getIsAuthoring(): boolean;
4
+ setIsAuthoring(isAuthoring: boolean): void;
5
+ getShowBabylonInspector(): boolean;
6
+ setShowBabylonInspector(showInspector: boolean): void;
7
+ addObserver(observer: BaseAppStateObserver): void;
8
+ removeObserver(observer: BaseAppStateObserver): void;
9
+ setVerbose(verbose: boolean): void;
10
+ getSerializedState(): SerializedStates;
11
+ setSerializedState(state: SerializedStates, transitionTime: number): void;
12
+ setDefaultState(transitionTime: number): void;
13
+ registerSerializableSystem(serializedSystem: SerializableSystem): void;
14
+ getIsTransitioning(): boolean;
15
+ abortTransition(): void;
16
+ setTransitionEaseFn: (easeFn: (normalizedTime: number) => number) => void;
17
+ setHostHandler(handler: Handler): void;
18
+ hasHostHandler(): boolean;
19
+ dispatchOnStateChange(stateObject: object): void;
20
+ dispatchOnStateComplete(): void;
21
+ dispatchSubmitResults(results: object): void;
22
+ dispatchGetAppAssetsURL(): string;
23
+ setDevicePreview(x: number, y: number): void;
24
+ clearDevicePreview(): void;
25
+ getUseDevicePreview(): boolean;
26
+ getDevicePreviewSize(): {
27
+ x: number;
28
+ y: number;
29
+ };
30
+ }
31
+ export interface BaseAppStateObserver {
32
+ onBaseAppChange: () => void;
33
+ }
34
+ export interface SerializedStates {
35
+ version: number;
36
+ systems: SystemState[];
37
+ }
38
+ export interface SystemState {
39
+ name: string;
40
+ seriliziationVersion: number;
41
+ state: object;
42
+ }
43
+ export interface SerializableSystem {
44
+ name: string;
45
+ seriliziationVersion: number;
46
+ getSerializedObject(): object;
47
+ intializeStateForTransition(serializedState: object | null, version: number): void;
48
+ applyTransition(percent: number): void;
49
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ export interface BaseAppState {
2
+ isAuthoring: boolean;
3
+ showBabyonInspector: boolean;
4
+ handler?: unknown;
5
+ appAssetsURL?: string;
6
+ useDevicePreview: boolean;
7
+ x: number;
8
+ y: number;
9
+ isTransitioning: boolean;
10
+ verbose: boolean;
11
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export declare class DuplicateSystemNameError extends Error {
2
+ constructor(name: string);
3
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DuplicateSystemNameError = void 0;
4
+ class DuplicateSystemNameError extends Error {
5
+ constructor(name) {
6
+ const msg = "Cannot add two serialized systems named " +
7
+ name +
8
+ ". Every system name must be unique";
9
+ super(msg);
10
+ }
11
+ }
12
+ exports.DuplicateSystemNameError = DuplicateSystemNameError;
@@ -0,0 +1,3 @@
1
+ export declare class ErrorNoHostHandler extends Error {
2
+ constructor();
3
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ErrorNoHostHandler = void 0;
4
+ class ErrorNoHostHandler extends Error {
5
+ constructor() {
6
+ const msg = "Host Handler has not been set";
7
+ super(msg);
8
+ }
9
+ }
10
+ exports.ErrorNoHostHandler = ErrorNoHostHandler;
@@ -0,0 +1,3 @@
1
+ export declare class UnsupportedVersionNumber extends Error {
2
+ constructor(version: number);
3
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnsupportedVersionNumber = void 0;
4
+ class UnsupportedVersionNumber extends Error {
5
+ constructor(version) {
6
+ const msg = "Serialization version " + version + " is not supported";
7
+ super(msg);
8
+ }
9
+ }
10
+ exports.UnsupportedVersionNumber = UnsupportedVersionNumber;
@@ -0,0 +1,3 @@
1
+ export * from "./ErrorDuplicateSystemName";
2
+ export * from "./ErrorUnsupportedVersionNumber";
3
+ export * from "./ErrorNoHostHandler";
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./ErrorDuplicateSystemName"), exports);
14
+ __exportStar(require("./ErrorUnsupportedVersionNumber"), exports);
15
+ __exportStar(require("./ErrorNoHostHandler"), exports);
@@ -0,0 +1,43 @@
1
+ import { Handler } from "@vived/app-host-boundary";
2
+ import { BaseAppStateObserver, BaseAppUC, SerializableSystem, SerializedStates } from "./Boundary";
3
+ export declare class BaseAppUCImp implements BaseAppUC {
4
+ private appState;
5
+ private observers;
6
+ private systems;
7
+ private serilizationVersion;
8
+ private currentInterval?;
9
+ private easeFunction;
10
+ constructor();
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: () => {
19
+ x: number;
20
+ y: number;
21
+ };
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;
41
+ private notify;
42
+ private dispatch;
43
+ }
@@ -0,0 +1,250 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseAppUCImp = void 0;
4
+ const app_host_boundary_1 = require("@vived/app-host-boundary");
5
+ const Errors_1 = require("./Errors");
6
+ class BaseAppUCImp {
7
+ constructor() {
8
+ this.observers = [];
9
+ this.systems = new Map();
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
+ };
184
+ this.appState = {
185
+ isAuthoring: false,
186
+ showBabyonInspector: false,
187
+ useDevicePreview: false,
188
+ x: -1,
189
+ y: -1,
190
+ isTransitioning: false,
191
+ verbose: false,
192
+ };
193
+ }
194
+ setVerbose(verbose) {
195
+ this.appState.verbose = verbose;
196
+ }
197
+ logToConsole(message) {
198
+ if (!this.appState.verbose)
199
+ return;
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);
209
+ }
210
+ else {
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;
223
+ }
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;
229
+ }
230
+ }, transitionDelta);
231
+ }
232
+ }
233
+ applyTransitionToSystems(percent) {
234
+ this.systems.forEach((system) => {
235
+ system.applyTransition(percent);
236
+ });
237
+ }
238
+ notify() {
239
+ this.observers.forEach((observer) => observer.onBaseAppChange());
240
+ }
241
+ dispatch(request) {
242
+ if (!this.appState.handler) {
243
+ throw new Errors_1.ErrorNoHostHandler();
244
+ }
245
+ const handler = this.appState.handler;
246
+ handler(request);
247
+ this.logToConsole(`Dispatched request: ${JSON.stringify(request)}`);
248
+ }
249
+ }
250
+ exports.BaseAppUCImp = BaseAppUCImp;
@@ -0,0 +1,14 @@
1
+ export interface BaseAppStateUC {
2
+ getIsAuthoring(): boolean;
3
+ setIsAuthoring(isAuthoring: boolean): void;
4
+ getShowBabylonInspector(): boolean;
5
+ setShowBabylonInspector(showInspector: boolean): void;
6
+ getAppContainer(): HTMLElement | undefined;
7
+ setAppContainer(container: HTMLElement): void;
8
+ clearAppContainer(): void;
9
+ addObserver(observer: BaseAppStateObserver): void;
10
+ removeObserver(observer: BaseAppStateObserver): void;
11
+ }
12
+ export interface BaseAppStateObserver {
13
+ onAppStateChange: () => void;
14
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });