squishjs 0.7.65 → 0.7.67
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/Asset.js +4 -0
- package/src/BaseNode.js +5 -2
- package/src/Squisher.js +7 -2
- package/src/util/listenable.js +7 -1
- package/test/main.test.js +58 -1
- package/metest.js +0 -26
package/package.json
CHANGED
package/src/Asset.js
CHANGED
|
@@ -126,6 +126,8 @@ class Asset {
|
|
|
126
126
|
this.doDownload(this.info.id, HG_ASSET_PATH).then((fileLocation) => {
|
|
127
127
|
this.initialized = true;
|
|
128
128
|
resolve(fileLocation);
|
|
129
|
+
}).catch(err => {
|
|
130
|
+
reject(err);
|
|
129
131
|
});
|
|
130
132
|
}
|
|
131
133
|
});
|
|
@@ -145,6 +147,8 @@ class Asset {
|
|
|
145
147
|
resolve(buf);
|
|
146
148
|
}
|
|
147
149
|
});
|
|
150
|
+
}).catch(err => {
|
|
151
|
+
reject(err);
|
|
148
152
|
});
|
|
149
153
|
}
|
|
150
154
|
});
|
package/src/BaseNode.js
CHANGED
|
@@ -91,11 +91,14 @@ class BaseNode {
|
|
|
91
91
|
this.node.clearChildren(excludedNodeIds);
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
|
|
95
94
|
clone() {
|
|
96
95
|
throw new Error("Clone not implemented");
|
|
97
96
|
}
|
|
97
|
+
|
|
98
|
+
free() {
|
|
99
|
+
this.node.free();
|
|
100
|
+
}
|
|
98
101
|
}
|
|
99
102
|
|
|
100
103
|
|
|
101
|
-
module.exports = {gameNode, BaseNode};
|
|
104
|
+
module.exports = {gameNode, BaseNode};
|
package/src/Squisher.js
CHANGED
|
@@ -227,6 +227,9 @@ class Squisher {
|
|
|
227
227
|
this.assetBundle = newAssetBundle;
|
|
228
228
|
resolve(newAssetBundle);
|
|
229
229
|
}
|
|
230
|
+
}).catch(err => {
|
|
231
|
+
console.error('Unable to get asset data for key ' + key);
|
|
232
|
+
console.error(err);
|
|
230
233
|
});
|
|
231
234
|
}
|
|
232
235
|
|
|
@@ -234,8 +237,10 @@ class Squisher {
|
|
|
234
237
|
}
|
|
235
238
|
|
|
236
239
|
handleStateChange(node, layerName) {
|
|
237
|
-
|
|
238
|
-
|
|
240
|
+
if (this.listeners.size > 0) {
|
|
241
|
+
this.state = this.squish(this.game.getLayers());
|
|
242
|
+
this.broadcast();
|
|
243
|
+
}
|
|
239
244
|
}
|
|
240
245
|
|
|
241
246
|
broadcast() {
|
package/src/util/listenable.js
CHANGED
|
@@ -15,7 +15,13 @@ const listenable = function(obj, onChange) {
|
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
const revocable = Proxy.revocable(obj, handler);
|
|
19
|
+
|
|
20
|
+
obj.free = () => {
|
|
21
|
+
revocable.revoke();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return revocable.proxy;
|
|
19
25
|
};
|
|
20
26
|
|
|
21
27
|
module.exports = listenable;
|
package/test/main.test.js
CHANGED
|
@@ -4,8 +4,11 @@ const { COLORS } = require("../src/Colors");
|
|
|
4
4
|
const Shapes = require('../src/Shapes');
|
|
5
5
|
const ShapeUtils = require('../src/util/shapes');
|
|
6
6
|
const { verifyArrayEquality } = require('./utils');
|
|
7
|
+
const Squisher = require('../src/Squisher');
|
|
8
|
+
const Game = require('../src/Game');
|
|
7
9
|
|
|
8
10
|
const assert = require('assert');
|
|
11
|
+
const process = require('process');
|
|
9
12
|
|
|
10
13
|
const hypLength = (x, y) => Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
|
|
11
14
|
|
|
@@ -24,7 +27,7 @@ const compareSquished = (preSquish, unsquished) => {
|
|
|
24
27
|
} else {
|
|
25
28
|
verifyArrayEquality(preSquish.coordinates2d, unsquished.coordinates2d);
|
|
26
29
|
}
|
|
27
|
-
} else if (key === 'input' || key == 'text') {
|
|
30
|
+
} else if (key === 'input' || key == 'text' || key == 'free') {
|
|
28
31
|
// TODO: Handle all of this in a more generic way
|
|
29
32
|
} else if (preSquish[key] === undefined || preSquish[key] === null) {
|
|
30
33
|
assert(unsquished[key] === undefined || unsquished[key] === null);
|
|
@@ -354,3 +357,57 @@ test("big big text", () => {
|
|
|
354
357
|
assert(unsquishedNode.text.size.toFixed(2) === scaledTextSize.toFixed(2));
|
|
355
358
|
});
|
|
356
359
|
|
|
360
|
+
// create one hundred nodes and ensure the memory is freed
|
|
361
|
+
test("allocate a bunch of nodes", () => {
|
|
362
|
+
const initialMemUsage = process.memoryUsage();
|
|
363
|
+
|
|
364
|
+
const nodeCount = Math.pow(10, 2);
|
|
365
|
+
|
|
366
|
+
const root = new GameNode.Text({
|
|
367
|
+
textInfo: {
|
|
368
|
+
text: 'I am root',
|
|
369
|
+
x: 4,
|
|
370
|
+
y: 20,
|
|
371
|
+
size: 5,
|
|
372
|
+
align: 'center',
|
|
373
|
+
color: COLORS.RED
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
const sizeEstimate = squish(root).length;
|
|
378
|
+
|
|
379
|
+
const fakeGame = new Game();
|
|
380
|
+
fakeGame.getLayers = () => {
|
|
381
|
+
return [
|
|
382
|
+
{
|
|
383
|
+
root
|
|
384
|
+
}
|
|
385
|
+
]
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
const squisher = new Squisher({game: fakeGame});
|
|
389
|
+
squisher.addListener(() => {
|
|
390
|
+
// necessary to hold the reference to the proxy that we should be revoking when we call delete
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
for (let i = 0; i < nodeCount; i++) {
|
|
394
|
+
const gameNode = new GameNode.Text({
|
|
395
|
+
textInfo: {
|
|
396
|
+
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?',
|
|
397
|
+
x: 4,
|
|
398
|
+
y: 20,
|
|
399
|
+
size: 5,
|
|
400
|
+
align: 'center',
|
|
401
|
+
color: COLORS.RED
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
root.addChild(gameNode);
|
|
406
|
+
root.removeChild(gameNode.node.id);
|
|
407
|
+
gameNode.free();
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
const postMemUsage = process.memoryUsage();
|
|
411
|
+
assert(postMemUsage.heapTotal - initialMemUsage.heapTotal <= (.05 * initialMemUsage.heapTotal));
|
|
412
|
+
});
|
|
413
|
+
|
package/metest.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const { GameNode, squish, unsquish } = require('./');
|
|
2
|
-
|
|
3
|
-
const ting = new GameNode.Shape({
|
|
4
|
-
coordinates2d: [
|
|
5
|
-
[0, 0],
|
|
6
|
-
[0, 0],
|
|
7
|
-
[0, 0],
|
|
8
|
-
[0, 0]
|
|
9
|
-
],
|
|
10
|
-
shapeType: 1
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
ting.node.id = 529025047768;
|
|
14
|
-
ting.id = 529025047768;
|
|
15
|
-
|
|
16
|
-
const squished = squish(ting);
|
|
17
|
-
|
|
18
|
-
const unsquished = unsquish(squished);
|
|
19
|
-
|
|
20
|
-
if (unsquished.node.id != Number(529025047768)) {
|
|
21
|
-
console.log('fuck man');
|
|
22
|
-
console.log(unsquished.node.id);
|
|
23
|
-
console.log(Number(ting.node.id));
|
|
24
|
-
} else {
|
|
25
|
-
console.log('um what');
|
|
26
|
-
}
|