squishjs 1.3.5 → 1.3.7

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": "1.3.5",
3
+ "version": "1.3.7",
4
4
  "description": "squish & unsquish stuff",
5
5
  "scripts": {
6
6
  "test": "node testRunner.js"
package/src/Asset.js CHANGED
@@ -95,7 +95,7 @@ class Asset {
95
95
  existsLocally() {
96
96
  return new Promise((resolve, reject) => {
97
97
  if (this.data) {
98
- resolve(true);
98
+ return resolve(true);
99
99
  }
100
100
  const fileLocation = this.getFileLocation(this.info.id);
101
101
  this.fs.exists(fileLocation, (exists) => {
@@ -118,7 +118,7 @@ class Asset {
118
118
  } else {
119
119
  const fileLocation2 = await downloadFileSync(this.info.id, HG_ASSET_PATH);
120
120
  this.initialized = true;
121
- return fileLocation;
121
+ return fileLocation2;
122
122
  }
123
123
  }
124
124
 
@@ -170,7 +170,7 @@ class Asset {
170
170
  const filePath = `${path}/${fileHash}`;
171
171
 
172
172
  const writeStream = this.fs.createWriteStream(filePath);
173
- const getModule = this.https;
173
+ const getModule = ASSET_URL.startsWith('https') ? this.https : this.http;
174
174
 
175
175
  writeStream.on('close', () => {
176
176
  resolve(filePath);
package/src/BaseNode.js CHANGED
@@ -104,7 +104,7 @@ class BaseNode {
104
104
  this.node.fill = params.fill;
105
105
  }
106
106
  if (params.coordinates2d) {
107
- this.node.coordinates2d = coordinates2d;
107
+ this.node.coordinates2d = params.coordinates2d;
108
108
  }
109
109
  }
110
110
  this.node.onStateChange();
package/src/Game.js CHANGED
@@ -11,7 +11,7 @@ class Game {
11
11
  }
12
12
 
13
13
  removeStateListener(listener) {
14
- this.listeners.remove(listener);
14
+ this.listeners.delete(listener);
15
15
  }
16
16
 
17
17
  findNode(id) {
package/src/Squisher.js CHANGED
@@ -42,7 +42,7 @@ class Squisher {
42
42
  }
43
43
 
44
44
  removeListener(listener) {
45
- this.listeners.remove(listener);
45
+ this.listeners.delete(listener);
46
46
  }
47
47
 
48
48
  unsquish(node) {
@@ -97,9 +97,7 @@ class Squisher {
97
97
  }
98
98
 
99
99
  handleNewAsset(key, asset) {
100
- return new Promise((resolve, reject) => {
101
- this.initialize().then(resolve);
102
- });
100
+ return this.initialize();
103
101
  }
104
102
 
105
103
  squishHelper(node, squishedNodes, scale = {x: 1, y: 1}, playerMap = {}, playerIdFilter = new Set()) {
@@ -122,15 +120,7 @@ class Squisher {
122
120
  }
123
121
 
124
122
  if (node.node.playerIds.length === 0 || node.node.playerIds.findIndex(i => Number(i) === Number(playerId)) >= 0) {
125
- if (node.node.asset) {
126
- const assetInfo = this.gameAssets[Object.keys(node.node.asset)[0]]?.info;
127
- if (assetInfo.type === 'audio' && !this.playerSettings[playerId]?.SOUND?.ENABLED) {
128
- } else {
129
- playerMap[playerId].push(squished);
130
- }
131
- } else {
132
- playerMap[playerId].push(squished);
133
- }
123
+ playerMap[playerId].push(squished);
134
124
  } else {
135
125
  playerIdsToRemove.add(playerId);
136
126
  }
@@ -205,6 +195,12 @@ class Squisher {
205
195
  let assetBundleSize = 0;
206
196
  let finishedCount = 0;
207
197
  const totalCount = Object.keys(allAssets).length;
198
+
199
+ if (totalCount === 0) {
200
+ this.assetBundle = [];
201
+ resolve([]);
202
+ return;
203
+ }
208
204
 
209
205
  for (const key in allAssets) {
210
206
  allAssets[key].getData().then(buf => {
@@ -245,11 +241,10 @@ class Squisher {
245
241
 
246
242
  if (finishedCount == totalCount) {
247
243
  const newAssetBundle = new Array(assetBundleSize);
248
- for (let index = 0; index < assetBundleSize; index++) {
249
- for (const key in this.assets) {
250
- for (let y = 0; y < this.assets[key].length; y++) {
251
- newAssetBundle[index++] = this.assets[key][y];
252
- }
244
+ let index = 0;
245
+ for (const key in this.assets) {
246
+ for (let y = 0; y < this.assets[key].length; y++) {
247
+ newAssetBundle[index++] = this.assets[key][y];
253
248
  }
254
249
  }
255
250
  this.assetBundle = newAssetBundle;
@@ -258,6 +253,7 @@ class Squisher {
258
253
  }).catch(err => {
259
254
  console.error('Unable to get asset data for key ' + key);
260
255
  console.error(err);
256
+ reject(err);
261
257
  });
262
258
  }
263
259