squishjs 0.7.62 → 0.7.66
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/Squisher.js +10 -1
- package/src/squishHelpers/text.js +67 -12
- package/test/main.test.js +19 -0
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/Squisher.js
CHANGED
|
@@ -190,7 +190,13 @@ class Squisher {
|
|
|
190
190
|
|
|
191
191
|
const encodedLength = (buf.length + assetKeyLength).toString(36);
|
|
192
192
|
|
|
193
|
-
const
|
|
193
|
+
const assetTypeMap = {
|
|
194
|
+
'image': 1,
|
|
195
|
+
'audio': 2,
|
|
196
|
+
'font': 3
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const assetType = assetTypeMap[allAssets[key].info.type];
|
|
194
200
|
|
|
195
201
|
const encodedMaxLength = 10;
|
|
196
202
|
let encodedLengthString = '';
|
|
@@ -221,6 +227,9 @@ class Squisher {
|
|
|
221
227
|
this.assetBundle = newAssetBundle;
|
|
222
228
|
resolve(newAssetBundle);
|
|
223
229
|
}
|
|
230
|
+
}).catch(err => {
|
|
231
|
+
console.error('Unable to get asset data for key ' + key);
|
|
232
|
+
console.error(err);
|
|
224
233
|
});
|
|
225
234
|
}
|
|
226
235
|
|
|
@@ -11,7 +11,8 @@ const squishText = {
|
|
|
11
11
|
const textY = scale ? (t.y * scale.y) + Math.round(100 * (1 - scale.y)) / 2 : t.y;
|
|
12
12
|
|
|
13
13
|
const align = t.align || 'left';
|
|
14
|
-
|
|
14
|
+
const font = t.font || 'default';
|
|
15
|
+
const squishedText = new Array(t.text.length + 10 + align.length + font.length);
|
|
15
16
|
|
|
16
17
|
squishedText[0] = Math.floor(textX);
|
|
17
18
|
squishedText[1] = Math.round(100 * (textX - Math.floor(textX)));
|
|
@@ -33,6 +34,7 @@ const squishText = {
|
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
squishedText[6 + squishedTextColor.length] = 3 * [...align].length;
|
|
37
|
+
squishedText[6 + squishedTextColor.length + 1] = 3 * [...font].length;// (3*[...align].length) + 1] = 3 * [...font].length;
|
|
36
38
|
|
|
37
39
|
let j = 0;
|
|
38
40
|
for (let i = 0; i < [...align].length; i++) {
|
|
@@ -52,12 +54,38 @@ const squishText = {
|
|
|
52
54
|
} else {
|
|
53
55
|
ting = [`${codePointString.charAt(0)}${codePointString.charAt(1)}`, `${codePointString.charAt(2)}${codePointString.charAt(3)}`, `${codePointString.charAt(4)}${codePointString.charAt(5)}`];
|
|
54
56
|
}
|
|
55
|
-
squishedText[6 + squishedTextColor.length +
|
|
56
|
-
squishedText[6 + squishedTextColor.length +
|
|
57
|
-
squishedText[6 + squishedTextColor.length +
|
|
57
|
+
squishedText[6 + squishedTextColor.length + 2 + j] = Number(ting[0]);
|
|
58
|
+
squishedText[6 + squishedTextColor.length + 2 + j + 1] = Number(ting[1]);
|
|
59
|
+
squishedText[6 + squishedTextColor.length + 2 + j + 2] = Number(ting[2]);
|
|
58
60
|
j += 3;
|
|
59
61
|
}
|
|
60
62
|
|
|
63
|
+
let f = 0;
|
|
64
|
+
for (let i = 0; i < [...font].length; i++) {
|
|
65
|
+
const codePointToInsert = [...font][i].codePointAt(0);
|
|
66
|
+
const codePointString = codePointToInsert.toString();
|
|
67
|
+
let ting;
|
|
68
|
+
if (codePointString.length == 1) {
|
|
69
|
+
ting = [`00`, `00`, `0${codePointString}`];
|
|
70
|
+
} else if (codePointString.length == 2) {
|
|
71
|
+
ting = [`00`, `00`, `${codePointString}`];
|
|
72
|
+
} else if (codePointString.length == 3) {
|
|
73
|
+
ting = [`00`, `0${codePointString.charAt(0)}`, `${codePointString.charAt(1)}${codePointString.charAt(2)}`];
|
|
74
|
+
} else if (codePointString.length == 4) {
|
|
75
|
+
ting = [`00`, `${codePointString.charAt(0)}${codePointString.charAt(1)}`, `${codePointString.charAt(2)}${codePointString.charAt(3)}`];
|
|
76
|
+
} else if (codePointString.length == 5) {
|
|
77
|
+
ting = [`0${codePointString.charAt(0)}`, `${codePointString.charAt(1)}${codePointString.charAt(2)}`, `${codePointString.charAt(3)}${codePointString.charAt(4)}`];
|
|
78
|
+
} else {
|
|
79
|
+
ting = [`${codePointString.charAt(0)}${codePointString.charAt(1)}`, `${codePointString.charAt(2)}${codePointString.charAt(3)}`, `${codePointString.charAt(4)}${codePointString.charAt(5)}`];
|
|
80
|
+
}
|
|
81
|
+
let startIndex = 6 + squishedTextColor.length + 2 + (3 * [...align].length);
|
|
82
|
+
squishedText[startIndex + f] = Number(ting[0]);
|
|
83
|
+
squishedText[startIndex + f + 1] = Number(ting[1]);
|
|
84
|
+
squishedText[startIndex + f + 2] = Number(ting[2]);
|
|
85
|
+
|
|
86
|
+
f += 3;
|
|
87
|
+
}
|
|
88
|
+
|
|
61
89
|
let k = 0;
|
|
62
90
|
for (let i = 0; i < [...t.text].length; i++) {
|
|
63
91
|
const codePointToInsert = [...t.text][i].codePointAt(0);
|
|
@@ -76,9 +104,11 @@ const squishText = {
|
|
|
76
104
|
} else {
|
|
77
105
|
ting = [`${codePointString.charAt(0)}${codePointString.charAt(1)}`, `${codePointString.charAt(2)}${codePointString.charAt(3)}`, `${codePointString.charAt(4)}${codePointString.charAt(5)}`];
|
|
78
106
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
squishedText[
|
|
107
|
+
|
|
108
|
+
let startIndex = 6 + squishedTextColor.length + 2 + (3 * [...align].length) + (3 * [...font].length);
|
|
109
|
+
squishedText[startIndex + k] = Number(ting[0]);
|
|
110
|
+
squishedText[startIndex + k + 1] = Number(ting[1]);
|
|
111
|
+
squishedText[startIndex + k + 2] = Number(ting[2]);
|
|
82
112
|
|
|
83
113
|
k += 3;
|
|
84
114
|
}
|
|
@@ -91,8 +121,10 @@ const squishText = {
|
|
|
91
121
|
const textSize = squished[4] + squished[5] / 100;
|
|
92
122
|
const textColor = squished.slice(6, 10);
|
|
93
123
|
const textAlignLength = squished[10];
|
|
94
|
-
|
|
95
|
-
const
|
|
124
|
+
const textFontLength = squished[11];
|
|
125
|
+
const textAlignVal = squished.slice(12, 12 + textAlignLength);
|
|
126
|
+
const textFontVal = squished.slice(12 + textAlignLength, 12 + textAlignLength + textFontLength);
|
|
127
|
+
const textVal = squished.slice(12 + textAlignLength + textFontLength);
|
|
96
128
|
|
|
97
129
|
let alignCodePoints = [];
|
|
98
130
|
for (let i = 0; i < textAlignVal.length; i+=3) {
|
|
@@ -114,6 +146,29 @@ const squishText = {
|
|
|
114
146
|
const codePoint = firstChunk + secondChunk + thirdChunk;
|
|
115
147
|
alignCodePoints.push(codePoint);
|
|
116
148
|
}
|
|
149
|
+
const align = String.fromCodePoint.apply(null, alignCodePoints);
|
|
150
|
+
|
|
151
|
+
let fontCodePoints = [];
|
|
152
|
+
for (let i = 0; i < textFontVal.length; i+=3) {
|
|
153
|
+
let firstChunk = textFontVal[i].toString();
|
|
154
|
+
if (firstChunk.length == 1) {
|
|
155
|
+
firstChunk = `0${firstChunk}`;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
let secondChunk = textFontVal[i + 1].toString();
|
|
159
|
+
if (secondChunk.length == 1) {
|
|
160
|
+
secondChunk = `0${secondChunk}`;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
let thirdChunk = textFontVal[i + 2].toString();
|
|
164
|
+
if (thirdChunk.length == 1) {
|
|
165
|
+
thirdChunk = `0${thirdChunk}`;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const codePoint = firstChunk + secondChunk + thirdChunk;
|
|
169
|
+
fontCodePoints.push(codePoint);
|
|
170
|
+
}
|
|
171
|
+
const font = String.fromCodePoint.apply(null, fontCodePoints);
|
|
117
172
|
|
|
118
173
|
const textCodePoints = [];
|
|
119
174
|
for (let i = 0; i < textVal.length; i+=3) {
|
|
@@ -134,8 +189,7 @@ const squishText = {
|
|
|
134
189
|
textCodePoints.push(codePoint);
|
|
135
190
|
}
|
|
136
191
|
|
|
137
|
-
|
|
138
|
-
const text = String.fromCodePoint.apply(null, textCodePoints);
|
|
192
|
+
const text = String.fromCodePoint.apply(null, textCodePoints);
|
|
139
193
|
|
|
140
194
|
return {
|
|
141
195
|
x: textPosX,
|
|
@@ -143,7 +197,8 @@ const squishText = {
|
|
|
143
197
|
text: text,
|
|
144
198
|
size: textSize,
|
|
145
199
|
color: textColor,
|
|
146
|
-
align
|
|
200
|
+
align,
|
|
201
|
+
font
|
|
147
202
|
};
|
|
148
203
|
}
|
|
149
204
|
}
|
package/test/main.test.js
CHANGED
|
@@ -149,6 +149,25 @@ test("Text node", () => {
|
|
|
149
149
|
compareSquished(squishedNode.node, unsquishedNode);
|
|
150
150
|
});
|
|
151
151
|
|
|
152
|
+
test("Text node with custom font", () => {
|
|
153
|
+
const gameNode = new GameNode.Text({
|
|
154
|
+
textInfo: {
|
|
155
|
+
text: 'ayy lmao',
|
|
156
|
+
font: 'test-font',
|
|
157
|
+
x: 40,
|
|
158
|
+
y: 40,
|
|
159
|
+
size: 1,
|
|
160
|
+
align: 'center',
|
|
161
|
+
color: COLORS.BLACK
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const squishedNode = squish(gameNode);
|
|
166
|
+
const unsquishedNode = unsquish(squishedNode).node;
|
|
167
|
+
assert(unsquishedNode.text.font === 'test-font');
|
|
168
|
+
compareSquished(squishedNode.node, unsquishedNode);
|
|
169
|
+
});
|
|
170
|
+
|
|
152
171
|
test("Asset node", () => {
|
|
153
172
|
const gameNode = new GameNode.Asset({
|
|
154
173
|
coordinates2d: ShapeUtils.rectangle(0, 0, 10, 10),
|