mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-12 22:19:17 -04:00
disallow variables on shadow blocks
This commit is contained in:
parent
ea846abc9f
commit
6a882ca2e8
2 changed files with 14 additions and 0 deletions
|
@ -29,6 +29,7 @@ goog.provide('Blockly.FieldVariable');
|
|||
goog.require('Blockly.FieldDropdown');
|
||||
goog.require('Blockly.Msg');
|
||||
goog.require('Blockly.Variables');
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.string');
|
||||
|
||||
|
||||
|
@ -73,6 +74,16 @@ Blockly.FieldVariable.prototype.init = function() {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Attach this field to a block.
|
||||
* @param {!Blockly.Block} block The block containing this field.
|
||||
*/
|
||||
Blockly.FieldVariable.prototype.setSourceBlock = function(block) {
|
||||
goog.asserts.assert(!block.isShadow(),
|
||||
'Variable fields are not allowed to exist on shadow blocks.');
|
||||
Blockly.FieldVariable.superClass_.setSourceBlock.call(this, block);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the variable's name (use a variableDB to convert into a real name).
|
||||
* Unline a regular dropdown, variables are literal and have no neutral value.
|
||||
|
|
|
@ -535,6 +535,9 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) {
|
|||
goog.asserts.assert(child.isShadow(),
|
||||
'Shadow block not allowed non-shadow child.');
|
||||
}
|
||||
// Ensure this block doesn't have any variable inputs.
|
||||
goog.asserts.assert(block.getVars().length == 0,
|
||||
'Shadow blocks cannot have variable fields.');
|
||||
block.setShadow(true);
|
||||
}
|
||||
return block;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue