squishjs 0.7.5 → 0.7.53

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.5",
3
+ "version": "0.7.53",
4
4
  "description": "squish & unsquish stuff",
5
5
  "scripts": {
6
6
  "test": "node testRunner.js"
package/src/BaseNode.js CHANGED
@@ -68,10 +68,10 @@ class BaseNode {
68
68
  }
69
69
 
70
70
  findChild(id) {
71
- return this.#findChildHelper(id, this);
71
+ return this.findChildHelper(id, this);
72
72
  }
73
73
 
74
- #findChildHelper(nodeId, node, found = null) {
74
+ findChildHelper(nodeId, node, found = null) {
75
75
  if (node.node.id === nodeId) {
76
76
  found = node;
77
77
  }
@@ -80,7 +80,7 @@ class BaseNode {
80
80
  if (found) {
81
81
  return found
82
82
  }
83
- found = this.#findChildHelper(nodeId, node.node.children[i], found);
83
+ found = this.findChildHelper(nodeId, node.node.children[i], found);
84
84
  }
85
85
 
86
86
  return found;
@@ -12,15 +12,12 @@ const makePlane = (s) => {
12
12
  };
13
13
 
14
14
  class ViewableGame extends Game {
15
- #plane;
16
- #fakeRoot;
17
- #planeSize;
18
15
  constructor(planeSize) {
19
16
  super();
20
- this.#planeSize = planeSize;
21
- this.#plane = makePlane(this.planeSize);
17
+ this.planeSize = planeSize;
18
+ this.plane = makePlane(this.planeSize);
22
19
 
23
- this.#fakeRoot = new GameNode.Shape({
20
+ this.fakeRoot = new GameNode.Shape({
24
21
  shapeType: Shapes.POLYGON,
25
22
  coordinates2d: ShapeUtils.rectangle(0, 0, 0, 0),
26
23
  fill: Colors.COLORS.BLACK,
@@ -28,14 +25,14 @@ class ViewableGame extends Game {
28
25
 
29
26
  this.layers = [
30
27
  {
31
- root: this.#fakeRoot
28
+ root: this.fakeRoot
32
29
  }
33
30
  ];
34
31
  }
35
32
 
36
33
  updatePlaneSize(s) {
37
- this.#planeSize = s;
38
- this.#plane.node.coordinates2d = ShapeUtils.rectangle(0, 0, s, s);
34
+ this.planeSize = s;
35
+ this.plane.node.coordinates2d = ShapeUtils.rectangle(0, 0, s, s);
39
36
  }
40
37
 
41
38
  getLayers() {
@@ -43,15 +40,15 @@ class ViewableGame extends Game {
43
40
  }
44
41
 
45
42
  getPlane() {
46
- return this.#plane;
43
+ return this.plane;
47
44
  }
48
45
 
49
46
  getPlaneSize() {
50
- return this.#planeSize;
47
+ return this.planeSize;
51
48
  }
52
49
 
53
50
  getViewRoot() {
54
- return this.#fakeRoot;
51
+ return this.fakeRoot;
55
52
  }
56
53
 
57
54
  }
package/src/squish.js CHANGED
@@ -1,5 +1,3 @@
1
- const assert = require('assert');
2
-
3
1
  const InternalGameNode = require("./InternalGameNode");
4
2
  const { CONSTRUCTOR_TO_TYPE, TYPE_TO_CONSTRUCTOR } = require('./node-types');
5
3
  const SUBTYPE_MAPPINGS = require('./subtype-mappings');
@@ -43,11 +41,15 @@ for (const key in squishSpec) {
43
41
  }
44
42
 
45
43
  const unsquish = (squished) => {
46
- assert(squished[0] == 3);
44
+ if (squished[0] != 3) {
45
+ throw new Error('Squished[0] isnt 3.');
46
+ }
47
47
 
48
- assert(squished.length === squished[1]);
48
+ if (squished.length !== squished[1] + squished[2] + squished[3]) {
49
+ throw new Error('Bad length value');
50
+ }
49
51
 
50
- let squishedIndex = 3;
52
+ let squishedIndex = 5;
51
53
 
52
54
  let constructedInternalNode = new InternalGameNode();
53
55
 
@@ -72,7 +74,8 @@ const unsquish = (squished) => {
72
74
  squishedIndex += subFrameLength;
73
75
  }
74
76
 
75
- const constructor = TYPE_TO_CONSTRUCTOR[squished[2]];
77
+ const constructor = TYPE_TO_CONSTRUCTOR[squished[4]];
78
+
76
79
  if (constructor) {
77
80
  return new constructor({ node: constructedInternalNode });
78
81
  }
@@ -125,7 +128,14 @@ const squish = (entity, scale = null) => {
125
128
  }
126
129
 
127
130
  const squished = squishedPieces.flat();
128
- return [3, squished.length + 3, nodeClassCode, ...squished];
131
+
132
+ // length + 5 bytes for what we're inserting here - 3 for length, one for type (3), one for class code
133
+ const totalLength = squished.length + 5;
134
+ const rightMost = Math.min(255, totalLength);
135
+ const middle = Math.min(255, Math.max(0, totalLength - 255));
136
+ const leftMost = Math.min(255, Math.max(0, totalLength - 510));
137
+
138
+ return [3, leftMost, middle, rightMost, nodeClassCode, ...squished];
129
139
 
130
140
  }
131
141
 
@@ -151,4 +151,4 @@ const squishText = {
151
151
  module.exports = {
152
152
  TEXT_SUBTYPE,
153
153
  squishText
154
- };
154
+ };
package/test/main.test.js CHANGED
@@ -309,5 +309,29 @@ test("scaled asset node", () => {
309
309
  assert(asset.size.y === .85 * 20);
310
310
  });
311
311
 
312
+ test("big big text", () => {
313
+ const gameNode = new GameNode.Text({
314
+ textInfo: {
315
+ text: 'I am going to write a whoooooole lot of text like more than 64 characters which is quite a bit. Not like a tweet long but still long, you know?',
316
+ x: 4,
317
+ y: 20,
318
+ size: 5,
319
+ align: 'center',
320
+ color: COLORS.RED
321
+ }
322
+ });
323
+
324
+ const xScale = .6;
325
+ const yScale = .5;
326
+
327
+ const scaledTextSize = 5 * hypLength(xScale, yScale);
328
+
329
+ const squishedScaledNode = squish(gameNode, {x: xScale, y: yScale});
330
+ const unsquishedNode = unsquish(squishedScaledNode).node;
312
331
 
332
+ assert(unsquishedNode.text.x.toFixed(2) === (4 * xScale + Math.round((1 - xScale) * 100) / 2).toFixed(2));
333
+ assert(unsquishedNode.text.y.toFixed(2) === (20 * yScale + Math.round((1 - yScale) * 100) / 2).toFixed(2));
334
+
335
+ assert(unsquishedNode.text.size.toFixed(2) === scaledTextSize.toFixed(2));
336
+ });
313
337