@flashist/appframework 0.0.3

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 (137) hide show
  1. package/gulp/tasks/clean.js +9 -0
  2. package/gulp/tasks/compile.js +27 -0
  3. package/gulp/tasks/copy-to-dist.js +15 -0
  4. package/gulp/tasks/generate-definitions.js +86 -0
  5. package/gulpfile.js +22 -0
  6. package/package.json +30 -0
  7. package/src/app/AppModule.ts +26 -0
  8. package/src/app/AppSettings.ts +9 -0
  9. package/src/app/commands/LoadAppConfigCommand.ts +61 -0
  10. package/src/app/commands/ParseStaticItemsConfigCommand.ts +32 -0
  11. package/src/app/data/AppConfigType.ts +1 -0
  12. package/src/app/data/AppConfigVO.ts +27 -0
  13. package/src/app/data/IAppModelStorageVO.ts +4 -0
  14. package/src/app/data/IItemsConfigVO.ts +5 -0
  15. package/src/app/managers/AppManager.ts +68 -0
  16. package/src/app/models/AppConfigModel.ts +20 -0
  17. package/src/app/models/AppModel.ts +18 -0
  18. package/src/app/views/AppMainContainer.ts +23 -0
  19. package/src/assets/AssetsModule.ts +13 -0
  20. package/src/assets/commands/ParseAssetsConfigCommand.ts +25 -0
  21. package/src/assets/data/IAssetsConfigVO.ts +5 -0
  22. package/src/assets/models/AssetsModel.ts +7 -0
  23. package/src/base/BaseObjectWithGlobalDispatcher.ts +23 -0
  24. package/src/base/commands/BaseAppCommand.ts +22 -0
  25. package/src/base/data/BaseAppObjectWithStaticVO.ts +15 -0
  26. package/src/base/managers/BaseAppManager.ts +5 -0
  27. package/src/base/mediators/BaseAppMediator.ts +24 -0
  28. package/src/base/models/BaseAppGenericObjectsModel.ts +23 -0
  29. package/src/base/models/BaseAppModel.ts +5 -0
  30. package/src/base/modules/AppModulesManager.ts +44 -0
  31. package/src/base/modules/BaseAppModule.ts +17 -0
  32. package/src/base/views/BaseAppView.ts +25 -0
  33. package/src/containers/ContainersModule.ts +13 -0
  34. package/src/containers/managers/ContainersManager.ts +27 -0
  35. package/src/data/IAppGenericObjectVO.ts +5 -0
  36. package/src/date/DateSettings.ts +6 -0
  37. package/src/debug/DebugModule.ts +22 -0
  38. package/src/dependencies/DependenciesModule.ts +13 -0
  39. package/src/display/data/IGetSizable.ts +5 -0
  40. package/src/display/tools/GetSizeTools.ts +25 -0
  41. package/src/display/views/AppContainer.ts +20 -0
  42. package/src/display/views/button/BaseBtn.ts +325 -0
  43. package/src/display/views/button/BaseBtnEvent.ts +4 -0
  44. package/src/display/views/button/BaseBtnState.ts +31 -0
  45. package/src/display/views/button/BaseBtnView.ts +230 -0
  46. package/src/display/views/button/DefaultButtonViewConfig.ts +10 -0
  47. package/src/display/views/button/IButtonViewConfig.ts +16 -0
  48. package/src/display/views/button/ISimpleButtonConfig.ts +22 -0
  49. package/src/display/views/button/SimpleButtonState.ts +31 -0
  50. package/src/display/views/button/SimpleButtonView.ts +226 -0
  51. package/src/display/views/getsize/GetSizeTools.ts +32 -0
  52. package/src/display/views/getsize/IGetSizeObject.ts +5 -0
  53. package/src/display/views/layout/BaseLayout.ts +160 -0
  54. package/src/display/views/layout/ColumnLayout.ts +120 -0
  55. package/src/display/views/layout/LayoutConfig.ts +15 -0
  56. package/src/display/views/layout/RowLayout.ts +115 -0
  57. package/src/display/views/layout/container/BaseLayoutableContainer.ts +21 -0
  58. package/src/display/views/layout/container/ILayoutableChild.ts +3 -0
  59. package/src/display/views/layout/container/ILayoutableContainer.ts +18 -0
  60. package/src/display/views/resize/IResizable.ts +6 -0
  61. package/src/display/views/resize/ResizableContainer.ts +80 -0
  62. package/src/display/views/simplelist/ISimpleListItem.ts +5 -0
  63. package/src/display/views/simplelist/SimpleList.ts +318 -0
  64. package/src/display/views/simplelist/SimpleListEvent.ts +4 -0
  65. package/src/display/views/sizedistributor/ISizeDistributorChild.ts +5 -0
  66. package/src/display/views/sizedistributor/SizeDistributor.ts +129 -0
  67. package/src/display/views/sizedistributor/SizeDistributorConfig.ts +12 -0
  68. package/src/display/views/togglegroup/IToggableItem.ts +6 -0
  69. package/src/display/views/togglegroup/IToggleGroupItem.ts +6 -0
  70. package/src/display/views/togglegroup/ToggleGroup.ts +140 -0
  71. package/src/display/views/togglegroup/ToggleGroupEvent.ts +3 -0
  72. package/src/display/views/viewstack/IViewStackItem.ts +7 -0
  73. package/src/display/views/viewstack/ViewLazyCreationServiceLocatorStack.ts +19 -0
  74. package/src/display/views/viewstack/ViewLazyCreationStack.ts +47 -0
  75. package/src/display/views/viewstack/ViewStack.ts +93 -0
  76. package/src/display/views/viewstack/ViewStackLazyCreation.ts +45 -0
  77. package/src/events/commands/DispatchGlobalEventCommand.ts +22 -0
  78. package/src/facade/Facade.ts +194 -0
  79. package/src/facade/IFacadeOptions.ts +7 -0
  80. package/src/globaleventdispatcher/GlobalEventDispatcherModule.ts +16 -0
  81. package/src/globaleventdispatcher/commands/WaitGlobalEventCommand.ts +25 -0
  82. package/src/globaleventdispatcher/dispatcher/GlobalEventDispatcher.ts +53 -0
  83. package/src/globaleventdispatcher/dispatcher/GlobalEventDispatcherEvent.ts +4 -0
  84. package/src/globaleventdispatcher/dispatcher/IGlobalDispatchEventVO.ts +4 -0
  85. package/src/globaleventdispatcher/managers/GlobalEventsCommandManager.ts +26 -0
  86. package/src/hints/commands/AnimateHintCommand.ts +99 -0
  87. package/src/hints/data/DefaultHintConfig.ts +22 -0
  88. package/src/hints/data/HintContainerId.ts +1 -0
  89. package/src/hints/data/IHintConfig.ts +20 -0
  90. package/src/html/HTMLModule.ts +13 -0
  91. package/src/html/managers/HTMLManager.ts +32 -0
  92. package/src/index.ts +21 -0
  93. package/src/init/commands/InitApplicationCommand.ts +34 -0
  94. package/src/init/commands/InitApplicationDataCommand.ts +19 -0
  95. package/src/init/commands/InitApplicationDataEvent.ts +3 -0
  96. package/src/load/LoadGroupName.ts +5 -0
  97. package/src/load/LoadModule.ts +23 -0
  98. package/src/load/LoaderId.ts +5 -0
  99. package/src/locales/LocalesModule.ts +11 -0
  100. package/src/locales/commands/ParseLocaleConfigCommand.ts +28 -0
  101. package/src/package.json +36 -0
  102. package/src/pages/PageId.ts +4 -0
  103. package/src/pages/PagesModule.ts +13 -0
  104. package/src/pages/commands/ChangePageCommand.ts +18 -0
  105. package/src/pages/models/PagesModel.ts +38 -0
  106. package/src/pages/models/PagesModelEvent.ts +3 -0
  107. package/src/pages/views/BasePageView.ts +75 -0
  108. package/src/pages/views/PagesView.ts +57 -0
  109. package/src/pool/ObjectsPoolModule.ts +13 -0
  110. package/src/renderer/RendererModule.ts +14 -0
  111. package/src/renderer/events/RendererManagerEvent.ts +3 -0
  112. package/src/renderer/managers/RendererManager.ts +52 -0
  113. package/src/server/ServerModule.ts +14 -0
  114. package/src/server/commands/BaseServerCommand.ts +39 -0
  115. package/src/server/data/IServerRequestVO.ts +12 -0
  116. package/src/server/data/IServerResponseVO.ts +15 -0
  117. package/src/server/data/ServerErrorCode.ts +3 -0
  118. package/src/server/models/ServerModel.ts +34 -0
  119. package/src/sounds/SoundsModule.ts +24 -0
  120. package/src/sounds/SoundsSettings.ts +5 -0
  121. package/src/sounds/managers/BackgroundMusicManager.ts +48 -0
  122. package/src/sounds/managers/SoundsStorageManager.ts +45 -0
  123. package/src/storage/StorageModule.ts +13 -0
  124. package/src/storage/StorageModuleConfig.ts +3 -0
  125. package/src/storage/managers/StorageManager.ts +159 -0
  126. package/src/strategy/managers/BaseStrategyManager.ts +37 -0
  127. package/src/strategy/models/BaseStrategyModel.ts +40 -0
  128. package/src/strategy/strategies/BaseStrategy.ts +21 -0
  129. package/src/time/TimeModule.ts +16 -0
  130. package/src/time/managers/TimeManager.ts +29 -0
  131. package/src/time/models/TimeModel.ts +29 -0
  132. package/src/time/models/TimeModelEvent.ts +3 -0
  133. package/src/windows/data/IWindowConfigVO.ts +9 -0
  134. package/src/windows/managers/IShowWindowVO.ts +4 -0
  135. package/src/windows/managers/WindowsManager.ts +72 -0
  136. package/src/windows/views/BaseWindow.ts +22 -0
  137. package/tsconfig.json +19 -0
