Skip to content

Commit d2fe285

Browse files
committed
feat: add layerOrder informaiton to stage and sprites
Validates the new layerOrder property for the stage and the sprites, adds tests for validation.
1 parent 2552f4d commit d2fe285

File tree

8 files changed

+861
-6
lines changed

8 files changed

+861
-6
lines changed

lib/sb3_definitions.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,11 @@
323323
"videoState": {
324324
"type": "string",
325325
"enum": ["on", "off", "on-flipped"]
326+
},
327+
"layerOrder": {
328+
"type": "integer",
329+
"enum": [0],
330+
"description": "The layer order of the stage should be 0, if specified."
326331
}
327332
},
328333
"required": [
@@ -363,6 +368,11 @@
363368
"rotationStyle": {
364369
"type": "string",
365370
"enum": ["all around", "don't rotate", "left-right"]
371+
},
372+
"layerOrder": {
373+
"type": "integer",
374+
"minimum": 1,
375+
"description": "The layer order of a sprite should be a positive number, if specified."
366376
}
367377
},
368378
"required": [

test/fixtures/data.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@ module.exports = {
4444
},
4545
sb3_comments: {
4646
comments: fs.readFileSync(path.resolve(__dirname, './data/_comments.sb3')),
47-
invalid_comments: fs.readFileSync(path.resolve(__dirname, './data/_invalid_comments.sb3'))
47+
invalid_comments: fs.readFileSync(path.resolve(__dirname, './data/invalid/_invalid_comments.sb3'))
4848
},
4949
sb: sb,
5050
sb2: sb2,
5151
sb3: sb3,
5252
json: json,
5353
gzipJson: gzipJson,
54-
sprite2: sprite2
54+
sprite2: sprite2,
55+
layerOrderSB3Json: fs.readFileSync(path.resolve(__dirname, './data/_layer_ordering.json')),
56+
invalidStageLayerSB3Json: fs.readFileSync(path.resolve(__dirname, './data/invalid/_invalid_stage_layer.json')),
57+
invalidSpriteLayerSB3Json: fs.readFileSync(path.resolve(__dirname, './data/invalid/_invalid_sprite_layer.json'))
5558
};
Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
{
2+
"targets": [
3+
{
4+
"isStage": true,
5+
"name": "Stage",
6+
"variables": {},
7+
"lists": {},
8+
"broadcasts": {},
9+
"blocks": {},
10+
"comments": {},
11+
"currentCostume": 0,
12+
"costumes": [
13+
{
14+
"assetId": "797b03bdb8cf6ccfc30c0692d533d998",
15+
"name": "backdrop1",
16+
"bitmapResolution": 2,
17+
"md5ext": "797b03bdb8cf6ccfc30c0692d533d998.png",
18+
"dataFormat": "png",
19+
"rotationCenterX": 480,
20+
"rotationCenterY": 360
21+
}
22+
],
23+
"sounds": [
24+
{
25+
"assetId": "83a9787d4cb6f3b7632b4ddfebf74367",
26+
"name": "pop",
27+
"dataFormat": "wav",
28+
"format": "",
29+
"rate": 44100,
30+
"sampleCount": 1032,
31+
"md5ext": "83a9787d4cb6f3b7632b4ddfebf74367.wav"
32+
}
33+
],
34+
"volume": 100,
35+
"layerOrder": 0,
36+
"tempo": 60,
37+
"videoTransparency": 50,
38+
"videoState": "on"
39+
},
40+
{
41+
"isStage": false,
42+
"name": "First",
43+
"variables": {},
44+
"lists": {},
45+
"broadcasts": {},
46+
"blocks": {},
47+
"comments": {},
48+
"currentCostume": 0,
49+
"costumes": [
50+
{
51+
"assetId": "613c377136af410d014ac9580d4b26f7",
52+
"name": "bowtie-a",
53+
"bitmapResolution": 1,
54+
"md5ext": "613c377136af410d014ac9580d4b26f7.svg",
55+
"dataFormat": "svg",
56+
"rotationCenterX": 11,
57+
"rotationCenterY": 4
58+
},
59+
{
60+
"assetId": "f56cc7c523a9e242221a8f5c72a6934a",
61+
"name": "bowtie-b",
62+
"bitmapResolution": 1,
63+
"md5ext": "f56cc7c523a9e242221a8f5c72a6934a.svg",
64+
"dataFormat": "svg",
65+
"rotationCenterX": 11,
66+
"rotationCenterY": 4
67+
}
68+
],
69+
"sounds": [
70+
{
71+
"assetId": "83a9787d4cb6f3b7632b4ddfebf74367",
72+
"name": "pop",
73+
"dataFormat": "wav",
74+
"format": "",
75+
"rate": 44100,
76+
"sampleCount": 1032,
77+
"md5ext": "83a9787d4cb6f3b7632b4ddfebf74367.wav"
78+
}
79+
],
80+
"volume": 100,
81+
"layerOrder": 2,
82+
"visible": true,
83+
"x": -22.88381743,
84+
"y": 5.96685083,
85+
"size": 160,
86+
"direction": 90,
87+
"draggable": true,
88+
"rotationStyle": "all around"
89+
},
90+
{
91+
"isStage": false,
92+
"name": "Second",
93+
"variables": {},
94+
"lists": {},
95+
"broadcasts": {},
96+
"blocks": {},
97+
"comments": {},
98+
"currentCostume": 0,
99+
"costumes": [
100+
{
101+
"assetId": "4490f27a28b3c677348f330297a3bb89",
102+
"name": "costume1",
103+
"bitmapResolution": 1,
104+
"md5ext": "4490f27a28b3c677348f330297a3bb89.svg",
105+
"dataFormat": "svg",
106+
"rotationCenterX": 47,
107+
"rotationCenterY": 55
108+
},
109+
{
110+
"assetId": "d15c553bc1cd08d2d9d15eba9df5cd1b",
111+
"name": "costume2",
112+
"bitmapResolution": 1,
113+
"md5ext": "d15c553bc1cd08d2d9d15eba9df5cd1b.svg",
114+
"dataFormat": "svg",
115+
"rotationCenterX": 47,
116+
"rotationCenterY": 55
117+
}
118+
],
119+
"sounds": [
120+
{
121+
"assetId": "83c36d806dc92327b9e7049a565c6bff",
122+
"name": "meow",
123+
"dataFormat": "wav",
124+
"format": "",
125+
"rate": 44100,
126+
"sampleCount": 37376,
127+
"md5ext": "83c36d806dc92327b9e7049a565c6bff.wav"
128+
}
129+
],
130+
"volume": 100,
131+
"layerOrder": 1,
132+
"visible": true,
133+
"x": 0,
134+
"y": 0,
135+
"size": 100,
136+
"direction": 90,
137+
"draggable": false,
138+
"rotationStyle": "all around"
139+
},
140+
{
141+
"isStage": false,
142+
"name": "Third",
143+
"variables": {},
144+
"lists": {},
145+
"broadcasts": {},
146+
"blocks": {},
147+
"comments": {},
148+
"currentCostume": 0,
149+
"costumes": [
150+
{
151+
"assetId": "ab53564b459a91028c3bf1a3551f1631",
152+
"name": "building-a",
153+
"bitmapResolution": 1,
154+
"md5ext": "ab53564b459a91028c3bf1a3551f1631.svg",
155+
"dataFormat": "svg",
156+
"rotationCenterX": 40,
157+
"rotationCenterY": 30
158+
},
159+
{
160+
"assetId": "b952a069c9ac22d4ac09c1af44424c67",
161+
"name": "building-b",
162+
"bitmapResolution": 1,
163+
"md5ext": "b952a069c9ac22d4ac09c1af44424c67.svg",
164+
"dataFormat": "svg",
165+
"rotationCenterX": 46,
166+
"rotationCenterY": -11
167+
},
168+
{
169+
"assetId": "50c6f56e0191f9436c64422044a92c76",
170+
"name": "building-c",
171+
"bitmapResolution": 1,
172+
"md5ext": "50c6f56e0191f9436c64422044a92c76.svg",
173+
"dataFormat": "svg",
174+
"rotationCenterX": 25,
175+
"rotationCenterY": 17
176+
},
177+
{
178+
"assetId": "d9790f9aecf011a31d572f120e2b118b",
179+
"name": "building-d",
180+
"bitmapResolution": 1,
181+
"md5ext": "d9790f9aecf011a31d572f120e2b118b.svg",
182+
"dataFormat": "svg",
183+
"rotationCenterX": 59,
184+
"rotationCenterY": -10
185+
},
186+
{
187+
"assetId": "fb8f053378c3bfd9725788f2132881d8",
188+
"name": "building-e",
189+
"bitmapResolution": 1,
190+
"md5ext": "fb8f053378c3bfd9725788f2132881d8.svg",
191+
"dataFormat": "svg",
192+
"rotationCenterX": 36,
193+
"rotationCenterY": 55
194+
},
195+
{
196+
"assetId": "6ea4b6088b955e6da28d1d02ed8b737b",
197+
"name": "building-f",
198+
"bitmapResolution": 1,
199+
"md5ext": "6ea4b6088b955e6da28d1d02ed8b737b.svg",
200+
"dataFormat": "svg",
201+
"rotationCenterX": 41,
202+
"rotationCenterY": 27
203+
},
204+
{
205+
"assetId": "51de720af9e3b180be7d8c55f2281f47",
206+
"name": "building-g",
207+
"bitmapResolution": 1,
208+
"md5ext": "51de720af9e3b180be7d8c55f2281f47.svg",
209+
"dataFormat": "svg",
210+
"rotationCenterX": 64,
211+
"rotationCenterY": -65
212+
},
213+
{
214+
"assetId": "83fb74916e865cb628305c203a5889f3",
215+
"name": "building-h",
216+
"bitmapResolution": 1,
217+
"md5ext": "83fb74916e865cb628305c203a5889f3.svg",
218+
"dataFormat": "svg",
219+
"rotationCenterX": 33,
220+
"rotationCenterY": 136
221+
},
222+
{
223+
"assetId": "7c75c78cddea6c2f4463c22a2a7b12c1",
224+
"name": "building-i",
225+
"bitmapResolution": 1,
226+
"md5ext": "7c75c78cddea6c2f4463c22a2a7b12c1.svg",
227+
"dataFormat": "svg",
228+
"rotationCenterX": 31,
229+
"rotationCenterY": -12
230+
},
231+
{
232+
"assetId": "0d08fd317df35626dd66973fb31c7fb2",
233+
"name": "building-j",
234+
"bitmapResolution": 1,
235+
"md5ext": "0d08fd317df35626dd66973fb31c7fb2.svg",
236+
"dataFormat": "svg",
237+
"rotationCenterX": 29,
238+
"rotationCenterY": 33
239+
}
240+
],
241+
"sounds": [
242+
{
243+
"assetId": "83a9787d4cb6f3b7632b4ddfebf74367",
244+
"name": "pop",
245+
"dataFormat": "wav",
246+
"format": "",
247+
"rate": 44100,
248+
"sampleCount": 1032,
249+
"md5ext": "83a9787d4cb6f3b7632b4ddfebf74367.wav"
250+
}
251+
],
252+
"volume": 100,
253+
"layerOrder": 3,
254+
"visible": true,
255+
"x": -22,
256+
"y": -23,
257+
"size": 100,
258+
"direction": 90,
259+
"draggable": false,
260+
"rotationStyle": "all around"
261+
}
262+
],
263+
"extensions": [],
264+
"meta": {
265+
"semver": "3.0.0",
266+
"vm": "0.2.0",
267+
"agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"
268+
}
269+
}

0 commit comments

Comments
 (0)