mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-25 00:49:53 -05:00
Spacing fix in blocks.js
This commit is contained in:
parent
9b843156b1
commit
8fa29bc6de
1 changed files with 162 additions and 162 deletions
|
@ -1,10 +1,10 @@
|
||||||
/**
|
/**
|
||||||
* @fileoverview
|
* @fileoverview
|
||||||
* Store and mutate the VM block representation,
|
* Store and mutate the VM block representation,
|
||||||
* and handle updates from Scratch Blocks events.
|
* and handle updates from Scratch Blocks events.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function Blocks () {
|
function Blocks () {
|
||||||
/**
|
/**
|
||||||
* All blocks in the workspace.
|
* All blocks in the workspace.
|
||||||
* Keys are block IDs, values are metadata about the block.
|
* Keys are block IDs, values are metadata about the block.
|
||||||
|
@ -18,42 +18,42 @@
|
||||||
* @type {Array.<String>}
|
* @type {Array.<String>}
|
||||||
*/
|
*/
|
||||||
this._stacks = [];
|
this._stacks = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide an object with metadata for the requested block ID.
|
* Provide an object with metadata for the requested block ID.
|
||||||
* @param {!string} blockId ID of block we have stored.
|
* @param {!string} blockId ID of block we have stored.
|
||||||
* @return {?Object} Metadata about the block, if it exists.
|
* @return {?Object} Metadata about the block, if it exists.
|
||||||
*/
|
*/
|
||||||
Blocks.prototype.getBlock = function (blockId) {
|
Blocks.prototype.getBlock = function (blockId) {
|
||||||
return this._blocks[blockId];
|
return this._blocks[blockId];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all known top-level blocks that start stacks.
|
* Get all known top-level blocks that start stacks.
|
||||||
* @return {Array.<string>} List of block IDs.
|
* @return {Array.<string>} List of block IDs.
|
||||||
*/
|
*/
|
||||||
Blocks.prototype.getStacks = function () {
|
Blocks.prototype.getStacks = function () {
|
||||||
return this._stacks;
|
return this._stacks;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the next block for a particular block
|
* Get the next block for a particular block
|
||||||
* @param {?string} id ID of block to get the next block for
|
* @param {?string} id ID of block to get the next block for
|
||||||
* @return {?string} ID of next block in the sequence
|
* @return {?string} ID of next block in the sequence
|
||||||
*/
|
*/
|
||||||
Blocks.prototype.getNextBlock = function (id) {
|
Blocks.prototype.getNextBlock = function (id) {
|
||||||
if (typeof this._blocks[id] === 'undefined') return null;
|
if (typeof this._blocks[id] === 'undefined') return null;
|
||||||
return this._blocks[id].next;
|
return this._blocks[id].next;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the substack for a particular C-shaped block
|
* Get the substack for a particular C-shaped block
|
||||||
* @param {?string} id ID for block to get the substack for
|
* @param {?string} id ID for block to get the substack for
|
||||||
* @param {?number} substackNum Which substack to select (e.g. for if-else)
|
* @param {?number} substackNum Which substack to select (e.g. for if-else)
|
||||||
* @return {?string} ID of block in the substack
|
* @return {?string} ID of block in the substack
|
||||||
*/
|
*/
|
||||||
Blocks.prototype.getSubstack = function (id, substackNum) {
|
Blocks.prototype.getSubstack = function (id, substackNum) {
|
||||||
var block = this._blocks[id];
|
var block = this._blocks[id];
|
||||||
if (typeof block === 'undefined') return null;
|
if (typeof block === 'undefined') return null;
|
||||||
if (!substackNum) substackNum = 1;
|
if (!substackNum) substackNum = 1;
|
||||||
|
@ -66,25 +66,25 @@
|
||||||
// Empty C-block?
|
// Empty C-block?
|
||||||
if (!(inputName in block.inputs)) return null;
|
if (!(inputName in block.inputs)) return null;
|
||||||
return block.inputs[inputName].block;
|
return block.inputs[inputName].block;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the opcode for a particular block
|
* Get the opcode for a particular block
|
||||||
* @param {?string} id ID of block to query
|
* @param {?string} id ID of block to query
|
||||||
* @return {?string} the opcode corresponding to that block
|
* @return {?string} the opcode corresponding to that block
|
||||||
*/
|
*/
|
||||||
Blocks.prototype.getOpcode = function (id) {
|
Blocks.prototype.getOpcode = function (id) {
|
||||||
if (typeof this._blocks[id] === 'undefined') return null;
|
if (typeof this._blocks[id] === 'undefined') return null;
|
||||||
return this._blocks[id].opcode;
|
return this._blocks[id].opcode;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Block management: create blocks and stacks from a `create` event
|
* Block management: create blocks and stacks from a `create` event
|
||||||
* @param {!Object} block Blockly create event to be processed
|
* @param {!Object} block Blockly create event to be processed
|
||||||
*/
|
*/
|
||||||
Blocks.prototype.createBlock = function (block, opt_isFlyoutBlock) {
|
Blocks.prototype.createBlock = function (block, opt_isFlyoutBlock) {
|
||||||
// Create new block
|
// Create new block
|
||||||
this._blocks[block.id] = block;
|
this._blocks[block.id] = block;
|
||||||
|
|
||||||
|
@ -95,13 +95,13 @@
|
||||||
if (!opt_isFlyoutBlock && block.topLevel) {
|
if (!opt_isFlyoutBlock && block.topLevel) {
|
||||||
this._addStack(block.id);
|
this._addStack(block.id);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Block management: change block field values
|
* Block management: change block field values
|
||||||
* @param {!Object} args Blockly change event to be processed
|
* @param {!Object} args Blockly change event to be processed
|
||||||
*/
|
*/
|
||||||
Blocks.prototype.changeBlock = function (args) {
|
Blocks.prototype.changeBlock = function (args) {
|
||||||
// Validate
|
// Validate
|
||||||
if (args.element !== 'field') return;
|
if (args.element !== 'field') return;
|
||||||
if (typeof this._blocks[args.id] === 'undefined') return;
|
if (typeof this._blocks[args.id] === 'undefined') return;
|
||||||
|
@ -109,13 +109,13 @@
|
||||||
|
|
||||||
// Update block value
|
// Update block value
|
||||||
this._blocks[args.id].fields[args.name].value = args.value;
|
this._blocks[args.id].fields[args.name].value = args.value;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Block management: move blocks from parent to parent
|
* Block management: move blocks from parent to parent
|
||||||
* @param {!Object} e Blockly move event to be processed
|
* @param {!Object} e Blockly move event to be processed
|
||||||
*/
|
*/
|
||||||
Blocks.prototype.moveBlock = function (e) {
|
Blocks.prototype.moveBlock = function (e) {
|
||||||
// Remove from any old parent.
|
// Remove from any old parent.
|
||||||
if (e.oldParent !== undefined) {
|
if (e.oldParent !== undefined) {
|
||||||
var oldParent = this._blocks[e.oldParent];
|
var oldParent = this._blocks[e.oldParent];
|
||||||
|
@ -147,13 +147,13 @@
|
||||||
this._blocks[e.newParent].next = e.id;
|
this._blocks[e.newParent].next = e.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Block management: delete blocks and their associated stacks
|
* Block management: delete blocks and their associated stacks
|
||||||
* @param {!Object} e Blockly delete event to be processed
|
* @param {!Object} e Blockly delete event to be processed
|
||||||
*/
|
*/
|
||||||
Blocks.prototype.deleteBlock = function (e) {
|
Blocks.prototype.deleteBlock = function (e) {
|
||||||
// @todo In runtime, stop threads running on this stack
|
// @todo In runtime, stop threads running on this stack
|
||||||
|
|
||||||
// Get block
|
// Get block
|
||||||
|
@ -177,31 +177,31 @@
|
||||||
|
|
||||||
// Delete block
|
// Delete block
|
||||||
delete this._blocks[e.id];
|
delete this._blocks[e.id];
|
||||||
};
|
};
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to add a stack to `this._stacks`
|
* Helper to add a stack to `this._stacks`
|
||||||
* @param {?string} id ID of block that starts the stack
|
* @param {?string} id ID of block that starts the stack
|
||||||
*/
|
*/
|
||||||
Blocks.prototype._addStack = function (id) {
|
Blocks.prototype._addStack = function (id) {
|
||||||
var i = this._stacks.indexOf(id);
|
var i = this._stacks.indexOf(id);
|
||||||
if (i > -1) return; // Already in stacks.
|
if (i > -1) return; // Already in stacks.
|
||||||
this._stacks.push(id);
|
this._stacks.push(id);
|
||||||
// Update `topLevel` property on the top block.
|
// Update `topLevel` property on the top block.
|
||||||
this._blocks[id].topLevel = true;
|
this._blocks[id].topLevel = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to remove a stack from `this._stacks`
|
* Helper to remove a stack from `this._stacks`
|
||||||
* @param {?string} id ID of block that starts the stack
|
* @param {?string} id ID of block that starts the stack
|
||||||
*/
|
*/
|
||||||
Blocks.prototype._deleteStack = function (id) {
|
Blocks.prototype._deleteStack = function (id) {
|
||||||
var i = this._stacks.indexOf(id);
|
var i = this._stacks.indexOf(id);
|
||||||
if (i > -1) this._stacks.splice(i, 1);
|
if (i > -1) this._stacks.splice(i, 1);
|
||||||
// Update `topLevel` property on the top block.
|
// Update `topLevel` property on the top block.
|
||||||
if (this._blocks[id]) this._blocks[id].topLevel = false;
|
if (this._blocks[id]) this._blocks[id].topLevel = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Blocks;
|
module.exports = Blocks;
|
||||||
|
|
Loading…
Reference in a new issue