Skip to content

Commit

Permalink
Merge branch 'develop' into greenkeeper/expose-loader-0.7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
thisandagain committed Nov 21, 2017
2 parents e052f1d + 8395fff commit 51bd034
Show file tree
Hide file tree
Showing 24 changed files with 367 additions and 105 deletions.
12 changes: 6 additions & 6 deletions package.json
Expand Up @@ -33,9 +33,9 @@
"copy-webpack-plugin": "4.0.1",
"escape-html": "1.0.3",
"eslint": "^4.5.0",
"eslint-config-scratch": "^4.0.0",
"eslint-config-scratch": "^5.0.0",
"expose-loader": "0.7.4",
"gh-pages": "^0.12.0",
"gh-pages": "^1.1.0",
"got": "5.7.1",
"highlightjs": "^9.8.0",
"htmlparser2": "3.9.2",
Expand All @@ -44,18 +44,18 @@
"json": "^9.0.4",
"lodash.defaultsdeep": "4.6.0",
"minilog": "3.1.0",
"promise": "7.1.1",
"promise": "8.0.1",
"scratch-audio": "latest",
"scratch-blocks": "latest",
"scratch-render": "latest",
"scratch-storage": "^0.3.0",
"script-loader": "0.7.0",
"socket.io-client": "1.7.3",
"script-loader": "0.7.2",
"socket.io-client": "2.0.4",
"stats.js": "^0.17.0",
"tap": "^10.2.0",
"tiny-worker": "^2.1.1",
"webpack": "^2.4.1",
"webpack-dev-server": "^2.4.1",
"worker-loader": "0.8.1"
"worker-loader": "1.1.0"
}
}
73 changes: 68 additions & 5 deletions src/engine/blocks.js
Expand Up @@ -25,6 +25,30 @@ class Blocks {
* @type {Array.<String>}
*/
this._scripts = [];

/**
* Runtime Cache
* @type {{inputs: {}, procedureParamNames: {}, procedureDefinitions: {}}}
* @private
*/
this._cache = {
/**
* Cache block inputs by block id
* @type {object.<string, !Array.<object>>}
*/
inputs: {},
/**
* Cache procedure Param Names by block id
* @type {object.<string, ?Array.<string>>}
*/
procedureParamNames: {},
/**
* Cache procedure definitions by block id
* @type {object.<string, ?string>}
*/
procedureDefinitions: {}
};

}

/**
Expand Down Expand Up @@ -105,18 +129,25 @@ class Blocks {
/**
* Get all non-branch inputs for a block.
* @param {?object} block the block to query.
* @return {!object} All non-branch inputs and their associated blocks.
* @return {?Array.<object>} All non-branch inputs and their associated blocks.
*/
getInputs (block) {
if (typeof block === 'undefined') return null;
const inputs = {};
let inputs = this._cache.inputs[block.id];
if (typeof inputs !== 'undefined') {
return inputs;
}

inputs = {};
for (const input in block.inputs) {
// Ignore blocks prefixed with branch prefix.
if (input.substring(0, Blocks.BRANCH_INPUT_PREFIX.length) !==
Blocks.BRANCH_INPUT_PREFIX) {
inputs[input] = block.inputs[input];
}
}

this._cache.inputs[block.id] = inputs;
return inputs;
}

Expand Down Expand Up @@ -149,16 +180,24 @@ class Blocks {
* @return {?string} ID of procedure definition.
*/
getProcedureDefinition (name) {
const blockID = this._cache.procedureDefinitions[name];
if (typeof blockID !== 'undefined') {
return blockID;
}

for (const id in this._blocks) {
if (!this._blocks.hasOwnProperty(id)) continue;
const block = this._blocks[id];
if (block.opcode === 'procedures_definition') {
const internal = this._getCustomBlockInternal(block);
if (internal && internal.mutation.proccode === name) {
return id; // The outer define block id
this._cache.procedureDefinitions[name] = id; // The outer define block id
return id;
}
}
}

this._cache.procedureDefinitions[name] = null;
return null;
}

Expand All @@ -168,14 +207,23 @@ class Blocks {
* @return {?Array.<string>} List of param names for a procedure.
*/
getProcedureParamNames (name) {
const cachedNames = this._cache.procedureParamNames[name];
if (typeof cachedNames !== 'undefined') {
return cachedNames;
}

for (const id in this._blocks) {
if (!this._blocks.hasOwnProperty(id)) continue;
const block = this._blocks[id];
if (block.opcode === 'procedures_prototype' &&
block.mutation.proccode === name) {
return JSON.parse(block.mutation.argumentnames);
const paramNames = JSON.parse(block.mutation.argumentnames);
this._cache.procedureParamNames[name] = paramNames;
return paramNames;
}
}

this._cache.procedureParamNames[name] = null;
return null;
}

Expand Down Expand Up @@ -271,6 +319,15 @@ class Blocks {

// ---------------------------------------------------------------------

/**
* Reset all runtime caches.
*/
resetCache () {
this._cache.inputs = {};
this._cache.procedureParamNames = {};
this._cache.procedureDefinitions = {};
}

/**
* Block management: create blocks and scripts from a `create` event
* @param {!object} block Blockly create event to be processed
Expand All @@ -289,6 +346,8 @@ class Blocks {
if (block.topLevel) {
this._addScript(block.id);
}

this.resetCache();
}

/**
Expand All @@ -301,7 +360,6 @@ class Blocks {
if (['field', 'mutation', 'checkbox'].indexOf(args.element) === -1) return;
const block = this._blocks[args.id];
if (typeof block === 'undefined') return;

const wasMonitored = block.isMonitored;
switch (args.element) {
case 'field':
Expand Down Expand Up @@ -337,6 +395,8 @@ class Blocks {
}
break;
}

this.resetCache();
}

/**
Expand Down Expand Up @@ -393,6 +453,7 @@ class Blocks {
}
this._blocks[e.id].parent = e.newParent;
}
this.resetCache();
}


Expand Down Expand Up @@ -447,6 +508,8 @@ class Blocks {

// Delete block itself.
delete this._blocks[blockId];

this.resetCache();
}

// ---------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/extension-support/extension-manager.js
Expand Up @@ -8,7 +8,7 @@ const BlockType = require('./block-type');
// TODO: change extension spec so that library info, including extension ID, can be collected through static methods
const Scratch3PenBlocks = require('../blocks/scratch3_pen');
const Scratch3WeDo2Blocks = require('../blocks/scratch3_wedo2');
const Scratch3MusicBlocks = require('../blocks/scratch3_music');
const Scratch3MusicBlocks = require('../extensions/scratch3_music');
const builtinExtensions = {
pen: Scratch3PenBlocks,
wedo2: Scratch3WeDo2Blocks,
Expand Down
Binary file added src/extensions/scratch3_music/assets/1-snare.mp3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added src/extensions/scratch3_music/assets/13-bongo.mp3
Binary file not shown.
Binary file added src/extensions/scratch3_music/assets/14-conga.mp3
Binary file not shown.
Binary file not shown.
Binary file added src/extensions/scratch3_music/assets/16-guiro.mp3
Binary file not shown.
Binary file not shown.
Binary file added src/extensions/scratch3_music/assets/18-cuica.mp3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 51bd034

Please sign in to comment.