@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,23 @@
1
+ import {GenericObjectsModel, getInstance, IGenericObjectVO} from "@flashist/flibs";
2
+
3
+ import {GlobalEventDispatcher} from "../../globaleventdispatcher/dispatcher/GlobalEventDispatcher";
4
+
5
+ // export class BaseAppGenericObjectsModel extends BaseObject {
6
+ export class BaseAppGenericObjectsModel<ItemType extends IGenericObjectVO = IGenericObjectVO> extends GenericObjectsModel<ItemType> {
7
+
8
+ protected globalDispatcher: GlobalEventDispatcher;
9
+
10
+ protected construction(...args): void {
11
+ this.globalDispatcher = getInstance(GlobalEventDispatcher);
12
+
13
+ super.construction(...args);
14
+ }
15
+
16
+ dispatchEvent(event: string, ...args: any[]): void {
17
+ super.dispatchEvent(event, ...args);
18
+
19
+ // Redispatch event to the global level
20
+ this.globalDispatcher.dispatchEvent(event, ...args);
21
+ }
22
+
23
+ }
@@ -0,0 +1,5 @@
1
+ import {BaseObjectWithGlobalDispatcher} from "../BaseObjectWithGlobalDispatcher";
2
+
3
+ export class BaseAppModel extends BaseObjectWithGlobalDispatcher {
4
+
5
+ }
@@ -0,0 +1,44 @@
1
+ import {ArrayTools} from "@flashist/fcore";
2
+ import {BaseAppModule} from "./BaseAppModule";
3
+
4
+ export class AppAppModulesManager {
5
+ protected modules: BaseAppModule[] = [];
6
+
7
+ destroy(): void {
8
+ this.modules = [];
9
+ }
10
+
11
+
12
+ // Modules
13
+
14
+ addModule(module: BaseAppModule): void {
15
+ this.modules.push(module);
16
+ }
17
+
18
+ removeModule(module: BaseAppModule): void {
19
+ ArrayTools.removeItem(this.modules, module);
20
+ }
21
+
22
+ initModules(): void {
23
+ let modulesCount: number = this.modules.length;
24
+ // Init all modules
25
+ for (let moduleIndex: number = 0; moduleIndex < modulesCount; moduleIndex++) {
26
+ this.modules[moduleIndex].init();
27
+ }
28
+
29
+ // Go through all modules and call the hook after completion,
30
+ // to add a way to do something, when everything is prepared
31
+ for (let moduleIndex: number = 0; moduleIndex < modulesCount; moduleIndex++) {
32
+ this.modules[moduleIndex].initCompleteHook();
33
+ }
34
+ }
35
+
36
+ activateModules(): void {
37
+ let modulesCount: number = this.modules.length;
38
+ // Go through all modules and call the hook after completion,
39
+ // to add a way to do something, when everything is prepared
40
+ for (let moduleIndex: number = 0; moduleIndex < modulesCount; moduleIndex++) {
41
+ this.modules[moduleIndex].activateCompleteHook();
42
+ }
43
+ }
44
+ }
@@ -0,0 +1,17 @@
1
+ import {BaseObject} from "@flashist/fcore";
2
+
3
+ export abstract class BaseAppModule extends BaseObject {
4
+
5
+ init(): void {
6
+ // Should be overridden in subclasses, if needed
7
+ }
8
+
9
+ initCompleteHook(): void {
10
+ // Should be overridden in subclasses, if needed
11
+ }
12
+
13
+ activateCompleteHook(): void {
14
+ // Should be overridden in subclasses, if needed
15
+ }
16
+
17
+ }
@@ -0,0 +1,25 @@
1
+ import { IEventListenerCallback } from "@flashist/fcore";
2
+ import { getInstance } from "@flashist/flibs";
3
+
4
+ import { ResizableContainer } from "../../display/views/resize/ResizableContainer";
5
+ import { GlobalEventDispatcher } from "../../globaleventdispatcher/dispatcher/GlobalEventDispatcher";
6
+
7
+ export class BaseAppView<DataType extends object = object> extends ResizableContainer<DataType> {
8
+
9
+ protected globalDispatcher: GlobalEventDispatcher;
10
+
11
+ protected construction(...args): void {
12
+ super.construction(...args);
13
+
14
+ this.globalDispatcher = getInstance(GlobalEventDispatcher);
15
+ }
16
+
17
+ protected addGlobalEventListener(event: string, fn: IEventListenerCallback): void {
18
+ this.eventListenerHelper.addEventListener(
19
+ this.globalDispatcher,
20
+ event,
21
+ fn
22
+ );
23
+ }
24
+
25
+ }
@@ -0,0 +1,13 @@
1
+ import {serviceLocatorAdd} from "@flashist/flibs";
2
+
3
+ import {BaseAppModule} from "../base/modules/BaseAppModule";
4
+ import {ContainersManager} from "./managers/ContainersManager";
5
+
6
+ export class ContainersModule extends BaseAppModule {
7
+
8
+ init(): void {
9
+ super.init();
10
+
11
+ serviceLocatorAdd(ContainersManager, {isSingleton: true});
12
+ }
13
+ }
@@ -0,0 +1,27 @@
1
+ import {FContainer} from "@flashist/flibs";
2
+
3
+ import {BaseAppManager} from "../../base/managers/BaseAppManager";
4
+
5
+ export class ContainersManager extends BaseAppManager {
6
+
7
+ private containersMap: { [key: string]: FContainer } = {};
8
+
9
+ public addContainer(container: FContainer, id: string): void {
10
+ this.containersMap[id] = container;
11
+ }
12
+
13
+ public removeContainer(id: string): void {
14
+ delete this.containersMap[id];
15
+ }
16
+
17
+ public getContainer(id: string): FContainer {
18
+ let result: FContainer;
19
+
20
+ if (this.containersMap[id]) {
21
+ result = this.containersMap[id];
22
+ }
23
+
24
+ return result;
25
+ }
26
+
27
+ }
@@ -0,0 +1,5 @@
1
+ import { IGenericObjectVO } from "@flashist/flibs";
2
+
3
+ export interface IAppGenericObjectVO extends IGenericObjectVO {
4
+ localeId?: string;
5
+ }
@@ -0,0 +1,6 @@
1
+ export const DateSettings = {
2
+ MS_IN_SECOND: 1000,
3
+ MS_IN_MINUTE: 1000 * 60,
4
+ MS_IN_HOUR: 1000 * 60 * 60,
5
+ MS_IN_DAY: 1000 * 60 * 60 * 24
6
+ };
@@ -0,0 +1,22 @@
1
+ import {ConsoleCustomLoggerItem, Logger} from "@flashist/fcore";
2
+ import {FApp} from "@flashist/flibs";
3
+ import {FC} from "@flashist/fconsole";
4
+
5
+ import {BaseAppModule} from "../base/modules/BaseAppModule";
6
+
7
+ export class DebugModule extends BaseAppModule {
8
+ activateCompleteHook(): void {
9
+ super.activateCompleteHook();
10
+
11
+ FC.startInit(
12
+ FApp.instance.stage,
13
+ {
14
+ console: {
15
+ defaultVisible: true
16
+ }
17
+ }
18
+ );
19
+
20
+ Logger.addLoggerItem(new ConsoleCustomLoggerItem());
21
+ }
22
+ }
@@ -0,0 +1,13 @@
1
+ import {GenericObjectsByTypeModel, serviceLocatorAdd} from "@flashist/flibs";
2
+
3
+ import {BaseAppModule} from "../base/modules/BaseAppModule";
4
+
5
+ export class DependenciesModule extends BaseAppModule {
6
+
7
+ init(): void {
8
+ super.init();
9
+
10
+ // Modules
11
+ serviceLocatorAdd(GenericObjectsByTypeModel, {isSingleton: true});
12
+ }
13
+ }
@@ -0,0 +1,5 @@
1
+ import {Point} from "@flashist/flibs";
2
+
3
+ export interface IGetSizable {
4
+ getSize():Point;
5
+ }
@@ -0,0 +1,25 @@
1
+ import {DisplayObjectContainer, Point} from "@flashist/flibs";
2
+ import {IGetSizable} from "../data/IGetSizable";
3
+
4
+ export class GetSizeTools {
5
+
6
+ static getObjectSize(sourceObject: DisplayObjectContainer): Point {
7
+ let result: Point = new Point();
8
+
9
+ let getSizeObject: IGetSizable = (sourceObject as any as IGetSizable);
10
+ if (getSizeObject.getSize) {
11
+ result = getSizeObject.getSize();
12
+
13
+ } else {
14
+ if (sourceObject.width) {
15
+ result.x = sourceObject.width;
16
+ }
17
+ if (sourceObject.height) {
18
+ result.y = sourceObject.height;
19
+ }
20
+ }
21
+
22
+ return result;
23
+ }
24
+
25
+ }
@@ -0,0 +1,20 @@
1
+ import {FContainer} from "@flashist/flibs";
2
+ import {EventListenerHelper} from "@flashist/fcore";
3
+
4
+ export class AppContainer<DataType extends any = any> extends FContainer<DataType> {
5
+
6
+ protected dataEventListenerHelper: EventListenerHelper;
7
+
8
+ protected construction(...args): void {
9
+ super.construction(...args);
10
+
11
+ this.dataEventListenerHelper = new EventListenerHelper(this);
12
+ }
13
+
14
+ protected processDataUnset(value: DataType): void {
15
+ super.processDataUnset(value);
16
+
17
+ this.dataEventListenerHelper.removeAllListeners();
18
+ }
19
+
20
+ }
@@ -0,0 +1,325 @@
1
+ import { BaseObject, EventListenerHelper, IDefaultEventDispatcher } from "@flashist/fcore";
2
+
3
+ import { DisplayObject, InteractiveEvent } from "@flashist/flibs";
4
+
5
+ import { BaseBtnState } from "./BaseBtnState";
6
+ import { BaseBtnEvent } from "./BaseBtnEvent";
7
+
8
+ export class BaseBtn extends BaseObject {
9
+
10
+ protected interactiveEventHelper: EventListenerHelper;
11
+
12
+ // ToDo: the previous code worked with MovieClip implementation,
13
+ // so this method might be moved to the MovieClip/Timeline-Button instead of the SimpleButton class
14
+ /*protected static SELECTED_FRAMES_FIRST_PART:string = "selected_";
15
+ protected static DISABLED_FRAME_NAME:string = "disabled";
16
+ protected static HIT_AREA_CLIP_NAME:string = "customHitArea";
17
+ protected static LABEL_FIELD_NAME:string = "labelField";*/
18
+
19
+ protected _hitArea: DisplayObject;
20
+
21
+ // protected label:BaseLabel;
22
+
23
+ private _state: string;
24
+ private _selected: boolean;
25
+
26
+ public autoToggleSelected: boolean;
27
+
28
+ private _enabled: boolean;
29
+
30
+
31
+ protected construction(): void {
32
+ super.construction();
33
+
34
+ this.interactiveEventHelper = new EventListenerHelper(this);
35
+ // this.label = new BaseLabel();
36
+
37
+ this.state = BaseBtnState.NORMAL;
38
+ this.enabled = true;
39
+ }
40
+
41
+ public destruction(): void {
42
+ super.destruction();
43
+
44
+ if (this.interactiveEventHelper) {
45
+ this.interactiveEventHelper.destruction();
46
+ this.interactiveEventHelper = null;
47
+ }
48
+ }
49
+
50
+ protected removeListeners(): void {
51
+ super.removeListeners();
52
+
53
+ this.removeMouseListeners();
54
+ }
55
+
56
+ protected addMouseListeners(dispatcher: IDefaultEventDispatcher<any>): void {
57
+ if (!dispatcher) {
58
+ return;
59
+ }
60
+
61
+ this.removeMouseListeners();
62
+
63
+ this.interactiveEventHelper.addEventListener(
64
+ dispatcher,
65
+ InteractiveEvent.OVER,
66
+ this.onOver
67
+ );
68
+
69
+ this.interactiveEventHelper.addEventListener(
70
+ dispatcher,
71
+ InteractiveEvent.OUT,
72
+ this.onOut
73
+ );
74
+
75
+ this.interactiveEventHelper.addEventListener(
76
+ dispatcher,
77
+ InteractiveEvent.DOWN,
78
+ this.onMouseDown
79
+ );
80
+
81
+ this.interactiveEventHelper.addEventListener(
82
+ dispatcher,
83
+ InteractiveEvent.TAP,
84
+ this.onTap
85
+ );
86
+ }
87
+
88
+ protected removeMouseListeners(): void {
89
+ if (!this.isConstructed) {
90
+ return;
91
+ }
92
+
93
+ this.interactiveEventHelper.removeAllListeners();
94
+ }
95
+
96
+
97
+ protected onOver(): void {
98
+ if (!this._enabled) {
99
+ return;
100
+ }
101
+
102
+ this.state = this.findStateValue(BaseBtnState.OVER);
103
+
104
+ this.redispatchEvent(InteractiveEvent.OVER);
105
+ }
106
+
107
+ protected onOut(): void {
108
+ if (!this._enabled) {
109
+ return;
110
+ }
111
+
112
+ this.state = this.findStateValue(BaseBtnState.NORMAL);
113
+
114
+ this.redispatchEvent(InteractiveEvent.OUT);
115
+ }
116
+
117
+ protected onMouseDown(): void {
118
+ if (!this._enabled) {
119
+ return;
120
+ }
121
+
122
+ this.state = this.findStateValue(BaseBtnState.PRESS);
123
+
124
+ this.redispatchEvent(InteractiveEvent.DOWN);
125
+ }
126
+
127
+ protected onTap(): void {
128
+ if (!this._enabled) {
129
+ return;
130
+ }
131
+
132
+ if (this.autoToggleSelected) {
133
+ this.selected = !this.selected;
134
+ }
135
+
136
+ this.state = this.findStateValue(BaseBtnState.OVER);
137
+
138
+ this.redispatchEvent(InteractiveEvent.TAP);
139
+ }
140
+
141
+
142
+ protected redispatchEvent(sourceEvent: string): void {
143
+ this.dispatchEvent(sourceEvent);
144
+ }
145
+
146
+ protected commitStateData(): void {
147
+ if (!this.isConstructed) {
148
+ return;
149
+ }
150
+
151
+ this.commitEnabledData();
152
+ }
153
+
154
+ protected commitEnabledData(): void {
155
+ if (this.hitArea) {
156
+ if (this.enabled) {
157
+ this.hitArea.interactive = true;
158
+ this.hitArea.buttonMode = true;
159
+
160
+ } else {
161
+ this.hitArea.interactive = false;
162
+ this.hitArea.buttonMode = false;
163
+ }
164
+ }
165
+ }
166
+
167
+ public get state(): string {
168
+ return this._state;
169
+ }
170
+ public set state(value: string) {
171
+ if (value == this.state) {
172
+ return;
173
+ }
174
+
175
+ this._state = value;
176
+
177
+ this.commitStateData();
178
+
179
+ this.dispatchEvent(BaseBtnEvent.STATE_CHANGE);
180
+ }
181
+
182
+ public get selected(): boolean {
183
+ return this._selected;
184
+ }
185
+ public set selected(value: boolean) {
186
+ if (value == this.selected) {
187
+ return;
188
+ }
189
+
190
+ this._selected = value;
191
+
192
+ if (this._selected) {
193
+ this.state = BaseBtnState.SELECTED_NORMAL;
194
+ } else {
195
+ this.state = BaseBtnState.NORMAL;
196
+ }
197
+
198
+ this.dispatchEvent(BaseBtnEvent.SELECTED_CHANGE);
199
+ }
200
+
201
+ public get enabled(): boolean {
202
+ return this._enabled;
203
+ }
204
+ public set enabled(value: boolean) {
205
+ if (value == this.enabled) {
206
+ return;
207
+ }
208
+
209
+ this._enabled = value;
210
+
211
+ if (this._enabled) {
212
+ this.state = this.findStateValue(BaseBtnState.NORMAL);
213
+ } else {
214
+ this.state = this.findStateValue(BaseBtnState.DISABLED);
215
+ }
216
+
217
+ this.commitEnabledData();
218
+ }
219
+
220
+
221
+ protected commitData(): void {
222
+ super.commitData();
223
+
224
+ if (!this.isConstructed) {
225
+ return;
226
+ }
227
+
228
+ // this.updateHitArea();
229
+ this.commitStateData();
230
+ }
231
+
232
+
233
+ public get hitArea(): DisplayObject {
234
+ return this._hitArea;
235
+ }
236
+ public set hitArea(value: DisplayObject) {
237
+ if (value == this.hitArea) {
238
+ return;
239
+ }
240
+
241
+ // Remove previous hit area
242
+ this.removeMouseListeners();
243
+
244
+ // Set the new hit area
245
+ this._hitArea = value;
246
+ this.addMouseListeners(this.hitArea);
247
+
248
+ this.commitData();
249
+ }
250
+
251
+ // protected updateHitArea():void {
252
+ // /*var tempNewHitArea:createjs.DisplayObject;
253
+ // if (this.view) {
254
+ // tempNewHitArea = (this.view[BaseBtn.HIT_AREA_CLIP_NAME] as createjs.DisplayObject);
255
+ // if (!tempNewHitArea) {
256
+ // tempNewHitArea = this.view;
257
+ // }
258
+ // }
259
+ //
260
+ // this.hitArea = tempNewHitArea;*/
261
+ // // ToDo: the previous code worked with MovieClip implementation,
262
+ // // so this method might be moved to the MovieClip/Timeline-Button instead of the SimpleButton class
263
+ // }
264
+
265
+ /*protected updateLabel():void {
266
+ // var tempNewField:createjs.Text;
267
+ // if (this.view) {
268
+ // tempNewField = DisplayObjectTools.findChildByName<createjs.Text>(this.view, BaseBtn.LABEL_FIELD_NAME, true);
269
+ // }
270
+ //
271
+ // this.label.field = tempNewField;
272
+ // ToDo: the previous code worked with MovieClip implementation,
273
+ // so this method might be moved to the MovieClip/Timeline-Button instead of the BaseBtn class
274
+ }*/
275
+
276
+ // Think whether we really need to have the label object in the BaseBtn class
277
+ /*public get text():string {
278
+ return this.label.text;
279
+ }
280
+ public set text(value:string) {
281
+ this.label.text = value;
282
+ }*/
283
+
284
+
285
+ /*public simulateClick():void {
286
+ if (this.enabled) {
287
+ var tempEvent:createjs.MouseEvent = new createjs.MouseEvent(createjs.MouseEvent.CLICK);
288
+ tempEvent.target = this;
289
+
290
+ this.onTap(tempEvent);
291
+ }
292
+ }*/
293
+
294
+
295
+ /*private _commitStateDataCallback: Function;
296
+ get commitStateDataCallback(): Function {
297
+ return this._commitStateDataCallback;
298
+ }
299
+ set commitStateDataCallback(value: Function) {
300
+ if (value === this.commitStateDataCallback) {
301
+ return;
302
+ }
303
+
304
+ this._commitStateDataCallback = value;
305
+
306
+ this.commitStateData();
307
+ }*/
308
+
309
+ protected findStateValue(sourceState: string): string {
310
+ let result: string;
311
+
312
+ if (this.selected) {
313
+ result = BaseBtnState.NORMAL_TO_SELECTED_MAP[sourceState];
314
+
315
+ } else {
316
+ result = BaseBtnState.SELECTED_TO_NORMAL_MAP[sourceState];
317
+ }
318
+
319
+ if (!result) {
320
+ result = sourceState;
321
+ }
322
+
323
+ return result;
324
+ }
325
+ }
@@ -0,0 +1,4 @@
1
+ export const BaseBtnEvent = {
2
+ STATE_CHANGE: "STATE_CHANGE",
3
+ SELECTED_CHANGE: "SELECTED_CHANGE"
4
+ };
@@ -0,0 +1,31 @@
1
+ export class BaseBtnState {
2
+ public static NORMAL:string = "normal";
3
+ public static OVER:string = "over";
4
+ public static PRESS:string = "press";
5
+ public static DISABLED:string = "disabled";
6
+
7
+ public static SELECTED_NORMAL:string = "selected_normal";
8
+ public static SELECTED_OVER:string = "selected_over";
9
+ public static SELECTED_PRESS:string = "selected_press";
10
+ public static SELECTED_DISABLED:string = "selected_disabled";
11
+
12
+ public static NORMAL_TO_SELECTED_MAP = ((): any => {
13
+ let result: any = {};
14
+ result[BaseBtnState.NORMAL] = BaseBtnState.SELECTED_NORMAL;
15
+ result[BaseBtnState.OVER] = BaseBtnState.SELECTED_OVER;
16
+ result[BaseBtnState.PRESS] = BaseBtnState.SELECTED_PRESS;
17
+ result[BaseBtnState.DISABLED] = BaseBtnState.SELECTED_DISABLED;
18
+
19
+ return result;
20
+ })();
21
+
22
+ public static SELECTED_TO_NORMAL_MAP = ((): any => {
23
+ let result: any = {};
24
+ result[BaseBtnState.SELECTED_NORMAL] = BaseBtnState.NORMAL;
25
+ result[BaseBtnState.SELECTED_OVER] = BaseBtnState.OVER;
26
+ result[BaseBtnState.SELECTED_PRESS] = BaseBtnState.PRESS;
27
+ result[BaseBtnState.SELECTED_DISABLED] = BaseBtnState.DISABLED;
28
+
29
+ return result;
30
+ })();
31
+ }