@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,34 @@
1
+ import {BaseAppGenericObjectsModel} from "../../base/models/BaseAppGenericObjectsModel";
2
+
3
+ export class ServerModel extends BaseAppGenericObjectsModel {
4
+
5
+ private _clientTimeWhenServerTimeChanged: number = 0;
6
+
7
+ private _serverTime: number = 0;
8
+ get serverTime(): number {
9
+ return this._serverTime;
10
+ }
11
+ set serverTime(value: number) {
12
+ if (value === this.serverTime) {
13
+ return;
14
+ }
15
+
16
+ this._serverTime = value;
17
+ this._clientTimeWhenServerTimeChanged = Date.now();
18
+ }
19
+
20
+ get clientTimeWhenServerTimeChanged(): number {
21
+ return this._clientTimeWhenServerTimeChanged;
22
+ }
23
+ set clientTimeWhenServerTimeChanged(value: number) {
24
+ throw new Error("ERROR! The param 'clientTimeWhenServerTimeChanged' can't be changed directly!");
25
+ }
26
+
27
+ get clientTimeDeltaSinceServerTimeChanged(): number {
28
+ return Date.now() - this._clientTimeWhenServerTimeChanged;
29
+ }
30
+
31
+ get clientToServerTimeDelta(): number {
32
+ return this._clientTimeWhenServerTimeChanged - this._serverTime;
33
+ }
34
+ }
@@ -0,0 +1,24 @@
1
+ import {getInstance, serviceLocatorAdd, SoundsManager} from "@flashist/flibs";
2
+
3
+ import {BaseAppModule} from "../base/modules/BaseAppModule";
4
+ import {BackgroundMusicManager} from "./managers/BackgroundMusicManager";
5
+ import {SoundsStorageManager} from "./managers/SoundsStorageManager";
6
+
7
+ export class SoundsModule extends BaseAppModule {
8
+
9
+ init(): void {
10
+ super.init();
11
+
12
+ // Load
13
+ serviceLocatorAdd(SoundsManager, {isSingleton: true});
14
+ serviceLocatorAdd(BackgroundMusicManager, {isSingleton: true});
15
+ serviceLocatorAdd(SoundsStorageManager, {isSingleton: true, forceCreation: true});
16
+ }
17
+
18
+ activateCompleteHook(): void {
19
+ super.activateCompleteHook();
20
+
21
+ const soundsStorageModule: SoundsStorageManager = getInstance(SoundsStorageManager);
22
+ soundsStorageModule.activateCompleteHook();
23
+ }
24
+ }
@@ -0,0 +1,5 @@
1
+ export const SoundsSettings = {
2
+ storage: {
3
+ isMutedParamId: "SoundsSettings.isMutedParamId"
4
+ }
5
+ };
@@ -0,0 +1,48 @@
1
+ import {BaseObject} from "@flashist/fcore";
2
+ import {getInstance, Sound, SoundsManager} from "@flashist/flibs";
3
+
4
+ export class BackgroundMusicManager extends BaseObject {
5
+
6
+ protected soundsManager: SoundsManager = getInstance(SoundsManager);
7
+
8
+ protected currentMusic: Sound;
9
+ protected currentMusicId: string;
10
+
11
+ public fadeInTime: number = 0.5;
12
+ public fadeOutTime: number = 0.5;
13
+
14
+ public changeMusic(id: string): void {
15
+ if (this.currentMusicId === id) {
16
+ return;
17
+ }
18
+
19
+ this.stopMusic();
20
+
21
+ this.currentMusicId = id;
22
+ this.currentMusic = this.soundsManager.getSound(id);
23
+ if (this.currentMusic) {
24
+ // this.currentMusic.setVolume(0);
25
+ this.currentMusic.play({loop: true});
26
+ this.currentMusic.tweenVolume(1, this.fadeInTime);
27
+ }
28
+ }
29
+
30
+ public stopMusic(): void {
31
+ if (!this.currentMusic) {
32
+ return;
33
+ }
34
+
35
+ // Make link-copy of the currently played music, as it might be changed after volume tween
36
+ const currentMusicCopy: Sound = this.currentMusic;
37
+ this.currentMusic = null;
38
+ this.currentMusicId = null;
39
+
40
+ currentMusicCopy.tweenVolume(
41
+ 0,
42
+ this.fadeOutTime,
43
+ () => {
44
+ currentMusicCopy.stop();
45
+ }
46
+ );
47
+ }
48
+ }
@@ -0,0 +1,45 @@
1
+ import {BaseObject} from "@flashist/fcore";
2
+ import {getInstance, SoundsManager, SoundsManagerEvent} from "@flashist/flibs";
3
+
4
+ import {StorageManager} from "../../storage/managers/StorageManager";
5
+ import {SoundsSettings} from "../SoundsSettings";
6
+
7
+ export class SoundsStorageManager extends BaseObject {
8
+
9
+ protected soundsManager: SoundsManager;
10
+ protected storageManager: StorageManager;
11
+
12
+ protected construction(...args): void {
13
+ this.soundsManager = getInstance(SoundsManager);
14
+ this.storageManager = getInstance(StorageManager);
15
+
16
+ super.construction(...args);
17
+ }
18
+
19
+ protected addListeners(): void {
20
+ super.addListeners();
21
+
22
+ this.eventListenerHelper.addEventListener(
23
+ this.soundsManager,
24
+ SoundsManagerEvent.IS_MUTED_CHANGE,
25
+ this.onSoundsDataChange
26
+ );
27
+ }
28
+
29
+ protected onSoundsDataChange(): void {
30
+ this.commitSoundsData();
31
+ }
32
+
33
+ public activateCompleteHook(): void {
34
+ const isMuted: boolean = this.storageManager.getParam<boolean>(SoundsSettings.storage.isMutedParamId);
35
+ if (isMuted === true || isMuted === false) {
36
+ this.soundsManager.isMuted = isMuted;
37
+ }
38
+
39
+ this.commitSoundsData();
40
+ }
41
+
42
+ protected commitSoundsData(): void {
43
+ this.storageManager.setParam(SoundsSettings.storage.isMutedParamId, this.soundsManager.isMuted);
44
+ }
45
+ }
@@ -0,0 +1,13 @@
1
+ import {serviceLocatorAdd} from "@flashist/flibs";
2
+ import {BaseAppModule} from "../base/modules/BaseAppModule";
3
+ import {StorageManager} from "./managers/StorageManager";
4
+
5
+ export class StorageModule extends BaseAppModule {
6
+
7
+ init(): void {
8
+ super.init();
9
+
10
+ serviceLocatorAdd(StorageManager, {isSingleton: true, forceCreation: true});
11
+ }
12
+
13
+ }
@@ -0,0 +1,3 @@
1
+ export const StorageModuleConfig = {
2
+ storageId: "defaultStorageId"
3
+ };
@@ -0,0 +1,159 @@
1
+ import {BaseObject} from "@flashist/fcore";
2
+ import {StorageModuleConfig} from "../StorageModuleConfig";
3
+
4
+ export class StorageManager extends BaseObject {
5
+
6
+ protected storageId: string;
7
+ protected storageData: any;
8
+
9
+ protected construction(): void {
10
+ super.construction();
11
+
12
+ this.storageId = StorageModuleConfig.storageId;
13
+
14
+ this.prepareStorage();
15
+ this.createStorage();
16
+ }
17
+
18
+ protected getWindowStorageObject(): any {
19
+ let rawData: string = localStorage.getItem(this.storageId);
20
+ if (!rawData) {
21
+ rawData = "{}";
22
+ }
23
+
24
+ return JSON.parse(rawData);
25
+ }
26
+
27
+ public setParam<DataType>(id: keyof DataType, value: DataType[keyof DataType]): void;
28
+ public setParam<ParamType>(id: string, value: ParamType): void;
29
+ public setParam(id: string, value: any): void {
30
+ if (this.storageData[id] === value) {
31
+ return;
32
+ }
33
+
34
+ this.storageData[id] = value;
35
+ this.writeSaves();
36
+ }
37
+
38
+ public getParam<DataType, ParamType>(id: keyof DataType): ParamType;
39
+ public getParam<DataType>(id: keyof DataType): DataType[keyof DataType];
40
+ public getParam<ParamType>(id: string): ParamType;
41
+ public getParam(id: string): any {
42
+ return this.storageData[id];
43
+ }
44
+
45
+ protected writeSaves(): void {
46
+ let rawData: string = JSON.stringify(this.storageData);
47
+ localStorage.setItem(this.storageId, rawData);
48
+ }
49
+
50
+ protected createStorage(): void {
51
+ this.storageData = this.getWindowStorageObject();
52
+
53
+ if (this.storageData.isCreated) {
54
+ this.initializeStorageData();
55
+ }
56
+ }
57
+
58
+ protected initializeStorageData(): void {
59
+ this.storageData.isCreated = true;
60
+
61
+ this.writeSaves();
62
+ }
63
+
64
+ public clearSaves(): void {
65
+ this.initializeStorageData();
66
+ }
67
+
68
+ protected prepareStorage(): void {
69
+ if (!window.localStorage) {
70
+ Object.defineProperty(window, "localStorage", new (function () {
71
+ var aKeys = [], oStorage = {};
72
+ Object.defineProperty(oStorage, "getItem", {
73
+ value: function (sKey) {
74
+ return this[sKey] ? this[sKey] : null;
75
+ },
76
+ writable: false,
77
+ configurable: false,
78
+ enumerable: false
79
+ });
80
+ Object.defineProperty(oStorage, "key", {
81
+ value: function (nKeyId) {
82
+ return aKeys[nKeyId];
83
+ },
84
+ writable: false,
85
+ configurable: false,
86
+ enumerable: false
87
+ });
88
+ Object.defineProperty(oStorage, "setItem", {
89
+ value: function (sKey, sValue) {
90
+ if (!sKey) {
91
+ return;
92
+ }
93
+ document.cookie = escape(sKey) + "=" + escape(sValue) + "; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/";
94
+ },
95
+ writable: false,
96
+ configurable: false,
97
+ enumerable: false
98
+ });
99
+ Object.defineProperty(oStorage, "length", {
100
+ get: function () {
101
+ return aKeys.length;
102
+ },
103
+ configurable: false,
104
+ enumerable: false
105
+ });
106
+ Object.defineProperty(oStorage, "removeItem", {
107
+ value: function (sKey) {
108
+ if (!sKey) {
109
+ return;
110
+ }
111
+ document.cookie = escape(sKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/";
112
+ },
113
+ writable: false,
114
+ configurable: false,
115
+ enumerable: false
116
+ });
117
+ Object.defineProperty(oStorage, "clear", {
118
+ value: function () {
119
+ if (!aKeys.length) {
120
+ return;
121
+ }
122
+ for (var sKey in oStorage) {
123
+ document.cookie = escape(sKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/";
124
+ }
125
+ },
126
+ writable: false,
127
+ configurable: false,
128
+ enumerable: false
129
+ });
130
+ this.get = function () {
131
+ var iThisIndx;
132
+ for (var sKey in oStorage) {
133
+ iThisIndx = aKeys.indexOf(sKey);
134
+ if (iThisIndx === -1) {
135
+ (oStorage as any).setItem(sKey, oStorage[sKey]);
136
+ }
137
+ else {
138
+ aKeys.splice(iThisIndx, 1);
139
+ }
140
+ delete oStorage[sKey];
141
+ }
142
+ for (aKeys; aKeys.length > 0; aKeys.splice(0, 1)) {
143
+ (oStorage as any).removeItem(aKeys[0]);
144
+ }
145
+ for (var aCouple, iKey, nIdx = 0, aCouples = document.cookie.split(/\s*;\s*/); nIdx < aCouples.length; nIdx++) {
146
+ aCouple = aCouples[nIdx].split(/\s*=\s*/);
147
+ if (aCouple.length > 1) {
148
+ oStorage[iKey = unescape(aCouple[0])] = unescape(aCouple[1]);
149
+ aKeys.push(iKey);
150
+ }
151
+ }
152
+ return oStorage;
153
+ };
154
+ this.configurable = false;
155
+ this.enumerable = true;
156
+ })());
157
+ }
158
+ }
159
+ }
@@ -0,0 +1,37 @@
1
+ import {BaseAppManager} from "../../base/managers/BaseAppManager";
2
+ import {BaseStrategyModel} from "../models/BaseStrategyModel";
3
+ import {BaseStrategy} from "../strategies/BaseStrategy";
4
+
5
+ export abstract class BaseStrategyManager<
6
+ StrategyType extends BaseStrategy = BaseStrategy,
7
+ StrategyModelType extends BaseStrategyModel<StrategyType> = BaseStrategyModel<StrategyType>
8
+ > extends BaseAppManager {
9
+
10
+ protected strategyModel: StrategyModelType;
11
+ protected lastActiveStrategy: StrategyType;
12
+
13
+ /**
14
+ * It's supposed, that there is an external common-purpose model,
15
+ * which provides some data (e.g. the ID of an active item),
16
+ * and based on this data the manager should make the decision,
17
+ * about which specific id for a strategy should be used.
18
+ */
19
+ protected abstract findIdForCurrentStrategy(): string;
20
+
21
+ protected commitStrategyData(): void {
22
+ const newToolStrategy: StrategyType = this.strategyModel.getStrategyById(this.findIdForCurrentStrategy());
23
+ if (this.lastActiveStrategy === newToolStrategy) {
24
+ return;
25
+ }
26
+
27
+ if (this.lastActiveStrategy) {
28
+ this.lastActiveStrategy.deactivate();
29
+ }
30
+
31
+ this.lastActiveStrategy = newToolStrategy;
32
+ if (this.lastActiveStrategy) {
33
+ this.lastActiveStrategy.activate();
34
+ }
35
+ }
36
+
37
+ }
@@ -0,0 +1,40 @@
1
+ import {AssociativeArray} from "@flashist/fcore";
2
+
3
+ import {BaseAppModel} from "../../base/models/BaseAppModel";
4
+ import {BaseStrategy} from "../strategies/BaseStrategy";
5
+
6
+ export class BaseStrategyModel<StrategyType extends BaseStrategy = BaseStrategy> extends BaseAppModel {
7
+
8
+ protected strategyToIdMap: AssociativeArray<StrategyType> = new AssociativeArray<StrategyType>();
9
+
10
+ private _strategyId: string = "";
11
+
12
+ public addStrategy(strategy: StrategyType, id: string): void {
13
+ this.strategyToIdMap.push(strategy, id);
14
+ }
15
+
16
+ public removeStrategy(id: string): void {
17
+ this.strategyToIdMap.removeByKey(id);
18
+ }
19
+
20
+ public getStrategyById(id: string): StrategyType {
21
+ if (!this.strategyToIdMap.containsKey(id)) {
22
+ console.log("BaseStrategyModel | getStrategyForId __ WARNING! Can't find strategy for id: ", id);
23
+ }
24
+
25
+ return this.strategyToIdMap.getItem(id);
26
+ }
27
+
28
+
29
+ get strategyId(): string {
30
+ return this._strategyId;
31
+ }
32
+
33
+ set strategyId(value: string) {
34
+ if (value === this._strategyId) {
35
+ return;
36
+ }
37
+
38
+ this._strategyId = value;
39
+ }
40
+ }
@@ -0,0 +1,21 @@
1
+ import {ArrayTools, Logger} from "@flashist/fcore";
2
+ import {BaseObjectWithGlobalDispatcher} from "../../base/BaseObjectWithGlobalDispatcher";
3
+
4
+ export abstract class BaseStrategy extends BaseObjectWithGlobalDispatcher {
5
+
6
+ protected static cache: BaseStrategy[] = [];
7
+
8
+ activate(): void {
9
+ Logger.log("BaseStrategy | activate __ this: ", this);
10
+
11
+ if (BaseStrategy.cache.indexOf(this) == -1) {
12
+ BaseStrategy.cache.push(this);
13
+ }
14
+ };
15
+
16
+ deactivate(): void {
17
+ this.eventListenerHelper.removeAllListeners();
18
+
19
+ ArrayTools.removeItem(BaseStrategy.cache, this);
20
+ }
21
+ }
@@ -0,0 +1,16 @@
1
+ import {serviceLocatorAdd} from "@flashist/flibs";
2
+
3
+ import {BaseAppModule} from "../base/modules/BaseAppModule";
4
+ import {TimeManager} from "./managers/TimeManager";
5
+ import {TimeModel} from "./models/TimeModel";
6
+
7
+ export class TimeModule extends BaseAppModule {
8
+
9
+ init(): void {
10
+ super.init();
11
+
12
+ serviceLocatorAdd(TimeModel, {isSingleton: true, forceCreation: true});
13
+ serviceLocatorAdd(TimeManager, {isSingleton: true, forceCreation: true});
14
+ }
15
+
16
+ }
@@ -0,0 +1,29 @@
1
+ import {Ticker} from "pixi.js";
2
+
3
+ import {getInstance} from "@flashist/flibs";
4
+
5
+ import {BaseAppManager} from "../../base/managers/BaseAppManager";
6
+ import {TimeModel} from "../models/TimeModel";
7
+
8
+
9
+ export class TimeManager extends BaseAppManager {
10
+
11
+ protected timeModel: TimeModel = getInstance(TimeModel);
12
+
13
+ protected addListeners(): void {
14
+ super.addListeners();
15
+
16
+ //this is the same PIXI's ticker as it uses for its purposes (like MovieClips atc)
17
+ Ticker.shared.add(this.onTick, this);
18
+ }
19
+
20
+ protected removeListeners(): void {
21
+ super.removeListeners();
22
+
23
+ Ticker.shared.remove(this.onTick, this);
24
+ }
25
+
26
+ protected onTick(deltaTime: number): void {
27
+ this.timeModel.changeTimeData(Date.now(), deltaTime);
28
+ }
29
+ }
@@ -0,0 +1,29 @@
1
+ import {BaseAppGenericObjectsModel} from "../../base/models/BaseAppGenericObjectsModel";
2
+ import {TimeModelEvent} from "./TimeModelEvent";
3
+
4
+ export class TimeModel extends BaseAppGenericObjectsModel {
5
+
6
+ public startTime: number = 0;
7
+ public prevTime: number = 0;
8
+ public currentTime: number = 0;
9
+ public lastRenderDeltaTime: number = 0;
10
+
11
+ protected construction(...args): void {
12
+ super.construction(args);
13
+
14
+ this.startTime = Date.now();
15
+ }
16
+
17
+ public changeTimeData(currentTime: number, lastRenderDeltaTime: number): void {
18
+ this.prevTime = this.currentTime;
19
+ this.currentTime = currentTime;
20
+
21
+ this.lastRenderDeltaTime = lastRenderDeltaTime;
22
+
23
+ this.dispatchEvent(TimeModelEvent.TIME_DATA_CHANGE);
24
+ }
25
+
26
+ public get timeDelta(): number {
27
+ return this.currentTime - this.prevTime;
28
+ }
29
+ }
@@ -0,0 +1,3 @@
1
+ export const TimeModelEvent = {
2
+ TIME_DATA_CHANGE: "TimeModelEvent.TIME_DATA_CHANGE"
3
+ };
@@ -0,0 +1,9 @@
1
+ import {IConstructor} from "@flashist/fcore";
2
+
3
+ import {BaseWindow} from "../views/BaseWindow";
4
+
5
+ export interface IWindowConfigVO {
6
+ type: string;
7
+ RenderClass: IConstructor<BaseWindow>;
8
+ bgConfig: {color: number, alpha: number};
9
+ }
@@ -0,0 +1,4 @@
1
+ export interface IShowWindowVO {
2
+ type: string;
3
+ data?: any;
4
+ }
@@ -0,0 +1,72 @@
1
+ import {FContainer} from "@flashist/flibs";
2
+
3
+ import {BaseAppManager} from "../../base/managers/BaseAppManager";
4
+ import {IWindowConfigVO} from "../data/IWindowConfigVO";
5
+ import {IShowWindowVO} from "./IShowWindowVO";
6
+ import {BaseWindow} from "../views/BaseWindow";
7
+
8
+ export class WindowsManager extends BaseAppManager {
9
+ protected windowsContainer: FContainer;
10
+
11
+ protected windowConfigToTypeMap: { [type: string]: IWindowConfigVO } = {};
12
+
13
+ protected windowsToShowQueue: IShowWindowVO[] = [];
14
+
15
+ protected shownWindows: BaseWindow[] = [];
16
+
17
+ public setup(windowsContainer: FContainer): void {
18
+ this.windowsContainer = windowsContainer;
19
+ }
20
+
21
+ public addWindowConfig(config: IWindowConfigVO): void {
22
+ this.windowConfigToTypeMap[config.type] = config;
23
+ }
24
+
25
+ public showWindow(type: string, data?: any): void {
26
+ this.windowsToShowQueue.push(
27
+ {
28
+ type: type,
29
+ data: data
30
+ }
31
+ );
32
+
33
+ // TODO: at the current moment there is no logic about using queues
34
+ // or to configure how whondows might behave with each other
35
+ // (e.g. the new window might require to hide all others)
36
+
37
+ this.showNextWindow();
38
+ }
39
+
40
+ protected showNextWindow(): void {
41
+ if (this.windowsToShowQueue.length <= 0) {
42
+ return;
43
+ }
44
+
45
+ let tempShowData: IShowWindowVO = this.windowsToShowQueue.shift();
46
+ let tempConfig: IWindowConfigVO = this.windowConfigToTypeMap[tempShowData.type];
47
+ if (!tempConfig) {
48
+ return;
49
+ }
50
+
51
+ // TODO: change logic, if more complex relationships between windows required
52
+ // (e.g. some windows might allow to some other windows to be shown)
53
+ this.hideAllWindows();
54
+
55
+ let tempWindow: BaseWindow = this.createWindow(tempConfig, tempShowData.data);
56
+ this.windowsContainer.addChild(tempWindow);
57
+ }
58
+
59
+ protected createWindow(config: IWindowConfigVO, data?: any): BaseWindow {
60
+ let result = new config.RenderClass();
61
+ result.config = config;
62
+ result.data = data;
63
+
64
+ return result;
65
+ }
66
+
67
+ public hideAllWindows(): void {
68
+ for (let tempWindow of this.shownWindows) {
69
+ tempWindow.visible = false;
70
+ }
71
+ }
72
+ }
@@ -0,0 +1,22 @@
1
+ import {FContainer} from "@flashist/flibs";
2
+ import {IWindowConfigVO} from "../data/IWindowConfigVO";
3
+
4
+ export class BaseWindow extends FContainer {
5
+
6
+ private _config: IWindowConfigVO;
7
+
8
+ get config(): IWindowConfigVO {
9
+ return this._config;
10
+ }
11
+ set config(value: IWindowConfigVO) {
12
+ if (value === this.config) {
13
+ return;
14
+ }
15
+
16
+ this._config = value;
17
+
18
+ this.commitData();
19
+ }
20
+
21
+
22
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es5",
4
+ "module": "es2015",
5
+ "moduleResolution": "node",
6
+ "allowSyntheticDefaultImports": true,
7
+ "lib": [
8
+ "es2015",
9
+ "dom"
10
+ ],
11
+ "sourceMap": true,
12
+ "declaration": true,
13
+ "outDir": "dist/",
14
+ "declarationDir": "dist/"
15
+ },
16
+ "include": [
17
+ "src/**/*"
18
+ ]
19
+ }