@urso/core 0.2.7 → 0.2.8
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/config/main.js +2 -1
- package/src/js/lib/helper.js +17 -2
- package/src/js/modules/assets/controller.js +5 -3
- package/src/js/modules/assets/service.js +18 -18
- package/src/js/modules/instances/controller.js +2 -1
- package/src/js/modules/logic/_info.js +0 -1
- package/src/js/modules/logic/config/_info.js +0 -1
- package/src/js/modules/objects/controller.js +6 -0
- package/src/js/modules/objects/create.js +34 -47
- package/src/js/modules/observer/events.js +1 -0
- package/src/js/modules/scenes/resolutions.js +8 -1
- package/src/js/modules/statesManager/controller.js +2 -3
- package/src/js/modules/statesManager/race.js +3 -3
- package/src/js/modules/transport/service.js +3 -1
- package/src/js/modules/logic/buttons.js +0 -120
- package/src/js/modules/logic/config/buttons.js +0 -63
package/package.json
CHANGED
package/src/js/app.js
CHANGED
|
@@ -44,8 +44,6 @@ class App {
|
|
|
44
44
|
|
|
45
45
|
//Modules
|
|
46
46
|
Urso.assets = Urso.getInstance('Modules.Assets.Controller');
|
|
47
|
-
Urso.buttons = Urso.getInstance('Modules.Buttons.Controller');
|
|
48
|
-
// TODO: CHECK FOR EVENT TO START COMMUNICATION WITH SERVER
|
|
49
47
|
Urso.transport = Urso.getInstance('Modules.Transport.Controller');
|
|
50
48
|
Urso.logic = Urso.getInstance('Modules.Logic.Controller');
|
|
51
49
|
Urso.objects = Urso.getInstance('Modules.Objects.Controller');
|
|
@@ -57,6 +55,9 @@ class App {
|
|
|
57
55
|
//set title
|
|
58
56
|
document.title = Urso.config.title;
|
|
59
57
|
|
|
58
|
+
//device type mode
|
|
59
|
+
Urso.addInstancesMode(!Urso.helper.mobileAndTabletCheck() ? 'desktop' : 'mobile');
|
|
60
|
+
|
|
60
61
|
//App.run
|
|
61
62
|
Urso.device.whenReady(() => {
|
|
62
63
|
Urso.assets.updateQuality();
|
package/src/js/config/main.js
CHANGED
|
@@ -3,7 +3,8 @@ let ConfigMain = {
|
|
|
3
3
|
mode: "development", // development/production/testing
|
|
4
4
|
extendingChain: ['Urso.Core'], //chain that will be set as Urso.Game
|
|
5
5
|
defaultScene: 'play', //default scene to display
|
|
6
|
-
useBinPath: false
|
|
6
|
+
useBinPath: false, // use assets from bin directory
|
|
7
|
+
useTransport: false // use transport module for connetcting with server
|
|
7
8
|
};
|
|
8
9
|
|
|
9
10
|
module.exports = ConfigMain;
|
package/src/js/lib/helper.js
CHANGED
|
@@ -123,6 +123,21 @@ class LibHelper {
|
|
|
123
123
|
return c;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Swap key with value in object
|
|
128
|
+
* @param {Object} obj
|
|
129
|
+
* @returns {Object}
|
|
130
|
+
*/
|
|
131
|
+
objectFlip(obj) {
|
|
132
|
+
const ret = {};
|
|
133
|
+
|
|
134
|
+
Object.keys(obj).forEach(key => {
|
|
135
|
+
ret[obj[key]] = key;
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
return ret;
|
|
139
|
+
}
|
|
140
|
+
|
|
126
141
|
/**
|
|
127
142
|
* recursive set value to object by key
|
|
128
143
|
* @param {String} key
|
|
@@ -208,8 +223,8 @@ class LibHelper {
|
|
|
208
223
|
*/
|
|
209
224
|
transpose(matrix) {
|
|
210
225
|
return Object.keys(matrix[0])
|
|
211
|
-
|
|
212
|
-
|
|
226
|
+
.map(colNumber => matrix
|
|
227
|
+
.map(rowNumber => rowNumber[colNumber]));
|
|
213
228
|
}
|
|
214
229
|
|
|
215
230
|
/**
|
|
@@ -6,16 +6,18 @@ class ModulesAssetsController {
|
|
|
6
6
|
/**
|
|
7
7
|
* Update quality
|
|
8
8
|
*/
|
|
9
|
-
updateQuality(){
|
|
10
|
-
if(Urso.config.useBinPath){
|
|
9
|
+
updateQuality() {
|
|
10
|
+
if (Urso.config.useBinPath) {
|
|
11
11
|
this.getInstance('Service').updateQuality();
|
|
12
12
|
}
|
|
13
|
+
|
|
14
|
+
console.log('[ASSETS] Quality set to', this.getInstance('Service').getQuality());
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
/**
|
|
16
18
|
* Current quality getter
|
|
17
19
|
*/
|
|
18
|
-
getQuality(){
|
|
20
|
+
getQuality() {
|
|
19
21
|
this.getInstance('Service').getQuality();
|
|
20
22
|
}
|
|
21
23
|
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
class ModulesAssetsService {
|
|
2
2
|
constructor() {
|
|
3
3
|
this.singleton = true;
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
this.assets = {};
|
|
6
6
|
|
|
7
7
|
this._currentQuality = 'auto';
|
|
8
8
|
this._addedAssetsCache = [];
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
getQuality(){
|
|
11
|
+
getQuality() {
|
|
12
12
|
return this._currentQuality;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
updateQuality(){
|
|
15
|
+
updateQuality() {
|
|
16
16
|
this._currentQuality = this._detectQuality();
|
|
17
|
-
Urso.addInstancesMode(this._currentQuality);
|
|
17
|
+
Urso.addInstancesMode(this._currentQuality + 'Quality');
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
sortAssets(assets) {
|
|
@@ -74,7 +74,7 @@ class ModulesAssetsService {
|
|
|
74
74
|
|
|
75
75
|
_processLoadedAtlases(group) {
|
|
76
76
|
const atlases = this.assets[group].filter(assetModel => assetModel.type === Urso.types.assets.ATLAS);
|
|
77
|
-
|
|
77
|
+
|
|
78
78
|
for (let assetModel of atlases) {
|
|
79
79
|
const assetKey = assetModel.key;
|
|
80
80
|
let imageData = Urso.cache.getAtlas(assetKey);
|
|
@@ -85,7 +85,7 @@ class ModulesAssetsService {
|
|
|
85
85
|
let texture = imageData.textures[i];
|
|
86
86
|
let newFilename = frame.filename;
|
|
87
87
|
|
|
88
|
-
if(frame.filename.indexOf('/') === -1)
|
|
88
|
+
if (frame.filename.indexOf('/') === -1)
|
|
89
89
|
newFilename = folderPath + '/' + frame.filename;
|
|
90
90
|
|
|
91
91
|
Urso.cache.addFile(newFilename, texture);
|
|
@@ -146,7 +146,7 @@ class ModulesAssetsService {
|
|
|
146
146
|
if (!imageData) {
|
|
147
147
|
//from atlas ?!
|
|
148
148
|
let texture = Urso.cache.getFile(assetModel.path);
|
|
149
|
-
|
|
149
|
+
|
|
150
150
|
if (!texture)
|
|
151
151
|
return Urso.logger.error('ModulesAssetsService process Loaded Image error: no image ', assetModel);
|
|
152
152
|
|
|
@@ -256,7 +256,7 @@ class ModulesAssetsService {
|
|
|
256
256
|
this.loadGroup(groupName, () => { this._continueLazyLoad(step + 1); })
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
-
_qualityReducer(qualityFactors, widthFactor){
|
|
259
|
+
_qualityReducer(qualityFactors, widthFactor) {
|
|
260
260
|
return [(acc, val) => {
|
|
261
261
|
if (acc === null) {
|
|
262
262
|
return val;
|
|
@@ -268,24 +268,24 @@ class ModulesAssetsService {
|
|
|
268
268
|
const nextQuality = (currentQuality > qualityFactor && qualityFactor >= widthFactor)
|
|
269
269
|
|| (qualityFactor >= widthFactor && widthFactor > currentQuality)
|
|
270
270
|
|| (widthFactor >= qualityFactor && qualityFactor > currentQuality);
|
|
271
|
-
|
|
271
|
+
|
|
272
272
|
return nextQuality ? val : acc;
|
|
273
|
-
|
|
273
|
+
|
|
274
274
|
}, null]
|
|
275
275
|
}
|
|
276
276
|
|
|
277
|
-
_detectQuality(){
|
|
277
|
+
_detectQuality() {
|
|
278
278
|
const { qualityFactors } = this.getInstance('Config');
|
|
279
279
|
const userQuality = Urso.helper.parseGetParams()['quality'];
|
|
280
|
-
|
|
281
|
-
if(userQuality && qualityFactors[userQuality]){
|
|
280
|
+
|
|
281
|
+
if (userQuality && qualityFactors[userQuality]) {
|
|
282
282
|
return userQuality;
|
|
283
283
|
}
|
|
284
|
-
|
|
284
|
+
|
|
285
285
|
return this._calculateQuality(qualityFactors);
|
|
286
286
|
}
|
|
287
287
|
|
|
288
|
-
_calculateQuality(qualityFactors){
|
|
288
|
+
_calculateQuality(qualityFactors) {
|
|
289
289
|
const { android, iOS, iPad, macOS } = Urso.device;
|
|
290
290
|
const isMobile = android || iOS || iPad;
|
|
291
291
|
|
|
@@ -293,12 +293,12 @@ class ModulesAssetsService {
|
|
|
293
293
|
return 'high';
|
|
294
294
|
}
|
|
295
295
|
|
|
296
|
-
if(macOS && iPad) {
|
|
296
|
+
if (macOS && iPad) {
|
|
297
297
|
return 'medium';
|
|
298
298
|
}
|
|
299
299
|
|
|
300
300
|
const resCfg = Urso.getInstance('Modules.Scenes.ResolutionsConfig').contents[0];
|
|
301
|
-
|
|
301
|
+
|
|
302
302
|
const { devicePixelRatio } = window;
|
|
303
303
|
let { width, height } = screen;
|
|
304
304
|
|
|
@@ -311,7 +311,7 @@ class ModulesAssetsService {
|
|
|
311
311
|
}
|
|
312
312
|
|
|
313
313
|
const widthFactor = width / resCfg.width;
|
|
314
|
-
|
|
314
|
+
|
|
315
315
|
return Object
|
|
316
316
|
.keys(qualityFactors)
|
|
317
317
|
.reduce(...this._qualityReducer(qualityFactors, widthFactor));
|
|
@@ -29,7 +29,7 @@ class ModulesInstancesController {
|
|
|
29
29
|
return false;
|
|
30
30
|
|
|
31
31
|
this._modes.push(mode);
|
|
32
|
-
|
|
32
|
+
Urso.observer.emit(Urso.events.MODULES_INSTANCES_MODES_CHANGED);
|
|
33
33
|
return true;
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -40,6 +40,7 @@ class ModulesInstancesController {
|
|
|
40
40
|
return false;
|
|
41
41
|
|
|
42
42
|
this._modes.splice(index, 1);
|
|
43
|
+
Urso.observer.emit(Urso.events.MODULES_INSTANCES_MODES_CHANGED);
|
|
43
44
|
return true;
|
|
44
45
|
}
|
|
45
46
|
|
|
@@ -8,6 +8,7 @@ class ModulesObjectsController {
|
|
|
8
8
|
|
|
9
9
|
this._newResolutionHandler = this._newResolutionHandler.bind(this);
|
|
10
10
|
this._resetWorld = this._resetWorld.bind(this);
|
|
11
|
+
this._applyClassesToWorld = this._applyClassesToWorld.bind(this);
|
|
11
12
|
};
|
|
12
13
|
|
|
13
14
|
create(objects, parent, doNotRefreshStylesFlag) { //TODO parse template for assets and objects (groups, components)
|
|
@@ -106,9 +107,14 @@ class ModulesObjectsController {
|
|
|
106
107
|
this.getInstance('Create').resetWorld();
|
|
107
108
|
}
|
|
108
109
|
|
|
110
|
+
_applyClassesToWorld() {
|
|
111
|
+
this.getInstance('Create').applyClassesToWorld();
|
|
112
|
+
}
|
|
113
|
+
|
|
109
114
|
_subscribeOnce() {
|
|
110
115
|
this.addListener(Urso.events.MODULES_SCENES_NEW_RESOLUTION, this._newResolutionHandler, true);
|
|
111
116
|
this.addListener(Urso.events.MODULES_SCENES_NEW_SCENE_INIT, this._resetWorld, true);
|
|
117
|
+
this.addListener(Urso.events.MODULES_INSTANCES_MODES_CHANGED, this._applyClassesToWorld, true);
|
|
112
118
|
}
|
|
113
119
|
}
|
|
114
120
|
|
|
@@ -4,6 +4,7 @@ class ModulesObjectsCreate {
|
|
|
4
4
|
|
|
5
5
|
this._world = null;
|
|
6
6
|
this._counter = 0;
|
|
7
|
+
this._objectsTypesFlipped;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
_checkWorld() {
|
|
@@ -23,6 +24,7 @@ class ModulesObjectsCreate {
|
|
|
23
24
|
|
|
24
25
|
this.updateWorldBounds({ template: Urso.scenes.getTemplateSize() })
|
|
25
26
|
this.getInstance('Cache').reset();
|
|
27
|
+
this.applyClassesToWorld();
|
|
26
28
|
this._addToCache(proxy);
|
|
27
29
|
}
|
|
28
30
|
|
|
@@ -34,6 +36,23 @@ class ModulesObjectsCreate {
|
|
|
34
36
|
Urso.objects._safeSetValueToTarget(this._world, 'height', params.template.height);
|
|
35
37
|
}
|
|
36
38
|
|
|
39
|
+
applyClassesToWorld() {
|
|
40
|
+
if (!this._world) {
|
|
41
|
+
return; //world do not created yet
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//remove old classes
|
|
45
|
+
if (this._world.class) {
|
|
46
|
+
this._world.class.split(' ').forEach((className) => this._world.removeClass(className, true));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//apply new classes
|
|
50
|
+
Urso.getInstancesModes().forEach((className) => this._world.addClass(className, true));
|
|
51
|
+
|
|
52
|
+
//refresh styles
|
|
53
|
+
Urso.objects.refreshStyles();
|
|
54
|
+
}
|
|
55
|
+
|
|
37
56
|
_getUid() {
|
|
38
57
|
this._counter++;
|
|
39
58
|
return 'object_' + this._counter;
|
|
@@ -56,71 +75,39 @@ class ModulesObjectsCreate {
|
|
|
56
75
|
object.contents = []; //clear contents. We will put here just correct models
|
|
57
76
|
}
|
|
58
77
|
|
|
78
|
+
if (!this._objectsTypesFlipped)
|
|
79
|
+
this._objectsTypesFlipped = Urso.helper.objectFlip(Urso.types.objects);
|
|
80
|
+
|
|
59
81
|
//set uid
|
|
60
82
|
object._uid = this._getUid();
|
|
61
83
|
|
|
62
84
|
switch (object.type) {
|
|
85
|
+
//exceptions with camelCase namings
|
|
86
|
+
case Urso.types.objects.ATLASIMAGE:
|
|
87
|
+
model = this.getInstance('Models.AtlasImage', object);
|
|
88
|
+
break;
|
|
63
89
|
case Urso.types.objects.BITMAPTEXT:
|
|
64
90
|
model = this.getInstance('Models.BitmapText', object);
|
|
65
91
|
break;
|
|
66
|
-
case Urso.types.objects.BUTTON:
|
|
67
|
-
model = this.getInstance('Models.Button', object);
|
|
68
|
-
break;
|
|
69
|
-
case Urso.types.objects.COMPONENT:
|
|
70
|
-
model = this.getInstance('Models.Component', object);
|
|
71
|
-
break;
|
|
72
|
-
case Urso.types.objects.CONTAINER:
|
|
73
|
-
model = this.getInstance('Models.Container', object);
|
|
74
|
-
break;
|
|
75
92
|
case Urso.types.objects.DRAGONBONES:
|
|
76
93
|
model = this.getInstance('Models.DragonBones', object);
|
|
77
94
|
break;
|
|
78
|
-
case Urso.types.objects.GROUP:
|
|
79
|
-
model = this.getInstance('Models.Group', object);
|
|
80
|
-
break;
|
|
81
|
-
case Urso.types.objects.IMAGE:
|
|
82
|
-
model = this.getInstance('Models.Image', object);
|
|
83
|
-
break;
|
|
84
|
-
case Urso.types.objects.ATLASIMAGE:
|
|
85
|
-
model = this.getInstance('Models.AtlasImage', object);
|
|
86
|
-
break;
|
|
87
|
-
case Urso.types.objects.IMAGES_ANIMATION:
|
|
88
|
-
model = this.getInstance('Models.ImagesAnimation', object);
|
|
89
|
-
break;
|
|
90
|
-
case Urso.types.objects.MASK:
|
|
91
|
-
model = this.getInstance('Models.Mask', object);
|
|
92
|
-
break;
|
|
93
|
-
case Urso.types.objects.SPINE:
|
|
94
|
-
model = this.getInstance('Models.Spine', object);
|
|
95
|
-
break;
|
|
96
|
-
case Urso.types.objects.TEXT:
|
|
97
|
-
model = this.getInstance('Models.Text', object);
|
|
98
|
-
break;
|
|
99
|
-
case Urso.types.objects.GRAPHICS:
|
|
100
|
-
model = this.getInstance('Models.Graphics', object);
|
|
101
|
-
break;
|
|
102
95
|
case Urso.types.objects.HITAREA:
|
|
103
96
|
model = this.getInstance('Models.HitArea', object);
|
|
104
97
|
break;
|
|
105
|
-
case Urso.types.objects.
|
|
106
|
-
model = this.getInstance('Models.
|
|
107
|
-
break;
|
|
108
|
-
case Urso.types.objects.SLIDER:
|
|
109
|
-
model = this.getInstance('Models.Slider', object);
|
|
110
|
-
break;
|
|
111
|
-
case Urso.types.objects.TOGGLE:
|
|
112
|
-
model = this.getInstance('Models.Toggle', object);
|
|
113
|
-
break;
|
|
114
|
-
case Urso.types.objects.CHECKBOX:
|
|
115
|
-
model = this.getInstance('Models.Checkbox', object);
|
|
116
|
-
break;
|
|
117
|
-
case Urso.types.objects.SCROLLBOX:
|
|
118
|
-
model = this.getInstance('Models.Scrollbox', object);
|
|
98
|
+
case Urso.types.objects.IMAGES_ANIMATION:
|
|
99
|
+
model = this.getInstance('Models.ImagesAnimation', object);
|
|
119
100
|
break;
|
|
120
101
|
case Urso.types.objects.TEXTINPUT:
|
|
121
102
|
model = this.getInstance('Models.TextInput', object);
|
|
122
103
|
break;
|
|
104
|
+
|
|
123
105
|
default:
|
|
106
|
+
const objectName = Urso.helper.capitaliseFirstLetter(
|
|
107
|
+
this._objectsTypesFlipped[object.type].toLowerCase()
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
model = this.getInstance(`Models.${objectName}`, object);
|
|
124
111
|
break;
|
|
125
112
|
}
|
|
126
113
|
|
|
@@ -6,6 +6,7 @@ class ModulesObserverConfig {
|
|
|
6
6
|
MODULES_ASSETS_GROUP_LOADED: 'modules.assets.group.loaded',
|
|
7
7
|
MODULES_ASSETS_LOAD_PROGRESS: 'modules.assets.load.progress',
|
|
8
8
|
MODULES_ASSETS_LAZYLOAD_FINISHED: 'modules.assets.lazyLoad.finished',
|
|
9
|
+
MODULES_INSTANCES_MODES_CHANGED: 'modules.instances.modes.changed',
|
|
9
10
|
MODULES_OBJECTS_BUTTON_PRESS: 'modules.objects.button.press',
|
|
10
11
|
MODULES_OBJECTS_HIT_AREA_PRESS: 'modules.objects.hitArea.press',
|
|
11
12
|
MODULES_OBJECTS_SLIDER_SET_NEW_VALUE: 'modules.objects.slider.setNewValue',
|
|
@@ -4,6 +4,7 @@ class ModulesScenesResolutions {
|
|
|
4
4
|
this.singleton = true;
|
|
5
5
|
this._activeResolution = false; //object
|
|
6
6
|
this._templateSize = { orientation: 0, width: 0, height: 0 };
|
|
7
|
+
this._orientations = { landscape: 'landscape', portrait: 'portrait' }
|
|
7
8
|
this._currentOrientation = null;
|
|
8
9
|
|
|
9
10
|
this.refreshSceneSize = this.refreshSceneSize.bind(this);
|
|
@@ -40,9 +41,15 @@ class ModulesScenesResolutions {
|
|
|
40
41
|
this._templateSize = this._calculateTemplateSize(currentResolution);
|
|
41
42
|
this._applyResolutionToPixi(currentResolution);
|
|
42
43
|
|
|
44
|
+
console.log('[SCENE] New Orientation', orientation);
|
|
43
45
|
console.log('[SCENE] New Resolution', currentResolution, 'windowSize:', windowSize);
|
|
44
46
|
console.log('[SCENE] New Template Size', this._templateSize);
|
|
45
47
|
|
|
48
|
+
//update InstancesModes
|
|
49
|
+
Object.values(this._orientations).forEach((orientationValue) => Urso.removeInstancesMode(orientationValue + 'Orientation'));
|
|
50
|
+
Urso.addInstancesMode(orientation + 'Orientation');
|
|
51
|
+
|
|
52
|
+
//send new resolution event
|
|
46
53
|
this.emit(Urso.events.MODULES_SCENES_NEW_RESOLUTION, { resolution: currentResolution, template: this._templateSize });
|
|
47
54
|
|
|
48
55
|
if (this._currentOrientation !== this._templateSize.orientation) {
|
|
@@ -71,7 +78,7 @@ class ModulesScenesResolutions {
|
|
|
71
78
|
}
|
|
72
79
|
|
|
73
80
|
_getOrientation(windowSize) {
|
|
74
|
-
return windowSize.width > windowSize.height ?
|
|
81
|
+
return windowSize.width > windowSize.height ? this._orientations.landscape : this._orientations.portrait; //todo move to constants
|
|
75
82
|
}
|
|
76
83
|
|
|
77
84
|
_getResolutionConfig(windowSize) {
|
|
@@ -36,11 +36,10 @@ class ModulesStatesManagerController {
|
|
|
36
36
|
if (this._currentState) {
|
|
37
37
|
const currentState = this._configStates[this._currentState];
|
|
38
38
|
|
|
39
|
-
if (currentState.nextState) { //nextState: ["PICK_GAME2", "PICK_GAME1", "IDLE"]
|
|
40
|
-
|
|
39
|
+
if (this.checkStateGuard(this._currentState) && currentState.nextState) { //nextState: ["PICK_GAME2", "PICK_GAME1", "IDLE"]
|
|
41
40
|
for (const stateKey of currentState.nextState) {
|
|
42
41
|
if (this.checkStateGuard(stateKey)) {
|
|
43
|
-
nextIndex = statesArray.indexOf(stateKey);
|
|
42
|
+
nextIndex = statesArray.indexOf(stateKey) + 1;
|
|
44
43
|
|
|
45
44
|
if (nextIndex === -1) {
|
|
46
45
|
Urso.logger.error('ModulesStatesManagerController: nextState name error', stateKey);
|
|
@@ -18,10 +18,10 @@ class ModulesStatesManagerRace extends Action {
|
|
|
18
18
|
//can we start this action?
|
|
19
19
|
guard() {
|
|
20
20
|
for (let action of this._actions)
|
|
21
|
-
if (
|
|
22
|
-
return
|
|
21
|
+
if (action.guard())
|
|
22
|
+
return true;
|
|
23
23
|
|
|
24
|
-
return
|
|
24
|
+
return false;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
run(onFinishCallback) {
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
class ModulesLogicButtons {
|
|
2
|
-
constructor() {
|
|
3
|
-
this.DEFAULT_STATE_NAME = 'default'; //MOVE TO CFG
|
|
4
|
-
this._buttonsFactors = {};
|
|
5
|
-
this._cfg = null;
|
|
6
|
-
|
|
7
|
-
this._updateCfg();
|
|
8
|
-
|
|
9
|
-
if (!this._cfg || Urso.helper.arraysGetUniqElements(Object.keys(this._cfg.eventsCfg), Object.keys(this._cfg.buttonStates)).length > 0)
|
|
10
|
-
console.error('Modules.Logic.Buttons error: invalid Modules.Logic.Config.Buttons');
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
_updateCfg() {
|
|
14
|
-
this._cfg = this.getInstance('Config.Buttons');
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
_getButtonState(button, state) {
|
|
18
|
-
const buttonStates = this._cfg.buttonStates;
|
|
19
|
-
|
|
20
|
-
if (!buttonStates[button] || !buttonStates[button][state])
|
|
21
|
-
return false;
|
|
22
|
-
|
|
23
|
-
let states = buttonStates[button],
|
|
24
|
-
base = false,
|
|
25
|
-
k,
|
|
26
|
-
res = {};
|
|
27
|
-
|
|
28
|
-
if (state !== 'default') {
|
|
29
|
-
if (typeof states[state].base !== 'undefined')
|
|
30
|
-
base = states[state].base;
|
|
31
|
-
else
|
|
32
|
-
base = 'default';
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (base)
|
|
36
|
-
res = Urso.helper.objectClone(states[base]);
|
|
37
|
-
|
|
38
|
-
for (k in states[state])
|
|
39
|
-
res[k] = states[state][k];
|
|
40
|
-
|
|
41
|
-
return res;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
_eventHandler(button, event) {
|
|
45
|
-
//todo _eventHandler?
|
|
46
|
-
this._addEventsMode(button, event);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
_addEventsMode(button, event) {
|
|
50
|
-
if (!this._buttonsFactors[button])
|
|
51
|
-
this._buttonsFactors[button] = {};
|
|
52
|
-
|
|
53
|
-
//check removeEvents
|
|
54
|
-
if (event.removeEvents && event.removeEvents.length > 0) {
|
|
55
|
-
let i;
|
|
56
|
-
|
|
57
|
-
for (i = 0; i < event.removeEvents.length; i++)
|
|
58
|
-
if (this._buttonsFactors[button][event.removeEvents[i]])
|
|
59
|
-
delete this._buttonsFactors[button][event.removeEvents[i]];
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
//if state -> write
|
|
63
|
-
if (event.state && !this._buttonsFactors[button][event.id])
|
|
64
|
-
this._buttonsFactors[button][event.id] = event;
|
|
65
|
-
|
|
66
|
-
//calc current state
|
|
67
|
-
let cur = false;
|
|
68
|
-
|
|
69
|
-
if (Object.keys(this._buttonsFactors[button]).length > 0)
|
|
70
|
-
cur = Object.values(this._buttonsFactors[button]).reduce(function (prev, current) {
|
|
71
|
-
return (prev.priority > current.priority) ? prev : current;
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
const state = this._getButtonState(button, (cur && cur.state) || this.DEFAULT_STATE_NAME);
|
|
75
|
-
this._changeButtonState(button, state);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
beforeUpdateHandler() { };
|
|
79
|
-
afterUpdateHandler() { };
|
|
80
|
-
|
|
81
|
-
_changeButtonState(button, params) {
|
|
82
|
-
console.log(100, button, params)
|
|
83
|
-
params.disableFrame = params.frames.disableFrame;
|
|
84
|
-
|
|
85
|
-
const buttonsData = {};
|
|
86
|
-
buttonsData[button] = params;
|
|
87
|
-
|
|
88
|
-
this.beforeUpdateHandler(params);
|
|
89
|
-
this.emit('buttons.changeData', buttonsData);
|
|
90
|
-
this.emit('button.setFrames', buttonsData);
|
|
91
|
-
this.afterUpdateHandler(params);
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
_subscribeButtonToEvents(buttonKey, buttonSubscribeCfg) {
|
|
95
|
-
for (let i = 0; i < buttonSubscribeCfg.length; i++) {
|
|
96
|
-
const { event } = buttonSubscribeCfg[i];
|
|
97
|
-
this.addListener(event, () => this._eventHandler(buttonKey, buttonSubscribeCfg[i]), true);
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
_subscribeButtonsToEvents() {
|
|
102
|
-
for (let k in this._cfg.eventsCfg) {
|
|
103
|
-
this._subscribeButtonToEvents(k, this._cfg.eventsCfg[k])
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
_pressHandler(btn = {}) {
|
|
108
|
-
const state = this._getButtonState(btn.name, this.DEFAULT_STATE_NAME);
|
|
109
|
-
|
|
110
|
-
if (state && state.callback)
|
|
111
|
-
state.callback();
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
_subscribe() {
|
|
115
|
-
this._subscribeButtonsToEvents();
|
|
116
|
-
this.addListener(Urso.events.MODULES_OBJECTS_BUTTON_PRESS, this._pressHandler.bind(this), true);
|
|
117
|
-
};
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
module.exports = ModulesLogicButtons;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
class ModulesLogicConfigButtons {
|
|
2
|
-
constructor(){
|
|
3
|
-
this.singleton = true;
|
|
4
|
-
this.buttonStates = this.setButtonStates();
|
|
5
|
-
this.eventsCfgBlank = this.setEventsCfgBlanks();
|
|
6
|
-
this.eventsCfg = this.setEventsCfg();
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
setButtonStates(){
|
|
10
|
-
return {
|
|
11
|
-
spin: {
|
|
12
|
-
default: { //base
|
|
13
|
-
'title': '',
|
|
14
|
-
'callback': function () {
|
|
15
|
-
this.emit('slotMachine.spinCommand');
|
|
16
|
-
},
|
|
17
|
-
'enabled': true,
|
|
18
|
-
'visible': true
|
|
19
|
-
},
|
|
20
|
-
//default extend
|
|
21
|
-
inactive: {
|
|
22
|
-
'enabled': false
|
|
23
|
-
},
|
|
24
|
-
stop: {
|
|
25
|
-
'callback': function () {
|
|
26
|
-
this.emit('slotMachine.stopCommand');
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
stopInactive: {
|
|
30
|
-
'base': 'stop',
|
|
31
|
-
'enabled': false
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
setEventsCfgBlanks(){
|
|
38
|
-
return {
|
|
39
|
-
globalUiGroup: [
|
|
40
|
-
{id: 1, event: 'Transport.close', state: false, priority: 100, removeEvents: [10, 11, 12, 13]},
|
|
41
|
-
{id: 2, event: 'freespinsStart', state: 'inactive', priority: 10},
|
|
42
|
-
{id: 3, event: 'freespinsStop', state: false, priority: 10, removeEvents: [1]}
|
|
43
|
-
]
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
setEventsCfg(){
|
|
48
|
-
return {
|
|
49
|
-
spin: [
|
|
50
|
-
{id: 1, event: 'Transport.close', state: false, priority: 100, removeEvents: [10, 11, 12, 13]},
|
|
51
|
-
{id: 10, event: 'freespinsStart', state: 'inactive', priority: 40},
|
|
52
|
-
{id: 11, event: 'freespinsStop', state: false, priority: 40, removeEvents: [10]},
|
|
53
|
-
{id: 12, event: 'SpinStart', state: 'inactive', priority: 20},
|
|
54
|
-
{id: 13, event: 'SpinResponce', state: 'stop', priority: 20},
|
|
55
|
-
{id: 14, event: 'StopPress', state: 'stopInactive', priority: 20},
|
|
56
|
-
{id: 15, event: 'SpinStop', state: false, priority: 20, removeEvents: [12]}
|
|
57
|
-
]
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
module.exports = ModulesLogicConfigButtons;
|