@urso/core 0.8.21 → 0.9.1-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 (134) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +227 -227
  3. package/build/js/index.js +77212 -2
  4. package/package.json +36 -50
  5. package/src/js/app.js +105 -104
  6. package/src/js/components/base/controller.js +76 -78
  7. package/src/js/components/debug/controller.js +39 -39
  8. package/src/js/components/debug/coords.js +23 -23
  9. package/src/js/components/debug/fps.js +36 -36
  10. package/src/js/components/debug/template.js +55 -55
  11. package/src/js/components/debug/timescale.js +60 -60
  12. package/src/js/components/deviceRotate/controller.js +95 -95
  13. package/src/js/components/editor/api.js +127 -127
  14. package/src/js/components/editor/controller.js +13 -13
  15. package/src/js/components/fullscreen/android.js +104 -104
  16. package/src/js/components/fullscreen/controller.js +76 -76
  17. package/src/js/components/fullscreen/desktop.js +49 -49
  18. package/src/js/components/fullscreen/ios.js +115 -115
  19. package/src/js/components/layersSwitcher/config.js +26 -26
  20. package/src/js/components/layersSwitcher/controller.js +36 -36
  21. package/src/js/components/loader/controller.js +66 -66
  22. package/src/js/components/loader/template.js +71 -71
  23. package/src/js/components/soundInitialPopup/controller.js +43 -43
  24. package/src/js/components/soundInitialPopup/template.js +110 -110
  25. package/src/js/components/stateDriven/controller.js +123 -123
  26. package/src/js/config/load.js +325 -194
  27. package/src/js/config/main.js +17 -17
  28. package/src/js/extra/browserEvents.js +57 -57
  29. package/src/js/extra/main.js +23 -25
  30. package/src/js/extra/pixiPatch.js +173 -171
  31. package/src/js/index.js +7 -7
  32. package/src/js/lib/cache.js +199 -125
  33. package/src/js/lib/composition.js +85 -85
  34. package/src/js/lib/device.js +1215 -1215
  35. package/src/js/lib/helper.js +678 -678
  36. package/src/js/lib/loader.js +216 -218
  37. package/src/js/lib/localData.js +29 -29
  38. package/src/js/lib/logger.js +69 -69
  39. package/src/js/lib/math.js +161 -161
  40. package/src/js/lib/objectPool.js +208 -208
  41. package/src/js/lib/time.js +19 -19
  42. package/src/js/lib/tween.js +153 -153
  43. package/src/js/modules/assets/baseModel.js +21 -21
  44. package/src/js/modules/assets/config.js +38 -38
  45. package/src/js/modules/assets/controller.js +65 -65
  46. package/src/js/modules/assets/models/atlas.js +19 -19
  47. package/src/js/modules/assets/models/audiosprite.js +28 -28
  48. package/src/js/modules/assets/models/bitmapFont.js +11 -11
  49. package/src/js/modules/assets/models/container.js +19 -19
  50. package/src/js/modules/assets/models/font.js +11 -11
  51. package/src/js/modules/assets/models/html.js +11 -11
  52. package/src/js/modules/assets/models/image.js +17 -17
  53. package/src/js/modules/assets/models/json.js +11 -11
  54. package/src/js/modules/assets/models/jsonAtlas.js +11 -11
  55. package/src/js/modules/assets/models/sound.js +17 -17
  56. package/src/js/modules/assets/models/spine.js +18 -17
  57. package/src/js/modules/assets/models/spineAtlas.js +11 -0
  58. package/src/js/modules/assets/service.js +564 -553
  59. package/src/js/modules/i18n/config.js +17 -17
  60. package/src/js/modules/i18n/controller.js +71 -71
  61. package/src/js/modules/instances/controller.js +357 -357
  62. package/src/js/modules/logic/config/sounds.js +23 -23
  63. package/src/js/modules/logic/controller.js +52 -52
  64. package/src/js/modules/logic/main.js +8 -8
  65. package/src/js/modules/logic/sounds.js +103 -103
  66. package/src/js/modules/objects/baseModel.js +205 -207
  67. package/src/js/modules/objects/cache.js +99 -99
  68. package/src/js/modules/objects/config.js +10 -10
  69. package/src/js/modules/objects/controller.js +139 -139
  70. package/src/js/modules/objects/find.js +58 -58
  71. package/src/js/modules/objects/models/bitmapText.js +56 -49
  72. package/src/js/modules/objects/models/button.js +208 -209
  73. package/src/js/modules/objects/models/buttonComposite.js +38 -38
  74. package/src/js/modules/objects/models/checkbox.js +100 -100
  75. package/src/js/modules/objects/models/collection.js +56 -54
  76. package/src/js/modules/objects/models/component.js +48 -48
  77. package/src/js/modules/objects/models/container.js +22 -22
  78. package/src/js/modules/objects/models/emitterFx.js +103 -114
  79. package/src/js/modules/objects/models/graphics.js +40 -40
  80. package/src/js/modules/objects/models/group.js +22 -22
  81. package/src/js/modules/objects/models/hitArea.js +187 -187
  82. package/src/js/modules/objects/models/image.js +36 -36
  83. package/src/js/modules/objects/models/imagesAnimation.js +115 -115
  84. package/src/js/modules/objects/models/mask.js +40 -40
  85. package/src/js/modules/objects/models/nineSlicePlane.js +32 -32
  86. package/src/js/modules/objects/models/slider.js +357 -357
  87. package/src/js/modules/objects/models/spine.js +354 -339
  88. package/src/js/modules/objects/models/text.js +70 -70
  89. package/src/js/modules/objects/models/toggle.js +186 -186
  90. package/src/js/modules/objects/models/world.js +22 -22
  91. package/src/js/modules/objects/pool.js +68 -68
  92. package/src/js/modules/objects/propertyAdapter.js +592 -592
  93. package/src/js/modules/objects/proxy.js +299 -298
  94. package/src/js/modules/objects/selector.js +136 -136
  95. package/src/js/modules/objects/service.js +255 -254
  96. package/src/js/modules/objects/styles.js +210 -210
  97. package/src/js/modules/observer/controller.js +168 -168
  98. package/src/js/modules/observer/events.js +51 -56
  99. package/src/js/modules/scenes/controller.js +126 -127
  100. package/src/js/modules/scenes/model.js +28 -28
  101. package/src/js/modules/scenes/pixiWrapper.js +360 -351
  102. package/src/js/modules/scenes/resolutions.js +173 -173
  103. package/src/js/modules/scenes/resolutionsConfig.js +73 -73
  104. package/src/js/modules/scenes/service.js +144 -146
  105. package/src/js/modules/soundManager/controller.js +103 -103
  106. package/src/js/modules/soundManager/soundSprite.js +314 -314
  107. package/src/js/modules/statesManager/action.js +97 -97
  108. package/src/js/modules/statesManager/all.js +23 -23
  109. package/src/js/modules/statesManager/configStates.js +77 -77
  110. package/src/js/modules/statesManager/controller.js +219 -219
  111. package/src/js/modules/statesManager/functionsStorage.js +83 -83
  112. package/src/js/modules/statesManager/helper.js +27 -27
  113. package/src/js/modules/statesManager/race.js +91 -91
  114. package/src/js/modules/statesManager/sequence.js +48 -48
  115. package/src/js/modules/template/controller.js +28 -28
  116. package/src/js/modules/template/model.js +11 -11
  117. package/src/js/modules/template/service.js +137 -137
  118. package/src/js/modules/template/types.js +50 -49
  119. package/src/js/modules/transport/baseConnectionType.js +25 -25
  120. package/src/js/modules/transport/config.js +13 -13
  121. package/src/js/modules/transport/connectionTypes/websocket.js +77 -77
  122. package/src/js/modules/transport/connectionTypes/xhr.js +47 -47
  123. package/src/js/modules/transport/controller.js +48 -48
  124. package/src/js/modules/transport/decorator.js +17 -17
  125. package/src/js/modules/transport/service.js +150 -150
  126. package/vite.config.js +31 -0
  127. package/.babelrc +0 -12
  128. package/build/js/index.js.LICENSE.txt +0 -227
  129. package/src/js/modules/objects/models/atlasImage.js +0 -52
  130. package/src/js/modules/objects/models/dragContainer.js +0 -665
  131. package/src/js/modules/objects/models/emitter.js +0 -69
  132. package/src/js/modules/objects/models/scrollbox.js +0 -67
  133. package/src/js/modules/objects/models/textInput.js +0 -68
  134. package/webpack.config.js +0 -47
