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