squishjs 1.0.7 → 1.0.9
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 +1 -1
- package/src/InternalGameNode.js +1 -1
- package/src/squishHelpers/id.js +15 -32
- package/test/main.test.js +11 -0
package/package.json
CHANGED
package/src/InternalGameNode.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
class InternalGameNode {
|
|
2
2
|
constructor(color, onClick, coordinates2d, border, fill, text, asset, playerIds = [], effects = null, input = null, subType = null, id = null, onHover, offHover) {
|
|
3
|
-
this.id = id ? Number(id) : Math.floor(Math.random() *
|
|
3
|
+
this.id = id ? Number(id) : Math.floor(Math.random() * 999999999);
|
|
4
4
|
this.children = new Array();
|
|
5
5
|
this.color = color;
|
|
6
6
|
this.handleClick = onClick;
|
package/src/squishHelpers/id.js
CHANGED
|
@@ -5,41 +5,24 @@ const squishId = {
|
|
|
5
5
|
squish: (i) => {
|
|
6
6
|
// max val: 10 000 000 000 000 000 (ten quadrillion)
|
|
7
7
|
const idStr = i.toString();
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
8
|
+
let thing = new Array(12);
|
|
9
|
+
let curI = 0;
|
|
10
|
+
for (curI; curI <= (12 - idStr.length); curI++) {
|
|
11
|
+
thing[curI] = 0;
|
|
12
|
+
}
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
strChunks.push('0' + idStr);
|
|
21
|
-
} else {
|
|
22
|
-
strChunks.push(idStr);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (strChunks.length < 8) {
|
|
27
|
-
while (strChunks.length < 8) {
|
|
28
|
-
strChunks = ["00", ...strChunks];
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return strChunks.map(c => new Number(c));
|
|
14
|
+
for (let i = 0; i < idStr.length; i++) {
|
|
15
|
+
let strChunks = [];
|
|
16
|
+
thing[i + curI] = Number(idStr.charAt(i));
|
|
17
|
+
}
|
|
18
|
+
return thing;
|
|
33
19
|
},
|
|
34
20
|
unsquish: (arr) => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return new Number(str);
|
|
21
|
+
let total = 0;
|
|
22
|
+
for (let i = 0; i < arr.length; i++) {
|
|
23
|
+
total += arr[i] * (Math.pow(10, arr.length - i - 1));
|
|
24
|
+
}
|
|
25
|
+
return Number(total);
|
|
43
26
|
}
|
|
44
27
|
}
|
|
45
28
|
|
package/test/main.test.js
CHANGED
|
@@ -447,4 +447,15 @@ test("Simple shape with updates", () => {
|
|
|
447
447
|
verifyArrayEquality(unsquish(state3[0]).node.fill, COLORS.GREEN);
|
|
448
448
|
});
|
|
449
449
|
|
|
450
|
+
test("id test", () => {
|
|
451
|
+
const node = new GameNode.Shape({
|
|
452
|
+
shapeType: Shapes.POLYGON,
|
|
453
|
+
coordinates2d: ShapeUtils.rectangle(0, 0, 100, 100),
|
|
454
|
+
id: 55559092036
|
|
455
|
+
});
|
|
456
|
+
const squished = squish(node);
|
|
457
|
+
const unsquished = unsquish(squished);
|
|
458
|
+
assert(unsquished.node.id == 55559092036);
|
|
459
|
+
});
|
|
460
|
+
|
|
450
461
|
|