@urso/core 0.7.88 → 0.7.90
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/build/162.js/index.js +1 -0
- package/build/24.js/index.js +1 -0
- package/build/js/index.js +1 -1
- package/build/js/index.js.LICENSE.txt +0 -176
- package/package.json +4 -6
- package/src/js/extra/main.js +0 -5
- package/src/js/lib/loader.js +13 -5
- package/src/js/lib/math.js +153 -28
|
@@ -36,14 +36,6 @@ object-assign
|
|
|
36
36
|
* Copyright 2019-2020, Ivan Igorevich Popelyshev <ivan.popelyshev@gmail.com>, All Rights Reserved
|
|
37
37
|
*/
|
|
38
38
|
|
|
39
|
-
/*!
|
|
40
|
-
* @pixi/accessibility - v6.5.10
|
|
41
|
-
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
42
|
-
*
|
|
43
|
-
* @pixi/accessibility is licensed under the MIT License.
|
|
44
|
-
* http://www.opensource.org/licenses/mit-license
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
39
|
/*!
|
|
48
40
|
* @pixi/app - v6.5.10
|
|
49
41
|
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
@@ -52,14 +44,6 @@ object-assign
|
|
|
52
44
|
* http://www.opensource.org/licenses/mit-license
|
|
53
45
|
*/
|
|
54
46
|
|
|
55
|
-
/*!
|
|
56
|
-
* @pixi/compressed-textures - v6.5.10
|
|
57
|
-
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
58
|
-
*
|
|
59
|
-
* @pixi/compressed-textures is licensed under the MIT License.
|
|
60
|
-
* http://www.opensource.org/licenses/mit-license
|
|
61
|
-
*/
|
|
62
|
-
|
|
63
47
|
/*!
|
|
64
48
|
* @pixi/constants - v6.5.10
|
|
65
49
|
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
@@ -92,38 +76,6 @@ object-assign
|
|
|
92
76
|
* http://www.opensource.org/licenses/mit-license
|
|
93
77
|
*/
|
|
94
78
|
|
|
95
|
-
/*!
|
|
96
|
-
* @pixi/extract - v6.5.10
|
|
97
|
-
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
98
|
-
*
|
|
99
|
-
* @pixi/extract is licensed under the MIT License.
|
|
100
|
-
* http://www.opensource.org/licenses/mit-license
|
|
101
|
-
*/
|
|
102
|
-
|
|
103
|
-
/*!
|
|
104
|
-
* @pixi/filter-alpha - v6.5.10
|
|
105
|
-
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
106
|
-
*
|
|
107
|
-
* @pixi/filter-alpha is licensed under the MIT License.
|
|
108
|
-
* http://www.opensource.org/licenses/mit-license
|
|
109
|
-
*/
|
|
110
|
-
|
|
111
|
-
/*!
|
|
112
|
-
* @pixi/filter-blur - v6.5.10
|
|
113
|
-
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
114
|
-
*
|
|
115
|
-
* @pixi/filter-blur is licensed under the MIT License.
|
|
116
|
-
* http://www.opensource.org/licenses/mit-license
|
|
117
|
-
*/
|
|
118
|
-
|
|
119
|
-
/*!
|
|
120
|
-
* @pixi/filter-color-matrix - v6.5.10
|
|
121
|
-
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
122
|
-
*
|
|
123
|
-
* @pixi/filter-color-matrix is licensed under the MIT License.
|
|
124
|
-
* http://www.opensource.org/licenses/mit-license
|
|
125
|
-
*/
|
|
126
|
-
|
|
127
79
|
/*!
|
|
128
80
|
* @pixi/filter-displacement - v6.5.10
|
|
129
81
|
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
@@ -132,46 +84,6 @@ object-assign
|
|
|
132
84
|
* http://www.opensource.org/licenses/mit-license
|
|
133
85
|
*/
|
|
134
86
|
|
|
135
|
-
/*!
|
|
136
|
-
* @pixi/filter-fxaa - v6.5.10
|
|
137
|
-
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
138
|
-
*
|
|
139
|
-
* @pixi/filter-fxaa is licensed under the MIT License.
|
|
140
|
-
* http://www.opensource.org/licenses/mit-license
|
|
141
|
-
*/
|
|
142
|
-
|
|
143
|
-
/*!
|
|
144
|
-
* @pixi/filter-noise - v6.5.10
|
|
145
|
-
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
146
|
-
*
|
|
147
|
-
* @pixi/filter-noise is licensed under the MIT License.
|
|
148
|
-
* http://www.opensource.org/licenses/mit-license
|
|
149
|
-
*/
|
|
150
|
-
|
|
151
|
-
/*!
|
|
152
|
-
* @pixi/graphics - v6.5.10
|
|
153
|
-
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
154
|
-
*
|
|
155
|
-
* @pixi/graphics is licensed under the MIT License.
|
|
156
|
-
* http://www.opensource.org/licenses/mit-license
|
|
157
|
-
*/
|
|
158
|
-
|
|
159
|
-
/*!
|
|
160
|
-
* @pixi/interaction - v6.5.10
|
|
161
|
-
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
162
|
-
*
|
|
163
|
-
* @pixi/interaction is licensed under the MIT License.
|
|
164
|
-
* http://www.opensource.org/licenses/mit-license
|
|
165
|
-
*/
|
|
166
|
-
|
|
167
|
-
/*!
|
|
168
|
-
* @pixi/loaders - v6.5.10
|
|
169
|
-
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
170
|
-
*
|
|
171
|
-
* @pixi/loaders is licensed under the MIT License.
|
|
172
|
-
* http://www.opensource.org/licenses/mit-license
|
|
173
|
-
*/
|
|
174
|
-
|
|
175
87
|
/*!
|
|
176
88
|
* @pixi/math - v6.5.10
|
|
177
89
|
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
@@ -180,30 +92,6 @@ object-assign
|
|
|
180
92
|
* http://www.opensource.org/licenses/mit-license
|
|
181
93
|
*/
|
|
182
94
|
|
|
183
|
-
/*!
|
|
184
|
-
* @pixi/mesh - v6.5.10
|
|
185
|
-
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
186
|
-
*
|
|
187
|
-
* @pixi/mesh is licensed under the MIT License.
|
|
188
|
-
* http://www.opensource.org/licenses/mit-license
|
|
189
|
-
*/
|
|
190
|
-
|
|
191
|
-
/*!
|
|
192
|
-
* @pixi/mesh-extras - v6.5.10
|
|
193
|
-
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
194
|
-
*
|
|
195
|
-
* @pixi/mesh-extras is licensed under the MIT License.
|
|
196
|
-
* http://www.opensource.org/licenses/mit-license
|
|
197
|
-
*/
|
|
198
|
-
|
|
199
|
-
/*!
|
|
200
|
-
* @pixi/mixin-cache-as-bitmap - v6.5.10
|
|
201
|
-
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
202
|
-
*
|
|
203
|
-
* @pixi/mixin-cache-as-bitmap is licensed under the MIT License.
|
|
204
|
-
* http://www.opensource.org/licenses/mit-license
|
|
205
|
-
*/
|
|
206
|
-
|
|
207
95
|
/*!
|
|
208
96
|
* @pixi/mixin-get-child-by-name - v6.5.10
|
|
209
97
|
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
@@ -220,14 +108,6 @@ object-assign
|
|
|
220
108
|
* http://www.opensource.org/licenses/mit-license
|
|
221
109
|
*/
|
|
222
110
|
|
|
223
|
-
/*!
|
|
224
|
-
* @pixi/particle-container - v6.5.10
|
|
225
|
-
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
226
|
-
*
|
|
227
|
-
* @pixi/particle-container is licensed under the MIT License.
|
|
228
|
-
* http://www.opensource.org/licenses/mit-license
|
|
229
|
-
*/
|
|
230
|
-
|
|
231
111
|
/*!
|
|
232
112
|
* @pixi/polyfill - v6.5.10
|
|
233
113
|
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
@@ -260,54 +140,6 @@ object-assign
|
|
|
260
140
|
* http://www.opensource.org/licenses/mit-license
|
|
261
141
|
*/
|
|
262
142
|
|
|
263
|
-
/*!
|
|
264
|
-
* @pixi/sprite - v6.5.10
|
|
265
|
-
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
266
|
-
*
|
|
267
|
-
* @pixi/sprite is licensed under the MIT License.
|
|
268
|
-
* http://www.opensource.org/licenses/mit-license
|
|
269
|
-
*/
|
|
270
|
-
|
|
271
|
-
/*!
|
|
272
|
-
* @pixi/sprite-animated - v6.5.10
|
|
273
|
-
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
274
|
-
*
|
|
275
|
-
* @pixi/sprite-animated is licensed under the MIT License.
|
|
276
|
-
* http://www.opensource.org/licenses/mit-license
|
|
277
|
-
*/
|
|
278
|
-
|
|
279
|
-
/*!
|
|
280
|
-
* @pixi/sprite-tiling - v6.5.10
|
|
281
|
-
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
282
|
-
*
|
|
283
|
-
* @pixi/sprite-tiling is licensed under the MIT License.
|
|
284
|
-
* http://www.opensource.org/licenses/mit-license
|
|
285
|
-
*/
|
|
286
|
-
|
|
287
|
-
/*!
|
|
288
|
-
* @pixi/spritesheet - v6.5.10
|
|
289
|
-
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
290
|
-
*
|
|
291
|
-
* @pixi/spritesheet is licensed under the MIT License.
|
|
292
|
-
* http://www.opensource.org/licenses/mit-license
|
|
293
|
-
*/
|
|
294
|
-
|
|
295
|
-
/*!
|
|
296
|
-
* @pixi/text - v6.5.10
|
|
297
|
-
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
298
|
-
*
|
|
299
|
-
* @pixi/text is licensed under the MIT License.
|
|
300
|
-
* http://www.opensource.org/licenses/mit-license
|
|
301
|
-
*/
|
|
302
|
-
|
|
303
|
-
/*!
|
|
304
|
-
* @pixi/text-bitmap - v6.5.10
|
|
305
|
-
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
306
|
-
*
|
|
307
|
-
* @pixi/text-bitmap is licensed under the MIT License.
|
|
308
|
-
* http://www.opensource.org/licenses/mit-license
|
|
309
|
-
*/
|
|
310
|
-
|
|
311
143
|
/*!
|
|
312
144
|
* @pixi/ticker - v6.5.10
|
|
313
145
|
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
@@ -316,14 +148,6 @@ object-assign
|
|
|
316
148
|
* http://www.opensource.org/licenses/mit-license
|
|
317
149
|
*/
|
|
318
150
|
|
|
319
|
-
/*!
|
|
320
|
-
* @pixi/utils - v6.5.10
|
|
321
|
-
* Compiled Thu, 06 Jul 2023 15:25:11 UTC
|
|
322
|
-
*
|
|
323
|
-
* @pixi/utils is licensed under the MIT License.
|
|
324
|
-
* http://www.opensource.org/licenses/mit-license
|
|
325
|
-
*/
|
|
326
|
-
|
|
327
151
|
/*!
|
|
328
152
|
* GSAP 3.12.5
|
|
329
153
|
* https://gsap.com
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@urso/core",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.90",
|
|
4
4
|
"description": "HTML5 game engine",
|
|
5
5
|
"main": "build/js/index.js",
|
|
6
6
|
"author": "Megbrimef",
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
},
|
|
23
23
|
"homepage": "https://github.com/megbrimef/urso#readme",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@pixi/filter-drop-shadow": "^3.2.0",
|
|
26
25
|
"@urso/revolt-fx": "^0.1.0",
|
|
27
26
|
"gsap": "^3.1.1",
|
|
28
27
|
"howler": "^2.2.1",
|
|
@@ -30,7 +29,6 @@
|
|
|
30
29
|
"pixi-projection": "0.3.15",
|
|
31
30
|
"pixi-scrollbox": "^2.3.1",
|
|
32
31
|
"pixi-spine": "^3.1.2",
|
|
33
|
-
"pixi-text-input": "^1.0.6",
|
|
34
32
|
"pixi-viewport": "^4.34.0",
|
|
35
33
|
"pixi.js": "^6.2.0"
|
|
36
34
|
},
|
|
@@ -45,8 +43,8 @@
|
|
|
45
43
|
"source-map-loader": "^1.0.0",
|
|
46
44
|
"string-replace-loader": "^3.0.3",
|
|
47
45
|
"style-loader": "^0.23.1",
|
|
48
|
-
"webpack": "^5.
|
|
49
|
-
"webpack-cli": "^
|
|
50
|
-
"webpack-dev-server": "^
|
|
46
|
+
"webpack": "^5.93.0",
|
|
47
|
+
"webpack-cli": "^5.1.4",
|
|
48
|
+
"webpack-dev-server": "^5.0.4"
|
|
51
49
|
}
|
|
52
50
|
}
|
package/src/js/extra/main.js
CHANGED
|
@@ -4,10 +4,6 @@ window.PIXI.particles = require('pixi-particles');
|
|
|
4
4
|
|
|
5
5
|
window.PIXI.particlesFx = require('@urso/revolt-fx');
|
|
6
6
|
|
|
7
|
-
import { DropShadowFilter } from '@pixi/filter-drop-shadow';
|
|
8
|
-
PIXI.filters['DropShadowFilter'] = DropShadowFilter;
|
|
9
|
-
|
|
10
|
-
|
|
11
7
|
window.PIXI.spine = require("pixi-spine");
|
|
12
8
|
|
|
13
9
|
import { AtlasAttachmentLoader, SkeletonJson } from "@pixi-spine/runtime-3.8";
|
|
@@ -15,7 +11,6 @@ window.PIXI.spine.AtlasAttachmentLoader = AtlasAttachmentLoader;
|
|
|
15
11
|
window.PIXI.spine.SkeletonJson = SkeletonJson;
|
|
16
12
|
|
|
17
13
|
require("pixi-projection");
|
|
18
|
-
require("pixi-text-input");
|
|
19
14
|
|
|
20
15
|
import { gsap } from 'gsap';
|
|
21
16
|
window.gsap = gsap;
|
package/src/js/lib/loader.js
CHANGED
|
@@ -123,11 +123,19 @@ class LibLoader {
|
|
|
123
123
|
|
|
124
124
|
let params = asset.params || false; // TODO: Set params field in base mode
|
|
125
125
|
|
|
126
|
-
if (asset.type === Urso.types.assets.JSON) { // check json in JSONATLAS
|
|
126
|
+
if (asset.type === Urso.types.assets.JSON || asset.type === Urso.types.assets.ATLAS) { // check json in JSONATLAS
|
|
127
127
|
const jsonData = this._getJsonDataFromJsonAtlases(asset.key);
|
|
128
|
-
|
|
128
|
+
alert(123)
|
|
129
129
|
if (jsonData) {
|
|
130
|
-
|
|
130
|
+
switch (asset.type) {
|
|
131
|
+
case Urso.types.assets.JSON:
|
|
132
|
+
Urso.cache.addJson(asset.key, { data: jsonData });
|
|
133
|
+
break;
|
|
134
|
+
case Urso.types.assets.ATLAS:
|
|
135
|
+
this._loader.add(asset.key, jsonData, params, (resource) => this._storeAsset(asset, resource));
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
|
|
131
139
|
return;
|
|
132
140
|
}
|
|
133
141
|
}
|
|
@@ -148,7 +156,7 @@ class LibLoader {
|
|
|
148
156
|
}
|
|
149
157
|
|
|
150
158
|
const loadPath = this._getLoadPath(asset);
|
|
151
|
-
this._loader.add(asset.key, loadPath, params, (resource) => this._storeAsset(asset, resource)) //TODO set assets resolution instead _processLoadedImage baseTexture resolution
|
|
159
|
+
this._loader.add(asset.key, loadPath, params, (resource) => this._storeAsset(asset, resource)); //TODO set assets resolution instead _processLoadedImage baseTexture resolution
|
|
152
160
|
});
|
|
153
161
|
|
|
154
162
|
this._onLoadUpdate({ progress: 0 });
|
|
@@ -184,7 +192,7 @@ class LibLoader {
|
|
|
184
192
|
const spineAtlasLoader = new PIXI.spine.AtlasAttachmentLoader(params.metadata.spineAtlas);
|
|
185
193
|
const spineJsonParser = new PIXI.spine.SkeletonJson(spineAtlasLoader);
|
|
186
194
|
const spineData = spineJsonParser.readSkeletonData(jsonData);
|
|
187
|
-
Urso.cache.addSpine(asset.key, {spineData});
|
|
195
|
+
Urso.cache.addSpine(asset.key, { spineData });
|
|
188
196
|
}
|
|
189
197
|
|
|
190
198
|
_onError(error) {
|
package/src/js/lib/math.js
CHANGED
|
@@ -1,36 +1,161 @@
|
|
|
1
1
|
class LibMath {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
/**
|
|
3
|
+
* validate number to make it value between min and max values
|
|
4
|
+
* @param {Number} num
|
|
5
|
+
* @param {Number} min
|
|
6
|
+
* @param {Number} max
|
|
7
|
+
*/
|
|
8
|
+
intMakeBetween(num, min, max) {
|
|
9
|
+
return Math.max.apply(Math, [min, Math.min.apply(Math, [max, num])]);
|
|
10
|
+
}
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Generates a random integer between 0 and the specified maximum value.
|
|
14
|
+
*
|
|
15
|
+
* @param {number} max - The maximum value for the random integer.
|
|
16
|
+
* @returns {number} The random integer generated.
|
|
17
|
+
*/
|
|
18
|
+
getRandomInt(max) {
|
|
19
|
+
return this.getRandomIntBetween(0, max);
|
|
20
|
+
}
|
|
15
21
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Generates a random integer between the given minimum and maximum values (inclusive).
|
|
24
|
+
*
|
|
25
|
+
* @param {number} min - The minimum value.
|
|
26
|
+
* @param {number} max - The maximum value.
|
|
27
|
+
* @returns {number} The random integer between min and max.
|
|
28
|
+
*/
|
|
29
|
+
getRandomIntBetween(min, max) {
|
|
30
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* round float number to digits count
|
|
35
|
+
* @param {Number} num
|
|
36
|
+
* @param {Number} digits - rounding digits count
|
|
37
|
+
* @returns {Number}
|
|
38
|
+
*/
|
|
39
|
+
roundToDigits(num, digits) {
|
|
40
|
+
if (isNaN(num) || isNaN(digits)) return false;
|
|
41
|
+
|
|
42
|
+
const pow = Math.pow(10, digits);
|
|
43
|
+
return Math.round(num * pow) / pow;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Checks if a given value is an integer.
|
|
48
|
+
*
|
|
49
|
+
* @param {number} n - The value to be checked.
|
|
50
|
+
* @returns {boolean} - Returns true if the value is an integer, otherwise returns false.
|
|
51
|
+
*/
|
|
52
|
+
isInt(n) {
|
|
53
|
+
return Number(n) === n && n % 1 === 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Checks if a given number is a floating-point number.
|
|
58
|
+
*
|
|
59
|
+
* @param {number} n - The number to be checked.
|
|
60
|
+
* @returns {boolean} - Returns true if the number is a floating-point number, otherwise returns false.
|
|
61
|
+
*/
|
|
62
|
+
isFloat(n) {
|
|
63
|
+
return Number(n) === n && n % 1 !== 0;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Calculates the length of the decimal part of a number.
|
|
68
|
+
*
|
|
69
|
+
* @param {number} number - The number to calculate the decimal length for.
|
|
70
|
+
* @returns {number} The length of the decimal part of the number.
|
|
71
|
+
*/
|
|
72
|
+
getDecimalsLength(number) {
|
|
73
|
+
return Number(number.toString().split(".")[1]?.length || 0);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Multiplies an array of floating-point numbers.
|
|
78
|
+
*
|
|
79
|
+
* @param {number[]} numsArray - The array of numbers to be multiplied.
|
|
80
|
+
* @returns {number} The result of multiplying all the numbers in the array.
|
|
81
|
+
*/
|
|
82
|
+
multiplyFloats(numsArray) {
|
|
83
|
+
let result = numsArray.reduce((acc, num) => acc * num);
|
|
84
|
+
return this._processFloat(result, numsArray);
|
|
85
|
+
}
|
|
19
86
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Adds an array of floating-point numbers.
|
|
89
|
+
*
|
|
90
|
+
* @param {number[]} numsArray - The array of numbers to be added.
|
|
91
|
+
* @returns {number} - The sum of the numbers in the array.
|
|
92
|
+
*/
|
|
93
|
+
addFloats(numsArray) {
|
|
94
|
+
let result = numsArray.reduce((acc, num) => acc + num);
|
|
95
|
+
return this._processFloat(result, numsArray);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Subtracts an array of floating-point numbers.
|
|
100
|
+
*
|
|
101
|
+
* @param {number[]} numsArray - The array of numbers to subtract.
|
|
102
|
+
* @returns {number} - The result of subtracting the numbers.
|
|
103
|
+
*/
|
|
104
|
+
subtractFloats(numsArray) {
|
|
105
|
+
let result = numsArray.reduce((acc, num) => acc - num);
|
|
106
|
+
return this._processFloat(result, numsArray);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Processes the float values in the given array and returns the result.
|
|
111
|
+
* @param {number} result - The initial result value.
|
|
112
|
+
* @param {number[]} numsArray - The array of numbers to process.
|
|
113
|
+
* @returns {number} - The processed result value.
|
|
114
|
+
*/
|
|
115
|
+
_processFloat(result, numsArray) {
|
|
116
|
+
let floatsExist = false;
|
|
117
|
+
|
|
118
|
+
numsArray.forEach((element) => {
|
|
119
|
+
if (this.isFloat(element)) {
|
|
120
|
+
floatsExist = true;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
if (floatsExist) {
|
|
125
|
+
result = this._strip(result);
|
|
32
126
|
}
|
|
33
127
|
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Calculates the maximum length of decimals in an array of numbers.
|
|
133
|
+
*
|
|
134
|
+
* @param {number[]} numsArray - The array of numbers.
|
|
135
|
+
* @returns {number} - The maximum length of decimals.
|
|
136
|
+
*/
|
|
137
|
+
getMaxDecimalsLength(numsArray) {
|
|
138
|
+
let maxDecimalLength = 0;
|
|
139
|
+
|
|
140
|
+
numsArray.forEach((num) => {
|
|
141
|
+
if (!num) return 0;
|
|
142
|
+
|
|
143
|
+
const currentDecimalLength = this.getDecimalsLength(num);
|
|
144
|
+
maxDecimalLength = Math.max(currentDecimalLength, maxDecimalLength);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
return maxDecimalLength;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Strips the decimal places of a number.
|
|
152
|
+
*
|
|
153
|
+
* @param {number} number - The number to strip the decimal places from.
|
|
154
|
+
* @returns {number} - The number with stripped decimal places.
|
|
155
|
+
*/
|
|
156
|
+
_strip(number) {
|
|
157
|
+
return Number(number.toPrecision(12));
|
|
158
|
+
}
|
|
34
159
|
}
|
|
35
160
|
|
|
36
|
-
module.exports = LibMath;
|
|
161
|
+
module.exports = LibMath;
|