squishjs 0.7.2 → 0.7.5

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.2",
3
+ "version": "0.7.5",
4
4
  "description": "squish & unsquish stuff",
5
5
  "scripts": {
6
6
  "test": "node testRunner.js"
package/src/Game.js CHANGED
@@ -1,18 +1,9 @@
1
1
  class Game {
2
2
  constructor() {
3
- this.players = {};
4
- this.spectators = {};
5
3
  this.listeners = new Set();
6
4
  this.intervals = [];
7
5
  this.timeouts = [];
8
- }
9
-
10
- _hgAddPlayer(player) {
11
- this.players[player.id] = player;
12
- }
13
-
14
- _hgRemovePlayer(playerId) {
15
- delete this.players[playerId];
6
+ this.playerInfoMap = {};
16
7
  }
17
8
 
18
9
  addStateListener(listener) {
package/src/GameNode.js CHANGED
@@ -36,7 +36,7 @@ class Shape extends BaseNode {
36
36
  }
37
37
 
38
38
  clone({ handleClick, input, id }) {
39
- const _id = id || null;
39
+ const _id = Number(id) || null;
40
40
  return new Shape({
41
41
  color: this.node.color,
42
42
  onClick: handleClick,
@@ -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
- this.spectatorState = this.game.getSpectatorLayers ? this.squish(this.game.getSpectatorLayers()) : [];
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);
@@ -45,7 +48,7 @@ class Squisher {
45
48
  }
46
49
 
47
50
  squish(layers, scale = null) {
48
-
51
+
49
52
  if (!layers) {
50
53
  return [];
51
54
  }
@@ -56,10 +59,6 @@ class Squisher {
56
59
 
57
60
  const playerMap = {};
58
61
 
59
- Object.keys(this.game.players).forEach(playerId => {
60
- playerMap[Number(playerId)] = [];
61
- });
62
-
63
62
  if (this.customBottomLayer) {
64
63
  const squishedLayer = [];
65
64
  this.squishHelper(this.customBottomLayer.root, squishedLayer, this.customBottomLayer.scale, playerMap);
@@ -80,7 +79,7 @@ class Squisher {
80
79
  }
81
80
 
82
81
 
83
- if (this.customTopLayer) {
82
+ if (this.customTopLayer) {
84
83
  const squishedLayer = [];
85
84
  this.squishHelper(this.customTopLayer.root, squishedLayer, this.customTopLayer.scale, playerMap);
86
85
  toSquish.push(squishedLayer);
@@ -95,7 +94,13 @@ class Squisher {
95
94
  return this.playerFrames[playerId];
96
95
  }
97
96
 
98
- squishHelper(node, squishedNodes, scale = {x: 1, y: 1}, playerMap = {}) {
97
+ handleNewAsset(key, asset) {
98
+ return new Promise((resolve, reject) => {
99
+ this.initialize().then(resolve);
100
+ });
101
+ }
102
+
103
+ squishHelper(node, squishedNodes, scale = {x: 1, y: 1}, playerMap = {}, playerIdFilter = new Set()) {
99
104
  if (!node.node.listeners.has(this)) {
100
105
  node.addListener(this);
101
106
  }
@@ -103,24 +108,32 @@ class Squisher {
103
108
  const squished = squish(node, scale);
104
109
  squishedNodes.push(squished);
105
110
 
106
- if (playerMap) {
107
- if (node.node.playerIds && node.node.playerIds.length) {
108
- node.node.playerIds.forEach(playerId => {
109
- if (playerMap[playerId]) {
110
- playerMap[playerId].push(squished);
111
- } else {
112
- console.warn(`Node references unknown player ID: ${playerId}`);
113
- }
114
- });
115
- } else {
116
- Object.keys(playerMap).forEach(playerId => {
117
- playerMap[playerId].push(squished);
118
- })
111
+ if (node.node.playerIds && node.node.playerIds.length > 0) {
112
+ node.node.playerIds.forEach(pId => playerIdFilter.add(pId));
113
+ }
114
+
115
+ if (playerIdFilter.size > 0) {
116
+ for (let playerId of playerIdFilter) {
117
+ if (!playerMap[playerId]) {
118
+ playerMap[Number(playerId)] = [];
119
+ }
120
+
121
+ playerMap[playerId].push(squished);
119
122
  }
123
+ } else {
124
+ Object.keys(playerMap).forEach(playerId => {
125
+ if (!playerMap[playerId]) {
126
+ playerMap[Number(playerId)] = [];
127
+ }
128
+ playerMap[playerId].push(squished);
129
+ })
120
130
  }
121
131
 
122
132
  for (let i = 0; i < node.node.children.length; i++) {
123
- this.squishHelper(node.node.children[i], squishedNodes, scale, playerMap);
133
+ // make a new set so child calls within a single generation arent
134
+ // modifying the same filter set
135
+ const pathFilter = new Set(playerIdFilter);
136
+ this.squishHelper(node.node.children[i], squishedNodes, scale, playerMap, pathFilter);
124
137
  }
125
138
 
126
139
  }
@@ -139,29 +152,34 @@ class Squisher {
139
152
 
140
153
  initialize() {
141
154
  return new Promise((resolve, reject) => {
142
- const gameMetadata = this.game.constructor.metadata && this.game.constructor.metadata();
155
+
143
156
 
144
- const gameAssets = gameMetadata && gameMetadata.assets ? gameMetadata.assets : {};
157
+ const assets = Object.assign({}, this.assets || {});
145
158
 
146
- if (this.customBottomLayer && this.customBottomLayer.assets) {
147
- Object.assign(gameAssets, this.customBottomLayer.assets);
148
- }
149
-
150
- if (this.customTopLayer && this.customTopLayer.assets) {
151
- Object.assign(gameAssets, this.customTopLayer.assets);
152
- }
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);
153
176
 
154
- if (this.game.getAssets && this.game.getAssets()) {
155
- Object.assign(gameAssets, this.game.getAssets());
156
- }
157
-
158
- const initializeAssetBundle = () => new Promise((resolve, reject) => {
159
177
  let assetBundleSize = 0;
160
178
  let finishedCount = 0;
161
- const totalCount = Object.keys(gameAssets).length;
179
+ const totalCount = Object.keys(allAssets).length;
162
180
 
163
- for (const key in gameAssets) {
164
- gameAssets[key].getData().then(buf => {
181
+ for (const key in allAssets) {
182
+ allAssets[key].getData().then(buf => {
165
183
  const assetKeyLength = 32;
166
184
  let keyIndex = 0;
167
185
  const assetKeyArray = new Array(32);
@@ -172,7 +190,7 @@ class Squisher {
172
190
 
173
191
  const encodedLength = (buf.length + assetKeyLength).toString(36);
174
192
 
175
- const assetType = gameAssets[key].info.type === 'image' ? 1 : 2;
193
+ const assetType = allAssets[key].info.type === 'image' ? 1 : 2;
176
194
 
177
195
  const encodedMaxLength = 10;
178
196
  let encodedLengthString = '';
@@ -200,16 +218,11 @@ class Squisher {
200
218
  }
201
219
  }
202
220
  }
203
- resolve(newAssetBundle);
221
+ this.assetBundle = newAssetBundle;
222
+ resolve(newAssetBundle);
204
223
  }
205
224
  });
206
225
  }
207
- });
208
-
209
- initializeAssetBundle().then((newAssetBundle) => {
210
- this.assetBundle = newAssetBundle;
211
- resolve();
212
- });
213
226
 
214
227
  });
215
228
  }
package/src/squish.js CHANGED
@@ -73,7 +73,13 @@ const unsquish = (squished) => {
73
73
  }
74
74
 
75
75
  const constructor = TYPE_TO_CONSTRUCTOR[squished[2]];
76
- return new constructor({ node: constructedInternalNode });
76
+ if (constructor) {
77
+ return new constructor({ node: constructedInternalNode });
78
+ }
79
+
80
+ return {
81
+ node: constructedInternalNode
82
+ }
77
83
  }
78
84
 
79
85
  // When squishing, we need to make sure that properties that other properties depend on are inserted first.
@@ -1,4 +1,4 @@
1
- const { getFractional } = require('../util')
1
+ const { getFractional } = require('../util');
2
2
 
3
3
  const ASSET_SUBTYPE = 48;
4
4
 
@@ -6,7 +6,7 @@ const squishAsset = {
6
6
  type: ASSET_SUBTYPE,
7
7
  squish: (a, scale) => {
8
8
  const assetKey = Object.keys(a)[0];
9
- const squishedAssets = new Array(8 + assetKey.length);
9
+ const squishedAssets = new Array(10 + assetKey.length);
10
10
 
11
11
  const asset = a[assetKey];
12
12
 
@@ -16,6 +16,8 @@ const squishAsset = {
16
16
  const sizeX = scale ? scale.x * asset.size.x : asset.size.x;
17
17
  const sizeY = scale ? scale.y * asset.size.y : asset.size.y;
18
18
 
19
+ const startTimeSecond = asset.startTime || 0;
20
+
19
21
  squishedAssets[0] = Math.floor(posX);
20
22
  squishedAssets[1] = getFractional(posX);
21
23
 
@@ -28,8 +30,11 @@ const squishAsset = {
28
30
  squishedAssets[6] = Math.floor(sizeY);
29
31
  squishedAssets[7] = getFractional(sizeY);
30
32
 
33
+ squishedAssets[8] = Math.floor(startTimeSecond);
34
+ squishedAssets[9] = getFractional(startTimeSecond);
35
+
31
36
  for (let i = 0; i < assetKey.length; i++) {
32
- squishedAssets[8 + i] = assetKey.codePointAt(i);
37
+ squishedAssets[10 + i] = assetKey.codePointAt(i);
33
38
  }
34
39
 
35
40
  return squishedAssets;
@@ -41,7 +46,10 @@ const squishAsset = {
41
46
  const assetSizeX = squished[4] + squished[5] / 100;
42
47
  const assetSizeY = squished[6] + squished[7] / 100;
43
48
 
44
- const assetKey = String.fromCodePoint.apply(null, squished.slice(8));
49
+ const startTime = squished[8] + squished[9] / 100;
50
+
51
+ const assetKey = String.fromCodePoint.apply(null, squished.slice(10));
52
+
45
53
  return {
46
54
  [assetKey]: {
47
55
  pos: {
@@ -51,7 +59,8 @@ const squishAsset = {
51
59
  size: {
52
60
  x: assetSizeX,
53
61
  y: assetSizeY
54
- }
62
+ },
63
+ startTime
55
64
  }
56
65
  }
57
66
  }
@@ -3,10 +3,43 @@ const ID_SUBTYPE = 43;
3
3
  const squishId = {
4
4
  type: ID_SUBTYPE,
5
5
  squish: (i) => {
6
- return [i];
6
+ // max val: 10 000 000 000 000 000 (ten quadrillion)
7
+ const idStr = i.toString();
8
+ let strChunks = [];
9
+ if (idStr.length > 2) {
10
+ let j;
11
+ for (j = 0; j + 2 <= idStr.length; j += 2) {
12
+ strChunks.push(idStr.substring(j, j + 2));
13
+ }
14
+
15
+ if (j == idStr.length - 1) {
16
+ strChunks.push(idStr.substring(j, j + 2));
17
+ }
18
+ } else {
19
+ if (idStr.length === 1) {
20
+ strChunks.push('0' + idStr);
21
+ } else {
22
+ strChunks.push(idStr);
23
+ }
24
+ }
25
+
26
+ if (strChunks.length < 8) {
27
+ while (strChunks.length < 8) {
28
+ strChunks = ["00", ...strChunks];
29
+ }
30
+ }
31
+
32
+ return strChunks.map(c => new Number(c));
7
33
  },
8
34
  unsquish: (arr) => {
9
- return arr[0];
35
+ // build up from right to left then parse
36
+ let str = '';
37
+ for (let i = arr.length - 1; i >= 0; i--) {
38
+ const val = arr[i];
39
+ str = val + str
40
+ }
41
+
42
+ return new Number(str);
10
43
  }
11
44
  }
12
45
 
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
- const xScale = 1//100 / (view.w || 100);
64
- const yScale = 1//100 / (view.h || 100);
60
+ if (translatedX < 0) {
61
+ translatedX = 0;
62
+ } else if (translatedX > 100) {
63
+ translatedX = 100;
64
+ }
65
65
 
66
- translatedX = xScale * translatedX;
67
- translatedY = yScale * translatedY;
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
- console.log("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
 
package/test/utils.js CHANGED
@@ -31,7 +31,7 @@ const verifyArrayEquality = (actual, expected) => {
31
31
  if (expected[i].length && actual[i].length) {
32
32
  verifyArrayEquality(expected[i], actual[i]);
33
33
  } else {
34
- assert(expected[i] === actual[i]);
34
+ assert(expected[i] - actual[i] === 0);
35
35
  }
36
36
  }
37
37
  };
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);
@@ -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
- });