@@ -0,0 +1,47 @@
1
+ import {AssociativeArray, IConstructor} from "@flashist/fcore";
2
+
3
+ import {DisplayObjectContainer} from "@flashist/flibs";
4
+
5
+ import {ViewStack} from "./ViewStack";
6
+
7
+ export class ViewLazyCreationStack<StackViewType extends DisplayObjectContainer = DisplayObjectContainer> extends ViewStack<StackViewType> {
8
+
9
+ protected viewClassToIdMap: AssociativeArray<IConstructor<StackViewType>>;
10
+
11
+ construction(...args): void {
12
+ super.construction(...args);
13
+
14
+ this.viewClassToIdMap = new AssociativeArray<IConstructor<StackViewType>>();
15
+ }
16
+
17
+ public addViewClass(ViewClass: IConstructor<StackViewType>, id: string): void {
18
+ this.viewClassToIdMap.push(ViewClass, id);
19
+ }
20
+
21
+ public removeViewClass(ViewClass: IConstructor<StackViewType>): void {
22
+ this.viewClassToIdMap.remove(ViewClass);
23
+ }
24
+
25
+ public getViewById(id: string): StackViewType {
26
+ // Check if the needed view exists, if not, then create it
27
+ if (!super.getViewById(id)) {
28
+ this.addView(
29
+ this.getNewInstance(id),
30
+ id
31
+ );
32
+ }
33
+
34
+ return super.getViewById(id);
35
+ }
36
+
37
+ protected getNewInstance(id: string): StackViewType {
38
+ let result: StackViewType;
39
+
40
+ let TempClass: IConstructor<any> = (this.viewClassToIdMap.getItem(id) as IConstructor<any>);
41
+ if (TempClass) {
42
+ result = new TempClass();
43
+ }
44
+
45
+ return result;
46
+ }
47
+ }
@@ -0,0 +1,93 @@
1
+ import {AssociativeArray, IDatable} from "@flashist/fcore";
2
+
3
+ import {DisplayObjectContainer} from "@flashist/flibs";
4
+
5
+ import {IResizable} from "../resize/IResizable";
6
+ import {ResizableContainer} from "../resize/ResizableContainer";
7
+
8
+ export class ViewStack
9
+ <
10
+ StackViewType extends DisplayObjectContainer = DisplayObjectContainer,
11
+ DataType extends object = object
12
+ >
13
+ extends ResizableContainer<DataType> implements IResizable {
14
+
15
+ protected viewToIdMap: AssociativeArray<StackViewType>;
16
+
17
+ protected _selectedId: string;
18
+ protected _selectedItem: StackViewType;
19
+
20
+ construction(...args): void {
21
+ super.construction(...args);
22
+
23
+ this.viewToIdMap = new AssociativeArray<StackViewType>();
24
+ }
25
+
26
+ public addView(view: StackViewType, id: string): void {
27
+ this.viewToIdMap.push(view, id);
28
+ }
29
+
30
+ public removeView(view: StackViewType): void {
31
+ this.viewToIdMap.remove(view);
32
+ }
33
+
34
+
35
+ public get selectedId(): string {
36
+ return this._selectedId;
37
+ }
38
+
39
+ public set selectedId(value: string) {
40
+ if (value == this.selectedId) {
41
+ return;
42
+ }
43
+
44
+ // Remove the previous view
45
+ if (this.selectedItem) {
46
+ this.selectedItem.parent.removeChild(this._selectedItem);
47
+ this._selectedItem = null;
48
+ }
49
+
50
+ this._selectedId = value;
51
+ this._selectedItem = this.getViewById(this.selectedId);
52
+ if (this.selectedItem) {
53
+ this.addChild(this.selectedItem);
54
+ }
55
+
56
+ this.commitData();
57
+ this.arrange();
58
+ }
59
+
60
+ protected getViewById(id: string): StackViewType {
61
+ return this.viewToIdMap.getItem(id)
62
+ }
63
+
64
+ public get selectedItem(): StackViewType {
65
+ return this._selectedItem;
66
+ }
67
+
68
+ protected commitData(): void {
69
+ super.commitData();
70
+
71
+ if (this.selectedItem) {
72
+ const selectedDatableItem: IDatable = this._selectedItem as any;
73
+ selectedDatableItem.data = this.data;
74
+ }
75
+ }
76
+
77
+ protected arrange(): void {
78
+ super.arrange();
79
+
80
+ if (this._selectedItem) {
81
+ if (this.resizeSize && this.resizeSize.x !== 0 && this.resizeSize.y !== 0) {
82
+ const selectedResizableItem: IResizable = this._selectedItem as any;
83
+ if (selectedResizableItem.resize) {
84
+ selectedResizableItem.resize(this.resizeSize.x, this.resizeSize.y);
85
+
86
+ } else {
87
+ this._selectedItem.width = this.resizeSize.x;
88
+ this._selectedItem.height = this.resizeSize.y;
89
+ }
90
+ }
91
+ }
92
+ }
93
+ }
@@ -0,0 +1,45 @@
1
+ import {AssociativeArray, IConstructor} from "@flashist/fcore";
2
+
3
+ import {DisplayObject, DisplayObjectContainer} from "@flashist/flibs";
4
+
5
+ import {ViewStack} from "./ViewStack";
6
+
7
+ export class ViewStackLazyCreation
8
+ <
9
+ StackViewType extends DisplayObjectContainer = DisplayObjectContainer,
10
+ DataType extends object = object
11
+ >
12
+ extends ViewStack<StackViewType, DataType> {
13
+
14
+ protected viewClassToIdMap: AssociativeArray<IConstructor<DisplayObject>>;
15
+
16
+ construction(...args: any[]): void {
17
+ super.construction(...args);
18
+
19
+ this.viewClassToIdMap = new AssociativeArray<IConstructor<DisplayObject>>();
20
+ }
21
+
22
+ public addViewClass(ViewClass: IConstructor<StackViewType>, id: string): void {
23
+ this.viewClassToIdMap.push(ViewClass, id);
24
+ }
25
+
26
+ public removeViewClass(ViewClass: IConstructor<StackViewType>): void {
27
+ this.viewClassToIdMap.remove(ViewClass);
28
+ }
29
+
30
+ public getViewById(id: string): StackViewType {
31
+ // Check if the needed view exists, if not, then create it
32
+ if (!super.getViewById(id)) {
33
+ let TempClass: IConstructor<any> = (this.viewClassToIdMap.getItem(id) as IConstructor<any>);
34
+ if (TempClass) {
35
+ this.addView(
36
+ new TempClass(),
37
+ id
38
+ );
39
+ }
40
+ }
41
+
42
+ return super.getViewById(id);
43
+ }
44
+
45
+ }
@@ -0,0 +1,22 @@
1
+ import {Command} from "@flashist/fcore";
2
+ import {getInstance} from "@flashist/flibs";
3
+
4
+ import {GlobalEventDispatcher} from "../../globaleventdispatcher/dispatcher/GlobalEventDispatcher";
5
+
6
+ export class DispatchGlobalEventCommand extends Command {
7
+
8
+ protected globalDispatcher: GlobalEventDispatcher;
9
+ protected event: string;
10
+
11
+ constructor(event: string) {
12
+ super();
13
+
14
+ this.event = event;
15
+ this.globalDispatcher = getInstance(GlobalEventDispatcher);
16
+ }
17
+
18
+ protected executeInternal(): void {
19
+ this.globalDispatcher.dispatchEvent(this.event);
20
+ this.notifyComplete();
21
+ }
22
+ }
@@ -0,0 +1,194 @@
1
+ import { BaseObject, Command } from "@flashist/fcore";
2
+
3
+ import { FApp, getInstance, HtmlTools, Point, ServiceLocator } from "@flashist/flibs";
4
+
5
+ import { GlobalEventDispatcherModule } from "../globaleventdispatcher/GlobalEventDispatcherModule";
6
+ import { AppAppModulesManager } from "../base/modules/AppModulesManager";
7
+ import { PagesModule } from "../pages/PagesModule";
8
+ import { RendererModule } from "../renderer/RendererModule";
9
+ import { IFacadeOptions } from "./IFacadeOptions";
10
+ import { AppModule } from "../app/AppModule";
11
+ import { TimeModule } from "../time/TimeModule";
12
+ import { DebugModule } from "../debug/DebugModule";
13
+ import { LoadModule } from "../load/LoadModule";
14
+ import { DependenciesModule } from "../dependencies/DependenciesModule";
15
+ import { AssetsModule } from "../assets/AssetsModule";
16
+ import { ContainersModule } from "../containers/ContainersModule";
17
+ import { ObjectsPoolModule } from "../pool/ObjectsPoolModule";
18
+ import { LocalesModule } from "../locales/LocalesModule";
19
+ import { StorageModule } from "../storage/StorageModule";
20
+ import { SoundsModule } from "../sounds/SoundsModule";
21
+ import { HTMLModule } from "../html/HTMLModule";
22
+ import { InitApplicationCommand } from "../init/commands/InitApplicationCommand";
23
+ import { RendererManager } from "../renderer/managers/RendererManager";
24
+ import { GlobalEventDispatcher } from "../globaleventdispatcher/dispatcher/GlobalEventDispatcher";
25
+ import { RendererManagerEvent } from "../renderer/events/RendererManagerEvent";
26
+ import { ServerModule } from "../server/ServerModule";
27
+ import { AppMainContainer } from "../app/views/AppMainContainer";
28
+ import { BaseAppModule } from "../base/modules/BaseAppModule";
29
+
30
+ export class Facade extends BaseObject {
31
+
32
+ protected options: IFacadeOptions;
33
+ protected modulesManager: AppAppModulesManager;
34
+
35
+ public app: FApp;
36
+ public mainContainer: AppMainContainer;
37
+
38
+ protected resizeListener: any;
39
+
40
+ constructor(options: IFacadeOptions) {
41
+ super(options);
42
+ }
43
+
44
+ protected construction(options: IFacadeOptions): void {
45
+ super.construction(options);
46
+
47
+ this.options = options;
48
+
49
+ Facade._instance = this;
50
+ if (this.options.debug) {
51
+ window["Facade"] = this;
52
+ }
53
+
54
+ ServiceLocator.startInit({ debug: this.options.debug });
55
+
56
+ this.addModules();
57
+ this.activateModules();
58
+
59
+ this.initView();
60
+
61
+ const initCmd: Command = getInstance(InitApplicationCommand);
62
+ initCmd.execute();
63
+ }
64
+
65
+ protected addModules(): void {
66
+ this.modulesManager = new AppAppModulesManager();
67
+
68
+ this.addSingleModule(new DependenciesModule());
69
+ this.addSingleModule(new ObjectsPoolModule());
70
+ this.addSingleModule(new GlobalEventDispatcherModule());
71
+ this.addSingleModule(new RendererModule());
72
+ this.addSingleModule(new StorageModule());
73
+ this.addSingleModule(new LoadModule());
74
+ this.addSingleModule(new SoundsModule());
75
+ this.addSingleModule(new HTMLModule());
76
+ this.addSingleModule(new LocalesModule());
77
+ this.addSingleModule(new AssetsModule());
78
+ this.addSingleModule(new PagesModule());
79
+
80
+ this.addSingleModule(new RendererModule());
81
+
82
+ this.addSingleModule(new AppModule());
83
+ this.addSingleModule(new TimeModule());
84
+ this.addSingleModule(new ContainersModule());
85
+ this.addSingleModule(new ServerModule());
86
+
87
+ if (this.options.debug) {
88
+ this.addSingleModule(new DebugModule());
89
+ }
90
+ }
91
+
92
+ public activateModules(): void {
93
+ // First: configure all injections
94
+ this.modulesManager.initModules();
95
+ // Second: activate the service locator object
96
+ ServiceLocator.activate();
97
+ // Activate modules (after Service Locator activation)
98
+ this.modulesManager.activateModules();
99
+ }
100
+
101
+ public addSingleModule(module: BaseAppModule): void {
102
+ this.modulesManager.addModule(module);
103
+ }
104
+
105
+ protected initView(): void {
106
+ this.mainContainer = getInstance(AppMainContainer);
107
+ FApp.instance.stage.addChild(this.mainContainer);
108
+
109
+ this.onWindowResize();
110
+ this.onRendererResize();
111
+ }
112
+
113
+ protected addListeners(): void {
114
+ super.addListeners();
115
+ /**
116
+ * Note: temporary solution, until pixi.js improvements are released in npm: https://github.com/pixijs/pixi.js/pull/6415
117
+ * (when they are released, the Renderer will emit resize event itself, it means
118
+ * that in combination with resizeTo there won't be a need to "control" resize outside)
119
+ */
120
+ this.resizeListener = () => {
121
+ this.onWindowResize();
122
+
123
+ // In some cases there is a need to add timeout for HTML DOM to be updated
124
+ setTimeout(
125
+ () => {
126
+ this.onWindowResize();
127
+ },
128
+ 100
129
+ );
130
+ };
131
+ window.addEventListener(
132
+ "resize",
133
+ this.resizeListener
134
+ );
135
+
136
+ const globalEventDispatcher: GlobalEventDispatcher = getInstance(GlobalEventDispatcher);
137
+ this.eventListenerHelper.addEventListener(
138
+ globalEventDispatcher,
139
+ RendererManagerEvent.RESIZE,
140
+ this.onRendererResize
141
+ )
142
+ }
143
+
144
+ protected removeListeners(): void {
145
+ super.removeListeners();
146
+
147
+ window.removeEventListener(
148
+ "resize",
149
+ this.resizeListener
150
+ );
151
+ }
152
+
153
+ protected onWindowResize(): void {
154
+ const rendererManager: RendererManager = getInstance(RendererManager);
155
+ const documentSize: Point = HtmlTools.getDocumentSize();
156
+ rendererManager.resize(documentSize.x, documentSize.y);
157
+ }
158
+
159
+ protected onRendererResize(): void {
160
+ this.arrange();
161
+ }
162
+
163
+ protected arrange(): void {
164
+ const rendererManager: RendererManager = getInstance(RendererManager);
165
+ this.mainContainer.resize(
166
+ rendererManager.rendererWidth,
167
+ rendererManager.rendererHeight
168
+ );
169
+ }
170
+
171
+ // - - - - -
172
+
173
+ private static _instance: Facade;
174
+
175
+ static init(options?: IFacadeOptions): void {
176
+ if (!options) {
177
+ options = {};
178
+ }
179
+ let FacadeClass = options.FacadeClass;
180
+ if (!FacadeClass) {
181
+ FacadeClass = Facade;
182
+ }
183
+
184
+ new FacadeClass(options);
185
+ }
186
+
187
+ static get instance(): Facade {
188
+ if (!Facade._instance) {
189
+ console.error("ERROR! Facade should be prepared via the Facade.init method before used via Facade.instance!");
190
+ return;
191
+ }
192
+ return Facade._instance;
193
+ }
194
+ }
@@ -0,0 +1,7 @@
1
+ import {IConstructor} from "@flashist/fcore";
2
+ import {Facade} from "./Facade";
3
+
4
+ export interface IFacadeOptions {
5
+ FacadeClass?: IConstructor<Facade>;
6
+ debug?: boolean;
7
+ }
@@ -0,0 +1,16 @@
1
+ import {serviceLocatorAdd} from "@flashist/flibs";
2
+
3
+ import {GlobalEventDispatcher} from "./dispatcher/GlobalEventDispatcher";
4
+ import {BaseAppModule} from "../base/modules/BaseAppModule";
5
+ import {GlobalEventsCommandManager} from "./managers/GlobalEventsCommandManager";
6
+
7
+ export class GlobalEventDispatcherModule extends BaseAppModule {
8
+
9
+ init(): void {
10
+ super.init();
11
+
12
+ serviceLocatorAdd(GlobalEventDispatcher, {isSingleton: true});
13
+ serviceLocatorAdd(GlobalEventsCommandManager, {isSingleton: true});
14
+ }
15
+
16
+ }
@@ -0,0 +1,25 @@
1
+ import {BaseAppCommand} from "../../base/commands/BaseAppCommand";
2
+
3
+ export class WaitGlobalEventCommand extends BaseAppCommand {
4
+
5
+ constructor(protected event: string, guard?: () => boolean) {
6
+ super();
7
+
8
+ if (guard) {
9
+ this.guard = guard;
10
+ }
11
+ }
12
+
13
+ protected executeInternal(): void {
14
+ this.eventListenerHelper.addEventListener(
15
+ this.globalDispatcher,
16
+ this.event,
17
+ () => {
18
+ if (!this.guard || this.guard()) {
19
+ this.notifyComplete();
20
+ }
21
+ }
22
+ );
23
+ }
24
+
25
+ }3
@@ -0,0 +1,53 @@
1
+ import {BaseObject, IEventListenerCallback} from "@flashist/fcore";
2
+
3
+ import {GlobalEventDispatcherEvent} from "./GlobalEventDispatcherEvent";
4
+
5
+ export class GlobalEventDispatcher extends BaseObject {
6
+
7
+ dispatchEvent(type: string, ...args): void {
8
+ super.dispatchEvent(
9
+ this.getModifiedEventType(type, GlobalEventDispatcherEvent.PRE_DISPATCH_EVENT),
10
+ ...args
11
+ );
12
+
13
+ super.dispatchEvent(type, ...args);
14
+
15
+ //
16
+ super.dispatchEvent(
17
+ this.getModifiedEventType(type, GlobalEventDispatcherEvent.POST_DISPATCH_EVENT),
18
+ ...args
19
+ );
20
+ }
21
+
22
+ public addPreEventListener(type: string, listener: IEventListenerCallback): void {
23
+ this.addEventListener(
24
+ this.getModifiedEventType(type, GlobalEventDispatcherEvent.PRE_DISPATCH_EVENT),
25
+ listener
26
+ );
27
+ }
28
+
29
+ public addPostEventListener(type: string, listener: IEventListenerCallback): void {
30
+ this.addEventListener(
31
+ this.getModifiedEventType(type, GlobalEventDispatcherEvent.POST_DISPATCH_EVENT),
32
+ listener
33
+ );
34
+ }
35
+
36
+ public removePreEventListener(type: string, listener: IEventListenerCallback): void {
37
+ this.removeEventListener(
38
+ this.getModifiedEventType(type, GlobalEventDispatcherEvent.PRE_DISPATCH_EVENT),
39
+ listener
40
+ );
41
+ }
42
+
43
+ public removePostEventListener(type: string, listener: IEventListenerCallback): void {
44
+ this.removeEventListener(
45
+ this.getModifiedEventType(type, GlobalEventDispatcherEvent.POST_DISPATCH_EVENT),
46
+ listener
47
+ );
48
+ }
49
+
50
+ protected getModifiedEventType(type: string, preText: string): string {
51
+ return preText + type;
52
+ }
53
+ }
@@ -0,0 +1,4 @@
1
+ export const GlobalEventDispatcherEvent = {
2
+ PRE_DISPATCH_EVENT: "GlobalEventDispatcherEvent.PRE_DISPATCH_EVENT ",
3
+ POST_DISPATCH_EVENT: "GlobalEventDispatcherEvent.POST_DISPATCH_EVENT "
4
+ };
@@ -0,0 +1,4 @@
1
+ export interface IGlobalDispatchEventVO {
2
+ event: string,
3
+ args: any[]
4
+ }
@@ -0,0 +1,26 @@
1
+ import {Dictionary, Command, IConstructor} from "@flashist/fcore";
2
+ import {getInstance} from "@flashist/flibs";
3
+
4
+ import {BaseAppManager} from "../../base/managers/BaseAppManager";
5
+
6
+ export class GlobalEventsCommandManager extends BaseAppManager {
7
+
8
+ public bindCommand(event: string, CommandClass: IConstructor<Command<any | never>>, guard?: (...args: any) => boolean): void {
9
+ this.eventListenerHelper.addEventListener(
10
+ this.globalDispatcher,
11
+ event,
12
+ (...args) => {
13
+ // If there is no guard function, or if there is a guard function and the checking is passed,
14
+ // then create command and execute it
15
+ if (!guard || guard(...args)) {
16
+ getInstance(CommandClass, ...args)
17
+ .execute();
18
+ }
19
+ }
20
+ );
21
+ }
22
+
23
+ // TODO: implement logic of REMOVING / UNBINDING commands from global events
24
+ // (should be possible to remove one binding without removing other,
25
+ // because one command might be binded to different events and to a single event, but with different guard methods)
26
+ }
@@ -0,0 +1,99 @@
1
+ import {NumberTools, ObjectTools} from "@flashist/fcore";
2
+ import {DisplayObject, FContainer, getInstance} from "@flashist/flibs";
3
+
4
+ import {Back, Sine, TweenLite} from "gsap";
5
+
6
+ import {BaseAppCommand} from "../../base/commands/BaseAppCommand";
7
+ import {ContainersManager} from "../../containers/managers/ContainersManager";
8
+ import {HintContainerId} from "../data/HintContainerId";
9
+ import {IHintConfig} from "../data/IHintConfig";
10
+ import {DefaultHintConfig} from "../data/DefaultHintConfig";
11
+
12
+ export class AnimateHintCommand extends BaseAppCommand {
13
+
14
+ protected config: IHintConfig;
15
+
16
+ constructor(protected hint: DisplayObject, config: Partial<IHintConfig>) {
17
+ super();
18
+
19
+ this.config = {} as any;
20
+
21
+ ObjectTools.copyProps(
22
+ this.config,
23
+ config
24
+ );
25
+
26
+ ObjectTools.copyProps(
27
+ this.config,
28
+ new DefaultHintConfig(),
29
+ {
30
+ ignoreExistedProperties: true
31
+ }
32
+ );
33
+ }
34
+
35
+ protected executeInternal(): void {
36
+
37
+ const containersManager: ContainersManager = getInstance(ContainersManager);
38
+ const effectsCont: FContainer = containersManager.getContainer(HintContainerId);
39
+ effectsCont.addChild(this.hint);
40
+
41
+ const localPos = effectsCont.toLocal(this.config.startGlobalPos);
42
+ this.hint.x = localPos.x;
43
+ this.hint.y = localPos.y;
44
+
45
+ const tempFinalY: number = localPos.y + NumberTools.getRandom(
46
+ this.config.finalGlobalPosMinChange.y,
47
+ this.config.finalGlobalPosMaxChange.y
48
+ );
49
+ TweenLite.to(
50
+ this.hint,
51
+ this.config.positionTweenDuration,
52
+ {
53
+ y: tempFinalY,
54
+ ease: Sine.easeOut
55
+ }
56
+ );
57
+
58
+ const tempFinalX: number = localPos.x + NumberTools.getRandom(
59
+ this.config.finalGlobalPosMinChange.x,
60
+ this.config.finalGlobalPosMaxChange.x
61
+ );
62
+ TweenLite.to(
63
+ this.hint,
64
+ this.config.positionTweenDuration,
65
+ {
66
+ x: tempFinalX,
67
+ ease: Back.easeOut
68
+ }
69
+ );
70
+
71
+ this.hint.alpha = this.config.startAlpha;
72
+ TweenLite.to(
73
+ this.hint,
74
+ this.config.startAlphaTweenDuration,
75
+ {
76
+ delay: this.config.startAlphaTweenDelay,
77
+
78
+ alpha: this.config.mainAlpha
79
+ }
80
+ );
81
+ TweenLite.to(
82
+ this.hint,
83
+ this.config.startAlphaTweenDuration,
84
+ {
85
+ delay: this.config.finalAlphaTweenDelay,
86
+ alpha: this.config.finalAlpha,
87
+ onComplete: () => {
88
+ this.readyToComplete();
89
+ }
90
+ }
91
+ );
92
+ }
93
+
94
+ protected readyToComplete(): void {
95
+ this.hint.parent.removeChild(this.hint);
96
+
97
+ this.notifyComplete();
98
+ }
99
+ }
@@ -0,0 +1,22 @@
1
+ import {IHintConfig} from "./IHintConfig";
2
+ import {Point} from "@flashist/flibs";
3
+ import {HintContainerId} from "./HintContainerId";
4
+
5
+ export class DefaultHintConfig implements Partial<IHintConfig> {
6
+
7
+ containerId: string = HintContainerId;
8
+
9
+ positionTweenDuration: number = 1.5;
10
+ finalGlobalPosMinChange: Point = new Point(0, -100);
11
+ finalGlobalPosMaxChange: Point = new Point(0, -150);
12
+
13
+ startAlphaTweenDuration: number = 0.25;
14
+ startAlphaTweenDelay: number = 0;
15
+ finalAlphaTweenDuration: number = 0.25;
16
+ finalAlphaTweenDelay: number = 1.25;
17
+
18
+ startAlpha: number = 0;
19
+ mainAlpha: number = 1;
20
+ finalAlpha: number = 0;
21
+
22
+ }
@@ -0,0 +1 @@
1
+ export const HintContainerId = "hintContainer";