squishjs 0.7.4 → 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/LICENSE.md +674 -21
- package/package.json +1 -1
- package/src/BaseNode.js +3 -3
- package/src/GameNode.js +1 -1
- package/src/InternalGameNode.js +1 -1
- package/src/Squisher.js +37 -28
- package/src/ViewableGame.js +9 -12
- package/src/squish.js +17 -7
- package/src/squishHelpers/text.js +1 -1
- package/src/util/views.js +15 -12
- package/test/main.test.js +31 -6
- package/test/utils.js +1 -1
- package/oldsvgexport.js +0 -89
- package/render-tester.js +0 -120
- package/test/StateUpdates.js +0 -10
- package/testapp.html +0 -26
- package/testapp.js +0 -988
package/package.json
CHANGED
package/src/BaseNode.js
CHANGED
|
@@ -68,10 +68,10 @@ class BaseNode {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
findChild(id) {
|
|
71
|
-
return this
|
|
71
|
+
return this.findChildHelper(id, this);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
|
|
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
|
|
83
|
+
found = this.findChildHelper(nodeId, node.node.children[i], found);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
return found;
|
package/src/GameNode.js
CHANGED
package/src/InternalGameNode.js
CHANGED
|
@@ -2,7 +2,7 @@ let _id = 0;
|
|
|
2
2
|
|
|
3
3
|
class InternalGameNode {
|
|
4
4
|
constructor(color, onClick, coordinates2d, border, fill, text, asset, playerIds = [], effects = null, input = null, subType = null, id = null) {
|
|
5
|
-
this.id = id ? Number(id) : _id
|
|
5
|
+
this.id = id ? Number(id) : Number(_id++);
|
|
6
6
|
this.children = new Array();
|
|
7
7
|
this.color = color;
|
|
8
8
|
this.handleClick = onClick;
|
package/src/Squisher.js
CHANGED
|
@@ -6,21 +6,24 @@ const INVISIBLE_PLAYER_ID = 0;
|
|
|
6
6
|
const DEFAULT_TICK_RATE = 60;
|
|
7
7
|
|
|
8
8
|
class Squisher {
|
|
9
|
-
constructor({ game, scale, customBottomLayer, customTopLayer }) {
|
|
9
|
+
constructor({ game, scale, customBottomLayer, customTopLayer, onAssetUpdate }) {
|
|
10
10
|
this.ids = new Set();
|
|
11
11
|
|
|
12
12
|
this.game = game;
|
|
13
|
+
this.assets = {};
|
|
13
14
|
|
|
14
15
|
this.customBottomLayer = customBottomLayer;
|
|
15
16
|
this.customTopLayer = customTopLayer;
|
|
16
17
|
|
|
18
|
+
this.initialize();
|
|
19
|
+
this.onAssetUpdate = onAssetUpdate;
|
|
20
|
+
|
|
17
21
|
this.playerFrames = {};
|
|
18
22
|
|
|
19
23
|
this.listeners = new Set();
|
|
20
24
|
this.scale = scale || {x: 1, y: 1};
|
|
21
25
|
this.state = this.squish(this.game.getLayers());
|
|
22
|
-
|
|
23
|
-
this.assets = {};
|
|
26
|
+
|
|
24
27
|
if (this.game.tick) {
|
|
25
28
|
const tickRate = this.gameMetadata && this.gameMetadata.tickRate ? this.gameMetadata.tickRate : DEFAULT_TICK_RATE;
|
|
26
29
|
setInterval(this.game.tick.bind(this.game), 1000 / tickRate);
|
|
@@ -91,6 +94,12 @@ class Squisher {
|
|
|
91
94
|
return this.playerFrames[playerId];
|
|
92
95
|
}
|
|
93
96
|
|
|
97
|
+
handleNewAsset(key, asset) {
|
|
98
|
+
return new Promise((resolve, reject) => {
|
|
99
|
+
this.initialize().then(resolve);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
94
103
|
squishHelper(node, squishedNodes, scale = {x: 1, y: 1}, playerMap = {}, playerIdFilter = new Set()) {
|
|
95
104
|
if (!node.node.listeners.has(this)) {
|
|
96
105
|
node.addListener(this);
|
|
@@ -143,29 +152,34 @@ class Squisher {
|
|
|
143
152
|
|
|
144
153
|
initialize() {
|
|
145
154
|
return new Promise((resolve, reject) => {
|
|
146
|
-
|
|
155
|
+
|
|
147
156
|
|
|
148
|
-
|
|
157
|
+
const assets = Object.assign({}, this.assets || {});
|
|
149
158
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
159
|
+
const gameMetadata = this.game.constructor.metadata && this.game.constructor.metadata();
|
|
160
|
+
|
|
161
|
+
const gameAssets = gameMetadata && gameMetadata.assets ? gameMetadata.assets : {};
|
|
162
|
+
|
|
163
|
+
if (this.customBottomLayer && this.customBottomLayer.assets) {
|
|
164
|
+
Object.assign(gameAssets, this.customBottomLayer.assets);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (this.customTopLayer && this.customTopLayer.assets) {
|
|
168
|
+
Object.assign(gameAssets, this.customTopLayer.assets);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (this.game.getAssets && this.game.getAssets()) {
|
|
172
|
+
Object.assign(gameAssets, this.game.getAssets());
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const allAssets = Object.assign(assets, gameAssets);
|
|
157
176
|
|
|
158
|
-
if (this.game.getAssets && this.game.getAssets()) {
|
|
159
|
-
Object.assign(gameAssets, this.game.getAssets());
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const initializeAssetBundle = () => new Promise((resolve, reject) => {
|
|
163
177
|
let assetBundleSize = 0;
|
|
164
178
|
let finishedCount = 0;
|
|
165
|
-
const totalCount = Object.keys(
|
|
179
|
+
const totalCount = Object.keys(allAssets).length;
|
|
166
180
|
|
|
167
|
-
for (const key in
|
|
168
|
-
|
|
181
|
+
for (const key in allAssets) {
|
|
182
|
+
allAssets[key].getData().then(buf => {
|
|
169
183
|
const assetKeyLength = 32;
|
|
170
184
|
let keyIndex = 0;
|
|
171
185
|
const assetKeyArray = new Array(32);
|
|
@@ -176,7 +190,7 @@ class Squisher {
|
|
|
176
190
|
|
|
177
191
|
const encodedLength = (buf.length + assetKeyLength).toString(36);
|
|
178
192
|
|
|
179
|
-
const assetType =
|
|
193
|
+
const assetType = allAssets[key].info.type === 'image' ? 1 : 2;
|
|
180
194
|
|
|
181
195
|
const encodedMaxLength = 10;
|
|
182
196
|
let encodedLengthString = '';
|
|
@@ -204,16 +218,11 @@ class Squisher {
|
|
|
204
218
|
}
|
|
205
219
|
}
|
|
206
220
|
}
|
|
207
|
-
|
|
221
|
+
this.assetBundle = newAssetBundle;
|
|
222
|
+
resolve(newAssetBundle);
|
|
208
223
|
}
|
|
209
224
|
});
|
|
210
225
|
}
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
initializeAssetBundle().then((newAssetBundle) => {
|
|
214
|
-
this.assetBundle = newAssetBundle;
|
|
215
|
-
resolve();
|
|
216
|
-
});
|
|
217
226
|
|
|
218
227
|
});
|
|
219
228
|
}
|
package/src/ViewableGame.js
CHANGED
|
@@ -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
|
|
21
|
-
this
|
|
17
|
+
this.planeSize = planeSize;
|
|
18
|
+
this.plane = makePlane(this.planeSize);
|
|
22
19
|
|
|
23
|
-
this
|
|
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
|
|
28
|
+
root: this.fakeRoot
|
|
32
29
|
}
|
|
33
30
|
];
|
|
34
31
|
}
|
|
35
32
|
|
|
36
33
|
updatePlaneSize(s) {
|
|
37
|
-
this
|
|
38
|
-
this
|
|
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
|
|
43
|
+
return this.plane;
|
|
47
44
|
}
|
|
48
45
|
|
|
49
46
|
getPlaneSize() {
|
|
50
|
-
return this
|
|
47
|
+
return this.planeSize;
|
|
51
48
|
}
|
|
52
49
|
|
|
53
50
|
getViewRoot() {
|
|
54
|
-
return this
|
|
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
|
-
|
|
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/src/util/views.js
CHANGED
|
@@ -4,7 +4,7 @@ const ShapeUtils = require('./shapes');
|
|
|
4
4
|
const GeometryUtils = require('./geometry');
|
|
5
5
|
const Colors = require('../Colors');
|
|
6
6
|
|
|
7
|
-
const getView = (plane, view, playerIds, translation = {}) => {
|
|
7
|
+
const getView = (plane, view, playerIds, translation = {}, scale = {}) => {
|
|
8
8
|
|
|
9
9
|
const wouldBeCollisions = GeometryUtils.checkCollisions(plane, {node: {coordinates2d: ShapeUtils.rectangle(view.x, view.y, view.w, view.h)}}, (node) => {
|
|
10
10
|
return node.node.id !== plane.node.id;
|
|
@@ -35,11 +35,15 @@ const getView = (plane, view, playerIds, translation = {}) => {
|
|
|
35
35
|
|
|
36
36
|
for (let coorPairIndex in vertices) {
|
|
37
37
|
const coordPair = vertices[coorPairIndex];
|
|
38
|
+
|
|
38
39
|
const x = coordPair[0];
|
|
39
40
|
const y = coordPair[1];
|
|
40
41
|
let translatedX = Math.max(Math.min(x - view.x, 100), 0);
|
|
41
42
|
let translatedY = Math.max(Math.min(y - view.y, 100), 0);
|
|
42
43
|
|
|
44
|
+
translatedX = (scale.x || 1) * translatedX;
|
|
45
|
+
translatedY = (scale.y || 1) * translatedY;
|
|
46
|
+
|
|
43
47
|
const shouldTranslate = translation.filter ? translation.filter(node) : true;
|
|
44
48
|
|
|
45
49
|
if (shouldTranslate) {
|
|
@@ -51,20 +55,19 @@ const getView = (plane, view, playerIds, translation = {}) => {
|
|
|
51
55
|
translatedY += translation.y;
|
|
52
56
|
}
|
|
53
57
|
|
|
54
|
-
if (translatedX < 0 || translatedX > 100) {
|
|
55
|
-
shouldInclude = false;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (translatedY < 0 || translatedY > 100) {
|
|
59
|
-
shouldInclude = false;
|
|
60
|
-
}
|
|
61
58
|
}
|
|
62
59
|
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
if (translatedX < 0) {
|
|
61
|
+
translatedX = 0;
|
|
62
|
+
} else if (translatedX > 100) {
|
|
63
|
+
translatedX = 100;
|
|
64
|
+
}
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
if (translatedY < 0) {
|
|
67
|
+
translatedY = 0;
|
|
68
|
+
} else if (translatedY > 100) {
|
|
69
|
+
translatedY = 100;
|
|
70
|
+
}
|
|
68
71
|
|
|
69
72
|
translatedCoords.push([translatedX, translatedY]);
|
|
70
73
|
}
|
package/test/main.test.js
CHANGED
|
@@ -48,6 +48,8 @@ const compareSquished = (preSquish, unsquished) => {
|
|
|
48
48
|
assert(preSquish[key][k] === unsquished[key][k]);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
+
} else if (key === 'id') {
|
|
52
|
+
assert(Number(preSquish[key]) === Number(unsquished[key]));
|
|
51
53
|
} else {
|
|
52
54
|
assert(preSquish[key] === unsquished[key]);
|
|
53
55
|
}
|
|
@@ -120,14 +122,13 @@ test("Text node with unicode", () => {
|
|
|
120
122
|
color: COLORS.BLACK
|
|
121
123
|
}
|
|
122
124
|
});
|
|
123
|
-
|
|
124
|
-
const squishedNode = new Uint8ClampedArray(squish(gameNode.node));
|
|
125
|
+
const squishedNode = new Uint8ClampedArray(squish(gameNode));
|
|
125
126
|
const unsquishedNode = unsquish(squishedNode);
|
|
126
127
|
compareSquished(squishedNode.node, unsquishedNode);
|
|
127
|
-
assert(unsquishedNode.text.text.length === 6);
|
|
128
|
-
assert([...unsquishedNode.text.text].length === 3);
|
|
129
|
-
assert(unsquishedNode.text.text.codePointAt(0) === '💯'.codePointAt(0));
|
|
130
|
-
assert(unsquishedNode.text.text.codePointAt(4) === '💯'.codePointAt(0));
|
|
128
|
+
assert(unsquishedNode.node.text.text.length === 6);
|
|
129
|
+
assert([...unsquishedNode.node.text.text].length === 3);
|
|
130
|
+
assert(unsquishedNode.node.text.text.codePointAt(0) === '💯'.codePointAt(0));
|
|
131
|
+
assert(unsquishedNode.node.text.text.codePointAt(4) === '💯'.codePointAt(0));
|
|
131
132
|
});
|
|
132
133
|
|
|
133
134
|
|
|
@@ -308,5 +309,29 @@ test("scaled asset node", () => {
|
|
|
308
309
|
assert(asset.size.y === .85 * 20);
|
|
309
310
|
});
|
|
310
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;
|
|
311
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
|
+
});
|
|
312
337
|
|
package/test/utils.js
CHANGED
package/oldsvgexport.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const { unsquish } = require('../src/squish');
|
|
3
|
-
const subtypes = require('../src/subtypes');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const svgText = (gameNode, container) => {
|
|
7
|
-
const fill = gameNode.node.text.color;
|
|
8
|
-
const align = gameNode.node.text.align;
|
|
9
|
-
|
|
10
|
-
let svgAlign;
|
|
11
|
-
if (align === 'left') {
|
|
12
|
-
svgAlign = 'end';
|
|
13
|
-
}
|
|
14
|
-
if (align === 'center') {
|
|
15
|
-
svgAlign = 'middle';
|
|
16
|
-
}
|
|
17
|
-
if (align === 'right') {
|
|
18
|
-
svgAlign = 'start';
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const fillString = `rgba(${fill[0]}, ${fill[1]}, ${fill[2]}, ${fill[3]})`
|
|
22
|
-
|
|
23
|
-
return `<text text-anchor="${svgAlign}" x="${scaleX(gameNode.node.text.x, container.x)}" y="${scaleX(gameNode.node.text.y, container.y)}" fill="${fillString}">${gameNode.node.text.text}</text>`;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const svgPolygon = (gameNode, container) => {
|
|
27
|
-
const coordPairs = gameNode.node.coordinates2d;
|
|
28
|
-
const fill = gameNode.node.fill;
|
|
29
|
-
|
|
30
|
-
const fillString = `rgba(${fill[0]}, ${fill[1]}, ${fill[2]}, ${fill[3]})`
|
|
31
|
-
|
|
32
|
-
const scaledCoords = coordPairs.map(coordPair => {
|
|
33
|
-
return [scaleX(coordPair[0], container.x), scaleY(coordPair[1], container.y)];
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
return `<polygon points="${scaledCoords.join(' ')}"
|
|
37
|
-
fill="${fillString}" stroke="black" />`;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const scaleX = (x, containerWidth) => {
|
|
41
|
-
const widthPercentage = x / 100;
|
|
42
|
-
return widthPercentage * containerWidth;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const scaleY = (y, containerHeight) => {
|
|
46
|
-
const heightPercentage = y / 100;
|
|
47
|
-
return heightPercentage * containerHeight;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const svgHelper = (gameNode, container) => {
|
|
51
|
-
|
|
52
|
-
if (gameNode.node.subType === subtypes.SHAPE_2D_POLYGON) {
|
|
53
|
-
console.log('sdfdsfdsf');
|
|
54
|
-
return svgPolygon(gameNode, container);
|
|
55
|
-
} else if (gameNode.node.subType === subtypes.SHAPE_2D_LINE) {
|
|
56
|
-
// svgString += svgPolygon(gameNode);
|
|
57
|
-
} else if (gameNode.node.subType === subtypes.SHAPE_2D_CIRCLE) {
|
|
58
|
-
// svgString += svgPolygon(gameNode);
|
|
59
|
-
} else if (gameNode.node.subType === subtypes.ASSET) {
|
|
60
|
-
// svgString += svgPolygon(gameNode);
|
|
61
|
-
} else if (gameNode.node.subType === subtypes.TEXT) {
|
|
62
|
-
console.log('yooooo his dgjdf top of the morning');
|
|
63
|
-
return svgText(gameNode, container);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// for (let i = 0; i < gameNode.node.children.length; i++) {
|
|
67
|
-
// svgHelper(gameNode.node.children[i], container, svgString);
|
|
68
|
-
// }
|
|
69
|
-
|
|
70
|
-
// return svgString;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
module.exports = (squishedLayers, outFile) => {
|
|
74
|
-
const pageWidth = 600;
|
|
75
|
-
const pageHeight = 600;
|
|
76
|
-
let svgString = `<svg height="${pageHeight}" width="${pageWidth}" xmlns="http://www.w3.org/2000/svg" xmlns:xlink= "http://www.w3.org/1999/xlink">`;
|
|
77
|
-
// <circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
|
|
78
|
-
// </svg>`;
|
|
79
|
-
const container = { x: pageWidth, y: pageHeight };
|
|
80
|
-
squishedLayers.forEach(squishedNode => {
|
|
81
|
-
console.log('squished node');
|
|
82
|
-
console.log(squishedNode);
|
|
83
|
-
const node = unsquish(squishedNode);
|
|
84
|
-
svgString += svgHelper(node, container);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
svgString += `</svg>`
|
|
88
|
-
fs.writeFileSync(outFile, svgString);
|
|
89
|
-
};
|
package/render-tester.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
console.log('ytoooo');
|
|
2
|
-
|
|
3
|
-
const canvas = document.getElementById('tester-canvas');
|
|
4
|
-
|
|
5
|
-
const ctx = canvas.getContext('2d');
|
|
6
|
-
|
|
7
|
-
const scaleCoordinate = ({ x, y }) => {
|
|
8
|
-
const xPercentage = x / 100;
|
|
9
|
-
const yPercentage = y / 100;
|
|
10
|
-
|
|
11
|
-
return {
|
|
12
|
-
scaledX: xPercentage * canvas.width,
|
|
13
|
-
scaledY: yPercentage * canvas.height
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
let thingToRender = [
|
|
19
|
-
[
|
|
20
|
-
3, 36, 2, 43, 3, 0, 44, 2, 52,
|
|
21
|
-
22, 5, 0, 5, 0, 95, 0, 5, 0,
|
|
22
|
-
95, 0, 95, 0, 5, 0, 95, 0, 5,
|
|
23
|
-
0, 5, 0, 53, 6, 255, 0, 0, 255
|
|
24
|
-
],
|
|
25
|
-
[
|
|
26
|
-
3, 36, 2, 43, 3, 1, 44, 2, 52,
|
|
27
|
-
22, 5, 0, 5, 0, 50, 0, 5, 0,
|
|
28
|
-
50, 0, 50, 0, 5, 0, 50, 0, 5,
|
|
29
|
-
0, 5, 0, 53, 6, 0, 0, 255, 255
|
|
30
|
-
],
|
|
31
|
-
[
|
|
32
|
-
3, 36, 2, 43, 3, 2, 44, 2, 52,
|
|
33
|
-
22, 50, 0, 5, 0, 95, 0, 5, 0,
|
|
34
|
-
95, 0, 50, 0, 50, 0, 50, 0, 50,
|
|
35
|
-
0, 5, 0, 53, 6, 0, 255, 0, 255
|
|
36
|
-
],
|
|
37
|
-
[
|
|
38
|
-
3, 36, 2, 43, 3, 3, 44, 2, 52,
|
|
39
|
-
22, 50, 0, 50, 0, 95, 0, 50, 0,
|
|
40
|
-
95, 0, 95, 0, 50, 0, 95, 0, 50,
|
|
41
|
-
0, 50, 0, 53, 6, 0, 0, 0, 255
|
|
42
|
-
],
|
|
43
|
-
[
|
|
44
|
-
3, 36, 2, 43, 3, 4, 44, 2, 52,
|
|
45
|
-
22, 5, 0, 50, 0, 50, 0, 50, 0,
|
|
46
|
-
50, 0, 95, 0, 5, 0, 95, 0, 5,
|
|
47
|
-
0, 50, 0, 53, 6, 255, 255, 255, 255
|
|
48
|
-
]
|
|
49
|
-
];
|
|
50
|
-
|
|
51
|
-
const drawMarker = ({ x, y, horizontal }) => {
|
|
52
|
-
const { scaledX, scaledY } = scaleCoordinate({ x, y });
|
|
53
|
-
|
|
54
|
-
if (horizontal) {
|
|
55
|
-
const lineWidth = .015 * canvas.width;
|
|
56
|
-
ctx.beginPath();
|
|
57
|
-
ctx.moveTo(scaledX, scaledY);
|
|
58
|
-
ctx.lineTo(scaledX + lineWidth, scaledY);
|
|
59
|
-
ctx.stroke();
|
|
60
|
-
} else {
|
|
61
|
-
// line is 1.5% of height
|
|
62
|
-
const lineHeight = .015 * canvas.height;
|
|
63
|
-
ctx.beginPath();
|
|
64
|
-
ctx.moveTo(scaledX, scaledY);
|
|
65
|
-
ctx.lineTo(scaledX, scaledY + lineHeight);
|
|
66
|
-
ctx.stroke();
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const drawMarkers = () => {
|
|
71
|
-
const horizontalPoints = [
|
|
72
|
-
[0, 10],
|
|
73
|
-
[0, 20],
|
|
74
|
-
[0, 30],
|
|
75
|
-
[0, 40],
|
|
76
|
-
[0, 50],
|
|
77
|
-
[0, 60],
|
|
78
|
-
[0, 70],
|
|
79
|
-
[0, 80],
|
|
80
|
-
[0, 90]
|
|
81
|
-
];
|
|
82
|
-
|
|
83
|
-
const verticalPoints = [
|
|
84
|
-
[10, 0],
|
|
85
|
-
[20, 0],
|
|
86
|
-
[30, 0],
|
|
87
|
-
[40, 0],
|
|
88
|
-
[50, 0],
|
|
89
|
-
[60, 0],
|
|
90
|
-
[70, 0],
|
|
91
|
-
[80, 0],
|
|
92
|
-
[90, 0]
|
|
93
|
-
];
|
|
94
|
-
|
|
95
|
-
verticalPoints.forEach(coord => {
|
|
96
|
-
drawMarker({x: coord[0], y: coord[1], horizontal: false });
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
horizontalPoints.forEach(coord => {
|
|
100
|
-
drawMarker({x: coord[0], y: coord[1], horizontal: true });
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const drawThing = () => {
|
|
106
|
-
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const draw = () => {
|
|
110
|
-
canvas.width = window.innerWidth;
|
|
111
|
-
canvas.height = window.innerHeight;
|
|
112
|
-
|
|
113
|
-
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
114
|
-
drawMarkers();
|
|
115
|
-
drawThing();
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
draw();
|
|
119
|
-
|
|
120
|
-
window.addEventListener('resize', draw);
|
package/test/StateUpdates.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
const { COLORS } = require("../src/Colors");
|
|
2
|
-
const assert = require("assert");
|
|
3
|
-
const Squisher = require('../src/Squisher');
|
|
4
|
-
const { unsquish } = require('../src/squish');
|
|
5
|
-
|
|
6
|
-
const { FakeGame, verifyArrayEquality, rectNode, polygonNode, circleNode } = require('./utils');
|
|
7
|
-
|
|
8
|
-
test("two layers - square over square", () => {
|
|
9
|
-
console.log("two layers - one square over another");
|
|
10
|
-
});
|
package/testapp.html
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE HTML>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<title>Homegames</title>
|
|
6
|
-
</head>
|
|
7
|
-
<body>
|
|
8
|
-
<div>
|
|
9
|
-
<canvas id='tester-canvas'></canvas>
|
|
10
|
-
</div>
|
|
11
|
-
</body>
|
|
12
|
-
<script src="src/squish.js"></script>
|
|
13
|
-
<script src="render-tester.js"></script>
|
|
14
|
-
<style>
|
|
15
|
-
|
|
16
|
-
body {
|
|
17
|
-
margin: 0;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
canvas, body {
|
|
21
|
-
width: 100vw;
|
|
22
|
-
height: 100vh;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
</style>
|
|
26
|
-
</html>
|