@urso/core 0.7.92 → 0.7.94-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.
Files changed (133) hide show
  1. package/.babelrc +11 -11
  2. package/LICENSE +20 -20
  3. package/README.md +227 -227
  4. package/build/162.js/index.js +1 -0
  5. package/build/24.js/index.js +1 -0
  6. package/build/js/index.js +1 -1
  7. package/package.json +50 -50
  8. package/src/js/app.js +104 -104
  9. package/src/js/components/base/controller.js +78 -78
  10. package/src/js/components/debug/controller.js +38 -38
  11. package/src/js/components/debug/coords.js +23 -23
  12. package/src/js/components/debug/fps.js +36 -36
  13. package/src/js/components/debug/template.js +55 -55
  14. package/src/js/components/debug/timescale.js +60 -60
  15. package/src/js/components/deviceRotate/controller.js +95 -95
  16. package/src/js/components/editor/api.js +127 -127
  17. package/src/js/components/editor/controller.js +12 -12
  18. package/src/js/components/fullscreen/android.js +104 -104
  19. package/src/js/components/fullscreen/controller.js +76 -76
  20. package/src/js/components/fullscreen/desktop.js +49 -49
  21. package/src/js/components/fullscreen/ios.js +115 -115
  22. package/src/js/components/layersSwitcher/config.js +26 -26
  23. package/src/js/components/layersSwitcher/controller.js +36 -36
  24. package/src/js/components/loader/controller.js +66 -66
  25. package/src/js/components/loader/template.js +70 -70
  26. package/src/js/components/soundInitialPopup/controller.js +42 -42
  27. package/src/js/components/soundInitialPopup/template.js +109 -109
  28. package/src/js/components/stateDriven/controller.js +123 -123
  29. package/src/js/config/load.js +194 -194
  30. package/src/js/config/main.js +17 -17
  31. package/src/js/extra/browserEvents.js +57 -57
  32. package/src/js/extra/main.js +19 -19
  33. package/src/js/extra/pixiPatch.js +171 -171
  34. package/src/js/index.js +7 -7
  35. package/src/js/lib/cache.js +125 -125
  36. package/src/js/lib/composition.js +85 -85
  37. package/src/js/lib/device.js +1215 -1215
  38. package/src/js/lib/helper.js +678 -678
  39. package/src/js/lib/loader.js +211 -211
  40. package/src/js/lib/localData.js +28 -28
  41. package/src/js/lib/logger.js +69 -69
  42. package/src/js/lib/math.js +161 -161
  43. package/src/js/lib/objectPool.js +207 -207
  44. package/src/js/lib/time.js +18 -18
  45. package/src/js/lib/tween.js +152 -152
  46. package/src/js/modules/assets/baseModel.js +20 -20
  47. package/src/js/modules/assets/config.js +38 -38
  48. package/src/js/modules/assets/controller.js +65 -65
  49. package/src/js/modules/assets/models/atlas.js +18 -18
  50. package/src/js/modules/assets/models/audiosprite.js +28 -28
  51. package/src/js/modules/assets/models/bitmapFont.js +10 -10
  52. package/src/js/modules/assets/models/container.js +18 -18
  53. package/src/js/modules/assets/models/font.js +10 -10
  54. package/src/js/modules/assets/models/html.js +10 -10
  55. package/src/js/modules/assets/models/image.js +17 -17
  56. package/src/js/modules/assets/models/json.js +10 -10
  57. package/src/js/modules/assets/models/jsonAtlas.js +10 -10
  58. package/src/js/modules/assets/models/sound.js +16 -16
  59. package/src/js/modules/assets/models/spine.js +16 -16
  60. package/src/js/modules/assets/service.js +541 -541
  61. package/src/js/modules/i18n/config.js +17 -17
  62. package/src/js/modules/i18n/controller.js +71 -71
  63. package/src/js/modules/instances/controller.js +357 -357
  64. package/src/js/modules/logic/config/sounds.js +23 -23
  65. package/src/js/modules/logic/controller.js +52 -52
  66. package/src/js/modules/logic/main.js +8 -8
  67. package/src/js/modules/logic/sounds.js +103 -103
  68. package/src/js/modules/objects/baseModel.js +207 -207
  69. package/src/js/modules/objects/cache.js +99 -99
  70. package/src/js/modules/objects/config.js +9 -9
  71. package/src/js/modules/objects/controller.js +139 -139
  72. package/src/js/modules/objects/find.js +58 -58
  73. package/src/js/modules/objects/models/atlasImage.js +52 -52
  74. package/src/js/modules/objects/models/bitmapText.js +48 -48
  75. package/src/js/modules/objects/models/button.js +196 -196
  76. package/src/js/modules/objects/models/buttonComposite.js +37 -37
  77. package/src/js/modules/objects/models/checkbox.js +96 -96
  78. package/src/js/modules/objects/models/collection.js +54 -54
  79. package/src/js/modules/objects/models/component.js +48 -48
  80. package/src/js/modules/objects/models/container.js +21 -21
  81. package/src/js/modules/objects/models/dragContainer.js +664 -664
  82. package/src/js/modules/objects/models/emitter.js +69 -69
  83. package/src/js/modules/objects/models/emitterFx.js +114 -114
  84. package/src/js/modules/objects/models/graphics.js +40 -40
  85. package/src/js/modules/objects/models/group.js +21 -21
  86. package/src/js/modules/objects/models/hitArea.js +119 -119
  87. package/src/js/modules/objects/models/image.js +36 -36
  88. package/src/js/modules/objects/models/imagesAnimation.js +115 -115
  89. package/src/js/modules/objects/models/mask.js +40 -40
  90. package/src/js/modules/objects/models/nineSlicePlane.js +32 -32
  91. package/src/js/modules/objects/models/scrollbox.js +66 -66
  92. package/src/js/modules/objects/models/slider.js +352 -352
  93. package/src/js/modules/objects/models/spine.js +338 -338
  94. package/src/js/modules/objects/models/text.js +70 -70
  95. package/src/js/modules/objects/models/textInput.js +68 -68
  96. package/src/js/modules/objects/models/toggle.js +179 -179
  97. package/src/js/modules/objects/models/world.js +21 -21
  98. package/src/js/modules/objects/pool.js +68 -68
  99. package/src/js/modules/objects/propertyAdapter.js +591 -588
  100. package/src/js/modules/objects/proxy.js +298 -298
  101. package/src/js/modules/objects/selector.js +136 -136
  102. package/src/js/modules/objects/service.js +254 -254
  103. package/src/js/modules/objects/styles.js +210 -210
  104. package/src/js/modules/observer/controller.js +167 -167
  105. package/src/js/modules/observer/events.js +56 -56
  106. package/src/js/modules/scenes/controller.js +127 -127
  107. package/src/js/modules/scenes/model.js +28 -28
  108. package/src/js/modules/scenes/pixiWrapper.js +351 -351
  109. package/src/js/modules/scenes/resolutions.js +173 -173
  110. package/src/js/modules/scenes/resolutionsConfig.js +73 -73
  111. package/src/js/modules/scenes/service.js +146 -146
  112. package/src/js/modules/soundManager/controller.js +103 -103
  113. package/src/js/modules/soundManager/soundSprite.js +285 -285
  114. package/src/js/modules/statesManager/action.js +97 -97
  115. package/src/js/modules/statesManager/all.js +23 -23
  116. package/src/js/modules/statesManager/configStates.js +77 -77
  117. package/src/js/modules/statesManager/controller.js +218 -218
  118. package/src/js/modules/statesManager/functionsStorage.js +82 -82
  119. package/src/js/modules/statesManager/helper.js +27 -27
  120. package/src/js/modules/statesManager/race.js +91 -91
  121. package/src/js/modules/statesManager/sequence.js +48 -48
  122. package/src/js/modules/template/controller.js +28 -28
  123. package/src/js/modules/template/model.js +11 -11
  124. package/src/js/modules/template/service.js +137 -137
  125. package/src/js/modules/template/types.js +48 -48
  126. package/src/js/modules/transport/baseConnectionType.js +25 -25
  127. package/src/js/modules/transport/config.js +13 -13
  128. package/src/js/modules/transport/connectionTypes/websocket.js +76 -76
  129. package/src/js/modules/transport/connectionTypes/xhr.js +46 -46
  130. package/src/js/modules/transport/controller.js +48 -48
  131. package/src/js/modules/transport/decorator.js +17 -17
  132. package/src/js/modules/transport/service.js +150 -150
  133. package/webpack.config.js +47 -47
