squishjs 1.0.8 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "squishjs",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "squish & unsquish stuff",
5
5
  "scripts": {
6
6
  "test": "node testRunner.js"
@@ -1,6 +1,5 @@
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
- // im about to hit the ye button
4
3
  this.id = id ? Number(id) : Math.floor(Math.random() * 999999999);
5
4
  this.children = new Array();
6
5
  this.color = color;
@@ -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
- let strChunks = [];
9
- if (idStr.length > 2) {
10
- let j;
11
- for (j = 0; j + 2 <= idStr.length; j += 2) {
12
- strChunks.push(idStr.substring(j, j + 2));
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
- if (j == idStr.length - 1) {
16
- strChunks.push(idStr.substring(j, j + 2));
17
- }
18
- } else {
19
- if (idStr.length === 1) {
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
- // build up from right to left then parse
36
- let str = '';
37
- for (let i = arr.length - 1; i >= 0; i--) {
38
- const val = arr[i] > 9 ? arr[i] : '0' + arr[i];
39
- str = val + str
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