@turbowarp/sb3fix 0.2.1 → 0.3.0
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 +2 -2
- package/src/sb3fix.js +44 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turbowarp/sb3fix",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Fix corrupted Scratch projects",
|
|
5
5
|
"main": "src/sb3fix.js",
|
|
6
6
|
"scripts": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"homepage": "https://github.com/TurboWarp/sb3fix#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"jszip": "^3.
|
|
23
|
+
"@turbowarp/jszip": "^3.11.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"copy-webpack-plugin": "^12.0.2",
|
package/src/sb3fix.js
CHANGED
|
@@ -330,23 +330,55 @@ const fixJSON = (data, options = {}) => {
|
|
|
330
330
|
fixTargetInPlace(target);
|
|
331
331
|
}
|
|
332
332
|
|
|
333
|
+
let stage;
|
|
333
334
|
const allStages = targets.filter((target) => target.isStage);
|
|
334
|
-
if (allStages.length
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
335
|
+
if (allStages.length === 0) {
|
|
336
|
+
log('stage is missing; adding an empty one');
|
|
337
|
+
stage = {
|
|
338
|
+
isStage: true,
|
|
339
|
+
name: 'Stage',
|
|
340
|
+
variables: {},
|
|
341
|
+
lists: {},
|
|
342
|
+
broadcasts: {},
|
|
343
|
+
blocks: {},
|
|
344
|
+
currentCostume: 0,
|
|
345
|
+
costumes: [
|
|
346
|
+
{
|
|
347
|
+
name: 'backdrop1',
|
|
348
|
+
dataFormat: 'svg',
|
|
349
|
+
assetId: 'cd21514d0531fdffb22204e0ec5ed84a',
|
|
350
|
+
md5ext: 'cd21514d0531fdffb22204e0ec5ed84a.svg',
|
|
351
|
+
rotationCenterX: 240,
|
|
352
|
+
rotationCenterY: 180
|
|
353
|
+
}
|
|
354
|
+
],
|
|
355
|
+
sounds: [],
|
|
356
|
+
volume: 100,
|
|
357
|
+
layerOrder: 0,
|
|
358
|
+
tempo: 60,
|
|
359
|
+
videoTransparency: 50,
|
|
360
|
+
videoState: "on",
|
|
361
|
+
textToSpeechLanguage: null
|
|
362
|
+
};
|
|
344
363
|
targets.unshift(stage);
|
|
364
|
+
} else if (allStages.length === 1) {
|
|
365
|
+
const stageIndex = targets.findIndex((target) => target.isStage);
|
|
366
|
+
// stageIndex guaranteed to not be -1 by earlier filter check
|
|
367
|
+
stage = targets[stageIndex];
|
|
368
|
+
// stage must be the first target
|
|
369
|
+
if (stageIndex !== 0) {
|
|
370
|
+
log(`stage was at wrong index: ${stageIndex}`);
|
|
371
|
+
targets.splice(stageIndex, 1);
|
|
372
|
+
targets.unshift(stage);
|
|
373
|
+
}
|
|
374
|
+
} else {
|
|
375
|
+
throw new Error(`wrong number of stages: ${allStages.length}`);
|
|
345
376
|
}
|
|
377
|
+
|
|
346
378
|
// stage's name must match exactly
|
|
347
379
|
if (stage.name !== 'Stage') {
|
|
380
|
+
log(`stage had wrong name: ${stage.name}`);
|
|
348
381
|
stage.name = 'Stage';
|
|
349
|
-
log('stage had wrong name');
|
|
350
382
|
}
|
|
351
383
|
|
|
352
384
|
const knownExtensions = getKnownExtensions(project);
|
|
@@ -389,7 +421,7 @@ const fixJSON = (data, options = {}) => {
|
|
|
389
421
|
*/
|
|
390
422
|
const fixZip = async (data, options = {}) => {
|
|
391
423
|
// JSZip is not a small library, so we'll load it somewhat lazily.
|
|
392
|
-
const JSZip = require('jszip');
|
|
424
|
+
const JSZip = require('@turbowarp/jszip');
|
|
393
425
|
|
|
394
426
|
const zip = await JSZip.loadAsync(data);
|
|
395
427
|
|