Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ var validate = require('./lib/validate');
* Unpacks, parses, validates, and analyzes Scratch projects. If successful,
* will return a valid Scratch project object with appended metadata.
* @param {Buffer | string} input Buffer or string representing project
* @param {boolean} isSprite Whether this is a sprite (true) or whole project (false)
* @param {Function} callback Returns error or project data
*/
module.exports = function (input, callback) {
module.exports = function (input, isSprite, callback) {

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

// First unpack the input (need this outside of the async waterfall so that
// unpackedProject can be refered to again)
unpack(input, function (err, unpackedProject) {
unpack(input, isSprite, function (err, unpackedProject) {
if (err) return callback(err);

async.waterfall([
function (cb) {
parse(unpackedProject[0], cb);
},
validate
// TODO is there a better way to pass this arg
// than partially applying this funciton?
validate.bind(null, isSprite)
], function (error, validatedInput) {
// One more callback wrapper so that we can re-package everything
// with the possible zip returned from unpack
Expand Down
5 changes: 3 additions & 2 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
* @return {void}
*/
module.exports = function (input, callback) {
var result;
try {
var result = JSON.parse(input);
callback(null, result);
result = JSON.parse(input);
} catch (e) {
return callback(e.toString());
}
return callback(null, result);
};
195 changes: 195 additions & 0 deletions lib/sb2_definitions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
{
"$id": "https://scratch.mit.edu/sb2_definitions.json",
"$schema": "http://json-schema.org/schema#",
"description": "Scratch 2.0 Project and Sprite Definitions",
"definitions": {
"scripts": {
"type": "array"
},
"sounds": {
"type": "array",
"properties": {
"soundName": {
"type": "string"
},
"soundID": {
"type": "number"
},
"md5": {
"type": "string"
},
"sampleCount": {
"type": "number"
},
"rate": {
"type": "number"
},
"format": {
"type": "string"
}
},
"required": [
"soundName",
"soundID",
"md5",
"sampleCount",
"rate",
"format"
]
},
"costumes": {
"type": "array",
"properties": {
"costumeName": {
"type": "string"
},
"baseLayerID": {
"type": "number"
},
"baseLayerMD5": {
"type": "string"
},
"bitmapResolution": {
"type": "number"
},
"rotationCenterX": {
"type": "number"
},
"rotationCenterY": {
"type": "number"
}
},
"required": [
"costumeName",
"baseLayerID",
"baseLayerMD5",
"bitmapResolution",
"rotationCenterX",
"rotationCenterY"
]
},
"variables": {
"type": "array",
"properties": {
"name": {
"type": "string"
},
"value": {
"type": "string"
},
"isPersistent": {
"type": "boolean"
}
},
"required": [
"name",
"value"
]
},
"sprite_object": {
"type": "object",
"properties": {
"objName": {
"type": "string"
},
"variables": {"$ref": "#/definitions/variables"},
"sounds": {"$ref":"#/definitions/sounds"},
"costumes": {"$ref":"#/definitions/costumes"},
"currentCostumeIndex": {
"type": "number",
"minimum": 0
}
},
"additionalProperties": true,
"required": [
"objName",
"sounds",
"costumes",
"currentCostumeIndex"
]
},
"stage_child": {
"type": "object",
"description": "A child of the stage, can be a sprite or a monitor"
},
"stage_object" : {
"type": "object",
"properties": {
"objName": {
"type": "string"
},
"variables": {"$ref": "#/definitions/variables"},
"lists": {
"type": "array",
"properties": {
"listName": {
"type": "string"
},
"contents": {
"type": "array"
},
"isPersistent": {
"type": "boolean"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
},
"width": {
"type": "number"
},
"height": {
"type": "number"
},
"visible": {
"type": "boolean"
}
},
"required": [
"listName",
"contents"
]
},
"scripts": {"$ref": "#/definitions/scripts"},
"sounds": {"$ref": "#/definitions/sounds"},
"costumes": {"$ref": "#/definitions/costumes"},
"currentCostumeIndex": {
"type": "number",
"minimum": 0
},
"penLayerMD5": {
"oneOf":[
{"type": "string"},
{"type": "null"}
]
},
"penLayerID": {
"type": "number",
"minimum": -1
},
"tempoBPM": {
"type": "number"
},
"videoAlpha": {
"type": "number",
"minimum": 0,
"maximum": 1
},
"children": {
"type": "array",
"items": {"$ref": "#/definitions/stage_child"}
}
},
"required": [
"objName",
"costumes",
"currentCostumeIndex",
"penLayerMD5",
"tempoBPM",
"children"
]
}
}
}
Loading