@turbowarp/sb3fix 0.3.4 → 0.3.6
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 +4 -4
- package/src/sb3fix.js +63 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turbowarp/sb3fix",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "Fix corrupted Scratch projects",
|
|
5
5
|
"main": "src/sb3fix.js",
|
|
6
6
|
"scripts": {
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"@turbowarp/jszip": "^3.11.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"copy-webpack-plugin": "^
|
|
28
|
-
"webpack": "^5.
|
|
29
|
-
"webpack-cli": "^
|
|
27
|
+
"copy-webpack-plugin": "^13.0.0",
|
|
28
|
+
"webpack": "^5.98.0",
|
|
29
|
+
"webpack-cli": "^6.0.1"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/src/sb3fix.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
sb3fix - https://github.com/TurboWarp/sb3fix
|
|
3
3
|
|
|
4
|
-
Copyright (C) 2023-
|
|
4
|
+
Copyright (C) 2023-2025 Thomas Weber
|
|
5
5
|
|
|
6
6
|
This Source Code Form is subject to the terms of the Mozilla Public
|
|
7
7
|
License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
@@ -143,7 +143,55 @@ const fixJSON = (data, options = {}) => {
|
|
|
143
143
|
if (typeof type !== 'number') {
|
|
144
144
|
throw new Error('native type is not a number');
|
|
145
145
|
}
|
|
146
|
+
|
|
146
147
|
switch (type) {
|
|
148
|
+
// Number primitive: [4, string|number]
|
|
149
|
+
// Positive number primitive: [5, string|number]
|
|
150
|
+
// Whole number primitive: [6, string|number]
|
|
151
|
+
// Integer primitive: [7, string|number]
|
|
152
|
+
// Angle primitive: [8, string|number]
|
|
153
|
+
case 4:
|
|
154
|
+
case 5:
|
|
155
|
+
case 6:
|
|
156
|
+
case 7:
|
|
157
|
+
case 8: {
|
|
158
|
+
if (native.length !== 2) {
|
|
159
|
+
throw new Error(`Number native is of unexpected length: ${native.length}`);
|
|
160
|
+
}
|
|
161
|
+
const value = native[1];
|
|
162
|
+
if (typeof value !== 'string' && typeof value !== 'number') {
|
|
163
|
+
log('number native had invalid value');
|
|
164
|
+
native[1] = String(value);
|
|
165
|
+
}
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Color: [9, hex color]
|
|
170
|
+
case 9: {
|
|
171
|
+
if (native.length !== 2) {
|
|
172
|
+
throw new Error(`Color native is of unexpected length: ${native.length}`);
|
|
173
|
+
}
|
|
174
|
+
const color = native[1];
|
|
175
|
+
if (typeof color !== 'string' || !/^#[a-f0-9]{6}$/i.test(color)) {
|
|
176
|
+
log('color native had invalid value');
|
|
177
|
+
native[1] = '#000000';
|
|
178
|
+
}
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Text: [10, string|number]
|
|
183
|
+
case 10: {
|
|
184
|
+
if (native.length !== 2) {
|
|
185
|
+
throw new Error(`Text native is of unexpected length: ${native.length}`);
|
|
186
|
+
}
|
|
187
|
+
const value = native[1];
|
|
188
|
+
if (typeof value !== 'string' && typeof value !== 'number') {
|
|
189
|
+
log('text native had invalid value');
|
|
190
|
+
native[1] = String(value);
|
|
191
|
+
}
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
|
|
147
195
|
// Variable: [12, variable name, variable id, x?, y?]
|
|
148
196
|
// List: [13, list name, list id, x?, y?]
|
|
149
197
|
// x and y only present if the native is a top-level block
|
|
@@ -355,6 +403,20 @@ const fixJSON = (data, options = {}) => {
|
|
|
355
403
|
log(`sprite had invalid rotation style ${target.rotationStyle}`);
|
|
356
404
|
target.rotationStyle = 'all around';
|
|
357
405
|
}
|
|
406
|
+
|
|
407
|
+
if (!target.isStage) {
|
|
408
|
+
const x = target.x;
|
|
409
|
+
if (typeof x !== 'number') {
|
|
410
|
+
log(`target x was ${typeof x}: ${x}`);
|
|
411
|
+
target.x = +x || 0;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const y = target.y;
|
|
415
|
+
if (typeof y !== 'number') {
|
|
416
|
+
log(`target y was ${typeof y}: ${y}`);
|
|
417
|
+
target.y = +y || 0;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
358
420
|
};
|
|
359
421
|
|
|
360
422
|
/**
|