@urso/core 0.1.92 → 0.2.1-dev
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.
- package/build/js/index.js +1 -1
- package/package.json +1 -1
- package/src/js/app.js +3 -2
- package/src/js/components/stateDriven/_info.js +1 -0
- package/src/js/components/stateDriven/actionConfig.js +7 -0
- package/src/js/components/stateDriven/controller.js +38 -32
- package/src/js/config/main.js +2 -1
- package/src/js/lib/loader.js +22 -1
- package/src/js/modules/assets/config.js +11 -1
- package/src/js/modules/assets/controller.js +16 -0
- package/src/js/modules/assets/service.js +64 -37
- package/src/js/modules/instances/controller.js +9 -9
- package/src/js/modules/statesManager/_info.js +2 -2
- package/src/js/modules/statesManager/action.js +16 -74
- package/src/js/modules/statesManager/configStates.js +3 -18
- package/src/js/modules/statesManager/controller.js +78 -37
- package/src/js/modules/statesManager/functionsStorage.js +83 -0
- package/src/js/modules/statesManager/helper.js +1 -11
- package/src/js/modules/statesManager/race.js +0 -5
- package/src/js/modules/statesManager/actionModel.js +0 -48
- package/src/js/modules/statesManager/configActions.js +0 -54
package/package.json
CHANGED
package/src/js/app.js
CHANGED
|
@@ -14,7 +14,7 @@ class App {
|
|
|
14
14
|
//setup Instances
|
|
15
15
|
let instances = new Urso.Core.Modules.Instances.Controller();
|
|
16
16
|
Urso.getInstance = instances.getInstance;
|
|
17
|
-
Urso.
|
|
17
|
+
Urso.getByPath = instances.getByPath;
|
|
18
18
|
Urso.getInstancesModes = instances.getModes;
|
|
19
19
|
Urso.addInstancesMode = instances.addMode;
|
|
20
20
|
Urso.removeInstancesMode = instances.removeMode;
|
|
@@ -34,7 +34,7 @@ class App {
|
|
|
34
34
|
|
|
35
35
|
//libs
|
|
36
36
|
Urso.cache = Urso.getInstance('Lib.Cache'); //all assets cache
|
|
37
|
-
Urso.device = Urso.
|
|
37
|
+
Urso.device = Urso.getByPath('Lib.Device'); //all device info
|
|
38
38
|
Urso.loader = Urso.getInstance('Lib.Loader'); //assets loader class
|
|
39
39
|
Urso.localData = Urso.getInstance('Lib.LocalData'); //local data storage
|
|
40
40
|
Urso.logger = Urso.getInstance('Lib.Logger'); //logger
|
|
@@ -59,6 +59,7 @@ class App {
|
|
|
59
59
|
|
|
60
60
|
//App.run
|
|
61
61
|
Urso.device.whenReady(() => {
|
|
62
|
+
Urso.assets.updateQuality();
|
|
62
63
|
Urso.getInstance('App').run();
|
|
63
64
|
});
|
|
64
65
|
}
|
|
@@ -1,50 +1,56 @@
|
|
|
1
1
|
ComponentsBaseController = require('./../base/controller.js');
|
|
2
2
|
|
|
3
3
|
class ComponentsStateDrivenController extends ComponentsBaseController {
|
|
4
|
-
//TODO subscribe to N actions
|
|
5
|
-
constructor(options) {
|
|
6
|
-
super(options);
|
|
7
|
-
//todo set guard
|
|
8
|
-
this.eventBlank = 'components.example';
|
|
9
|
-
|
|
10
|
-
this._finished = this._finished.bind(this);
|
|
11
|
-
this._terminated = this._terminated.bind(this);
|
|
12
|
-
}
|
|
13
4
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
configStates = {
|
|
6
|
+
/*IDLE: {
|
|
7
|
+
guard: () => { log(123, 'IDLE guard'); return true; }
|
|
8
|
+
}*/
|
|
9
|
+
};
|
|
17
10
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
configActions = {
|
|
12
|
+
/*startSpin: {
|
|
13
|
+
guard: () => { log(123, 'guard'); return true; },
|
|
14
|
+
run: (finish) => { log(123, 'run'); finish(); },
|
|
15
|
+
terminate: () => { log(123, 'terminate'); }
|
|
16
|
+
}*/
|
|
17
|
+
};
|
|
23
18
|
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
_processStates() {
|
|
20
|
+
for (const stateKey in this.configStates) {
|
|
21
|
+
Urso.statesManager.setStateGuard(stateKey, this.configStates[stateKey].guard.bind(this));
|
|
22
|
+
}
|
|
26
23
|
}
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
this._finished();
|
|
31
|
-
}
|
|
25
|
+
_processActions() {
|
|
26
|
+
for (const actionKey in this.configActions) {
|
|
32
27
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
//const actionCfg = this.getInstance('ActionConfig', this.configActions[actionKey]);
|
|
29
|
+
const actionCfg = this.configActions[actionKey];
|
|
30
|
+
|
|
31
|
+
if (actionCfg.run)
|
|
32
|
+
Urso.statesManager.addActionRun(actionKey, actionCfg.run.bind(this));
|
|
33
|
+
else {
|
|
34
|
+
Urso.logger.error('ComponentsStateDrivenController: no run function in config', actionKey, this);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
if (actionCfg.terminate)
|
|
39
|
+
Urso.statesManager.addActionTerminate(actionKey, actionCfg.terminate.bind(this));
|
|
40
|
+
|
|
41
|
+
if (actionCfg.guard)
|
|
42
|
+
Urso.statesManager.addActionGuard(actionKey, actionCfg.guard.bind(this));
|
|
43
|
+
}
|
|
40
44
|
}
|
|
41
45
|
|
|
42
|
-
|
|
43
|
-
this.
|
|
46
|
+
_subscribeOnce() {
|
|
47
|
+
this._processStates();
|
|
48
|
+
this._processActions();
|
|
44
49
|
}
|
|
45
50
|
|
|
51
|
+
//todo
|
|
46
52
|
destroy() {
|
|
47
|
-
Urso.
|
|
53
|
+
Urso.logger.error('ComponentsStateDrivenController will remove States and Actions by configs');
|
|
48
54
|
}
|
|
49
55
|
|
|
50
56
|
}
|
package/src/js/config/main.js
CHANGED
|
@@ -2,7 +2,8 @@ let ConfigMain = {
|
|
|
2
2
|
title: 'Urso', //game title
|
|
3
3
|
mode: "development", // development/production/testing
|
|
4
4
|
extendingChain: ['Urso.Core'], //chain that will be set as Urso.Game
|
|
5
|
-
defaultScene: 'play' //default scene to display
|
|
5
|
+
defaultScene: 'play', //default scene to display
|
|
6
|
+
useBinPath: false
|
|
6
7
|
};
|
|
7
8
|
|
|
8
9
|
module.exports = ConfigMain;
|
package/src/js/lib/loader.js
CHANGED
|
@@ -17,6 +17,26 @@ class LibLoader {
|
|
|
17
17
|
this._assetsQuery.push(asset);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* gets part of loading path
|
|
22
|
+
*/
|
|
23
|
+
_getLoadPath(asset){
|
|
24
|
+
const { path } = asset;
|
|
25
|
+
|
|
26
|
+
if(!Urso.config.useBinPath) {
|
|
27
|
+
return `assets/${path}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const quality = Urso.getInstance('Modules.Assets.Service').getQuality();
|
|
31
|
+
const splitted = path.split('/');
|
|
32
|
+
|
|
33
|
+
if (splitted[0] === 'images') {
|
|
34
|
+
splitted.splice(1, 0, quality);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return `bin/${splitted.join('/')}`;
|
|
38
|
+
};
|
|
39
|
+
|
|
20
40
|
/**
|
|
21
41
|
* store loaded asset in cache
|
|
22
42
|
*/
|
|
@@ -79,7 +99,8 @@ class LibLoader {
|
|
|
79
99
|
// TODO: check to load
|
|
80
100
|
|
|
81
101
|
const params = asset.params || false; // TODO: Set params field in base mode
|
|
82
|
-
|
|
102
|
+
const loadPath = this._getLoadPath(asset);
|
|
103
|
+
loader.add(asset.key, loadPath, params, (resource) => this._storeAsset(asset, resource)) //TODO set assets resolution instead _processLoadedImage baseTexture resolution
|
|
83
104
|
});
|
|
84
105
|
|
|
85
106
|
this._onLoadUpdate({progress: 0});
|
|
@@ -2,6 +2,16 @@ class ModulesAssetsConfig {
|
|
|
2
2
|
constructor() {
|
|
3
3
|
this.singleton = true;
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* quality settings for resource loading selection
|
|
7
|
+
*/
|
|
8
|
+
this.qualityFactors = {
|
|
9
|
+
medium: 0.5,
|
|
10
|
+
hd: 0.75,
|
|
11
|
+
high: 1
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
|
|
5
15
|
/**
|
|
6
16
|
* initial is the default and will load on the preload
|
|
7
17
|
* also you can call preload manualy by assets.loadGroup('groupName')
|
|
@@ -10,7 +20,7 @@ class ModulesAssetsConfig {
|
|
|
10
20
|
initial: 0 //will load on the preload
|
|
11
21
|
/*lazyPart1: 'lazyPart1',
|
|
12
22
|
lazyPart2: 'lazyPart2'*/
|
|
13
|
-
}
|
|
23
|
+
};
|
|
14
24
|
|
|
15
25
|
/**
|
|
16
26
|
* you can make lazy load groups priority here
|
|
@@ -3,6 +3,22 @@ class ModulesAssetsController {
|
|
|
3
3
|
this.singleton = true;
|
|
4
4
|
};
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Update quality
|
|
8
|
+
*/
|
|
9
|
+
updateQuality(){
|
|
10
|
+
if(Urso.config.useBinPath){
|
|
11
|
+
this.getInstance('Service').updateQuality();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Current quality getter
|
|
17
|
+
*/
|
|
18
|
+
getQuality(){
|
|
19
|
+
this.getInstance('Service').getQuality();
|
|
20
|
+
}
|
|
21
|
+
|
|
6
22
|
/**
|
|
7
23
|
* instantly load initial assets and start lazy loading process, if needed
|
|
8
24
|
* @param {Mixed} assets - asset or array of assets
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
class ModulesAssetsService {
|
|
2
2
|
constructor() {
|
|
3
3
|
this.singleton = true;
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
this.assets = {};
|
|
6
6
|
|
|
7
|
+
this._currentQuality = 'auto';
|
|
7
8
|
this._addedAssetsCache = [];
|
|
8
9
|
};
|
|
9
10
|
|
|
11
|
+
getQuality(){
|
|
12
|
+
return this._currentQuality;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
updateQuality(){
|
|
16
|
+
this._currentQuality = this._detectQuality();
|
|
17
|
+
Urso.addInstancesMode(this._currentQuality);
|
|
18
|
+
}
|
|
19
|
+
|
|
10
20
|
sortAssets(assets) {
|
|
11
21
|
this.assets[this.getInstance('Config').loadingGroups.initial] = [];
|
|
12
22
|
|
|
@@ -125,13 +135,9 @@ class ModulesAssetsService {
|
|
|
125
135
|
}
|
|
126
136
|
|
|
127
137
|
_processLoadedImage(assetModel) {
|
|
128
|
-
const {
|
|
129
|
-
let imageQualityKey = assetModel.useBinPath;
|
|
138
|
+
const { qualityFactors } = this.getInstance('Config');
|
|
130
139
|
|
|
131
|
-
|
|
132
|
-
imageQualityKey = current;
|
|
133
|
-
|
|
134
|
-
let qualityTextureResolution = params[imageQualityKey] || 1;
|
|
140
|
+
const resolution = qualityFactors[this._currentQuality] || 1;
|
|
135
141
|
|
|
136
142
|
const assetKey = assetModel.key;
|
|
137
143
|
//textures cache
|
|
@@ -140,14 +146,14 @@ class ModulesAssetsService {
|
|
|
140
146
|
if (!imageData) {
|
|
141
147
|
//from atlas ?!
|
|
142
148
|
let texture = Urso.cache.getFile(assetModel.path);
|
|
143
|
-
|
|
149
|
+
|
|
144
150
|
if (!texture)
|
|
145
151
|
return Urso.logger.error('ModulesAssetsService process Loaded Image error: no image ', assetModel);
|
|
146
152
|
|
|
147
153
|
Urso.cache.addTexture(assetKey, texture); //TODO change resolution of base texture
|
|
148
154
|
} else {
|
|
149
155
|
//regular image
|
|
150
|
-
const baseTexture = new PIXI.BaseTexture(imageData.data, { resolution
|
|
156
|
+
const baseTexture = new PIXI.BaseTexture(imageData.data, { resolution });
|
|
151
157
|
const texture = new PIXI.Texture(baseTexture);
|
|
152
158
|
Urso.cache.addTexture(assetKey, texture);
|
|
153
159
|
}
|
|
@@ -215,9 +221,6 @@ class ModulesAssetsService {
|
|
|
215
221
|
//set loadingGroup
|
|
216
222
|
model.loadingGroup = loadingGroup || model.loadingGroup || this.getInstance('Config').loadingGroups.initial;
|
|
217
223
|
|
|
218
|
-
//setup path if its need
|
|
219
|
-
this._setQualityPath(model); //TODO adapt for dragonbones
|
|
220
|
-
|
|
221
224
|
//check if container or dragonbones
|
|
222
225
|
if (model.contents) {
|
|
223
226
|
for (let content of model.contents) {
|
|
@@ -253,41 +256,65 @@ class ModulesAssetsService {
|
|
|
253
256
|
this.loadGroup(groupName, () => { this._continueLazyLoad(step + 1); })
|
|
254
257
|
}
|
|
255
258
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
259
|
+
_qualityReducer(qualityFactors, widthFactor){
|
|
260
|
+
return [(acc, val) => {
|
|
261
|
+
if (acc === null) {
|
|
262
|
+
return val;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const currentQuality = qualityFactors[acc];
|
|
266
|
+
const qualityFactor = qualityFactors[val];
|
|
267
|
+
|
|
268
|
+
const nextQuality = (currentQuality > qualityFactor && qualityFactor >= widthFactor)
|
|
269
|
+
|| (qualityFactor >= widthFactor && widthFactor > currentQuality)
|
|
270
|
+
|| (widthFactor >= qualityFactor && qualityFactor > currentQuality);
|
|
271
|
+
|
|
272
|
+
return nextQuality ? val : acc;
|
|
273
|
+
|
|
274
|
+
}, null]
|
|
266
275
|
}
|
|
267
276
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
277
|
+
_detectQuality(){
|
|
278
|
+
const { qualityFactors } = this.getInstance('Config');
|
|
279
|
+
const userQuality = Urso.helper.parseGetParams()['quality'];
|
|
280
|
+
|
|
281
|
+
if(userQuality && qualityFactors[userQuality]){
|
|
282
|
+
return userQuality;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return this._calculateQuality(qualityFactors);
|
|
286
|
+
}
|
|
271
287
|
|
|
272
|
-
|
|
288
|
+
_calculateQuality(qualityFactors){
|
|
289
|
+
const { android, iOS, iPad, macOS } = Urso.device;
|
|
290
|
+
const isMobile = android || iOS || iPad;
|
|
273
291
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
asset.path = asset.path.replace('assets', `bin/${qualityPath}`);
|
|
292
|
+
if (macOS && !isMobile) {
|
|
293
|
+
return 'high';
|
|
277
294
|
}
|
|
278
295
|
|
|
279
|
-
if
|
|
280
|
-
|
|
281
|
-
return;
|
|
296
|
+
if(macOS && iPad) {
|
|
297
|
+
return 'medium';
|
|
282
298
|
}
|
|
283
299
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
300
|
+
const resCfg = Urso.getInstance('Modules.Scenes.ResolutionsConfig').contents[0];
|
|
301
|
+
|
|
302
|
+
const { devicePixelRatio } = window;
|
|
303
|
+
let { width, height } = screen;
|
|
287
304
|
|
|
288
|
-
|
|
289
|
-
|
|
305
|
+
if (isMobile) {
|
|
306
|
+
width = (width > height) ? width : height;
|
|
290
307
|
}
|
|
308
|
+
|
|
309
|
+
if (iOS) {
|
|
310
|
+
width *= devicePixelRatio;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const widthFactor = width / resCfg.width;
|
|
314
|
+
|
|
315
|
+
return Object
|
|
316
|
+
.keys(qualityFactors)
|
|
317
|
+
.reduce(...this._qualityReducer(qualityFactors, widthFactor));
|
|
291
318
|
}
|
|
292
319
|
|
|
293
320
|
_addAssetToLoader(assetModel, loader) {
|
|
@@ -4,7 +4,7 @@ class ModulesInstancesController {
|
|
|
4
4
|
this._cache = {};
|
|
5
5
|
|
|
6
6
|
this.getInstance = this.getInstance.bind(this);
|
|
7
|
-
this.
|
|
7
|
+
this.getByPath = this.getByPath.bind(this);
|
|
8
8
|
this._setComonFunctions = this._setComonFunctions.bind(this);
|
|
9
9
|
|
|
10
10
|
this.getModes = this.getModes.bind(this);
|
|
@@ -12,12 +12,12 @@ class ModulesInstancesController {
|
|
|
12
12
|
this.removeMode = this.removeMode.bind(this);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
getByPath(path, noModes, modeName) {
|
|
16
16
|
let callback = (a) => {
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
return this._findClass({ path
|
|
20
|
+
return this._findClass({ path, callback, noModes, modeName });
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
getModes() {
|
|
@@ -64,7 +64,7 @@ class ModulesInstancesController {
|
|
|
64
64
|
return instance;
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
-
return this._findClass({ path
|
|
67
|
+
return this._findClass({ path, callback, noModes, modeName });
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
_setComonFunctions(classObject, path) {
|
|
@@ -147,7 +147,7 @@ class ModulesInstancesController {
|
|
|
147
147
|
return this._cache[cacheKey] ? params.callback(this._cache[cacheKey]) : false;
|
|
148
148
|
|
|
149
149
|
//no class in cache - we will find class by path
|
|
150
|
-
let classObject = this._getClassByPath(params.path);
|
|
150
|
+
let classObject = this._getClassByPath(params.path, params.noModes);
|
|
151
151
|
|
|
152
152
|
if (!classObject)
|
|
153
153
|
return false;
|
|
@@ -166,10 +166,10 @@ class ModulesInstancesController {
|
|
|
166
166
|
return params.callback(this._cache[cacheKey]);
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
_getClassByPath(path) {
|
|
169
|
+
_getClassByPath(path, noModes) {
|
|
170
170
|
let pathArr = path.split('.');
|
|
171
171
|
let entitiesArray = Urso.helper.mergeArrays(['Urso', 'Game'], pathArr);
|
|
172
|
-
return this._checkPathExist(entitiesArray);
|
|
172
|
+
return this._checkPathExist(entitiesArray, noModes);
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
/**
|
|
@@ -177,12 +177,12 @@ class ModulesInstancesController {
|
|
|
177
177
|
* @param {Object} entitiesArray like ['Urso', 'Game', 'Lib', 'Helper']
|
|
178
178
|
* @returns {mixed}
|
|
179
179
|
*/
|
|
180
|
-
_checkPathExist(entitiesArray) {
|
|
180
|
+
_checkPathExist(entitiesArray, noModes) {
|
|
181
181
|
let currentTestObject = window;
|
|
182
182
|
let testMode;
|
|
183
183
|
|
|
184
184
|
for (let entitiesIndex = 0; entitiesIndex < entitiesArray.length; entitiesIndex++) {
|
|
185
|
-
if (this._modes && entitiesIndex === entitiesArray.length - 1)
|
|
185
|
+
if (!noModes && this._modes && entitiesIndex === entitiesArray.length - 1)
|
|
186
186
|
testMode = this._checkPathWithModes(currentTestObject, entitiesArray, entitiesIndex);
|
|
187
187
|
|
|
188
188
|
if (testMode)
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Urso.Core.Modules.StatesManager = {
|
|
2
2
|
Action: require('./action.js'),
|
|
3
|
-
ActionModel: require('./actionModel.js'),
|
|
4
3
|
All: require('./all.js'),
|
|
5
|
-
ConfigActions: require('./configActions.js'),
|
|
6
4
|
ConfigStates: require('./configStates.js'),
|
|
7
5
|
Controller: require('./controller.js'),
|
|
6
|
+
FunctionsStorage: require('./functionsStorage.js'),
|
|
8
7
|
Helper: require('./helper.js'),
|
|
9
8
|
Race: require('./race.js'),
|
|
10
9
|
Sequence: require('./sequence.js')
|
|
11
10
|
};
|
|
11
|
+
|
|
12
12
|
require('./actions/_info.js');
|
|
@@ -1,113 +1,55 @@
|
|
|
1
1
|
class ModulesStatesManagerAction {
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
name
|
|
5
|
-
events: {
|
|
6
|
-
onStart: 'action.showWinPopup.start',
|
|
7
|
-
toComplete: 'winPopup.display.finished'
|
|
8
|
-
},
|
|
9
|
-
isTerminable: true,
|
|
10
|
-
terminateEvents:{
|
|
11
|
-
onStart: 'action.showWinPopup.terminate',
|
|
12
|
-
toComplete: 'winPopup.display.terminated'
|
|
13
|
-
}
|
|
14
|
-
}*/
|
|
15
|
-
|
|
3
|
+
constructor(name) {
|
|
4
|
+
this.name = name;
|
|
16
5
|
|
|
17
|
-
constructor(params) {
|
|
18
6
|
this._terminating = false;
|
|
19
7
|
this.finished = false;
|
|
20
8
|
this._onFinishCallback = false;
|
|
21
9
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (options) {
|
|
25
|
-
this.options = options;
|
|
26
|
-
this.name = options.name;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
this._onComplete = this._onComplete.bind(this);
|
|
30
|
-
this._onTerminate = this._onTerminate.bind(this);
|
|
10
|
+
this._onFinish = this._onFinish.bind(this);
|
|
31
11
|
}
|
|
32
12
|
|
|
33
13
|
//can we start this action?
|
|
34
14
|
guard() {
|
|
35
|
-
|
|
36
|
-
return this.getInstance('Controller').checkGuard(this.options._eventBlank);
|
|
37
|
-
else
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
//can action be terminated ?
|
|
42
|
-
isTerminable() {
|
|
43
|
-
if (this.options)
|
|
44
|
-
return this.options.isTerminable;
|
|
45
|
-
|
|
46
|
-
return true;
|
|
15
|
+
return this.getInstance('Controller').checkActionGuard(this.name);
|
|
47
16
|
}
|
|
48
17
|
|
|
49
18
|
run(onFinishCallback) {
|
|
50
|
-
log(`%c action run ---> ${this.name}`, 'color: blue'
|
|
19
|
+
log(`%c action run ---> ${this.name}`, 'color: blue');
|
|
51
20
|
|
|
52
21
|
this.finished = false;
|
|
53
22
|
this._onFinishCallback = onFinishCallback;
|
|
54
|
-
this._addListeners();
|
|
55
23
|
|
|
56
|
-
|
|
57
|
-
this.emit(this.options.events.onStart);
|
|
24
|
+
Urso.statesManager.runAction(this.name, this._onFinish);
|
|
58
25
|
|
|
59
26
|
//TODO remove temp for debug
|
|
60
|
-
//
|
|
61
|
-
// setTimeout(() => { this._onFinish(); }, timeout);
|
|
27
|
+
//let timeout = Math.floor(Math.random() * 2000);
|
|
28
|
+
//Urso.statesManager.runAction(this.name, () => setTimeout(() => { this._onFinish(); }, timeout));
|
|
62
29
|
}
|
|
63
30
|
|
|
64
31
|
terminate() {
|
|
65
|
-
if (
|
|
32
|
+
if (this._terminating) {
|
|
33
|
+
Urso.logger.error('ModulesStatesManagerAction: action alredy terminating', this.name);
|
|
66
34
|
return;
|
|
35
|
+
}
|
|
67
36
|
|
|
68
37
|
log(`%c action terminate X ${this.name}`, 'color: blue');
|
|
69
|
-
|
|
70
38
|
this._terminating = true;
|
|
71
|
-
|
|
72
|
-
if (this.options && Urso.helper.recursiveGet('options.terminateEvents.onStart', this, false))
|
|
73
|
-
this.emit(this.options.terminateEvents.onStart);
|
|
39
|
+
Urso.statesManager.terminateAction(this.name);
|
|
74
40
|
}
|
|
75
41
|
|
|
76
42
|
_onFinish() {
|
|
77
|
-
if (this.finished)
|
|
43
|
+
if (this.finished) {
|
|
44
|
+
Urso.logger.error('ModulesStatesManagerAction: action alredy finished', this.name);
|
|
78
45
|
return;
|
|
46
|
+
}
|
|
79
47
|
|
|
80
|
-
this.
|
|
48
|
+
this._terminating = false;
|
|
81
49
|
this.finished = true;
|
|
82
50
|
log(`%c action finish <--- ${this.name}`, 'color: blue');
|
|
83
51
|
this._onFinishCallback();
|
|
84
52
|
}
|
|
85
|
-
|
|
86
|
-
_onComplete() {
|
|
87
|
-
this._onFinish();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
_onTerminate() {
|
|
91
|
-
this._terminating = false;
|
|
92
|
-
this._onFinish();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
_addListeners() {
|
|
96
|
-
if (this.options && Urso.helper.recursiveGet('options.events.toComplete', this, false))
|
|
97
|
-
this.addListener(this.options.events.toComplete, this._onComplete, true);
|
|
98
|
-
|
|
99
|
-
if (this.options && Urso.helper.recursiveGet('options.terminateEvents.toComplete', this, false))
|
|
100
|
-
this.addListener(this.options.terminateEvents.toComplete, this._onTerminate, true);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
_removeListeners() {
|
|
104
|
-
if (this.options && Urso.helper.recursiveGet('options.events.toComplete', this, false))
|
|
105
|
-
this.removeListener(this.options.events.toComplete, this._onComplete, true);
|
|
106
|
-
|
|
107
|
-
if (this.options && Urso.helper.recursiveGet('options.terminateEvents.toComplete', this, false))
|
|
108
|
-
this.removeListener(this.options.terminateEvents.toComplete, this._onTerminate, true);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
53
|
}
|
|
112
54
|
|
|
113
55
|
module.exports = ModulesStatesManagerAction;
|
|
@@ -19,15 +19,15 @@ class ModulesStatesManagerConfigStates {
|
|
|
19
19
|
PICK_GAME1: {
|
|
20
20
|
sequence: [
|
|
21
21
|
{ action: 'someAction' },
|
|
22
|
-
{ action: 'showPickGame' }, //showPickGame -->
|
|
22
|
+
{ action: 'showPickGame' }, //showPickGame --> addActionGuard(showPickGame, funk)
|
|
23
23
|
{ action: 'showBIGWin' }
|
|
24
24
|
],
|
|
25
|
-
nextState: ["PICK_GAME2", "PICK_GAME1", "IDLE"]
|
|
25
|
+
nextState: ["PICK_GAME2", "PICK_GAME1", "IDLE"] //setGuardState(PICK_GAME2, func)
|
|
26
26
|
},
|
|
27
27
|
|
|
28
28
|
PICK_GAME2: {
|
|
29
29
|
sequence: [
|
|
30
|
-
{ action: 'showWheel' }, //showWheel -->
|
|
30
|
+
{ action: 'showWheel' }, //showWheel --> addActionGuard(showWheel, funk)
|
|
31
31
|
{ action: 'showBIGWin' }
|
|
32
32
|
],
|
|
33
33
|
nextState: ["PICK_GAME1", "IDLE"]
|
|
@@ -60,21 +60,6 @@ class ModulesStatesManagerConfigStates {
|
|
|
60
60
|
]
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
|
-
|
|
64
|
-
// this.actionsParams = {
|
|
65
|
-
// showWinPopup: {
|
|
66
|
-
// name: 'showWinPopup',
|
|
67
|
-
// events: {
|
|
68
|
-
// onStart: 'action.showWinPopup.start',
|
|
69
|
-
// toComplete: 'winPopup.display.finished'
|
|
70
|
-
// },
|
|
71
|
-
// isTerminable: true,
|
|
72
|
-
// terminateEvents: {
|
|
73
|
-
// onStart: 'action.showWinPopup.terminate',
|
|
74
|
-
// toComplete: 'winPopup.display.terminated'
|
|
75
|
-
// }
|
|
76
|
-
// }
|
|
77
|
-
// };
|
|
78
63
|
}
|
|
79
64
|
|
|
80
65
|
get() {
|