squishjs 0.7.52 → 0.7.55

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": "0.7.52",
3
+ "version": "0.7.55",
4
4
  "description": "squish & unsquish stuff",
5
5
  "scripts": {
6
6
  "test": "node testRunner.js"
@@ -1,8 +1,6 @@
1
- let _id = 0;
2
-
3
1
  class InternalGameNode {
4
2
  constructor(color, onClick, coordinates2d, border, fill, text, asset, playerIds = [], effects = null, input = null, subType = null, id = null) {
5
- this.id = id ? Number(id) : Number(_id++);
3
+ this.id = id ? Number(id) : Math.floor(Math.random() * 999999999999);
6
4
  this.children = new Array();
7
5
  this.color = color;
8
6
  this.handleClick = onClick;
package/src/squish.js CHANGED
@@ -56,8 +56,8 @@ const unsquish = (squished) => {
56
56
  while(squishedIndex < squished.length) {
57
57
 
58
58
  const subFrameType = squished[squishedIndex];
59
- const subFrameLength = squished[squishedIndex + 1];
60
- const subFrame = squished.slice(squishedIndex + 2, squishedIndex + subFrameLength);
59
+ const subFrameLength = squished[squishedIndex + 1] + squished[squishedIndex + 2];
60
+ const subFrame = squished.slice(squishedIndex + 3, squishedIndex + subFrameLength);
61
61
 
62
62
  if (!typeToSquishMap[subFrameType]) {
63
63
  console.warn("Unknown sub frame type " + subFrameType);
@@ -115,7 +115,11 @@ const squish = (entity, scale = null) => {
115
115
  const attr = internalNode[key];
116
116
  if (attr !== undefined && attr !== null) {
117
117
  const squished = squishSpec[key].squish(attr, scale, internalNode);
118
- squishedPieces.push([squishSpec[key]['type'], squished.length + 2, ...squished]);
118
+ const totalLength = squished.length + 3;
119
+ const rightMost = Math.min(255, totalLength);
120
+ const leftMost = Math.min(255, Math.max(0, totalLength - 255));
121
+
122
+ squishedPieces.push([squishSpec[key]['type'], leftMost, rightMost, ...squished]);
119
123
  }
120
124
  }
121
125
  }
@@ -131,9 +135,9 @@ const squish = (entity, scale = null) => {
131
135
 
132
136
  // length + 5 bytes for what we're inserting here - 3 for length, one for type (3), one for class code
133
137
  const totalLength = squished.length + 5;
134
- const rightMost = Math.min(256, totalLength);
135
- const middle = Math.min(256, Math.max(0, totalLength - 256));
136
- const leftMost = Math.min(256, Math.max(0, totalLength - 512));
138
+ const rightMost = Math.min(255, totalLength);
139
+ const middle = Math.min(255, Math.max(0, totalLength - 255));
140
+ const leftMost = Math.min(255, Math.max(0, totalLength - 510));
137
141
 
138
142
  return [3, leftMost, middle, rightMost, nodeClassCode, ...squished];
139
143