@urso/core 0.6.16-dev → 0.6.16
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/.babelrc +11 -11
- package/LICENSE +20 -20
- package/README.md +227 -227
- package/build/js/index.js +1 -1
- package/build/js/index.js.LICENSE.txt +38 -270
- package/package.json +52 -52
- package/src/js/app.js +79 -79
- package/src/js/components/_info.js +11 -11
- package/src/js/components/base/_info.js +3 -3
- package/src/js/components/base/controller.js +78 -78
- package/src/js/components/debug/_info.js +7 -7
- package/src/js/components/debug/controller.js +38 -38
- package/src/js/components/debug/coords.js +23 -23
- package/src/js/components/debug/fps.js +36 -36
- package/src/js/components/debug/template.js +55 -55
- package/src/js/components/debug/timescale.js +60 -60
- package/src/js/components/deviceRotate/_info.js +3 -3
- package/src/js/components/deviceRotate/controller.js +86 -86
- package/src/js/components/fullscreen/_info.js +6 -6
- package/src/js/components/fullscreen/android.js +104 -104
- package/src/js/components/fullscreen/controller.js +76 -76
- package/src/js/components/fullscreen/desktop.js +49 -49
- package/src/js/components/fullscreen/ios.js +115 -115
- package/src/js/components/layersSwitcher/_info.js +4 -4
- package/src/js/components/layersSwitcher/config.js +26 -26
- package/src/js/components/layersSwitcher/controller.js +34 -34
- package/src/js/components/loader/_info.js +4 -4
- package/src/js/components/loader/controller.js +65 -65
- package/src/js/components/loader/template.js +70 -70
- package/src/js/components/soundInitialPopup/_info.js +3 -3
- package/src/js/components/soundInitialPopup/controller.js +42 -42
- package/src/js/components/soundInitialPopup/template.js +109 -109
- package/src/js/components/stateDriven/_info.js +3 -3
- package/src/js/components/stateDriven/controller.js +118 -118
- package/src/js/config/load.js +5 -5
- package/src/js/config/main.js +16 -16
- package/src/js/extra/_info.js +26 -26
- package/src/js/extra/browserEvents.js +51 -51
- package/src/js/extra/pixiPatch.js +150 -150
- package/src/js/extra/setTimeout.js +7 -7
- package/src/js/index.js +8 -8
- package/src/js/lib/_info.js +13 -13
- package/src/js/lib/cache.js +105 -105
- package/src/js/lib/composition.js +85 -85
- package/src/js/lib/device.js +1286 -1286
- package/src/js/lib/helper.js +556 -556
- package/src/js/lib/loader.js +136 -136
- package/src/js/lib/localData.js +15 -15
- package/src/js/lib/logger.js +69 -69
- package/src/js/lib/math.js +35 -35
- package/src/js/lib/objectPool.js +203 -203
- package/src/js/lib/time.js +18 -18
- package/src/js/lib/tween.js +147 -147
- package/src/js/modules/_info.js +12 -12
- package/src/js/modules/assets/_info.js +7 -7
- package/src/js/modules/assets/baseModel.js +20 -20
- package/src/js/modules/assets/config.js +37 -37
- package/src/js/modules/assets/controller.js +46 -46
- package/src/js/modules/assets/models/_info.js +11 -11
- package/src/js/modules/assets/models/atlas.js +8 -8
- package/src/js/modules/assets/models/audiosprite.js +27 -27
- package/src/js/modules/assets/models/bitmapFont.js +8 -8
- package/src/js/modules/assets/models/container.js +16 -16
- package/src/js/modules/assets/models/font.js +8 -8
- package/src/js/modules/assets/models/image.js +15 -15
- package/src/js/modules/assets/models/json.js +8 -8
- package/src/js/modules/assets/models/sound.js +14 -14
- package/src/js/modules/assets/models/spine.js +14 -14
- package/src/js/modules/assets/service.js +366 -366
- package/src/js/modules/i18n/_info.js +4 -4
- package/src/js/modules/i18n/config.js +17 -17
- package/src/js/modules/i18n/controller.js +79 -79
- package/src/js/modules/instances/_info.js +3 -3
- package/src/js/modules/instances/controller.js +357 -357
- package/src/js/modules/logic/_info.js +4 -4
- package/src/js/modules/logic/config/_info.js +2 -2
- package/src/js/modules/logic/config/sounds.js +23 -23
- package/src/js/modules/logic/controller.js +48 -48
- package/src/js/modules/logic/sounds.js +103 -103
- package/src/js/modules/objects/_info.js +13 -13
- package/src/js/modules/objects/baseModel.js +200 -200
- package/src/js/modules/objects/cache.js +99 -99
- package/src/js/modules/objects/controller.js +131 -131
- package/src/js/modules/objects/find.js +58 -58
- package/src/js/modules/objects/models/_info.js +27 -27
- package/src/js/modules/objects/models/atlasImage.js +50 -50
- package/src/js/modules/objects/models/bitmapText.js +37 -37
- package/src/js/modules/objects/models/button.js +189 -189
- package/src/js/modules/objects/models/buttonComposite.js +35 -35
- package/src/js/modules/objects/models/checkbox.js +96 -96
- package/src/js/modules/objects/models/collection.js +54 -54
- package/src/js/modules/objects/models/component.js +46 -46
- package/src/js/modules/objects/models/container.js +19 -19
- package/src/js/modules/objects/models/dragContainer.js +667 -667
- package/src/js/modules/objects/models/emitter.js +67 -67
- package/src/js/modules/objects/models/emitterFx.js +99 -99
- package/src/js/modules/objects/models/graphics.js +38 -38
- package/src/js/modules/objects/models/group.js +19 -19
- package/src/js/modules/objects/models/hitArea.js +104 -104
- package/src/js/modules/objects/models/image.js +34 -34
- package/src/js/modules/objects/models/imagesAnimation.js +113 -113
- package/src/js/modules/objects/models/mask.js +38 -38
- package/src/js/modules/objects/models/nineSlicePlane.js +30 -30
- package/src/js/modules/objects/models/scrollbox.js +64 -64
- package/src/js/modules/objects/models/slider.js +253 -253
- package/src/js/modules/objects/models/spine.js +296 -287
- package/src/js/modules/objects/models/text.js +59 -59
- package/src/js/modules/objects/models/textInput.js +66 -66
- package/src/js/modules/objects/models/toggle.js +180 -180
- package/src/js/modules/objects/models/world.js +19 -19
- package/src/js/modules/objects/propertyAdapter.js +588 -587
- package/src/js/modules/objects/proxy.js +294 -294
- package/src/js/modules/objects/selector.js +136 -136
- package/src/js/modules/objects/service.js +242 -242
- package/src/js/modules/objects/styles.js +210 -210
- package/src/js/modules/observer/_info.js +4 -4
- package/src/js/modules/observer/controller.js +99 -99
- package/src/js/modules/observer/events.js +52 -52
- package/src/js/modules/scenes/_info.js +8 -8
- package/src/js/modules/scenes/controller.js +119 -119
- package/src/js/modules/scenes/model.js +28 -28
- package/src/js/modules/scenes/pixiWrapper.js +336 -336
- package/src/js/modules/scenes/resolutions.js +173 -173
- package/src/js/modules/scenes/resolutionsConfig.js +73 -73
- package/src/js/modules/scenes/service.js +142 -142
- package/src/js/modules/soundManager/_info.js +3 -3
- package/src/js/modules/soundManager/controller.js +100 -100
- package/src/js/modules/soundManager/soundSprite.js +251 -251
- package/src/js/modules/statesManager/_info.js +12 -12
- package/src/js/modules/statesManager/action.js +68 -68
- package/src/js/modules/statesManager/actions/_info.js +3 -3
- package/src/js/modules/statesManager/all.js +23 -23
- package/src/js/modules/statesManager/configStates.js +71 -71
- package/src/js/modules/statesManager/controller.js +170 -170
- package/src/js/modules/statesManager/functionsStorage.js +82 -82
- package/src/js/modules/statesManager/helper.js +27 -27
- package/src/js/modules/statesManager/race.js +75 -75
- package/src/js/modules/statesManager/sequence.js +47 -47
- package/src/js/modules/template/_info.js +6 -6
- package/src/js/modules/template/controller.js +28 -28
- package/src/js/modules/template/model.js +11 -11
- package/src/js/modules/template/service.js +137 -137
- package/src/js/modules/template/types.js +46 -46
- package/src/js/modules/transport/_info.js +8 -8
- package/src/js/modules/transport/baseConnectionType.js +24 -24
- package/src/js/modules/transport/config.js +13 -13
- package/src/js/modules/transport/connectionTypes/_info.js +3 -3
- package/src/js/modules/transport/connectionTypes/websocket.js +74 -74
- package/src/js/modules/transport/connectionTypes/xhr.js +44 -44
- package/src/js/modules/transport/controller.js +48 -48
- package/src/js/modules/transport/decorator.js +17 -17
- package/src/js/modules/transport/service.js +153 -153
- package/src/js/templates/_info.js +4 -4
- package/src/js/templates/groups/_info.js +1 -1
- package/src/js/templates/scenes/_info.js +1 -1
- package/webpack.config.js +47 -47
|
@@ -1,588 +1,589 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* adapter Urso to Pixi objects
|
|
3
|
-
*/
|
|
4
|
-
class PropertyAdapter {
|
|
5
|
-
|
|
6
|
-
constructor() {
|
|
7
|
-
this.singleton = true;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* dependencies, functions to handle changing property
|
|
11
|
-
*/
|
|
12
|
-
this._dependencies = {
|
|
13
|
-
'x': this._updateHorizontal.bind(this),
|
|
14
|
-
'y': this._updateVertical.bind(this),
|
|
15
|
-
'anchorX': this._updateHorizontal.bind(this),
|
|
16
|
-
'anchorY': this._updateVertical.bind(this),
|
|
17
|
-
'scaleX': this._adaptScaleX.bind(this),
|
|
18
|
-
'scaleY': this._adaptScaleY.bind(this),
|
|
19
|
-
'alignX': this._updateHorizontal.bind(this),
|
|
20
|
-
'alignY': this._updateVertical.bind(this),
|
|
21
|
-
'width': this._updateHorizontal.bind(this),
|
|
22
|
-
'height': this._updateVertical.bind(this),
|
|
23
|
-
'angle': this._updateAngle.bind(this),
|
|
24
|
-
'stretchingType': this._adaptStretchingType.bind(this), //todo check on parent change
|
|
25
|
-
'parent': this._parentChangeHandler.bind(this)
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* functions to handle changing parent property
|
|
30
|
-
*/
|
|
31
|
-
this._parentToChildDependencies = {
|
|
32
|
-
'width': { children: ['width'] },
|
|
33
|
-
'height': { children: ['height'] },
|
|
34
|
-
'anchorX': { children: ['x'] },
|
|
35
|
-
'anchorY': { children: ['y'] },
|
|
36
|
-
'stretchingType': { children: ['width', 'height'] }
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* parent types list
|
|
41
|
-
*/
|
|
42
|
-
this._parentTypes = [
|
|
43
|
-
Urso.types.objects.COMPONENT,
|
|
44
|
-
Urso.types.objects.CONTAINER,
|
|
45
|
-
Urso.types.objects.DRAGCONTAINER,
|
|
46
|
-
Urso.types.objects.GROUP,
|
|
47
|
-
Urso.types.objects.SCROLLBOX,
|
|
48
|
-
Urso.types.objects.SLIDER,
|
|
49
|
-
Urso.types.objects.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
Urso.types.objects.
|
|
58
|
-
Urso.types.objects.
|
|
59
|
-
Urso.types.objects.
|
|
60
|
-
Urso.types.objects.
|
|
61
|
-
Urso.types.objects.
|
|
62
|
-
Urso.types.objects.
|
|
63
|
-
Urso.types.objects.
|
|
64
|
-
Urso.types.objects.
|
|
65
|
-
Urso.types.objects.
|
|
66
|
-
Urso.types.objects.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
*
|
|
73
|
-
* @
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
*
|
|
82
|
-
* @param {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
this.
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
*
|
|
92
|
-
* @param {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
*
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
x
|
|
106
|
-
x += this.
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
*
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
this.
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
*
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
y
|
|
134
|
-
y += this.
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
*
|
|
143
|
-
* @param {
|
|
144
|
-
* @param {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
*
|
|
153
|
-
* @param {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
*
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
*
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
pixiObject
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
*
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
pixiObject
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
*
|
|
257
|
-
* @param {
|
|
258
|
-
* @
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
const
|
|
263
|
-
const
|
|
264
|
-
const
|
|
265
|
-
const
|
|
266
|
-
const
|
|
267
|
-
const
|
|
268
|
-
const
|
|
269
|
-
const
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
*
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
pixiObject
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
*
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
pixiObject
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
*
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
*
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
*
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
pixiObject
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
*
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
pixiObject
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
*
|
|
408
|
-
* @
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
*
|
|
417
|
-
* @
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
*
|
|
426
|
-
* @
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
*
|
|
435
|
-
* @
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
*
|
|
444
|
-
* @param {
|
|
445
|
-
* @param {String}
|
|
446
|
-
* @
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
*
|
|
471
|
-
* @param {
|
|
472
|
-
* @
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
*
|
|
482
|
-
* @
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
*
|
|
491
|
-
* @
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
*
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
*
|
|
526
|
-
* @param {
|
|
527
|
-
* @param {
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
*
|
|
537
|
-
* @param {Object}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
*
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
const
|
|
558
|
-
const
|
|
559
|
-
const
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
const
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
*
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
const
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
*
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
const
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
}
|
|
587
|
-
|
|
1
|
+
/**
|
|
2
|
+
* adapter Urso to Pixi objects
|
|
3
|
+
*/
|
|
4
|
+
class PropertyAdapter {
|
|
5
|
+
|
|
6
|
+
constructor() {
|
|
7
|
+
this.singleton = true;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* dependencies, functions to handle changing property
|
|
11
|
+
*/
|
|
12
|
+
this._dependencies = {
|
|
13
|
+
'x': this._updateHorizontal.bind(this),
|
|
14
|
+
'y': this._updateVertical.bind(this),
|
|
15
|
+
'anchorX': this._updateHorizontal.bind(this),
|
|
16
|
+
'anchorY': this._updateVertical.bind(this),
|
|
17
|
+
'scaleX': this._adaptScaleX.bind(this),
|
|
18
|
+
'scaleY': this._adaptScaleY.bind(this),
|
|
19
|
+
'alignX': this._updateHorizontal.bind(this),
|
|
20
|
+
'alignY': this._updateVertical.bind(this),
|
|
21
|
+
'width': this._updateHorizontal.bind(this),
|
|
22
|
+
'height': this._updateVertical.bind(this),
|
|
23
|
+
'angle': this._updateAngle.bind(this),
|
|
24
|
+
'stretchingType': this._adaptStretchingType.bind(this), //todo check on parent change
|
|
25
|
+
'parent': this._parentChangeHandler.bind(this)
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* functions to handle changing parent property
|
|
30
|
+
*/
|
|
31
|
+
this._parentToChildDependencies = {
|
|
32
|
+
'width': { children: ['width'] },
|
|
33
|
+
'height': { children: ['height'] },
|
|
34
|
+
'anchorX': { children: ['x'] },
|
|
35
|
+
'anchorY': { children: ['y'] },
|
|
36
|
+
'stretchingType': { children: ['width', 'height'] }
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* parent types list
|
|
41
|
+
*/
|
|
42
|
+
this._parentTypes = [
|
|
43
|
+
Urso.types.objects.COMPONENT,
|
|
44
|
+
Urso.types.objects.CONTAINER,
|
|
45
|
+
Urso.types.objects.DRAGCONTAINER,
|
|
46
|
+
Urso.types.objects.GROUP,
|
|
47
|
+
Urso.types.objects.SCROLLBOX,
|
|
48
|
+
Urso.types.objects.SLIDER,
|
|
49
|
+
Urso.types.objects.SPINE,
|
|
50
|
+
Urso.types.objects.WORLD
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* types without ahchor list
|
|
55
|
+
*/
|
|
56
|
+
this._typesWithoutAnchor = [
|
|
57
|
+
Urso.types.objects.CHECKBOX,
|
|
58
|
+
Urso.types.objects.EMITTER,
|
|
59
|
+
Urso.types.objects.EMITTERFX,
|
|
60
|
+
Urso.types.objects.GRAPHICS,
|
|
61
|
+
Urso.types.objects.HITAREA,
|
|
62
|
+
Urso.types.objects.MASK,
|
|
63
|
+
Urso.types.objects.NINESLICEPLANE,
|
|
64
|
+
Urso.types.objects.SLIDER,
|
|
65
|
+
Urso.types.objects.SPINE,
|
|
66
|
+
Urso.types.objects.TEXTINPUT,
|
|
67
|
+
Urso.types.objects.WORLD
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* check is adaptive property
|
|
73
|
+
* @param {String} property
|
|
74
|
+
* @returns {Boolean}
|
|
75
|
+
*/
|
|
76
|
+
isAdaptiveProperty(property) {
|
|
77
|
+
return Object.keys(this._dependencies).includes(property);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* property change handler (main function)
|
|
82
|
+
* @param {Object} object
|
|
83
|
+
* @param {String} propertyName
|
|
84
|
+
*/
|
|
85
|
+
propertyChangeHandler(object, propertyName) {
|
|
86
|
+
this._adaptProperty(object, propertyName);
|
|
87
|
+
this._adaptChildProperties(object, propertyName);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* adapt property (launch handler changing property)
|
|
92
|
+
* @param {Object} object
|
|
93
|
+
* @param {String} propertyName
|
|
94
|
+
*/
|
|
95
|
+
_adaptProperty(object, propertyName) {
|
|
96
|
+
if (this._dependencies[propertyName])
|
|
97
|
+
this._dependencies[propertyName](object);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* main function to calculate x and width
|
|
102
|
+
* @param {Object} object
|
|
103
|
+
*/
|
|
104
|
+
_updateHorizontal(object) {
|
|
105
|
+
let x = this._getXAsNumber(object);
|
|
106
|
+
x += this._adaptAnchorX(object);
|
|
107
|
+
x += this._adaptAlignX(object);
|
|
108
|
+
object._baseObject.x = x;
|
|
109
|
+
|
|
110
|
+
this._adaptWidth(object);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* main function to calculate angle
|
|
115
|
+
* @param {Object} object
|
|
116
|
+
*/
|
|
117
|
+
_updateAngle(object) {
|
|
118
|
+
object._baseObject.angle = object.angle;
|
|
119
|
+
|
|
120
|
+
if (!this._canBeParent(object)) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
this._updateHorizontal(object);
|
|
125
|
+
this._updateVertical(object);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* main function to calculate y and height
|
|
130
|
+
* @param {Object} object
|
|
131
|
+
*/
|
|
132
|
+
_updateVertical(object) {
|
|
133
|
+
let y = this._getYAsNumber(object);
|
|
134
|
+
y += this._adaptAnchorY(object);
|
|
135
|
+
y += this._adaptAlignY(object);
|
|
136
|
+
object._baseObject.y = y;
|
|
137
|
+
|
|
138
|
+
this._adaptHeight(object);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* set property value without adaptation
|
|
143
|
+
* @param {Object} object
|
|
144
|
+
* @param {String} propertyName
|
|
145
|
+
* @param {mixed} value
|
|
146
|
+
*/
|
|
147
|
+
_setPropertyWithoutAdaption(object, propertyName, value) { //in error case
|
|
148
|
+
object[propertyName] = value;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* adapt child properties if parent properties was changed
|
|
153
|
+
* @param {Object} object
|
|
154
|
+
* @param {String} propertyName
|
|
155
|
+
*/
|
|
156
|
+
_adaptChildProperties(object, propertyName) {
|
|
157
|
+
const { children } = this._parentToChildDependencies[propertyName] || {};
|
|
158
|
+
const objectHasChildren = this._canBeParent(object) && object.hasOwnProperty('contents');
|
|
159
|
+
|
|
160
|
+
if (!children || !objectHasChildren)
|
|
161
|
+
return;
|
|
162
|
+
|
|
163
|
+
for (let dependency of children)
|
|
164
|
+
for (let child of object.contents)
|
|
165
|
+
this.propertyChangeHandler(child, dependency);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* main handler when new parent was setted
|
|
170
|
+
* @param {Object} child
|
|
171
|
+
*/
|
|
172
|
+
_parentChangeHandler(child) {
|
|
173
|
+
if (child.parent == null)
|
|
174
|
+
return;
|
|
175
|
+
|
|
176
|
+
for (let propertyName of this._propertiesDependentOnParent())
|
|
177
|
+
this.propertyChangeHandler(child, propertyName);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* get array of properties dependent on parent
|
|
182
|
+
* //todo cache them and get just one time
|
|
183
|
+
* @returns {Array}
|
|
184
|
+
*/
|
|
185
|
+
_propertiesDependentOnParent() {
|
|
186
|
+
const properties = [];
|
|
187
|
+
|
|
188
|
+
for (let propertyName of Object.keys(this._parentToChildDependencies)) {
|
|
189
|
+
const { children } = this._parentToChildDependencies[propertyName];
|
|
190
|
+
|
|
191
|
+
if (children)
|
|
192
|
+
for (let dependency of children)
|
|
193
|
+
properties.push(dependency);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return properties;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* adapt anchorX
|
|
201
|
+
* @param {Object} object
|
|
202
|
+
*/
|
|
203
|
+
_adaptAnchorX(object) {
|
|
204
|
+
if (typeof object.anchorX !== 'number' || object.anchorX < 0 || object.anchorX > 1)
|
|
205
|
+
Urso.logger.error('AnchorX value is not valid!', object);
|
|
206
|
+
|
|
207
|
+
if (this._canBeParent(object) && !this._typesWithoutAnchor.includes(object.type)) { //parent types
|
|
208
|
+
if (object.anchorX === 0)
|
|
209
|
+
return 0;
|
|
210
|
+
|
|
211
|
+
if (object.angle) {
|
|
212
|
+
return this._getAnchorOffsetByAngle(object, 'x');
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const objectWidth = this._getWidthAsNumber(object);
|
|
216
|
+
return - objectWidth * object.anchorX;
|
|
217
|
+
} else if (!this._typesWithoutAnchor.includes(object.type)) { //regular type and not a type without anchor
|
|
218
|
+
const pixiObject = object._baseObject;
|
|
219
|
+
pixiObject.anchor.x = object.anchorX;
|
|
220
|
+
} else {
|
|
221
|
+
Urso.logger.warn(); ('AnchorX value cannot be used with this object type !', object);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return 0;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* adapt anchorY
|
|
229
|
+
* @param {Object} object
|
|
230
|
+
*/
|
|
231
|
+
_adaptAnchorY(object) {
|
|
232
|
+
if (typeof object.anchorY !== 'number' || object.anchorY < 0 || object.anchorY > 1)
|
|
233
|
+
Urso.logger.error('AnchorY value is not valid!', object);
|
|
234
|
+
|
|
235
|
+
if (this._canBeParent(object) && !this._typesWithoutAnchor.includes(object.type)) { //parent types
|
|
236
|
+
if (object.anchorY === 0)
|
|
237
|
+
return 0;
|
|
238
|
+
|
|
239
|
+
if (object.angle) {
|
|
240
|
+
return this._getAnchorOffsetByAngle(object, 'y');
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const objectHeight = this._getHeightAsNumber(object);
|
|
244
|
+
return - objectHeight * object.anchorY;
|
|
245
|
+
} else if (!this._typesWithoutAnchor.includes(object.type)) { //regular type and not a type without anchor
|
|
246
|
+
const pixiObject = object._baseObject;
|
|
247
|
+
pixiObject.anchor.y = object.anchorY;
|
|
248
|
+
} else {
|
|
249
|
+
Urso.logger.warn(); ('AnchorY value cannot be used with this object type !', object);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return 0;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* get anchor offset by angle for parent types
|
|
257
|
+
* @param {Object} object
|
|
258
|
+
* @param {String} side - x or y
|
|
259
|
+
* @returns {Number}
|
|
260
|
+
*/
|
|
261
|
+
_getAnchorOffsetByAngle(object, side) { //side can be x or y
|
|
262
|
+
const objectWidth = this._getWidthAsNumber(object);
|
|
263
|
+
const objectHeight = this._getHeightAsNumber(object);
|
|
264
|
+
const xCatet = (objectWidth * object.anchorX);
|
|
265
|
+
const yCatet = (objectHeight * object.anchorY);
|
|
266
|
+
const offsetRadius = Math.sqrt(Math.pow(xCatet, 2) + Math.pow(yCatet, 2));
|
|
267
|
+
const angleRadian = Math.atan(xCatet / yCatet); //todo or yCatet/xCatet ?
|
|
268
|
+
const angle = Urso.helper.getAngle(angleRadian);
|
|
269
|
+
const offsetAngle = object.angle + angle;
|
|
270
|
+
const offsetFunction = side === 'x' ? 'cos' : 'sin';
|
|
271
|
+
const angleOffset = - offsetRadius * Math[offsetFunction](Urso.helper.getRadian(offsetAngle));
|
|
272
|
+
|
|
273
|
+
return angleOffset;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* adapt scaleX
|
|
278
|
+
* @param {Object} object
|
|
279
|
+
*/
|
|
280
|
+
_adaptScaleX(object) {
|
|
281
|
+
if (object.scaleX !== 1 && typeof object.width !== 'boolean') {
|
|
282
|
+
Urso.logger.error('ScaleX value cannot be set. Width already used!!');
|
|
283
|
+
this._setPropertyWithoutAdaption(object, 'scaleX', 1);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (typeof object.scaleX === 'number') {
|
|
288
|
+
const pixiObject = object._baseObject;
|
|
289
|
+
pixiObject.scale.x = object.scaleX;
|
|
290
|
+
} else
|
|
291
|
+
Urso.logger.error('ScaleX value is not valid!');
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* adapt scaleY
|
|
296
|
+
* @param {Object} object
|
|
297
|
+
*/
|
|
298
|
+
_adaptScaleY(object) {
|
|
299
|
+
if (object.scaleY !== 1 && typeof object.height !== 'boolean') {
|
|
300
|
+
Urso.logger.error('ScaleY value cannot be set. Height already used!!');
|
|
301
|
+
this._setPropertyWithoutAdaption(object, 'scaleY', 1);
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (typeof object.scaleY === 'number' && object.scaleY >= 0) { // TODO: CHECK SCALE CAN BE NEGATIVE
|
|
306
|
+
const pixiObject = object._baseObject;
|
|
307
|
+
pixiObject.scale.y = object.scaleY;
|
|
308
|
+
} else
|
|
309
|
+
Urso.logger.error('ScaleY value is not valid!');
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* adapt alignX
|
|
314
|
+
* @param {Object} object
|
|
315
|
+
*/
|
|
316
|
+
_adaptAlignX(object) {
|
|
317
|
+
if (typeof object.alignX !== 'string') {
|
|
318
|
+
Urso.logger.error('AlignX value is not string!');
|
|
319
|
+
return 0;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
switch (object.alignX) {
|
|
323
|
+
case 'left':
|
|
324
|
+
return 0;
|
|
325
|
+
case 'right':
|
|
326
|
+
return object.parent ? this._getWidthAsNumber(object.parent) : 0; //parentWidth
|
|
327
|
+
case 'center':
|
|
328
|
+
const parentWidth = object.parent ? this._getWidthAsNumber(object.parent) : 0;
|
|
329
|
+
return parentWidth / 2;
|
|
330
|
+
default:
|
|
331
|
+
Urso.logger.error('AlignX string is not valid!');
|
|
332
|
+
return 0;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* adapt alignY
|
|
338
|
+
* @param {Object} object
|
|
339
|
+
*/
|
|
340
|
+
_adaptAlignY(object) {
|
|
341
|
+
if (typeof object.alignY !== 'string') {
|
|
342
|
+
Urso.logger.error('AlignY value is not string!');
|
|
343
|
+
return 0;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
switch (object.alignY) {
|
|
347
|
+
case 'top':
|
|
348
|
+
return 0;
|
|
349
|
+
case 'bottom':
|
|
350
|
+
return object.parent ? this._getHeightAsNumber(object.parent) : 0; //parentHeight
|
|
351
|
+
case 'center':
|
|
352
|
+
const parentHeight = object.parent ? this._getHeightAsNumber(object.parent) : 0;
|
|
353
|
+
return parentHeight / 2;
|
|
354
|
+
default:
|
|
355
|
+
Urso.logger.error('AlignY string is not valid!');
|
|
356
|
+
return 0;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* adapt width
|
|
362
|
+
* @param {Object} object
|
|
363
|
+
*/
|
|
364
|
+
_adaptWidth(object) {
|
|
365
|
+
if (typeof object.width !== 'boolean' && object.scaleX !== 1) {
|
|
366
|
+
Urso.logger.error('Width value cannot be set. ScaleX already used!!', object);
|
|
367
|
+
this._setPropertyWithoutAdaption(object, 'width', false);
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
if (!object.width)
|
|
372
|
+
return;
|
|
373
|
+
|
|
374
|
+
if (!this._isValueANumberOrPercentsString(object.width))
|
|
375
|
+
return Urso.logger.error('Width value is not valid!!');
|
|
376
|
+
|
|
377
|
+
if (!this._canBeParent(object)) {
|
|
378
|
+
const pixiObject = object._baseObject;
|
|
379
|
+
pixiObject.width = this._getWidthAsNumber(object);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* adapt height
|
|
385
|
+
* @param {Object} object
|
|
386
|
+
*/
|
|
387
|
+
_adaptHeight(object) {
|
|
388
|
+
if (typeof object.height !== 'boolean' && object.scaleY !== 1) {
|
|
389
|
+
Urso.logger.error('Height value cannot be set. ScaleY already used!!', object);
|
|
390
|
+
this._setPropertyWithoutAdaption(object, 'height', false);
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
if (!object.height)
|
|
395
|
+
return;
|
|
396
|
+
|
|
397
|
+
if (!this._isValueANumberOrPercentsString(object.height))
|
|
398
|
+
return Urso.logger.error('Height value not valid!');
|
|
399
|
+
|
|
400
|
+
if (!this._canBeParent(object)) {
|
|
401
|
+
const pixiObject = object._baseObject;
|
|
402
|
+
pixiObject.height = this._getHeightAsNumber(object);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* get x number value
|
|
408
|
+
* @param {Object} object
|
|
409
|
+
* @returns {Number}
|
|
410
|
+
*/
|
|
411
|
+
_getXAsNumber(object) {
|
|
412
|
+
return this._getPropertyAsNumber(object, 'x', 'width');
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* get y number value
|
|
417
|
+
* @param {Object} object
|
|
418
|
+
* @returns {Number}
|
|
419
|
+
*/
|
|
420
|
+
_getYAsNumber(object) {
|
|
421
|
+
return this._getPropertyAsNumber(object, 'y', 'height');
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* get width number value
|
|
426
|
+
* @param {Object} object
|
|
427
|
+
* @returns {Number}
|
|
428
|
+
*/
|
|
429
|
+
_getWidthAsNumber(object) {
|
|
430
|
+
return this._getPropertyAsNumber(object, 'width', 'width');
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* get height number value
|
|
435
|
+
* @param {Object} object
|
|
436
|
+
* @returns {Number}
|
|
437
|
+
*/
|
|
438
|
+
_getHeightAsNumber(object) {
|
|
439
|
+
return this._getPropertyAsNumber(object, 'height', 'height');
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* get x, y, width or height number value
|
|
444
|
+
* @param {Object} object
|
|
445
|
+
* @param {String} propertyName
|
|
446
|
+
* @param {String} parentPropertyName
|
|
447
|
+
* @returns {Number}
|
|
448
|
+
*/
|
|
449
|
+
_getPropertyAsNumber(object, propertyName, parentPropertyName) {
|
|
450
|
+
const propType = typeof object[propertyName];
|
|
451
|
+
|
|
452
|
+
switch (propType) {
|
|
453
|
+
case 'number':
|
|
454
|
+
return object[propertyName];
|
|
455
|
+
|
|
456
|
+
case 'string':
|
|
457
|
+
const parentValue = this._getPropertyAsNumber(object.parent, parentPropertyName, parentPropertyName);
|
|
458
|
+
return this._getRoundedPercentageOfNumber(object[propertyName], parentValue);
|
|
459
|
+
|
|
460
|
+
case 'boolean':
|
|
461
|
+
return this._getPropertyAsNumber(object.parent, propertyName, parentPropertyName)
|
|
462
|
+
|
|
463
|
+
default:
|
|
464
|
+
Urso.logger.error('Property value not number or string!', object, propertyName);
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* get rounded persents of number
|
|
471
|
+
* @param {String} percentsString
|
|
472
|
+
* @param {Number} number
|
|
473
|
+
* @returns {Number}
|
|
474
|
+
*/
|
|
475
|
+
_getRoundedPercentageOfNumber(percentsString, number) {
|
|
476
|
+
const percentsFloat = parseFloat(percentsString);
|
|
477
|
+
return ~~(percentsFloat * number / 100);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* check can be object a parent (by type)
|
|
482
|
+
* @param {Object} object
|
|
483
|
+
* @returns {Boolean}
|
|
484
|
+
*/
|
|
485
|
+
_canBeParent(object) {
|
|
486
|
+
return this._parentTypes.includes(object.type);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* check is value a number or a percents string
|
|
491
|
+
* @param {mixed} value
|
|
492
|
+
* @returns {Boolean}
|
|
493
|
+
*/
|
|
494
|
+
_isValueANumberOrPercentsString(value) {
|
|
495
|
+
return typeof value === 'number' || (typeof value === 'string' && value.endsWith('%'))
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* main function to handle stretchingType
|
|
500
|
+
* @param {Object} object
|
|
501
|
+
*/
|
|
502
|
+
_adaptStretchingType(object) {
|
|
503
|
+
if (object.width !== '100%' || object.height !== '100%' || !object.stretchingType)
|
|
504
|
+
return;
|
|
505
|
+
|
|
506
|
+
switch (object.stretchingType) {
|
|
507
|
+
case 'inscribed':
|
|
508
|
+
this._inscribe(object);
|
|
509
|
+
break;
|
|
510
|
+
|
|
511
|
+
case 'circumscribed':
|
|
512
|
+
this._circumscribe(object);
|
|
513
|
+
break;
|
|
514
|
+
|
|
515
|
+
case 'false':
|
|
516
|
+
break;
|
|
517
|
+
|
|
518
|
+
default:
|
|
519
|
+
Urso.logger.error('StretchingType value not valid!');
|
|
520
|
+
break;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* set property and adapt it (only for stretchingType)
|
|
526
|
+
* @param {Object} object
|
|
527
|
+
* @param {String} propertyName
|
|
528
|
+
* @param {Number} value
|
|
529
|
+
*/
|
|
530
|
+
_setPropertyAndAdaptIt(object, propertyName, value) {
|
|
531
|
+
object[propertyName] = value;
|
|
532
|
+
this.propertyChangeHandler(object, propertyName);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* set streching (only for stretchingType)
|
|
537
|
+
* @param {Object} object
|
|
538
|
+
* @param {Object} params
|
|
539
|
+
*/
|
|
540
|
+
_setStreching(object, { scale, objectWidth, objectHeight }) {
|
|
541
|
+
if (object.scaleX === 1)
|
|
542
|
+
this._setPropertyAndAdaptIt(object, 'width', objectWidth * scale);
|
|
543
|
+
else
|
|
544
|
+
this._setPropertyAndAdaptIt(object, 'scaleX', scale);
|
|
545
|
+
|
|
546
|
+
if (object.scaleY === 1)
|
|
547
|
+
this._setPropertyAndAdaptIt(object, 'height', objectHeight * scale);
|
|
548
|
+
else
|
|
549
|
+
this._setPropertyAndAdaptIt(object, 'scaleY', scale);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* get object values for streching (only for stretchingType)
|
|
554
|
+
* @param {Object} object
|
|
555
|
+
*/
|
|
556
|
+
_getObjectValuesForStreching(object) {
|
|
557
|
+
const objectWidth = this._getWidthAsNumber(object);
|
|
558
|
+
const objectHeight = this._getHeightAsNumber(object);
|
|
559
|
+
const parentWidth = this._getWidthAsNumber(object.parent);
|
|
560
|
+
const parentHeight = this._getHeightAsNumber(object.parent);
|
|
561
|
+
|
|
562
|
+
const scaleX = parentWidth / objectWidth;
|
|
563
|
+
const scaleY = parentHeight / objectHeight;
|
|
564
|
+
|
|
565
|
+
return { objectWidth, objectHeight, scaleX, scaleY };
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* inscribe handler (only for stretchingType)
|
|
570
|
+
* @param {Object} object
|
|
571
|
+
*/
|
|
572
|
+
_inscribe(object) {
|
|
573
|
+
const { objectWidth, objectHeight, scaleX, scaleY } = this._getObjectValuesForStreching(object);
|
|
574
|
+
const scale = Math.min(scaleX, scaleY);
|
|
575
|
+
this._setStreching(object, { scale, objectWidth, objectHeight });
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* circumscribe handler (only for stretchingType)
|
|
580
|
+
* @param {Object} object
|
|
581
|
+
*/
|
|
582
|
+
_circumscribe(object) {
|
|
583
|
+
const { objectWidth, objectHeight, scaleX, scaleY } = this._getObjectValuesForStreching(object);
|
|
584
|
+
const scale = Math.max(scaleX, scaleY);
|
|
585
|
+
this._setStreching(object, { scale, objectWidth, objectHeight });
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
|
|
588
589
|
module.exports = PropertyAdapter;
|