Skip to content

Commit 63b123f

Browse files
committed
Merge branch 'master' of https://github.com/TurboWarp/scratch-parser into oh-no-our-table
2 parents e7e67e4 + 5e21d95 commit 63b123f

File tree

8 files changed

+145
-28
lines changed

8 files changed

+145
-28
lines changed

.github/workflows/node.js.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ jobs:
88
build:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
11+
- uses: actions/checkout@v4
1212
with:
1313
persist-credentials: false
1414
- name: Install Node.js
15-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af
15+
uses: actions/setup-node@v4
1616
with:
17-
node-version: 20
17+
node-version: 22
1818
cache: npm
1919
- run: npm ci
2020
- run: npm run test:lint

lib/sb3_definitions.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,7 @@
3535
{"type": "number"}
3636
]
3737
},
38-
"scalarVal": {
39-
"oneOf": [
40-
{"$ref":"#/definitions/optionalJSON"},
41-
{"$ref":"#/definitions/stringOrNumber"},
42-
{"type": "boolean"}
43-
]
44-
},
38+
"scalarVal": {},
4539
"assetId": {
4640
"type": "string",
4741
"pattern": "^[a-fA-F0-9]{32}$"

lib/unpack.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ module.exports = function (input, isSprite, callback) {
4040

4141
// If not legacy or zip, convert buffer to UTF-8 string and return
4242
if (!isZip && !isLegacy) {
43-
return callback(null, [input.toString('utf-8'), null]);
43+
// In browsers, the native TextDecoder can handle much larger values than the JavaScript polyfill for
44+
// Buffer.toString('utf-8'), particularly in Chrome.
45+
const decoder = new TextDecoder();
46+
return callback(null, [decoder.decode(input), null]);
4447
}
4548

4649
// Return error if legacy encoding detected

lib/validate.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ module.exports = function (isSprite, input, callback) {
4444
// eslint-disable-next-line global-require
4545
var sb3fix = require('@turbowarp/sb3fix');
4646

47-
var fixed = sb3fix.fixJSON(input);
47+
var fixed = sb3fix.fixJSON(input, {
48+
platform: 'turbowarp'
49+
});
4850
validate(isSprite, fixed, function (err2, result2) {
4951
if (err2) {
5052
// Original validation error will be most useful

package-lock.json

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"dependencies": {
2323
"@turbowarp/json": "^0.1.1",
2424
"@turbowarp/jszip": "^3.11.0",
25-
"@turbowarp/sb3fix": "^0.3.0",
25+
"@turbowarp/sb3fix": "^0.4.0",
2626
"ajv": "6.3.0",
2727
"pify": "4.0.1"
2828
},
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{
2+
"targets": [
3+
{
4+
"isStage": true,
5+
"name": "Stage",
6+
"variables": {
7+
"8Ct!xBe$u3!.nz_Bh/]#": [
8+
"object",
9+
{
10+
"hello": "world"
11+
}
12+
]
13+
},
14+
"lists": {
15+
"u(}PhnFj*Oe*`Ka~{hhc": [
16+
"list of objects",
17+
[
18+
{
19+
"a": 1
20+
},
21+
{
22+
"b": 2
23+
}
24+
]
25+
]
26+
},
27+
"broadcasts": {},
28+
"blocks": {},
29+
"comments": {},
30+
"currentCostume": 0,
31+
"costumes": [
32+
{
33+
"name": "backdrop1",
34+
"dataFormat": "svg",
35+
"assetId": "cd21514d0531fdffb22204e0ec5ed84a",
36+
"md5ext": "cd21514d0531fdffb22204e0ec5ed84a.svg",
37+
"rotationCenterX": 240,
38+
"rotationCenterY": 180
39+
}
40+
],
41+
"sounds": [],
42+
"volume": 100,
43+
"layerOrder": 0,
44+
"tempo": 60,
45+
"videoTransparency": 50,
46+
"videoState": "on",
47+
"textToSpeechLanguage": null
48+
}
49+
],
50+
"monitors": [
51+
{
52+
"id": "8Ct!xBe$u3!.nz_Bh/]#",
53+
"mode": "default",
54+
"opcode": "data_variable",
55+
"params": {
56+
"VARIABLE": "object"
57+
},
58+
"spriteName": null,
59+
"value": 0,
60+
"width": 0,
61+
"height": 0,
62+
"x": 5,
63+
"y": 5,
64+
"visible": true,
65+
"sliderMin": 0,
66+
"sliderMax": 100,
67+
"isDiscrete": true
68+
},
69+
{
70+
"id": "u(}PhnFj*Oe*`Ka~{hhc",
71+
"mode": "list",
72+
"opcode": "data_listcontents",
73+
"params": {
74+
"LIST": "list of objects"
75+
},
76+
"spriteName": null,
77+
"value": [],
78+
"width": 0,
79+
"height": 0,
80+
"x": 5,
81+
"y": 32,
82+
"visible": true
83+
}
84+
],
85+
"extensions": [],
86+
"meta": {
87+
"semver": "3.0.0",
88+
"vm": "0.2.0",
89+
"agent": "",
90+
"platform": {
91+
"name": "TurboWarp",
92+
"url": "https://turbowarp.org/"
93+
}
94+
}
95+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const test = require('tap').test;
2+
const fs = require('fs');
3+
const path = require('path');
4+
const parser = require('../../index');
5+
6+
test('non scalar variables', function (t) {
7+
const fixture = fs.readFileSync(path.join(__dirname, '../fixtures/tw_non_scalar_variables.json'), 'utf-8');
8+
parser(fixture, false, function (err, result) {
9+
t.equal(err, null);
10+
t.same(result[0].targets[0].variables['8Ct!xBe$u3!.nz_Bh/]#'][1], {
11+
hello: 'world'
12+
});
13+
t.same(result[0].targets[0].lists['u(}PhnFj*Oe*`Ka~{hhc'][1], [
14+
{
15+
a: 1
16+
},
17+
{
18+
b: 2
19+
}
20+
]);
21+
t.end();
22+
});
23+
});

0 commit comments

Comments
 (0)