squishjs 0.7.51 → 0.7.52
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/squish.js +17 -7
- package/src/squishHelpers/text.js +1 -1
- package/test/main.test.js +24 -0
package/package.json
CHANGED
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
|
-
|
|
44
|
+
if (squished[0] != 3) {
|
|
45
|
+
throw new Error('Squished[0] isnt 3.');
|
|
46
|
+
}
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
if (squished.length !== squished[1] + squished[2] + squished[3]) {
|
|
49
|
+
throw new Error('Bad length value');
|
|
50
|
+
}
|
|
49
51
|
|
|
50
|
-
let squishedIndex =
|
|
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[
|
|
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
|
-
|
|
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(256, totalLength);
|
|
135
|
+
const middle = Math.min(256, Math.max(0, totalLength - 256));
|
|
136
|
+
const leftMost = Math.min(256, Math.max(0, totalLength - 512));
|
|
137
|
+
|
|
138
|
+
return [3, leftMost, middle, rightMost, nodeClassCode, ...squished];
|
|
129
139
|
|
|
130
140
|
}
|
|
131
141
|
|
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
|
|