@turbowarp/sb3fix 0.2.1 → 0.2.2

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/sb3fix.js +43 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turbowarp/sb3fix",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Fix corrupted Scratch projects",
5
5
  "main": "src/sb3fix.js",
6
6
  "scripts": {
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 !== 1) {
335
- throw new Error(`wrong number of stages: ${allStages.length}`);
336
- }
337
- const stageIndex = targets.findIndex((target) => target.isStage);
338
- // stageIndex guaranteed to not be -1 by earlier check
339
- const stage = targets[stageIndex];
340
- // stage must be the first target
341
- if (stageIndex !== 0) {
342
- log('stage was not at start');
343
- targets.splice(stageIndex, 1);
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);