@@ -1,678 +1,678 @@
1
- class LibHelper {
2
-
3
- constructor() {
4
-
5
- /**
6
- * angle radian factor
7
- * @type Number
8
- */
9
- this._arFactor = (Math.PI / 180);
10
- }
11
-
12
- /**
13
- * getting GET param(s) by name or all params list
14
- *
15
- * @param {string} [name] - get param name
16
- * @returns {Object}
17
- */
18
- parseGetParams(name) {
19
- let $_GET = {};
20
- const _GET = window.location.href.substring(1).split("?");
21
-
22
- if (_GET[1]) {
23
- const __GET = _GET[1].split("&");
24
-
25
- for (let i = 0; i < __GET.length; i++) {
26
- let getVar = __GET[i].split("=");
27
- $_GET[getVar[0]] = typeof getVar[1] === "undefined" ? "" : getVar[1];
28
- }
29
- }
30
-
31
- if (!name)
32
- return $_GET;
33
-
34
- return $_GET[name];
35
- }
36
-
37
- /**
38
- * waiter for dom element on page
39
- * @param {String} selector
40
- * @returns {Promice}
41
- *
42
- * @example
43
- * waitForDomElement(.game-container).then(()=>{...})
44
- */
45
- waitForDomElement(selector) {
46
- return new Promise(resolve => {
47
- if (document.querySelector(selector)) {
48
- return resolve(document.querySelector(selector));
49
- }
50
-
51
- const observer = new MutationObserver(mutations => {
52
- if (document.querySelector(selector)) {
53
- resolve(document.querySelector(selector));
54
- observer.disconnect();
55
- }
56
- });
57
-
58
- observer.observe(document.body, {
59
- childList: true,
60
- subtree: true
61
- });
62
- });
63
- }
64
-
65
- /**
66
- * get uniq elements from two arrays
67
- * @param {Array} array1
68
- * @param {Array} array2
69
- * @example arraysGetUniqElements([1,2,3], [2,3,4]) returns [1, 4]
70
- */
71
- arraysGetUniqElements(array1, array2) {
72
- const result = [];
73
- const tempObject = {};
74
- let key, element;
75
-
76
- const parseArray = function (arrayObject) {
77
- for (element of arrayObject) {
78
- if (!tempObject[element])
79
- tempObject[element] = { counter: 1, value: element };
80
- else
81
- tempObject[element].counter++;
82
- }
83
- };
84
-
85
- parseArray(array1);
86
- parseArray(array2);
87
-
88
- for (key in tempObject)
89
- if (tempObject[key].counter === 1)
90
- result.push(tempObject[key].value);
91
-
92
- return result;
93
- }
94
-
95
- /**
96
- * replase string pattern in the string
97
- * @param {String} needle
98
- * @param {String} replacement
99
- * @param {String} haystack
100
- * @returns {String}
101
- */
102
- stringReplace(needle, replacement, haystack) {
103
- return haystack.split(needle).join(replacement);
104
- }
105
-
106
- /**
107
- * capitalise first letter in the string
108
- * @param {String} str
109
- * @returns {String}
110
- */
111
- capitaliseFirstLetter(str) {
112
- return str.charAt(0).toUpperCase() + str.slice(1);
113
- }
114
-
115
- /**
116
- * returns array without last element
117
- * @param {Array} array
118
- * @returns {Array}
119
- */
120
- initial(array) {
121
- array.pop();
122
- return array;
123
- }
124
-
125
- /**
126
- * lead degree zero
127
- * @param {Number} num
128
- * @param {Number} count
129
- * @returns {String}
130
- */
131
- ldgZero(num, count) {
132
- let numZeropad = num + '';
133
-
134
- while (numZeropad.length < count) {
135
- numZeropad = "0" + numZeropad;
136
- }
137
-
138
- return numZeropad;
139
- }
140
-
141
- /**
142
- * merge two arrays into new array
143
- * @param {Array} a
144
- * @param {Array} b
145
- */
146
- mergeArrays(a, b) {
147
- let c = a.concat(b.filter(function (item) {
148
- return a.indexOf(item) < 0;
149
- }));
150
-
151
- return c;
152
- }
153
-
154
- /**
155
- * Swap key with value in object
156
- * @param {Object} obj
157
- * @returns {Object}
158
- */
159
- objectFlip(obj) {
160
- const ret = {};
161
-
162
- Object.keys(obj).forEach(key => {
163
- ret[obj[key]] = key;
164
- });
165
-
166
- return ret;
167
- }
168
-
169
- /**
170
- * recursive set value to object by key
171
- * (*) you can use '.' as objects keys splitter
172
- * @param {String} key
173
- * @param {Mixed} value
174
- * @param {Object} object
175
- * @returns {Boolean}
176
- */
177
- recursiveSet(key, value, object) {
178
- key = (typeof key === 'string') ? key.split(".") : key;
179
-
180
- let firstKey = key.shift();
181
-
182
- if (key.length > 0) {
183
- if (!object[firstKey])
184
- object[firstKey] = {};
185
-
186
- this.recursiveSet(key, value, object[firstKey]);
187
- } else
188
- object[firstKey] = value;
189
-
190
- return true;
191
- }
192
-
193
- /**
194
- * @param {Array} matrix
195
- * @returns {Array}
196
- */
197
- rowsToCols(matrix) {
198
- return Object.keys(matrix[0])
199
- .map(colNumber => matrix.map(rowNumber => rowNumber[colNumber]));
200
- }
201
-
202
- /**
203
- * recursive get value from object by key
204
- * (*) you can use '.' as objects keys splitter
205
- * @param {String} key
206
- * @param {Object} object
207
- * @returns {Mixed}
208
- */
209
- recursiveGet(key, object, defaultResult) {
210
- if (object === undefined)
211
- return defaultResult;
212
-
213
- key = (typeof key === 'string') ? key.split(".") : key;
214
-
215
- for (let k of key) {
216
- if (typeof object[k] === 'undefined')
217
- return defaultResult;
218
-
219
- object = object[k];
220
- }
221
-
222
- return object;
223
- }
224
-
225
- /**
226
- * recursive delete value from object by key
227
- * (*) you can use '.' as objects keys splitter
228
- * @param {String} key
229
- * @param {Object} object
230
- * @returns {Boolean}
231
- */
232
- recursiveDelete(key, obj) {
233
- key = (typeof key === 'string') ? key.split(".") : key;
234
-
235
- for (let k = 0; k < key.length; k++) {
236
- let ok = key[k];
237
-
238
- if (typeof obj[ok] === 'undefined')
239
- return false;
240
-
241
- if (k === (key.length - 1))
242
- delete (obj[ok]);
243
- else
244
- obj = obj[ok];
245
- }
246
-
247
- return true;
248
- }
249
-
250
- /**
251
- * tranpose matrix (rows to cols)
252
- * @param {Array} matrix
253
- * @returns {Array}
254
- */
255
- transpose(matrix) {
256
- return Object.keys(matrix[0])
257
- .map(colNumber => matrix
258
- .map(rowNumber => rowNumber[colNumber]));
259
- }
260
-
261
- /**
262
- * recursive merge two objects into one
263
- * @param {Object} obj1
264
- * @param {Object} obj2
265
- * @param {Boolean} mergeInFirstFlag
266
- * @returns {Object}
267
- */
268
- mergeObjectsRecursive(obj1, obj2, mergeInFirstFlag) {
269
- let newObj = (mergeInFirstFlag) ? obj1 : this.objectClone(obj1);
270
-
271
- for (let k in obj2) {
272
- if (typeof obj2[k] === 'object' && typeof obj1[k] === 'object')
273
- newObj[k] = this.mergeObjectsRecursive(obj1[k], obj2[k], mergeInFirstFlag);
274
- else
275
- newObj[k] = obj2[k];
276
- }
277
-
278
- return newObj;
279
- }
280
-
281
- /**
282
- * rename objects key
283
- * @param {Object} obj
284
- * @param {String} oldKey
285
- * @param {String} newKey
286
- */
287
- renameObjectsKey(obj, oldKey, newKey) {
288
- if (oldKey !== newKey) {
289
- Object.defineProperty(
290
- obj, newKey,
291
- Object.getOwnPropertyDescriptor(obj, oldKey)
292
- );
293
-
294
- delete obj[oldKey];
295
- }
296
- }
297
-
298
- /**
299
- * clone object
300
- * @param {Object} obj
301
- * @param {Number} recursiveCalls
302
- * @returns {Object}
303
- */
304
- objectClone(obj, recursiveCalls) {
305
- if (!obj || "object" !== typeof obj)
306
- return obj;
307
-
308
- if (typeof recursiveCalls === 'undefined')
309
- recursiveCalls = 999;
310
-
311
- let clone = "function" === typeof obj.pop ? [] : {}; //object o array
312
- let prop, propValue;
313
-
314
- if (obj.hasOwnProperty)
315
- for (prop in obj) {
316
- if (obj.hasOwnProperty(prop)) {
317
- propValue = obj[prop];
318
-
319
- if (prop === "imageSrc")
320
- clone[prop] = propValue;
321
- else if (propValue && "object" === typeof propValue)
322
- clone[prop] = (recursiveCalls) ? this.objectClone(propValue, recursiveCalls - 1) : '[object Object]';
323
- else
324
- clone[prop] = propValue;
325
- }
326
- }
327
-
328
- return clone;
329
- }
330
-
331
- /**
332
- * get object size (keys length)
333
- * @param {Object} obj
334
- * @returns {Number}
335
- */
336
- getObjectSize(obj) {
337
- return Object.keys(obj).length;
338
- }
339
-
340
- /**
341
- * object apply
342
- * @param {Object} fromObj
343
- * @param {Object} toObj
344
- * @returns {Object}
345
- */
346
- objectApply(fromObj, toObj, recursiveCalls = 999) {
347
- if (!recursiveCalls)
348
- return fromObj;
349
-
350
- for (let k in toObj) {
351
- let paramTo = toObj[k];
352
-
353
- if (!fromObj[k]) {
354
- fromObj[k] = paramTo;
355
- } else if (typeof paramTo === "array" || typeof paramTo === "object") {
356
- fromObj[k] = this.objectApply(fromObj[k], toObj[k], recursiveCalls - 1);
357
- } else {
358
- if (toObj[k] !== fromObj[k]) {
359
- fromObj[k] = paramTo;
360
- }
361
- }
362
- }
363
-
364
- return fromObj;
365
- }
366
-
367
- /**
368
- * check deep objects equal
369
- * @param {Object} obj1
370
- * @param {Object} obj2
371
- * @returns {Boolean}
372
- */
373
- checkDeepEqual(obj1, obj2) {
374
- return JSON.stringify(obj1) === JSON.stringify(obj2);
375
- }
376
-
377
- /**
378
- * check objects equal
379
- * @param {Object} obj1
380
- * @param {Object} obj2
381
- * @returns {Boolean}
382
- */
383
- checkEqual(obj1, obj2) {
384
- const objSort = (o) => {
385
- const sortedObj = {};
386
- const keys = Object.keys(o);
387
- keys.sort();
388
-
389
- for (let index in keys) {
390
- if (keys.hasOwnProperty(index)) {
391
- let key = keys[index];
392
- let value = o[key];
393
-
394
- if (typeof o[key] === 'object')
395
- value = objSort(value);
396
-
397
- sortedObj[key] = value;
398
- }
399
- }
400
-
401
- return sortedObj;
402
- };
403
-
404
- const o1s = objSort(obj1);
405
- const o2s = objSort(obj2);
406
-
407
- return this.checkDeepEqual(o1s, o2s);
408
- }
409
-
410
- /**
411
- * check Arrays Partial Entry
412
- * @param {Object} main
413
- * @param {Object} partial
414
- * @returns {Boolean}
415
- */
416
- checkArraysPartialEntry(main, partial) {
417
- if (!main || !partial)
418
- return false;
419
-
420
- main = main.sort();
421
- partial = partial.sort();
422
-
423
- let kPartial = partial.length - 1;
424
-
425
- for (let i = main.length - 1; i >= 0; i--) {
426
- if (JSON.stringify(main[i]) === JSON.stringify(partial[kPartial]))
427
- kPartial--;
428
-
429
- if (kPartial === -1)
430
- return true;
431
- }
432
-
433
- return false;
434
- }
435
-
436
- /**
437
- * check is device mobile or tablet
438
- * @returns {Boolean}
439
- */
440
- mobileAndTabletCheck() {
441
- let check = false;
442
- (function (a) {
443
- if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4)))
444
- check = true;
445
- })(navigator.userAgent || navigator.vendor || window.opera);
446
-
447
- return check || Urso.helper.isIpadOS();
448
- }
449
-
450
- /**
451
- * check for Ipad OS
452
- */
453
- isIpadOS = () => {
454
- return navigator.maxTouchPoints &&
455
- navigator.maxTouchPoints > 2 &&
456
- /MacIntel/.test(navigator.platform);
457
- }
458
-
459
- /**
460
- * make objects property reactive
461
- * @param {Object} targetObject
462
- * @param {String} key
463
- * @param {Function} callback
464
- * @returns
465
- */
466
- reactive(targetObject, key, callback) {
467
- let descriptor = Object.getOwnPropertyDescriptor(targetObject, key);
468
- let targetObjectTemp = targetObject;
469
-
470
- while (!descriptor && targetObjectTemp.__proto__) {
471
- targetObjectTemp = targetObjectTemp.__proto__;
472
- let descriptorTemp = Object.getOwnPropertyDescriptor(targetObjectTemp, key);
473
-
474
- if (descriptorTemp && (descriptorTemp.value || descriptorTemp.set || descriptorTemp.get)) {
475
- descriptor = descriptorTemp;
476
- }
477
- }
478
-
479
- if (!descriptor) // bad descriptors and its IOS mobile
480
- return false;
481
-
482
- if (typeof descriptor.value !== 'undefined') {
483
- let value = descriptor.value;
484
- descriptor.get = function () { return value; };
485
- descriptor.set = function (v) { value = v; };
486
-
487
- delete descriptor.value;
488
- delete descriptor.writable;
489
- }
490
-
491
- let setter = descriptor.set;
492
-
493
- descriptor.set = function (v) {
494
- if (setter)
495
- setter.call(targetObject, v);
496
-
497
- callback.call(targetObject, v);
498
- };
499
-
500
- Object.defineProperty(targetObject, key, descriptor);
501
-
502
- return true;
503
- }
504
-
505
-
506
- /**
507
- * calc length between two points
508
- *
509
- * @param {Object} point1
510
- * @param {Object} point1
511
- * @return {Number}
512
- */
513
- getLengthBy2Points(point1, point2) {
514
- return Math.sqrt((point2.x - point1.x) * (point2.x - point1.x) +
515
- (point2.y - point1.y) * (point2.y - point1.y));
516
- }
517
-
518
- /**
519
- * calc angle between three points (in radians)
520
- *
521
- * @param {Object} point1
522
- * @param {Object} point2
523
- * @param {Object} point3
524
- * @return {Number}
525
- */
526
- getAngleBy3Points(point1, point2, point3) {
527
- let angle = 0;
528
- const c = this.getLengthBy2Points(point1, point3);
529
- const a = this.getLengthBy2Points(point1, point2);
530
- const b = this.getLengthBy2Points(point2, point3);
531
-
532
- if (a !== 0 && b !== 0) {
533
- const cornerRcos = Urso.math.intMakeBetween(
534
- (a * a + b * b - c * c) / (2 * a * b),
535
- -1, 1
536
- );
537
-
538
- angle = Math.acos(cornerRcos);
539
- }
540
-
541
- return angle;
542
- }
543
-
544
-
545
- /**
546
- * get angle in radians from degrees
547
- *
548
- * @param {Number} angle
549
- * @return {Number}
550
- */
551
- getRadian(angle) {
552
- return (angle * this._arFactor);
553
- }
554
-
555
- /**
556
- * get angle in degrees from radians
557
- *
558
- * @param {Number} radian
559
- * @return {Number}
560
- */
561
- getAngle(radian) {
562
- return (radian / this._arFactor);
563
- }
564
-
565
- /**
566
- * arguments {oblect} (ClassInstance, functionName, param1, param2, ...)
567
- * needs {Object} obj._logicBlocks;
568
- * creates {Object} obj._logicBlocksInstances;
569
- * @returns {Array} execution results
570
- */
571
- logicBlocksDo() {
572
- const params = Array.prototype.slice.call(arguments);
573
- const entity = params.shift();
574
- const funcName = params.shift();
575
-
576
- //if no instances we will create them
577
- if (!entity._logicBlocksInstances) {
578
- entity._logicBlocksInstances = {};
579
-
580
- for (let k in entity._logicBlocks) {
581
- const name = entity._logicBlocks[k];
582
- const nameCap = this.capitaliseFirstLetter(name);
583
- entity._logicBlocksInstances[name] = entity.getInstance(nameCap);
584
- }
585
- }
586
-
587
- let results = [];
588
- //game
589
- for (let name in entity._logicBlocksInstances) {
590
- if (entity._logicBlocksInstances[name][funcName]) {
591
- const res = entity._logicBlocksInstances[name][funcName].apply(this, params);
592
- results.push(res);
593
- }
594
- }
595
-
596
- return results;
597
- }
598
-
599
- /**
600
- * apply params to string
601
- * @param {String} string
602
- * @param {Object} params
603
- * @returns {String}
604
- *
605
- * @example interpolate('Bet ${bet} with Multi ${multi}', {bet:12,multi:13})
606
- * returns 'Bet 12 with Multi 13'
607
- */
608
- interpolate(string, params) {
609
- for (const [key, value] of Object.entries(params)) {
610
- string = Urso.helper.stringReplace('${' + key + '}', value, string);
611
- }
612
-
613
- return string
614
- }
615
-
616
- /**
617
- * Converts color number to object that contents RGB values
618
- * @param { Number } color - color number
619
- * @returns { Object }
620
- */
621
- getRGB(color) {
622
- return {
623
- alpha: 16777215 < color ? color >>> 24 : 255,
624
- red: color >> 16 & 255,
625
- green: color >> 8 & 255,
626
- blue: 255 & color
627
- };
628
- }
629
-
630
- /**
631
- * Converts RGB values to 32 bit
632
- * @param { Number } alpha
633
- * @param { Number } red
634
- * @param { Number } green
635
- * @param { Number } blue
636
- * @returns { Number }
637
- */
638
- getColor32(alpha, red, green, blue) {
639
- return alpha << 24 | red << 16 | green << 8 | blue;
640
- }
641
-
642
- /**
643
- * Returns color interpolation depends on step value
644
- * @param { Number } startColor
645
- * @param { Number } targetColor
646
- * @param { Number } step - intermediate value from 0 to 1
647
- * @returns { Number }
648
- */
649
- interpolateColor32(startColor, targetColor, step) {
650
- if (startColor === targetColor)
651
- return startColor;
652
-
653
- const startColorRGB = this.getRGB(startColor);
654
- const targetColorRGB = this.getRGB(targetColor);
655
- const nextColorRGB = this.interpolateColorRGB(startColorRGB, targetColorRGB, step);
656
- const color32 = this.getColor32(255, nextColorRGB.red, nextColorRGB.green, nextColorRGB.blue);
657
- return 16777215 + color32;
658
- }
659
-
660
- /**
661
- * Returns color interpolation as RGB object depends on step value
662
- * @param { Object } startColorRGB - object that contents start values for red, green and blue
663
- * @param { Object } targetColorRGB - object that contents target values for red, green and blue
664
- * @param { Number } step - intermediate value from 0 to 1
665
- * @returns { Object }
666
- */
667
- interpolateColorRGB(startColorRGB, targetColorRGB, step) {
668
- const nextRGB = {};
669
-
670
- Object.keys(startColorRGB).forEach(color => {
671
- nextRGB[color] = (targetColorRGB[color] - startColorRGB[color]) * step + startColorRGB[color];
672
- });
673
-
674
- return nextRGB;
675
- }
676
- }
677
-
678
- module.exports = LibHelper;
1
+ class LibHelper {
2
+
3
+ constructor() {
4
+
5
+ /**
6
+ * angle radian factor
7
+ * @type Number
8
+ */
9
+ this._arFactor = (Math.PI / 180);
10
+ }
11
+
12
+ /**
13
+ * getting GET param(s) by name or all params list
14
+ *
15
+ * @param {string} [name] - get param name
16
+ * @returns {Object}
17
+ */
18
+ parseGetParams(name) {
19
+ let $_GET = {};
20
+ const _GET = window.location.href.substring(1).split("?");
21
+
22
+ if (_GET[1]) {
23
+ const __GET = _GET[1].split("&");
24
+
25
+ for (let i = 0; i < __GET.length; i++) {
26
+ let getVar = __GET[i].split("=");
27
+ $_GET[getVar[0]] = typeof getVar[1] === "undefined" ? "" : getVar[1];
28
+ }
29
+ }
30
+
31
+ if (!name)
32
+ return $_GET;
33
+
34
+ return $_GET[name];
35
+ }
36
+
37
+ /**
38
+ * waiter for dom element on page
39
+ * @param {String} selector
40
+ * @returns {Promice}
41
+ *
42
+ * @example
43
+ * waitForDomElement(.game-container).then(()=>{...})
44
+ */
45
+ waitForDomElement(selector) {
46
+ return new Promise(resolve => {
47
+ if (document.querySelector(selector)) {
48
+ return resolve(document.querySelector(selector));
49
+ }
50
+
51
+ const observer = new MutationObserver(mutations => {
52
+ if (document.querySelector(selector)) {
53
+ resolve(document.querySelector(selector));
54
+ observer.disconnect();
55
+ }
56
+ });
57
+
58
+ observer.observe(document.body, {
59
+ childList: true,
60
+ subtree: true
61
+ });
62
+ });
63
+ }
64
+
65
+ /**
66
+ * get uniq elements from two arrays
67
+ * @param {Array} array1
68
+ * @param {Array} array2
69
+ * @example arraysGetUniqElements([1,2,3], [2,3,4]) returns [1, 4]
70
+ */
71
+ arraysGetUniqElements(array1, array2) {
72
+ const result = [];
73
+ const tempObject = {};
74
+ let key, element;
75
+
76
+ const parseArray = function (arrayObject) {
77
+ for (element of arrayObject) {
78
+ if (!tempObject[element])
79
+ tempObject[element] = { counter: 1, value: element };
80
+ else
81
+ tempObject[element].counter++;
82
+ }
83
+ };
84
+
85
+ parseArray(array1);
86
+ parseArray(array2);
87
+
88
+ for (key in tempObject)
89
+ if (tempObject[key].counter === 1)
90
+ result.push(tempObject[key].value);
91
+
92
+ return result;
93
+ }
94
+
95
+ /**
96
+ * replase string pattern in the string
97
+ * @param {String} needle
98
+ * @param {String} replacement
99
+ * @param {String} haystack
100
+ * @returns {String}
101
+ */
102
+ stringReplace(needle, replacement, haystack) {
103
+ return haystack.split(needle).join(replacement);
104
+ }
105
+
106
+ /**
107
+ * capitalise first letter in the string
108
+ * @param {String} str
109
+ * @returns {String}
110
+ */
111
+ capitaliseFirstLetter(str) {
112
+ return str.charAt(0).toUpperCase() + str.slice(1);
113
+ }
114
+
115
+ /**
116
+ * returns array without last element
117
+ * @param {Array} array
118
+ * @returns {Array}
119
+ */
120
+ initial(array) {
121
+ array.pop();
122
+ return array;
123
+ }
124
+
125
+ /**
126
+ * lead degree zero
127
+ * @param {Number} num
128
+ * @param {Number} count
129
+ * @returns {String}
130
+ */
131
+ ldgZero(num, count) {
132
+ let numZeropad = num + '';
133
+
134
+ while (numZeropad.length < count) {
135
+ numZeropad = "0" + numZeropad;
136
+ }
137
+
138
+ return numZeropad;
139
+ }
140
+
141
+ /**
142
+ * merge two arrays into new array
143
+ * @param {Array} a
144
+ * @param {Array} b
145
+ */
146
+ mergeArrays(a, b) {
147
+ let c = a.concat(b.filter(function (item) {
148
+ return a.indexOf(item) < 0;
149
+ }));
150
+
151
+ return c;
152
+ }
153
+
154
+ /**
155
+ * Swap key with value in object
156
+ * @param {Object} obj
157
+ * @returns {Object}
158
+ */
159
+ objectFlip(obj) {
160
+ const ret = {};
161
+
162
+ Object.keys(obj).forEach(key => {
163
+ ret[obj[key]] = key;
164
+ });
165
+
166
+ return ret;
167
+ }
168
+
169
+ /**
170
+ * recursive set value to object by key
171
+ * (*) you can use '.' as objects keys splitter
172
+ * @param {String} key
173
+ * @param {Mixed} value
174
+ * @param {Object} object
175
+ * @returns {Boolean}
176
+ */
177
+ recursiveSet(key, value, object) {
178
+ key = (typeof key === 'string') ? key.split(".") : key;
179
+
180
+ let firstKey = key.shift();
181
+
182
+ if (key.length > 0) {
183
+ if (!object[firstKey])
184
+ object[firstKey] = {};
185
+
186
+ this.recursiveSet(key, value, object[firstKey]);
187
+ } else
188
+ object[firstKey] = value;
189
+
190
+ return true;
191
+ }
192
+
193
+ /**
194
+ * @param {Array} matrix
195
+ * @returns {Array}
196
+ */
197
+ rowsToCols(matrix) {
198
+ return Object.keys(matrix[0])
199
+ .map(colNumber => matrix.map(rowNumber => rowNumber[colNumber]));
200
+ }
201
+
202
+ /**
203
+ * recursive get value from object by key
204
+ * (*) you can use '.' as objects keys splitter
205
+ * @param {String} key
206
+ * @param {Object} object
207
+ * @returns {Mixed}
208
+ */
209
+ recursiveGet(key, object, defaultResult) {
210
+ if (object === undefined)
211
+ return defaultResult;
212
+
213
+ key = (typeof key === 'string') ? key.split(".") : key;
214
+
215
+ for (let k of key) {
216
+ if (typeof object[k] === 'undefined')
217
+ return defaultResult;
218
+
219
+ object = object[k];
220
+ }
221
+
222
+ return object;
223
+ }
224
+
225
+ /**
226
+ * recursive delete value from object by key
227
+ * (*) you can use '.' as objects keys splitter
228
+ * @param {String} key
229
+ * @param {Object} object
230
+ * @returns {Boolean}
231
+ */
232
+ recursiveDelete(key, obj) {
233
+ key = (typeof key === 'string') ? key.split(".") : key;
234
+
235
+ for (let k = 0; k < key.length; k++) {
236
+ let ok = key[k];
237
+
238
+ if (typeof obj[ok] === 'undefined')
239
+ return false;
240
+
241
+ if (k === (key.length - 1))
242
+ delete (obj[ok]);
243
+ else
244
+ obj = obj[ok];
245
+ }
246
+
247
+ return true;
248
+ }
249
+
250
+ /**
251
+ * tranpose matrix (rows to cols)
252
+ * @param {Array} matrix
253
+ * @returns {Array}
254
+ */
255
+ transpose(matrix) {
256
+ return Object.keys(matrix[0])
257
+ .map(colNumber => matrix
258
+ .map(rowNumber => rowNumber[colNumber]));
259
+ }
260
+
261
+ /**
262
+ * recursive merge two objects into one
263
+ * @param {Object} obj1
264
+ * @param {Object} obj2
265
+ * @param {Boolean} mergeInFirstFlag
266
+ * @returns {Object}
267
+ */
268
+ mergeObjectsRecursive(obj1, obj2, mergeInFirstFlag) {
269
+ let newObj = (mergeInFirstFlag) ? obj1 : this.objectClone(obj1);
270
+
271
+ for (let k in obj2) {
272
+ if (typeof obj2[k] === 'object' && typeof obj1[k] === 'object')
273
+ newObj[k] = this.mergeObjectsRecursive(obj1[k], obj2[k], mergeInFirstFlag);
274
+ else
275
+ newObj[k] = obj2[k];
276
+ }
277
+
278
+ return newObj;
279
+ }
280
+
281
+ /**
282
+ * rename objects key
283
+ * @param {Object} obj
284
+ * @param {String} oldKey
285
+ * @param {String} newKey
286
+ */
287
+ renameObjectsKey(obj, oldKey, newKey) {
288
+ if (oldKey !== newKey) {
289
+ Object.defineProperty(
290
+ obj, newKey,
291
+ Object.getOwnPropertyDescriptor(obj, oldKey)
292
+ );
293
+
294
+ delete obj[oldKey];
295
+ }
296
+ }
297
+
298
+ /**
299
+ * clone object
300
+ * @param {Object} obj
301
+ * @param {Number} recursiveCalls
302
+ * @returns {Object}
303
+ */
304
+ objectClone(obj, recursiveCalls) {
305
+ if (!obj || "object" !== typeof obj)
306
+ return obj;
307
+
308
+ if (typeof recursiveCalls === 'undefined')
309
+ recursiveCalls = 999;
310
+
311
+ let clone = "function" === typeof obj.pop ? [] : {}; //object o array
312
+ let prop, propValue;
313
+
314
+ if (obj.hasOwnProperty)
315
+ for (prop in obj) {
316
+ if (obj.hasOwnProperty(prop)) {
317
+ propValue = obj[prop];
318
+
319
+ if (prop === "imageSrc")
320
+ clone[prop] = propValue;
321
+ else if (propValue && "object" === typeof propValue)
322
+ clone[prop] = (recursiveCalls) ? this.objectClone(propValue, recursiveCalls - 1) : '[object Object]';
323
+ else
324
+ clone[prop] = propValue;
325
+ }
326
+ }
327
+
328
+ return clone;
329
+ }
330
+
331
+ /**
332
+ * get object size (keys length)
333
+ * @param {Object} obj
334
+ * @returns {Number}
335
+ */
336
+ getObjectSize(obj) {
337
+ return Object.keys(obj).length;
338
+ }
339
+
340
+ /**
341
+ * object apply
342
+ * @param {Object} fromObj
343
+ * @param {Object} toObj
344
+ * @returns {Object}
345
+ */
346
+ objectApply(fromObj, toObj, recursiveCalls = 999) {
347
+ if (!recursiveCalls)
348
+ return fromObj;
349
+
350
+ for (let k in toObj) {
351
+ let paramTo = toObj[k];
352
+
353
+ if (!fromObj[k]) {
354
+ fromObj[k] = paramTo;
355
+ } else if (typeof paramTo === "array" || typeof paramTo === "object") {
356
+ fromObj[k] = this.objectApply(fromObj[k], toObj[k], recursiveCalls - 1);
357
+ } else {
358
+ if (toObj[k] !== fromObj[k]) {
359
+ fromObj[k] = paramTo;
360
+ }
361
+ }
362
+ }
363
+
364
+ return fromObj;
365
+ }
366
+
367
+ /**
368
+ * check deep objects equal
369
+ * @param {Object} obj1
370
+ * @param {Object} obj2
371
+ * @returns {Boolean}
372
+ */
373
+ checkDeepEqual(obj1, obj2) {
374
+ return JSON.stringify(obj1) === JSON.stringify(obj2);
375
+ }
376
+
377
+ /**
378
+ * check objects equal
379
+ * @param {Object} obj1
380
+ * @param {Object} obj2
381
+ * @returns {Boolean}
382
+ */
383
+ checkEqual(obj1, obj2) {
384
+ const objSort = (o) => {
385
+ const sortedObj = {};
386
+ const keys = Object.keys(o);
387
+ keys.sort();
388
+
389
+ for (let index in keys) {
390
+ if (keys.hasOwnProperty(index)) {
391
+ let key = keys[index];
392
+ let value = o[key];
393
+
394
+ if (typeof o[key] === 'object')
395
+ value = objSort(value);
396
+
397
+ sortedObj[key] = value;
398
+ }
399
+ }
400
+
401
+ return sortedObj;
402
+ };
403
+
404
+ const o1s = objSort(obj1);
405
+ const o2s = objSort(obj2);
406
+
407
+ return this.checkDeepEqual(o1s, o2s);
408
+ }
409
+
410
+ /**
411
+ * check Arrays Partial Entry
412
+ * @param {Object} main
413
+ * @param {Object} partial
414
+ * @returns {Boolean}
415
+ */
416
+ checkArraysPartialEntry(main, partial) {
417
+ if (!main || !partial)
418
+ return false;
419
+
420
+ main = main.sort();
421
+ partial = partial.sort();
422
+
423
+ let kPartial = partial.length - 1;
424
+
425
+ for (let i = main.length - 1; i >= 0; i--) {
426
+ if (JSON.stringify(main[i]) === JSON.stringify(partial[kPartial]))
427
+ kPartial--;
428
+
429
+ if (kPartial === -1)
430
+ return true;
431
+ }
432
+
433
+ return false;
434
+ }
435
+
436
+ /**
437
+ * check is device mobile or tablet
438
+ * @returns {Boolean}
439
+ */
440
+ mobileAndTabletCheck() {
441
+ let check = false;
442
+ (function (a) {
443
+ if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4)))
444
+ check = true;
445
+ })(navigator.userAgent || navigator.vendor || window.opera);
446
+
447
+ return check || Urso.helper.isIpadOS();
448
+ }
449
+
450
+ /**
451
+ * check for Ipad OS
452
+ */
453
+ isIpadOS = () => {
454
+ return navigator.maxTouchPoints &&
455
+ navigator.maxTouchPoints > 2 &&
456
+ /MacIntel/.test(navigator.platform);
457
+ }
458
+
459
+ /**
460
+ * make objects property reactive
461
+ * @param {Object} targetObject
462
+ * @param {String} key
463
+ * @param {Function} callback
464
+ * @returns
465
+ */
466
+ reactive(targetObject, key, callback) {
467
+ let descriptor = Object.getOwnPropertyDescriptor(targetObject, key);
468
+ let targetObjectTemp = targetObject;
469
+
470
+ while (!descriptor && targetObjectTemp.__proto__) {
471
+ targetObjectTemp = targetObjectTemp.__proto__;
472
+ let descriptorTemp = Object.getOwnPropertyDescriptor(targetObjectTemp, key);
473
+
474
+ if (descriptorTemp && (descriptorTemp.value || descriptorTemp.set || descriptorTemp.get)) {
475
+ descriptor = descriptorTemp;
476
+ }
477
+ }
478
+
479
+ if (!descriptor) // bad descriptors and its IOS mobile
480
+ return false;
481
+
482
+ if (typeof descriptor.value !== 'undefined') {
483
+ let value = descriptor.value;
484
+ descriptor.get = function () { return value; };
485
+ descriptor.set = function (v) { value = v; };
486
+
487
+ delete descriptor.value;
488
+ delete descriptor.writable;
489
+ }
490
+
491
+ let setter = descriptor.set;
492
+
493
+ descriptor.set = function (v) {
494
+ if (setter)
495
+ setter.call(targetObject, v);
496
+
497
+ callback.call(targetObject, v);
498
+ };
499
+
500
+ Object.defineProperty(targetObject, key, descriptor);
501
+
502
+ return true;
503
+ }
504
+
505
+
506
+ /**
507
+ * calc length between two points
508
+ *
509
+ * @param {Object} point1
510
+ * @param {Object} point1
511
+ * @return {Number}
512
+ */
513
+ getLengthBy2Points(point1, point2) {
514
+ return Math.sqrt((point2.x - point1.x) * (point2.x - point1.x) +
515
+ (point2.y - point1.y) * (point2.y - point1.y));
516
+ }
517
+
518
+ /**
519
+ * calc angle between three points (in radians)
520
+ *
521
+ * @param {Object} point1
522
+ * @param {Object} point2
523
+ * @param {Object} point3
524
+ * @return {Number}
525
+ */
526
+ getAngleBy3Points(point1, point2, point3) {
527
+ let angle = 0;
528
+ const c = this.getLengthBy2Points(point1, point3);
529
+ const a = this.getLengthBy2Points(point1, point2);
530
+ const b = this.getLengthBy2Points(point2, point3);
531
+
532
+ if (a !== 0 && b !== 0) {
533
+ const cornerRcos = Urso.math.intMakeBetween(
534
+ (a * a + b * b - c * c) / (2 * a * b),
535
+ -1, 1
536
+ );
537
+
538
+ angle = Math.acos(cornerRcos);
539
+ }
540
+
541
+ return angle;
542
+ }
543
+
544
+
545
+ /**
546
+ * get angle in radians from degrees
547
+ *
548
+ * @param {Number} angle
549
+ * @return {Number}
550
+ */
551
+ getRadian(angle) {
552
+ return (angle * this._arFactor);
553
+ }
554
+
555
+ /**
556
+ * get angle in degrees from radians
557
+ *
558
+ * @param {Number} radian
559
+ * @return {Number}
560
+ */
561
+ getAngle(radian) {
562
+ return (radian / this._arFactor);
563
+ }
564
+
565
+ /**
566
+ * arguments {oblect} (ClassInstance, functionName, param1, param2, ...)
567
+ * needs {Object} obj._logicBlocks;
568
+ * creates {Object} obj._logicBlocksInstances;
569
+ * @returns {Array} execution results
570
+ */
571
+ logicBlocksDo() {
572
+ const params = Array.prototype.slice.call(arguments);
573
+ const entity = params.shift();
574
+ const funcName = params.shift();
575
+
576
+ //if no instances we will create them
577
+ if (!entity._logicBlocksInstances) {
578
+ entity._logicBlocksInstances = {};
579
+
580
+ for (let k in entity._logicBlocks) {
581
+ const name = entity._logicBlocks[k];
582
+ const nameCap = this.capitaliseFirstLetter(name);
583
+ entity._logicBlocksInstances[name] = entity.getInstance(nameCap);
584
+ }
585
+ }
586
+
587
+ let results = [];
588
+ //game
589
+ for (let name in entity._logicBlocksInstances) {
590
+ if (entity._logicBlocksInstances[name][funcName]) {
591
+ const res = entity._logicBlocksInstances[name][funcName].apply(this, params);
592
+ results.push(res);
593
+ }
594
+ }
595
+
596
+ return results;
597
+ }
598
+
599
+ /**
600
+ * apply params to string
601
+ * @param {String} string
602
+ * @param {Object} params
603
+ * @returns {String}
604
+ *
605
+ * @example interpolate('Bet ${bet} with Multi ${multi}', {bet:12,multi:13})
606
+ * returns 'Bet 12 with Multi 13'
607
+ */
608
+ interpolate(string, params) {
609
+ for (const [key, value] of Object.entries(params)) {
610
+ string = Urso.helper.stringReplace('${' + key + '}', value, string);
611
+ }
612
+
613
+ return string
614
+ }
615
+
616
+ /**
617
+ * Converts color number to object that contents RGB values
618
+ * @param { Number } color - color number
619
+ * @returns { Object }
620
+ */
621
+ getRGB(color) {
622
+ return {
623
+ alpha: 16777215 < color ? color >>> 24 : 255,
624
+ red: color >> 16 & 255,
625
+ green: color >> 8 & 255,
626
+ blue: 255 & color
627
+ };
628
+ }
629
+
630
+ /**
631
+ * Converts RGB values to 32 bit
632
+ * @param { Number } alpha
633
+ * @param { Number } red
634
+ * @param { Number } green
635
+ * @param { Number } blue
636
+ * @returns { Number }
637
+ */
638
+ getColor32(alpha, red, green, blue) {
639
+ return alpha << 24 | red << 16 | green << 8 | blue;
640
+ }
641
+
642
+ /**
643
+ * Returns color interpolation depends on step value
644
+ * @param { Number } startColor
645
+ * @param { Number } targetColor
646
+ * @param { Number } step - intermediate value from 0 to 1
647
+ * @returns { Number }
648
+ */
649
+ interpolateColor32(startColor, targetColor, step) {
650
+ if (startColor === targetColor)
651
+ return startColor;
652
+
653
+ const startColorRGB = this.getRGB(startColor);
654
+ const targetColorRGB = this.getRGB(targetColor);
655
+ const nextColorRGB = this.interpolateColorRGB(startColorRGB, targetColorRGB, step);
656
+ const color32 = this.getColor32(255, nextColorRGB.red, nextColorRGB.green, nextColorRGB.blue);
657
+ return 16777215 + color32;
658
+ }
659
+
660
+ /**
661
+ * Returns color interpolation as RGB object depends on step value
662
+ * @param { Object } startColorRGB - object that contents start values for red, green and blue
663
+ * @param { Object } targetColorRGB - object that contents target values for red, green and blue
664
+ * @param { Number } step - intermediate value from 0 to 1
665
+ * @returns { Object }
666
+ */
667
+ interpolateColorRGB(startColorRGB, targetColorRGB, step) {
668
+ const nextRGB = {};
669
+
670
+ Object.keys(startColorRGB).forEach(color => {
671
+ nextRGB[color] = (targetColorRGB[color] - startColorRGB[color]) * step + startColorRGB[color];
672
+ });
673
+
674
+ return nextRGB;
675
+ }
676
+ }
677
+
678
+ export default LibHelper;