@turbowarp/sb3fix 0.2.0 → 0.2.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.
- package/package.json +1 -1
- package/src/sb3fix.js +11 -7
package/package.json
CHANGED
package/src/sb3fix.js
CHANGED
|
@@ -134,7 +134,7 @@ const fixJSON = (data, options = {}) => {
|
|
|
134
134
|
/**
|
|
135
135
|
* @param {unknown[]} native
|
|
136
136
|
*/
|
|
137
|
-
const
|
|
137
|
+
const fixCompressedNativeInPlace = (native) => {
|
|
138
138
|
if (!Array.isArray(native)) {
|
|
139
139
|
throw new Error('native is not an array');
|
|
140
140
|
}
|
|
@@ -144,10 +144,13 @@ const fixJSON = (data, options = {}) => {
|
|
|
144
144
|
throw new Error('native type is not a number');
|
|
145
145
|
}
|
|
146
146
|
switch (type) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
147
|
+
// Variable: [12, variable name, variable id, x?, y?]
|
|
148
|
+
// List: [13, list name, list id, x?, y?]
|
|
149
|
+
// x and y only present if the native is a top-level block
|
|
150
|
+
case 12:
|
|
151
|
+
case 13: {
|
|
152
|
+
if (native.length !== 3 && native.length !== 5) {
|
|
153
|
+
throw new Error(`Variable or list native is of unexpected length: ${native.length}`);
|
|
151
154
|
}
|
|
152
155
|
const name = native[1];
|
|
153
156
|
if (typeof name !== 'string') {
|
|
@@ -155,6 +158,7 @@ const fixJSON = (data, options = {}) => {
|
|
|
155
158
|
native[1] = String(native[1]);
|
|
156
159
|
}
|
|
157
160
|
break;
|
|
161
|
+
}
|
|
158
162
|
}
|
|
159
163
|
};
|
|
160
164
|
|
|
@@ -164,7 +168,7 @@ const fixJSON = (data, options = {}) => {
|
|
|
164
168
|
*/
|
|
165
169
|
const fixBlockInPlace = (id, block) => {
|
|
166
170
|
if (Array.isArray(block)) {
|
|
167
|
-
|
|
171
|
+
fixCompressedNativeInPlace(block);
|
|
168
172
|
} else if (isObject(block)) {
|
|
169
173
|
const inputs = block.inputs;
|
|
170
174
|
if (!isObject(inputs)) {
|
|
@@ -176,7 +180,7 @@ const fixJSON = (data, options = {}) => {
|
|
|
176
180
|
}
|
|
177
181
|
for (let i = 1; i < input.length; i++) {
|
|
178
182
|
if (Array.isArray(input[i])) {
|
|
179
|
-
|
|
183
|
+
fixCompressedNativeInPlace(input[i]);
|
|
180
184
|
}
|
|
181
185
|
}
|
|
182
186
|
}
|