squishjs 0.7.67 → 1.0.1
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 -9
- package/src/Squisher.js +27 -1
- package/test/Layers.test.js +3 -0
package/package.json
CHANGED
package/src/Asset.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
|
|
3
|
+
const HG_ASSET_PATH = path.join(getAppDataPath(), 'asset-cache');
|
|
4
|
+
|
|
1
5
|
class Asset {
|
|
2
6
|
constructor(info, data = null) {
|
|
3
7
|
this.info = info;
|
|
@@ -66,9 +70,6 @@ class Asset {
|
|
|
66
70
|
};
|
|
67
71
|
|
|
68
72
|
getFileLocation() {
|
|
69
|
-
|
|
70
|
-
const HG_ASSET_PATH = this.getConfigValue('HG_ASSET_PATH', `${process.cwd()}/.asset_cache`);
|
|
71
|
-
|
|
72
73
|
const fileHash = this.getHash(this.info.id);
|
|
73
74
|
return `${HG_ASSET_PATH}/${fileHash}`;
|
|
74
75
|
}
|
|
@@ -91,9 +92,6 @@ class Asset {
|
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
async downloadSync(force) {
|
|
94
|
-
|
|
95
|
-
const HG_ASSET_PATH = this.getConfigValue('HG_ASSET_PATH', `${process.cwd()}/.asset_cache`);
|
|
96
|
-
|
|
97
95
|
if (!fs.existsSync(HG_ASSET_PATH)) {
|
|
98
96
|
fs.mkdirSync(HG_ASSET_PATH);
|
|
99
97
|
}
|
|
@@ -111,9 +109,6 @@ class Asset {
|
|
|
111
109
|
}
|
|
112
110
|
|
|
113
111
|
download(force) {
|
|
114
|
-
|
|
115
|
-
const HG_ASSET_PATH = this.getConfigValue('HG_ASSET_PATH', `${process.cwd()}/.asset_cache`);
|
|
116
|
-
|
|
117
112
|
if (!this.fs.existsSync(HG_ASSET_PATH)) {
|
|
118
113
|
this.fs.mkdirSync(HG_ASSET_PATH);
|
|
119
114
|
}
|
package/src/Squisher.js
CHANGED
|
@@ -10,6 +10,7 @@ class Squisher {
|
|
|
10
10
|
this.ids = new Set();
|
|
11
11
|
|
|
12
12
|
this.game = game;
|
|
13
|
+
this.gameMetadata = game.constructor.metadata && game.constructor.metadata();
|
|
13
14
|
this.assets = {};
|
|
14
15
|
|
|
15
16
|
this.customBottomLayer = customBottomLayer;
|
|
@@ -113,12 +114,21 @@ class Squisher {
|
|
|
113
114
|
}
|
|
114
115
|
|
|
115
116
|
if (playerIdFilter.size > 0) {
|
|
117
|
+
|
|
118
|
+
let playerIdsToRemove = new Set();
|
|
116
119
|
for (let playerId of playerIdFilter) {
|
|
117
120
|
if (!playerMap[playerId]) {
|
|
118
121
|
playerMap[Number(playerId)] = [];
|
|
119
122
|
}
|
|
120
123
|
|
|
121
|
-
|
|
124
|
+
if (node.node.playerIds.length === 0 || node.node.playerIds.findIndex(i => Number(i) === Number(playerId)) >= 0) {
|
|
125
|
+
playerMap[playerId].push(squished);
|
|
126
|
+
} else {
|
|
127
|
+
playerIdsToRemove.add(playerId);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
for (let id of playerIdsToRemove) {
|
|
131
|
+
playerIdFilter.delete(id);
|
|
122
132
|
}
|
|
123
133
|
} else {
|
|
124
134
|
Object.keys(playerMap).forEach(playerId => {
|
|
@@ -130,12 +140,28 @@ class Squisher {
|
|
|
130
140
|
}
|
|
131
141
|
|
|
132
142
|
for (let i = 0; i < node.node.children.length; i++) {
|
|
143
|
+
// if (node.node.children[i].node.playerIds
|
|
133
144
|
// make a new set so child calls within a single generation arent
|
|
134
145
|
// modifying the same filter set
|
|
135
146
|
const pathFilter = new Set(playerIdFilter);
|
|
136
147
|
this.squishHelper(node.node.children[i], squishedNodes, scale, playerMap, pathFilter);
|
|
137
148
|
}
|
|
138
149
|
|
|
150
|
+
// debug
|
|
151
|
+
for (let k in playerMap) {
|
|
152
|
+
for (let squished in playerMap[k]) {
|
|
153
|
+
const unsquished = unsquish(playerMap[k][squished]);
|
|
154
|
+
if (unsquished.node.playerIds.length > 0 && unsquished.node.playerIds.findIndex(i => Number(i) === Number(k)) < 0) {
|
|
155
|
+
console.log(unsquished.node.playerIds);
|
|
156
|
+
console.log(k);
|
|
157
|
+
console.log(unsquished.node.playerIds.indexOf(k));
|
|
158
|
+
if (k != 254) {
|
|
159
|
+
throw new Error('fuk');
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
139
165
|
}
|
|
140
166
|
|
|
141
167
|
getJson() {
|
package/test/Layers.test.js
CHANGED
|
@@ -43,6 +43,9 @@ test("test layer with child added", () => {
|
|
|
43
43
|
]);
|
|
44
44
|
|
|
45
45
|
const squisher = new Squisher({ game });
|
|
46
|
+
|
|
47
|
+
// add listener so squisher cares about update
|
|
48
|
+
squisher.addListener(() => {});
|
|
46
49
|
|
|
47
50
|
const initialState = Array.from(squisher.state);
|
|
48
51
|
assert(initialState.length === 2);
|