@turbowarp/sb3fix 0.3.3 → 0.3.4
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/sb3fix.js +41 -0
package/package.json
CHANGED
package/src/sb3fix.js
CHANGED
|
@@ -199,6 +199,29 @@ const fixJSON = (data, options = {}) => {
|
|
|
199
199
|
}
|
|
200
200
|
};
|
|
201
201
|
|
|
202
|
+
/**
|
|
203
|
+
* @param {string} id
|
|
204
|
+
* @param {unknown} comment
|
|
205
|
+
*/
|
|
206
|
+
const fixCommentInPlace = (id, comment) => {
|
|
207
|
+
if (!isObject(comment)) {
|
|
208
|
+
throw new Error('comment is not an object');
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (typeof comment.text !== 'string') {
|
|
212
|
+
throw new Error('comment text is not a string');
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Scratch requires comments to not exceed 8000 characters.
|
|
216
|
+
// We'll store the excess in .extraText so the text won't be truncated if opened in TurboWarp.
|
|
217
|
+
const MAX_LENGTH = 8000;
|
|
218
|
+
if (comment.text.length > MAX_LENGTH) {
|
|
219
|
+
log(`comment ${id} had length ${comment.text.length}`);
|
|
220
|
+
comment.extraText = comment.text.substring(MAX_LENGTH);
|
|
221
|
+
comment.text = comment.text.substring(0, MAX_LENGTH);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
|
|
202
225
|
/**
|
|
203
226
|
* @param {unknown} target
|
|
204
227
|
*/
|
|
@@ -287,6 +310,14 @@ const fixJSON = (data, options = {}) => {
|
|
|
287
310
|
fixBlockInPlace(blockId, block);
|
|
288
311
|
}
|
|
289
312
|
|
|
313
|
+
// Comments are not required
|
|
314
|
+
const comments = target.comments;
|
|
315
|
+
if (comments) {
|
|
316
|
+
for (const [commentId, comment] of Object.entries(comments)) {
|
|
317
|
+
fixCommentInPlace(commentId, comment);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
290
321
|
const variables = target.variables;
|
|
291
322
|
if (!isObject(variables)) {
|
|
292
323
|
throw new Error('variables is not an object');
|
|
@@ -314,6 +345,16 @@ const fixJSON = (data, options = {}) => {
|
|
|
314
345
|
target.layerOrder = 1;
|
|
315
346
|
}
|
|
316
347
|
}
|
|
348
|
+
|
|
349
|
+
const ROTATION_STYLES = [
|
|
350
|
+
'all around',
|
|
351
|
+
'don\'t rotate',
|
|
352
|
+
'left-right'
|
|
353
|
+
];
|
|
354
|
+
if (!target.isStage && !ROTATION_STYLES.includes(target.rotationStyle)) {
|
|
355
|
+
log(`sprite had invalid rotation style ${target.rotationStyle}`);
|
|
356
|
+
target.rotationStyle = 'all around';
|
|
357
|
+
}
|
|
317
358
|
};
|
|
318
359
|
|
|
319
360
|
/**
|