@@ -1,352 +1,352 @@
1
- const ModulesObjectsBaseModel = require('./../baseModel');
2
-
3
- class ModulesObjectsModelsSlider extends ModulesObjectsBaseModel {
4
- constructor(params) {
5
- super(params);
6
-
7
- this.type = Urso.types.objects.SLIDER;
8
- this._sliderBg = null;
9
- this._sliderHandle = null;
10
- this._baseObject = null;
11
- this._handleIsPulling = false;
12
- this._points = [];
13
- this._addBaseObject();
14
- }
15
-
16
- /**
17
- * Returns slider size according to handle size.
18
- * @returns { Number }
19
- */
20
- get sliderSize() {
21
- const anchorType = this.sizeKey === 'width' ? 'anchorX' : 'anchorY';
22
- const anchor = this._sliderHandle[anchorType];
23
- const handleSize = this._sliderHandle[this.sizeKey];
24
- return this._sliderBg._baseObject[this.sizeKey] - handleSize + handleSize * anchor * 2;
25
- }
26
-
27
- setupParams(params) {
28
- super.setupParams(params);
29
- this.contents = [];
30
- this.points = Urso.helper.recursiveGet('points', params, [0, 1]);
31
- this.defaultValue = Urso.helper.recursiveGet('defaultValue', params, false);
32
- this.bgTexture = Urso.helper.recursiveGet('bgTexture', params, false);
33
- this.fillTexture = Urso.helper.recursiveGet('fillTexture', params, false);
34
- this.handleTexture = Urso.helper.recursiveGet('handleTexture', params, false);
35
- this.minValueTextModel = Urso.helper.recursiveGet('minValueTextModel', params, false);
36
- this.maxValueTextModel = Urso.helper.recursiveGet('maxValueTextModel', params, false);
37
- this.currentValueTextModel = Urso.helper.recursiveGet('currentValueTextModel', params, false);
38
- this.isVertical = Urso.helper.recursiveGet('isVertical', params, false);
39
- }
40
-
41
- /**
42
- * Sets handle position on a nearest possible point.
43
- * @param { Number } coefficient - might be in range 0 - 1.
44
- */
45
- setHandlePosition(coefficient) {
46
- let position = {};
47
-
48
- const targetPosition = this.sliderSize * coefficient;
49
- position[this.positionKey] = targetPosition;
50
-
51
- const { coord, value } = this._calculateClosestPoint(position);
52
- this._setNewValue(coord, value);
53
- }
54
-
55
- /**
56
- * Sets variables depends on slider type: vertical or horizontal.
57
- */
58
- _setVariables() {
59
- if (this.isVertical) {
60
- this.positionKey = 'y';
61
- this.sizeKey = 'height';
62
- } else {
63
- this.positionKey = 'x';
64
- this.sizeKey = 'width';
65
- }
66
- }
67
-
68
- /**
69
- * Creates Urso objects from given models of handle and background. If needed - creates fill texture.
70
- */
71
- _createSliderTextures() {
72
- this._sliderBg = this._createTexture(this.bgTexture);
73
-
74
- if (this.fillTexture)
75
- this._fillTexture = this._createFillTexture(this.fillTexture);
76
-
77
- this._sliderHandle = this._createTexture(this.handleTexture);
78
-
79
- this._setEvents(this._sliderBg._baseObject);
80
- this._setEvents(this._sliderHandle._baseObject);
81
- }
82
-
83
- /**
84
- * Creates and returns Urso GRAPHICS object for fill bar.
85
- * @param { Object } model
86
- * @returns { Object }
87
- */
88
- _createFillTexture(model) {
89
- const fillTexture = this._createTexture(model);
90
- const { width, height } = fillTexture._baseObject;
91
-
92
- this._fillMask = Urso.objects.create({
93
- type: Urso.types.objects.GRAPHICS,
94
- figure: {
95
- rectangle: [0, 0, width, height]
96
- },
97
- x: -width * fillTexture.anchorX,
98
- y: -height * fillTexture.anchorY,
99
- }, this);
100
-
101
- fillTexture._baseObject.mask = this._fillMask._baseObject;
102
- return fillTexture;
103
- }
104
-
105
- /**
106
- * If needed creates Urso TEXT objects for min max and current value.
107
- */
108
- _createValueText() {
109
- if (this.minValueTextModel) {
110
- this.minValueText = Urso.objects.create(this.minValueTextModel, this);
111
- this.minValueText.text = this._points[0];
112
- }
113
-
114
- if (this.maxValueTextModel) {
115
- this.maxValueText = Urso.objects.create(this.maxValueTextModel, this);
116
- this.maxValueText.text = this._points.length <= 2 ? '100' : this._points[this._points.length - 1];
117
- }
118
-
119
- if (this.currentValueTextModel) {
120
- this.currentValueText = Urso.objects.create(this.currentValueTextModel, this);
121
- }
122
- }
123
- /**
124
- * Creates and return Urso object for texture. Model type might be GRAPHICS or IMAGE.
125
- * @param { Object } model
126
- * @returns { Object }
127
- */
128
- _createTexture(model) {
129
- if (model.type === Urso.types.objects.GRAPHICS || model.type === Urso.types.objects.IMAGE)
130
- return Urso.objects.create(model, this);
131
- else
132
- Urso.logger.error('ModulesObjectsModelsSlider objects error: textures should be GRAPHICS or IMAGE type');
133
- }
134
-
135
- /**
136
- * Subscribes on pointer events.
137
- * @param { Object } obj
138
- */
139
- _setEvents(obj) {
140
- obj.interactive = true;
141
- obj.buttonMode = true;
142
-
143
- obj
144
- .on('pointerdown', this._onPointerDown.bind(this))
145
- .on('pointerup', this._onPointerUp.bind(this))
146
- .on('pointerupoutside', this._onPointerUp.bind(this))
147
- .on('touchmove', this._onTouchmove.bind(this));
148
- };
149
-
150
- /**
151
- * Handler for touchmove event.
152
- * @param { Object } event
153
- */
154
- _onTouchmove(event) {
155
- const position = this._getEventLocalPosition(event);
156
- this._onPointerMove(position);
157
- }
158
-
159
- /**
160
- * Calculate pointer coords inside PIXI World.
161
- * @param { Object } event
162
- * @returns
163
- */
164
- _getEventLocalPosition(event) {
165
- const world = Urso.objects.getWorld();
166
- const worldScale = world._baseObject.scale;
167
-
168
- const x = event.data.global.x / worldScale.x;
169
- const y = event.data.global.y / worldScale.y;
170
-
171
- return { x, y };
172
- }
173
-
174
- /**
175
- * Creates base object and set up slider.
176
- */
177
- _addBaseObject() {
178
- this._baseObject = new PIXI.Container();
179
-
180
- this._setPoints();
181
- this._setVariables();
182
- this._createSliderTextures();
183
- this._createValueText();
184
- this._setDefaultValue();
185
- };
186
-
187
- /**
188
- * Handler for pointerdown event.
189
- * @param { Object } event
190
- */
191
- _onPointerDown(obj) {
192
- if (obj.target === this._sliderHandle._baseObject)
193
- this._handleIsDragging = true;
194
- }
195
-
196
- /**
197
- * Handler for touchmove and pointermove events.
198
- * @param { Object } param
199
- */
200
- _onPointerMove({ x, y }) {
201
- if (!this._handleIsDragging)
202
- return
203
-
204
- const value = this.isVertical ? y : x;
205
- const globalPosition = this.toGlobal(this[this.positionKey])[this.positionKey];
206
-
207
- if (value < globalPosition)
208
- this._sliderHandle[this.positionKey] = 0;
209
- else if (value >= globalPosition + this.sliderSize)
210
- this._sliderHandle[this.positionKey] = this.sliderSize;
211
- else
212
- this._sliderHandle[this.positionKey] = value - globalPosition;
213
-
214
- this._updateValueOnMove()
215
- }
216
-
217
- /**
218
- * Updates slider value while moving.
219
- */
220
- _updateValueOnMove() {
221
- const { value } = this._calculateClosestPoint(this._sliderHandle);
222
-
223
- if (this.currentValueText)
224
- this.currentValueText.text = value;
225
-
226
- const data = { class: this.class, name: this.name, position: this._sliderHandle[this.positionKey] };
227
- this.emit(Urso.events.MODULES_OBJECTS_SLIDER_HANDLE_MOVE, data)
228
- }
229
-
230
- /**
231
- * Handler for pointerup event.
232
- * @param { Object } obj
233
- */
234
- _onPointerUp(obj) {
235
- this._handleIsDragging = false;
236
- let targetObj;
237
-
238
- if (obj.target === this._sliderBg._baseObject)
239
- targetObj = obj.data.getLocalPosition(obj.target)
240
- else
241
- targetObj = this._sliderHandle;
242
-
243
- const { coord, value } = this._calculateClosestPoint(targetObj);
244
- this._dropHandle(coord, value);
245
- }
246
-
247
- /**
248
- * Sets possible values (points) of slider
249
- */
250
- _setPoints() {
251
- if (this.points.length > 1) {
252
- this._points = [...this.points];
253
- return;
254
- }
255
-
256
- const firstPoint = this.points[0] > 0 ? 0 : this.points[0];
257
- const lastPoint = this.points[0] > 0 ? this.points[0] : 0;
258
-
259
- for (let i = firstPoint; i <= lastPoint; i++)
260
- this._points.push(i);
261
- }
262
-
263
- /**
264
- * Sets given default value or 0.
265
- */
266
- _setDefaultValue() {
267
- if (!this.defaultValue)
268
- this.defaultValue = this._points[0];
269
-
270
- if (!this._points.includes(this.defaultValue))
271
- this.defaultValue = this._points[0];
272
-
273
- let value = this._points.indexOf(this.defaultValue) * this.sliderSize / (this._points.length - 1);
274
- this._setNewValue(value, this.defaultValue);
275
- }
276
-
277
- /**
278
- * When handle drops sets final value and emits event
279
- * @param { Number } coord
280
- * @param { Number } value
281
- */
282
- _dropHandle(coord, value) {
283
- const data = { class: this.class, name: this.name, position: coord, value: value };
284
-
285
- this.emit(Urso.events.MODULES_OBJECTS_SLIDER_HANDLE_DROP, data);
286
- this._setNewValue(coord, value);
287
- }
288
-
289
- /**
290
- * Calculates closest possible value (point) from given coords.
291
- * @param { Object } obj
292
- * @returns { Object }
293
- */
294
- _calculateClosestPoint(obj) {
295
- const givenValue = obj[this.positionKey];
296
- let value, coord;
297
-
298
- if (this._points.length <= 2) {
299
- coord = givenValue;
300
- value = ~~(100 / this.sliderSize * givenValue);
301
- }
302
- // calculate closest point
303
- else {
304
- for (let i = 0; i < this._points.length; i++) {
305
- let pointCoord = i * this.sliderSize / (this._points.length - 1);
306
-
307
- if (typeof (coord) === 'number' && givenValue - pointCoord < coord - givenValue) {
308
- coord = coord;
309
- } else {
310
- coord = pointCoord;
311
- value = this._points[i];
312
- }
313
- }
314
- }
315
-
316
- return { coord, value };
317
- }
318
-
319
- /**
320
- * Set mask for fill texture depends on handle position.
321
- */
322
- _setFillMask() {
323
- if (!this._fillMask)
324
- return
325
-
326
- const progress = (this._sliderHandle[this.positionKey] - this._sliderBg[this.positionKey]) *
327
- 100 / this._fillTexture._baseObject[this.sizeKey] * 0.01;
328
-
329
- const scaleKey = this.isVertical ? 'scaleY' : 'scaleX';
330
- this._fillMask[scaleKey] = progress;
331
- }
332
-
333
- /**
334
- * Set handle position and value.
335
- * @param { Number } coord
336
- * @param { Number } value
337
- */
338
- _setNewValue(coord, value) {
339
- this._sliderHandle[this.positionKey] = coord;
340
-
341
- if (this.currentValueText)
342
- this.currentValueText.text = value;
343
-
344
- this._setFillMask();
345
- }
346
-
347
- _subscribeOnce() {
348
- this.addListener(Urso.events.MODULES_SCENES_MOUSE_NEW_POSITION, this._onPointerMove.bind(this));
349
- }
350
- }
351
-
352
- module.exports = ModulesObjectsModelsSlider;
1
+ const ModulesObjectsBaseModel = require('./../baseModel');
2
+
3
+ class ModulesObjectsModelsSlider extends ModulesObjectsBaseModel {
4
+ constructor(params) {
5
+ super(params);
6
+
7
+ this.type = Urso.types.objects.SLIDER;
8
+ this._sliderBg = null;
9
+ this._sliderHandle = null;
10
+ this._baseObject = null;
11
+ this._handleIsPulling = false;
12
+ this._points = [];
13
+ this._addBaseObject();
14
+ }
15
+
16
+ /**
17
+ * Returns slider size according to handle size.
18
+ * @returns { Number }
19
+ */
20
+ get sliderSize() {
21
+ const anchorType = this.sizeKey === 'width' ? 'anchorX' : 'anchorY';
22
+ const anchor = this._sliderHandle[anchorType];
23
+ const handleSize = this._sliderHandle[this.sizeKey];
24
+ return this._sliderBg._baseObject[this.sizeKey] - handleSize + handleSize * anchor * 2;
25
+ }
26
+
27
+ setupParams(params) {
28
+ super.setupParams(params);
29
+ this.contents = [];
30
+ this.points = Urso.helper.recursiveGet('points', params, [0, 1]);
31
+ this.defaultValue = Urso.helper.recursiveGet('defaultValue', params, false);
32
+ this.bgTexture = Urso.helper.recursiveGet('bgTexture', params, false);
33
+ this.fillTexture = Urso.helper.recursiveGet('fillTexture', params, false);
34
+ this.handleTexture = Urso.helper.recursiveGet('handleTexture', params, false);
35
+ this.minValueTextModel = Urso.helper.recursiveGet('minValueTextModel', params, false);
36
+ this.maxValueTextModel = Urso.helper.recursiveGet('maxValueTextModel', params, false);
37
+ this.currentValueTextModel = Urso.helper.recursiveGet('currentValueTextModel', params, false);
38
+ this.isVertical = Urso.helper.recursiveGet('isVertical', params, false);
39
+ }
40
+
41
+ /**
42
+ * Sets handle position on a nearest possible point.
43
+ * @param { Number } coefficient - might be in range 0 - 1.
44
+ */
45
+ setHandlePosition(coefficient) {
46
+ let position = {};
47
+
48
+ const targetPosition = this.sliderSize * coefficient;
49
+ position[this.positionKey] = targetPosition;
50
+
51
+ const { coord, value } = this._calculateClosestPoint(position);
52
+ this._setNewValue(coord, value);
53
+ }
54
+
55
+ /**
56
+ * Sets variables depends on slider type: vertical or horizontal.
57
+ */
58
+ _setVariables() {
59
+ if (this.isVertical) {
60
+ this.positionKey = 'y';
61
+ this.sizeKey = 'height';
62
+ } else {
63
+ this.positionKey = 'x';
64
+ this.sizeKey = 'width';
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Creates Urso objects from given models of handle and background. If needed - creates fill texture.
70
+ */
71
+ _createSliderTextures() {
72
+ this._sliderBg = this._createTexture(this.bgTexture);
73
+
74
+ if (this.fillTexture)
75
+ this._fillTexture = this._createFillTexture(this.fillTexture);
76
+
77
+ this._sliderHandle = this._createTexture(this.handleTexture);
78
+
79
+ this._setEvents(this._sliderBg._baseObject);
80
+ this._setEvents(this._sliderHandle._baseObject);
81
+ }
82
+
83
+ /**
84
+ * Creates and returns Urso GRAPHICS object for fill bar.
85
+ * @param { Object } model
86
+ * @returns { Object }
87
+ */
88
+ _createFillTexture(model) {
89
+ const fillTexture = this._createTexture(model);
90
+ const { width, height } = fillTexture._baseObject;
91
+
92
+ this._fillMask = Urso.objects.create({
93
+ type: Urso.types.objects.GRAPHICS,
94
+ figure: {
95
+ rectangle: [0, 0, width, height]
96
+ },
97
+ x: -width * fillTexture.anchorX,
98
+ y: -height * fillTexture.anchorY,
99
+ }, this);
100
+
101
+ fillTexture._baseObject.mask = this._fillMask._baseObject;
102
+ return fillTexture;
103
+ }
104
+
105
+ /**
106
+ * If needed creates Urso TEXT objects for min max and current value.
107
+ */
108
+ _createValueText() {
109
+ if (this.minValueTextModel) {
110
+ this.minValueText = Urso.objects.create(this.minValueTextModel, this);
111
+ this.minValueText.text = this._points[0];
112
+ }
113
+
114
+ if (this.maxValueTextModel) {
115
+ this.maxValueText = Urso.objects.create(this.maxValueTextModel, this);
116
+ this.maxValueText.text = this._points.length <= 2 ? '100' : this._points[this._points.length - 1];
117
+ }
118
+
119
+ if (this.currentValueTextModel) {
120
+ this.currentValueText = Urso.objects.create(this.currentValueTextModel, this);
121
+ }
122
+ }
123
+ /**
124
+ * Creates and return Urso object for texture. Model type might be GRAPHICS or IMAGE.
125
+ * @param { Object } model
126
+ * @returns { Object }
127
+ */
128
+ _createTexture(model) {
129
+ if (model.type === Urso.types.objects.GRAPHICS || model.type === Urso.types.objects.IMAGE)
130
+ return Urso.objects.create(model, this);
131
+ else
132
+ Urso.logger.error('ModulesObjectsModelsSlider objects error: textures should be GRAPHICS or IMAGE type');
133
+ }
134
+
135
+ /**
136
+ * Subscribes on pointer events.
137
+ * @param { Object } obj
138
+ */
139
+ _setEvents(obj) {
140
+ obj.interactive = true;
141
+ obj.buttonMode = true;
142
+
143
+ obj
144
+ .on('pointerdown', this._onPointerDown.bind(this))
145
+ .on('pointerup', this._onPointerUp.bind(this))
146
+ .on('pointerupoutside', this._onPointerUp.bind(this))
147
+ .on('touchmove', this._onTouchmove.bind(this));
148
+ };
149
+
150
+ /**
151
+ * Handler for touchmove event.
152
+ * @param { Object } event
153
+ */
154
+ _onTouchmove(event) {
155
+ const position = this._getEventLocalPosition(event);
156
+ this._onPointerMove(position);
157
+ }
158
+
159
+ /**
160
+ * Calculate pointer coords inside PIXI World.
161
+ * @param { Object } event
162
+ * @returns
163
+ */
164
+ _getEventLocalPosition(event) {
165
+ const world = Urso.objects.getWorld();
166
+ const worldScale = world._baseObject.scale;
167
+
168
+ const x = event.data.global.x / worldScale.x;
169
+ const y = event.data.global.y / worldScale.y;
170
+
171
+ return { x, y };
172
+ }
173
+
174
+ /**
175
+ * Creates base object and set up slider.
176
+ */
177
+ _addBaseObject() {
178
+ this._baseObject = new PIXI.Container();
179
+
180
+ this._setPoints();
181
+ this._setVariables();
182
+ this._createSliderTextures();
183
+ this._createValueText();
184
+ this._setDefaultValue();
185
+ };
186
+
187
+ /**
188
+ * Handler for pointerdown event.
189
+ * @param { Object } event
190
+ */
191
+ _onPointerDown(obj) {
192
+ if (obj.target === this._sliderHandle._baseObject)
193
+ this._handleIsDragging = true;
194
+ }
195
+
196
+ /**
197
+ * Handler for touchmove and pointermove events.
198
+ * @param { Object } param
199
+ */
200
+ _onPointerMove({ x, y }) {
201
+ if (!this._handleIsDragging)
202
+ return
203
+
204
+ const value = this.isVertical ? y : x;
205
+ const globalPosition = this.toGlobal(this[this.positionKey])[this.positionKey];
206
+
207
+ if (value < globalPosition)
208
+ this._sliderHandle[this.positionKey] = 0;
209
+ else if (value >= globalPosition + this.sliderSize)
210
+ this._sliderHandle[this.positionKey] = this.sliderSize;
211
+ else
212
+ this._sliderHandle[this.positionKey] = value - globalPosition;
213
+
214
+ this._updateValueOnMove()
215
+ }
216
+
217
+ /**
218
+ * Updates slider value while moving.
219
+ */
220
+ _updateValueOnMove() {
221
+ const { value } = this._calculateClosestPoint(this._sliderHandle);
222
+
223
+ if (this.currentValueText)
224
+ this.currentValueText.text = value;
225
+
226
+ const data = { class: this.class, name: this.name, position: this._sliderHandle[this.positionKey] };
227
+ this.emit(Urso.events.MODULES_OBJECTS_SLIDER_HANDLE_MOVE, data)
228
+ }
229
+
230
+ /**
231
+ * Handler for pointerup event.
232
+ * @param { Object } obj
233
+ */
234
+ _onPointerUp(obj) {
235
+ this._handleIsDragging = false;
236
+ let targetObj;
237
+
238
+ if (obj.target === this._sliderBg._baseObject)
239
+ targetObj = obj.data.getLocalPosition(obj.target)
240
+ else
241
+ targetObj = this._sliderHandle;
242
+
243
+ const { coord, value } = this._calculateClosestPoint(targetObj);
244
+ this._dropHandle(coord, value);
245
+ }
246
+
247
+ /**
248
+ * Sets possible values (points) of slider
249
+ */
250
+ _setPoints() {
251
+ if (this.points.length > 1) {
252
+ this._points = [...this.points];
253
+ return;
254
+ }
255
+
256
+ const firstPoint = this.points[0] > 0 ? 0 : this.points[0];
257
+ const lastPoint = this.points[0] > 0 ? this.points[0] : 0;
258
+
259
+ for (let i = firstPoint; i <= lastPoint; i++)
260
+ this._points.push(i);
261
+ }
262
+
263
+ /**
264
+ * Sets given default value or 0.
265
+ */
266
+ _setDefaultValue() {
267
+ if (!this.defaultValue)
268
+ this.defaultValue = this._points[0];
269
+
270
+ if (!this._points.includes(this.defaultValue))
271
+ this.defaultValue = this._points[0];
272
+
273
+ let value = this._points.indexOf(this.defaultValue) * this.sliderSize / (this._points.length - 1);
274
+ this._setNewValue(value, this.defaultValue);
275
+ }
276
+
277
+ /**
278
+ * When handle drops sets final value and emits event
279
+ * @param { Number } coord
280
+ * @param { Number } value
281
+ */
282
+ _dropHandle(coord, value) {
283
+ const data = { class: this.class, name: this.name, position: coord, value: value };
284
+
285
+ this.emit(Urso.events.MODULES_OBJECTS_SLIDER_HANDLE_DROP, data);
286
+ this._setNewValue(coord, value);
287
+ }
288
+
289
+ /**
290
+ * Calculates closest possible value (point) from given coords.
291
+ * @param { Object } obj
292
+ * @returns { Object }
293
+ */
294
+ _calculateClosestPoint(obj) {
295
+ const givenValue = obj[this.positionKey];
296
+ let value, coord;
297
+
298
+ if (this._points.length <= 2) {
299
+ coord = givenValue;
300
+ value = ~~(100 / this.sliderSize * givenValue);
301
+ }
302
+ // calculate closest point
303
+ else {
304
+ for (let i = 0; i < this._points.length; i++) {
305
+ let pointCoord = i * this.sliderSize / (this._points.length - 1);
306
+
307
+ if (typeof (coord) === 'number' && givenValue - pointCoord < coord - givenValue) {
308
+ coord = coord;
309
+ } else {
310
+ coord = pointCoord;
311
+ value = this._points[i];
312
+ }
313
+ }
314
+ }
315
+
316
+ return { coord, value };
317
+ }
318
+
319
+ /**
320
+ * Set mask for fill texture depends on handle position.
321
+ */
322
+ _setFillMask() {
323
+ if (!this._fillMask)
324
+ return
325
+
326
+ const progress = (this._sliderHandle[this.positionKey] - this._sliderBg[this.positionKey]) *
327
+ 100 / this._fillTexture._baseObject[this.sizeKey] * 0.01;
328
+
329
+ const scaleKey = this.isVertical ? 'scaleY' : 'scaleX';
330
+ this._fillMask[scaleKey] = progress;
331
+ }
332
+
333
+ /**
334
+ * Set handle position and value.
335
+ * @param { Number } coord
336
+ * @param { Number } value
337
+ */
338
+ _setNewValue(coord, value) {
339
+ this._sliderHandle[this.positionKey] = coord;
340
+
341
+ if (this.currentValueText)
342
+ this.currentValueText.text = value;
343
+
344
+ this._setFillMask();
345
+ }
346
+
347
+ _subscribeOnce() {
348
+ this.addListener(Urso.events.MODULES_SCENES_MOUSE_NEW_POSITION, this._onPointerMove.bind(this));
349
+ }
350
+ }
351
+
352
+ module.exports = ModulesObjectsModelsSlider;