@turbowarp/sb3fix 0.3.0 → 0.3.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/sb3fix.js +14 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turbowarp/sb3fix",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Fix corrupted Scratch projects",
5
5
  "main": "src/sb3fix.js",
6
6
  "scripts": {
package/src/sb3fix.js CHANGED
@@ -218,6 +218,20 @@ const fixJSON = (data, options = {}) => {
218
218
  costume.name = String(costume.name);
219
219
  }
220
220
 
221
+ // https://github.com/scratchfoundation/scratch-parser/blob/665f05d739a202d565a4af70a201909393d456b2/lib/sb3_definitions.json#L51
222
+ const knownDataFormats = ['png', 'svg', 'jpeg', 'jpg', 'bmp', 'gif'];
223
+ if (!knownDataFormats.includes(costume.dataFormat)) {
224
+ if (typeof costume.md5ext === 'string' && costume.md5ext.endsWith('.svg')) {
225
+ log(`costume ${i} is vector, had invalid dataFormat ${costume.dataFormat}`);
226
+ costume.dataFormat = 'svg';
227
+ } else {
228
+ log(`costume ${i} is bitmap, had invalid dataFormat ${costume.dataFormat}`);
229
+ // dataFormat is only really used to detect vector or bitmap, so we don't
230
+ // need to set this to the real format
231
+ costume.dataFormat = 'png';
232
+ }
233
+ }
234
+
221
235
  if (!('assetId' in costume)) {
222
236
  log(`costume ${i} was missing assetId, deleted`);
223
237
  costumes.splice(i, 1);