Merge branch 'develop' of https://github.com/LLK/scratch-vm into develop

This commit is contained in:
morant 2017-02-07 09:53:17 -05:00
commit e16f2924a3
34 changed files with 382 additions and 205 deletions
src/serialization

View file

@ -17,7 +17,7 @@ var List = require('../engine/list');
/**
* Parse a single "Scratch object" and create all its in-memory VM objects.
* @param {!Object} object From-JSON "Scratch object:" sprite, stage, watcher.
* @param {!object} object From-JSON "Scratch object:" sprite, stage, watcher.
* @param {!Runtime} runtime Runtime object to load all structures into.
* @param {boolean} topLevel Whether this is the top-level object (stage).
* @return {?Target} Target created (stage or sprite).
@ -61,7 +61,8 @@ var parseScratchObject = function (object, runtime, topLevel) {
rate: sound.rate,
sampleCount: sound.sampleCount,
soundID: sound.soundID,
name: sound.soundName
name: sound.soundName,
md5: sound.md5
});
}
}
@ -138,7 +139,7 @@ var parseScratchObject = function (object, runtime, topLevel) {
* and process the top-level object (the stage object).
* @param {!string} json SB2-format JSON to load.
* @param {!Runtime} runtime Runtime object to load all structures into.
* @param {Boolean=} optForceSprite If set, treat as sprite (Sprite2).
* @param {boolean=} optForceSprite If set, treat as sprite (Sprite2).
* @return {?Target} Top-level target created (stage or sprite).
*/
var sb2import = function (json, runtime, optForceSprite) {
@ -152,7 +153,7 @@ var sb2import = function (json, runtime, optForceSprite) {
/**
* Parse a Scratch object's scripts into VM blocks.
* This should only handle top-level scripts that include X, Y coordinates.
* @param {!Object} scripts Scripts object from SB2 JSON.
* @param {!object} scripts Scripts object from SB2 JSON.
* @param {!Blocks} blocks Blocks object to load parsed blocks into.
*/
var parseScripts = function (scripts, blocks) {
@ -166,8 +167,8 @@ var parseScripts = function (scripts, blocks) {
// Adjust script coordinates to account for
// larger block size in scratch-blocks.
// @todo: Determine more precisely the right formulas here.
parsedBlockList[0].x = scriptX * 1.1;
parsedBlockList[0].y = scriptY * 1.1;
parsedBlockList[0].x = scriptX * 1.5;
parsedBlockList[0].y = scriptY * 2.2;
parsedBlockList[0].topLevel = true;
parsedBlockList[0].parent = null;
}
@ -184,8 +185,8 @@ var parseScripts = function (scripts, blocks) {
* Could be used to parse a top-level script,
* a list of blocks in a branch (e.g., in forever),
* or a list of blocks in an argument (e.g., move [pick random...]).
* @param {Array.<Object>} blockList SB2 JSON-format block list.
* @return {Array.<Object>} Scratch VM-format block list.
* @param {Array.<object>} blockList SB2 JSON-format block list.
* @return {Array.<object>} Scratch VM-format block list.
*/
var parseBlockList = function (blockList) {
var resultingList = [];
@ -193,6 +194,7 @@ var parseBlockList = function (blockList) {
for (var i = 0; i < blockList.length; i++) {
var block = blockList[i];
var parsedBlock = parseBlock(block);
if (typeof parsedBlock === 'undefined') continue;
if (previousBlock) {
parsedBlock.parent = previousBlock.id;
previousBlock.next = parsedBlock.id;
@ -206,8 +208,8 @@ var parseBlockList = function (blockList) {
/**
* Flatten a block tree into a block list.
* Children are temporarily stored on the `block.children` property.
* @param {Array.<Object>} blocks list generated by `parseBlockList`.
* @return {Array.<Object>} Flattened list to be passed to `blocks.createBlock`.
* @param {Array.<object>} blocks list generated by `parseBlockList`.
* @return {Array.<object>} Flattened list to be passed to `blocks.createBlock`.
*/
var flatten = function (blocks) {
var finalBlocks = [];
@ -227,7 +229,7 @@ var flatten = function (blocks) {
* into an argument map. This allows us to provide the expected inputs
* to a mutated procedure call.
* @param {string} procCode Scratch 2.0 procedure string.
* @return {Object} Argument map compatible with those in sb2specmap.
* @return {object} Argument map compatible with those in sb2specmap.
*/
var parseProcedureArgMap = function (procCode) {
var argMap = [
@ -258,8 +260,8 @@ var parseProcedureArgMap = function (procCode) {
/**
* Parse a single SB2 JSON-formatted block and its children.
* @param {!Object} sb2block SB2 JSON-formatted block.
* @return {Object} Scratch VM format block.
* @param {!object} sb2block SB2 JSON-formatted block.
* @return {object} Scratch VM format block.
*/
var parseBlock = function (sb2block) {
// First item in block object is the old opcode (e.g., 'forward:').

View file

@ -408,7 +408,7 @@ var specMap = {
{
type: 'input',
inputOp: 'math_number',
inputName: 'DRUMTYPE'
inputName: 'DRUM'
},
{
type: 'input',