@urso/core 0.6.17 → 0.6.19

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@urso/core",
3
- "version": "0.6.17",
3
+ "version": "0.6.19",
4
4
  "description": "HTML5 game engine",
5
5
  "main": "build/js/index.js",
6
6
  "author": "Megbrimef",
@@ -200,7 +200,7 @@ class ModulesObjectsModelsDragContainer extends ModulesObjectsModelsContainer {
200
200
  /**
201
201
  * Function takes dragContainer object and recurcievly calculates it's global scale and position
202
202
  * @param { Object }
203
- * @returns
203
+ * @returns { Object }
204
204
  */
205
205
  _getScaleAndPositionRecursive({ scaleX, scaleY, parent, x, y }) {
206
206
  if (!parent) {
@@ -226,7 +226,8 @@ class ModulesObjectsModelsDragContainer extends ModulesObjectsModelsContainer {
226
226
  return;
227
227
 
228
228
  this._moveInProgress = true;
229
- let offset = e.offsetY || e.changedTouches[0].offsetY || e.changedTouches[0].clientY;
229
+
230
+ const offset = e.offsetY ?? changedOffsetY ?? clientY ?? 0;
230
231
 
231
232
  if (Math.abs(this._moveStartedY - offset) > this._minMoveDistance && !this._dragStarted) {
232
233
  this._dragStarted = true;
@@ -367,7 +368,7 @@ class ModulesObjectsModelsDragContainer extends ModulesObjectsModelsContainer {
367
368
  * Validates next dragContainer position.
368
369
  * @param { Number } lastY
369
370
  * @param { Boolean } isWheel
370
- * @returns
371
+ * @returns { Number }
371
372
  */
372
373
  _validateY(lastY, isWheel) {
373
374
  const deltaY = isWheel ? lastY * this.speed : ((lastY - this._startPosition.y) * this.speed);
@@ -415,10 +416,8 @@ class ModulesObjectsModelsDragContainer extends ModulesObjectsModelsContainer {
415
416
  return;
416
417
 
417
418
  const { height } = this.getAbsoluteSize();
418
-
419
- const positionChange = y / (height - this.height);
420
- const { _sliderHandle, _sliderSize } = this._slider;
421
- _sliderHandle.y = -(_sliderSize * positionChange);
419
+ const positionCoefficient = Math.abs(y / (height - this.height));
420
+ this._slider.setHandlePosition(positionCoefficient);
422
421
  }
423
422
 
424
423
  /**
@@ -552,13 +551,13 @@ class ModulesObjectsModelsDragContainer extends ModulesObjectsModelsContainer {
552
551
  return
553
552
 
554
553
  if (this.height >= this._baseObject.height) {
555
- this._slider._moveSlider({ x: 0, y: 0 }, true, true);
554
+ this._slider.setHandlePosition(0);
556
555
  return;
557
556
  }
558
557
 
559
- const { _sliderSize } = this._slider;
558
+ const { sliderSize } = this._slider;
560
559
  const containerHeight = this._mask.height - this._baseObject.height;
561
- const diffY = position > 0 ? position / _sliderSize * containerHeight : 0;
560
+ const diffY = position > 0 ? position / sliderSize * containerHeight : 0;
562
561
 
563
562
  this._needMoveSlider = false;
564
563
  this._move(diffY, true)
@@ -591,7 +590,6 @@ class ModulesObjectsModelsDragContainer extends ModulesObjectsModelsContainer {
591
590
  /**
592
591
  * Checks if need to set slider. If no dragContainerName - slider will be set for all dragContainers.
593
592
  * @param {String} dragContainerName
594
- * @returns
595
593
  */
596
594
  _setSliderHandler(dragContainerName) {
597
595
  if (dragContainerName && dragContainerName !== this.name)
@@ -11,6 +11,17 @@ class ModulesObjectsModelsSlider extends Urso.Core.Modules.Objects.BaseModel {
11
11
  this._addBaseObject();
12
12
  }
13
13
 
14
+ /**
15
+ * Returns slider size according to handle size.
16
+ * @returns { Number }
17
+ */
18
+ get sliderSize() {
19
+ const anchorType = this.sizeKey === 'width' ? 'anchorX' : 'anchorY';
20
+ const anchor = this._sliderHandle[anchorType];
21
+ const handleSize = this._sliderHandle[this.sizeKey];
22
+ return this._sliderBg._baseObject[this.sizeKey] - handleSize + handleSize * anchor * 2;
23
+ }
24
+
14
25
  setupParams(params) {
15
26
  super.setupParams(params);
16
27
  this.contents = [];
@@ -25,6 +36,23 @@ class ModulesObjectsModelsSlider extends Urso.Core.Modules.Objects.BaseModel {
25
36
  this.isVertical = Urso.helper.recursiveGet('isVertical', params, false);
26
37
  }
27
38
 
39
+ /**
40
+ * Sets handle position on a nearest possible point.
41
+ * @param { Number } coefficient - might be in range 0 - 1.
42
+ */
43
+ setHandlePosition(coefficient) {
44
+ let position = {};
45
+
46
+ const targetPosition = this.sliderSize * coefficient;
47
+ position[this.positionKey] = targetPosition;
48
+
49
+ const { coord, value } = this._calculateClosestPoint(position);
50
+ this._setNewValue( coord, value);
51
+ }
52
+
53
+ /**
54
+ * Sets variables depends on slider type: vertical or horizontal.
55
+ */
28
56
  _setVariables() {
29
57
  if (this.isVertical) {
30
58
  this.positionKey = 'y';
@@ -35,6 +63,9 @@ class ModulesObjectsModelsSlider extends Urso.Core.Modules.Objects.BaseModel {
35
63
  }
36
64
  }
37
65
 
66
+ /**
67
+ * Creates Urso objects from given models of handle and background. If needed - creates fill texture.
68
+ */
38
69
  _createSliderTextures() {
39
70
  this._sliderBg = this._createTexture(this.bgTexture);
40
71
 
@@ -47,9 +78,15 @@ class ModulesObjectsModelsSlider extends Urso.Core.Modules.Objects.BaseModel {
47
78
  this._setEvents(this._sliderHandle._baseObject);
48
79
  }
49
80
 
81
+ /**
82
+ * Creates and returns Urso GRAPHICS object for fill bar.
83
+ * @param { Object } model
84
+ * @returns { Object }
85
+ */
50
86
  _createFillTexture(model) {
51
87
  const fillTexture = this._createTexture(model);
52
88
  const { width, height } = fillTexture._baseObject;
89
+
53
90
  this._fillMask = Urso.objects.create({
54
91
  type: Urso.types.objects.GRAPHICS,
55
92
  figure: {
@@ -60,9 +97,12 @@ class ModulesObjectsModelsSlider extends Urso.Core.Modules.Objects.BaseModel {
60
97
  }, this);
61
98
 
62
99
  fillTexture._baseObject.mask = this._fillMask._baseObject;
63
- return fillTexture
100
+ return fillTexture;
64
101
  }
65
102
 
103
+ /**
104
+ * If needed creates Urso TEXT objects for min max and current value.
105
+ */
66
106
  _createValueText() {
67
107
  if (this.minValueTextModel) {
68
108
  this.minValueText = Urso.objects.create(this.minValueTextModel, this);
@@ -78,7 +118,11 @@ class ModulesObjectsModelsSlider extends Urso.Core.Modules.Objects.BaseModel {
78
118
  this.currentValueText = Urso.objects.create(this.currentValueTextModel, this);
79
119
  }
80
120
  }
81
-
121
+ /**
122
+ * Creates and return Urso object for texture. Model type might be GRAPHICS or IMAGE.
123
+ * @param { Object } model
124
+ * @returns { Object }
125
+ */
82
126
  _createTexture(model) {
83
127
  if (model.type === Urso.types.objects.GRAPHICS || model.type === Urso.types.objects.IMAGE)
84
128
  return Urso.objects.create(model, this);
@@ -86,6 +130,10 @@ class ModulesObjectsModelsSlider extends Urso.Core.Modules.Objects.BaseModel {
86
130
  Urso.logger.error('ModulesObjectsModelsSlider objects error: textures should be GRAPHICS or IMAGE type');
87
131
  }
88
132
 
133
+ /**
134
+ * Subscribes on pointer events.
135
+ * @param { Object } obj
136
+ */
89
137
  _setEvents(obj) {
90
138
  obj.interactive = true;
91
139
  obj.buttonMode = true;
@@ -97,11 +145,20 @@ class ModulesObjectsModelsSlider extends Urso.Core.Modules.Objects.BaseModel {
97
145
  .on('touchmove', this._onTouchmove.bind(this));
98
146
  };
99
147
 
148
+ /**
149
+ * Handler for touchmove event.
150
+ * @param { Object } event
151
+ */
100
152
  _onTouchmove(event) {
101
153
  const position = this._getEventLocalPosition(event);
102
154
  this._onPointerMove(position);
103
155
  }
104
156
 
157
+ /**
158
+ * Calculate pointer coords inside PIXI World.
159
+ * @param { Object } event
160
+ * @returns
161
+ */
105
162
  _getEventLocalPosition(event) {
106
163
  const world = Urso.objects.getWorld();
107
164
  const worldScale = world._baseObject.scale;
@@ -112,6 +169,9 @@ class ModulesObjectsModelsSlider extends Urso.Core.Modules.Objects.BaseModel {
112
169
  return { x, y };
113
170
  }
114
171
 
172
+ /**
173
+ * Creates base object and set up slider.
174
+ */
115
175
  _addBaseObject() {
116
176
  this._baseObject = new PIXI.Container();
117
177
 
@@ -122,11 +182,19 @@ class ModulesObjectsModelsSlider extends Urso.Core.Modules.Objects.BaseModel {
122
182
  this._setDefaultValue();
123
183
  };
124
184
 
185
+ /**
186
+ * Handler for pointerdown event.
187
+ * @param { Object } event
188
+ */
125
189
  _onPointerDown(obj) {
126
190
  if (obj.target === this._sliderHandle._baseObject)
127
191
  this._handleIsDragging = true;
128
192
  }
129
193
 
194
+ /**
195
+ * Handler for touchmove and pointermove events.
196
+ * @param { Object } param
197
+ */
130
198
  _onPointerMove({ x, y }) {
131
199
  if (!this._handleIsDragging)
132
200
  return
@@ -136,14 +204,17 @@ class ModulesObjectsModelsSlider extends Urso.Core.Modules.Objects.BaseModel {
136
204
 
137
205
  if (value < globalPosition)
138
206
  this._sliderHandle[this.positionKey] = 0;
139
- else if (value >= globalPosition + this._sliderBg._baseObject[this.sizeKey])
140
- this._sliderHandle[this.positionKey] = this._sliderBg._baseObject[this.sizeKey];
207
+ else if (value >= globalPosition + this.sliderSize)
208
+ this._sliderHandle[this.positionKey] = this.sliderSize;
141
209
  else
142
- this._sliderHandle[this.positionKey] = value - globalPosition
210
+ this._sliderHandle[this.positionKey] = value - globalPosition;
143
211
 
144
212
  this._updateValueOnMove()
145
213
  }
146
214
 
215
+ /**
216
+ * Updates slider value while moving.
217
+ */
147
218
  _updateValueOnMove() {
148
219
  const { value } = this._calculateClosestPoint(this._sliderHandle);
149
220
 
@@ -154,6 +225,10 @@ class ModulesObjectsModelsSlider extends Urso.Core.Modules.Objects.BaseModel {
154
225
  this.emit(Urso.events.MODULES_OBJECTS_SLIDER_HANDLE_MOVE, data)
155
226
  }
156
227
 
228
+ /**
229
+ * Handler for pointerup event.
230
+ * @param { Object } obj
231
+ */
157
232
  _onPointerUp(obj) {
158
233
  this._handleIsDragging = false;
159
234
  let targetObj;
@@ -167,6 +242,9 @@ class ModulesObjectsModelsSlider extends Urso.Core.Modules.Objects.BaseModel {
167
242
  this._dropHandle(coord, value);
168
243
  }
169
244
 
245
+ /**
246
+ * Sets possible values (points) of slider
247
+ */
170
248
  _setPoints() {
171
249
  if (this.points.length > 1) {
172
250
  this._points = [...this.points];
@@ -180,6 +258,9 @@ class ModulesObjectsModelsSlider extends Urso.Core.Modules.Objects.BaseModel {
180
258
  this._points.push(i);
181
259
  }
182
260
 
261
+ /**
262
+ * Sets given default value or 0.
263
+ */
183
264
  _setDefaultValue() {
184
265
  if(!this.defaultValue)
185
266
  this.defaultValue = this._points[0];
@@ -187,12 +268,15 @@ class ModulesObjectsModelsSlider extends Urso.Core.Modules.Objects.BaseModel {
187
268
  if (!this._points.includes(this.defaultValue))
188
269
  this.defaultValue = this._points[0];
189
270
 
190
- let value = this._points.indexOf(this.defaultValue) *
191
- this._sliderBg._baseObject[this.sizeKey] / (this._points.length - 1);
192
-
271
+ let value = this._points.indexOf(this.defaultValue) * this.sliderSize / (this._points.length - 1);
193
272
  this._setNewValue(value, this.defaultValue);
194
273
  }
195
274
 
275
+ /**
276
+ * When handle drops sets final value and emits event
277
+ * @param { Number } coord
278
+ * @param { Number } value
279
+ */
196
280
  _dropHandle(coord, value) {
197
281
  const data = { class: this.class, name: this.name, position: coord, value: value };
198
282
 
@@ -200,18 +284,23 @@ class ModulesObjectsModelsSlider extends Urso.Core.Modules.Objects.BaseModel {
200
284
  this._setNewValue(coord, value);
201
285
  }
202
286
 
203
- _calculateClosestPoint({ x, y }) {
204
- const givenValue = this.isVertical ? y : x;
287
+ /**
288
+ * Calculates closest possible value (point) from given coords.
289
+ * @param { Object } obj
290
+ * @returns { Object }
291
+ */
292
+ _calculateClosestPoint(obj) {
293
+ const givenValue = obj[this.positionKey];
205
294
  let value, coord;
206
295
 
207
296
  if (this._points.length <= 2) {
208
297
  coord = givenValue;
209
- value = ~~(100 / this._sliderBg._baseObject[this.sizeKey] * givenValue);
298
+ value = ~~(100 / this.sliderSize * givenValue);
210
299
  }
211
300
  // calculate closest point
212
301
  else {
213
302
  for (let i = 0; i < this._points.length; i++) {
214
- let pointCoord = i * this._sliderBg._baseObject[this.sizeKey] / (this._points.length - 1);
303
+ let pointCoord = i * this.sliderSize / (this._points.length - 1);
215
304
 
216
305
  if (typeof (coord) === 'number' && givenValue - pointCoord < coord - givenValue) {
217
306
  coord = coord;
@@ -225,6 +314,9 @@ class ModulesObjectsModelsSlider extends Urso.Core.Modules.Objects.BaseModel {
225
314
  return { coord, value };
226
315
  }
227
316
 
317
+ /**
318
+ * Set mask for fill texture depends on handle position.
319
+ */
228
320
  _setFillMask() {
229
321
  if (!this._fillMask)
230
322
  return
@@ -236,6 +328,11 @@ class ModulesObjectsModelsSlider extends Urso.Core.Modules.Objects.BaseModel {
236
328
  this._fillMask[scaleKey] = progress;
237
329
  }
238
330
 
331
+ /**
332
+ * Set handle position and value.
333
+ * @param { Number } coord
334
+ * @param { Number } value
335
+ */
239
336
  _setNewValue(coord, value) {
240
337
  this._sliderHandle[this.positionKey] = coord;
241
338
 
@@ -246,6 +246,9 @@ class ModulesObjectsModelsSpine extends Urso.Core.Modules.Objects.BaseModel {
246
246
  if (!spineAsset)
247
247
  Urso.logger.error('ModulesObjectsModelsSpine assets error: no spine object ' + this.assetKey);
248
248
 
249
+ if (!spineAsset.spineData)
250
+ Urso.logger.error('ModulesObjectsModelsSpine assets error: no spine correct object (no spineData) for key ' + this.assetKey);
251
+
249
252
  this._baseObject = new PIXI.spine.Spine(spineAsset.spineData);
250
253
  //this._baseObject.state.timeScale = this.animation.timeScale;
251
254
  Object.defineProperty(this._baseObject.state, 'timeScale', { get: this.getTimeScale.bind(this) });