mirror of
https://github.com/google/blockly.git
synced 2026-01-10 02:17:09 +01:00
Fix missing fields in json mode.
This commit is contained in:
@@ -1050,10 +1050,11 @@ Blockly.Block.prototype.getInheritedDisabled=function(){for(var a=this;;){a=a.ge
|
||||
Blockly.Block.prototype.toString=function(a){var b=[];if(this.collapsed_)b.push(this.getInput("_TEMP_COLLAPSED_INPUT").fieldRow[0].text_);else for(var c=0,d;d=this.inputList[c];c++){for(var e=0,f;f=d.fieldRow[e];e++)b.push(f.getText());d.connection&&((d=d.connection.targetBlock())?b.push(d.toString()):b.push("?"))}b=goog.string.trim(b.join(" "))||"???";a&&(b=goog.string.truncate(b,a));return b};Blockly.Block.prototype.appendValueInput=function(a){return this.appendInput_(Blockly.INPUT_VALUE,a)};
|
||||
Blockly.Block.prototype.appendStatementInput=function(a){return this.appendInput_(Blockly.NEXT_STATEMENT,a)};Blockly.Block.prototype.appendDummyInput=function(a){return this.appendInput_(Blockly.DUMMY_INPUT,a||"")};
|
||||
Blockly.Block.prototype.jsonInit=function(a){goog.asserts.assertString(a.message,"No message.");goog.asserts.assertArray(a.args,"No args.");goog.asserts.assert(void 0==a.output||void 0==a.previousStatement,"Must not have both an output and a previousStatement.");this.setColour(a.colour);for(var b=a.message.split(/(%\d+)/),c=[],d=0,e=[],f=0;f<b.length;f++){var g=b[f];if(g.match(/^%\d+$/)){var h=parseInt(g.substring(1),10);goog.asserts.assert(0<h&&h<=a.args.length,'Message index "%s" out of range.',
|
||||
g);goog.asserts.assert(!c[h],'Message index "%s" duplicated.',g);c[h]=!0;d++;e.push(a.args[h-1])}else(g=g.replace(/%%/g,"%").trim())&&e.push(g)}goog.asserts.assert(d==a.args.length,"Message does not reference all %s arg(s).",a.args.length);e.length&&"string"==typeof e[e.length-1]&&(b={type:"input_dummy"},a.lastDummyAlign&&(b.align=a.lastDummyAlign),e.push(b));c={LEFT:Blockly.ALIGN_LEFT,RIGHT:Blockly.ALIGN_RIGHT,CENTRE:Blockly.ALIGN_CENTRE};d=[];for(f=0;f<e.length;f++)if(g=e[f],"string"==typeof g)d.push([g,
|
||||
void 0]);else{b=h=null;switch(g.type){case "field_input":h=new Blockly.FieldTextInput(g.text);break;case "field_angle":h=new Blockly.FieldAngle(g.angle);break;case "field_checkbox":h=new Blockly.FieldCheckbox(g.checked);break;case "field_colour":h=new Blockly.FieldColour(g.colour);break;case "field_date":h=new Blockly.FieldDate(g.date);break;case "field_variable":h=new Blockly.FieldVariable(g.variable);break;case "field_dropdown":h=new Blockly.FieldDropdown(g.options);break;case "field_image":h=new Blockly.FieldImage(g.src,
|
||||
g.width,g.height,g.alt);break;case "input_value":b=this.appendValueInput(g.name);break;case "input_statement":b=this.appendStatementInput(g.name);break;case "input_dummy":b=this.appendDummyInput(g.name);break;default:throw"Unknown element type: "+g.type;}if(h)d.push([h,g.name]);else if(b){g.check&&b.setCheck(g.check);g.align&&b.setAlign(c[g.align]);for(g=0;g<d.length;g++)b.appendField(d[g][0],d[g][1]);d.length=0}}a.inputsInline&&this.setInputsInline(!0);void 0!==a.output&&this.setOutput(!0,a.output);
|
||||
void 0!==a.previousStatement&&this.setPreviousStatement(!0,a.previousStatement);void 0!==a.nextStatement&&this.setNextStatement(!0,a.nextStatement);this.setTooltip(a.tooltip);this.setHelpUrl(a.helpUrl)};Blockly.Block.prototype.appendInput_=function(a,b){var c=null;if(a==Blockly.INPUT_VALUE||a==Blockly.NEXT_STATEMENT)c=new Blockly.Connection(this,a);c=new Blockly.Input(a,b,this,c);this.inputList.push(c);this.rendered&&(this.render(),this.bumpNeighbours_());return c};
|
||||
g);goog.asserts.assert(!c[h],'Message index "%s" duplicated.',g);c[h]=!0;d++;e.push(a.args[h-1])}else(g=g.replace(/%%/g,"%").trim())&&e.push(g)}goog.asserts.assert(d==a.args.length,"Message does not reference all %s arg(s).",a.args.length);!e.length||"string"!=typeof e[e.length-1]&&0!=e[e.length-1].type.indexOf("field_")||(b={type:"input_dummy"},a.lastDummyAlign&&(b.align=a.lastDummyAlign),e.push(b));c={LEFT:Blockly.ALIGN_LEFT,RIGHT:Blockly.ALIGN_RIGHT,CENTRE:Blockly.ALIGN_CENTRE};d=[];for(f=0;f<
|
||||
e.length;f++)if(g=e[f],"string"==typeof g)d.push([g,void 0]);else{b=h=null;switch(g.type){case "field_input":h=new Blockly.FieldTextInput(g.text);break;case "field_angle":h=new Blockly.FieldAngle(g.angle);break;case "field_checkbox":h=new Blockly.FieldCheckbox(g.checked);break;case "field_colour":h=new Blockly.FieldColour(g.colour);break;case "field_date":h=new Blockly.FieldDate(g.date);break;case "field_variable":h=new Blockly.FieldVariable(g.variable);break;case "field_dropdown":h=new Blockly.FieldDropdown(g.options);
|
||||
break;case "field_image":h=new Blockly.FieldImage(g.src,g.width,g.height,g.alt);break;case "input_value":b=this.appendValueInput(g.name);break;case "input_statement":b=this.appendStatementInput(g.name);break;case "input_dummy":b=this.appendDummyInput(g.name);break;default:throw"Unknown element type: "+g.type;}if(h)d.push([h,g.name]);else if(b){g.check&&b.setCheck(g.check);g.align&&b.setAlign(c[g.align]);for(g=0;g<d.length;g++)b.appendField(d[g][0],d[g][1]);d.length=0}}void 0!==a.inputsInline&&this.setInputsInline(a.inputsInline);
|
||||
void 0!==a.output&&this.setOutput(!0,a.output);void 0!==a.previousStatement&&this.setPreviousStatement(!0,a.previousStatement);void 0!==a.nextStatement&&this.setNextStatement(!0,a.nextStatement);this.setTooltip(a.tooltip);this.setHelpUrl(a.helpUrl)};
|
||||
Blockly.Block.prototype.appendInput_=function(a,b){var c=null;if(a==Blockly.INPUT_VALUE||a==Blockly.NEXT_STATEMENT)c=new Blockly.Connection(this,a);c=new Blockly.Input(a,b,this,c);this.inputList.push(c);this.rendered&&(this.render(),this.bumpNeighbours_());return c};
|
||||
Blockly.Block.prototype.moveInputBefore=function(a,b){if(a!=b){for(var c=-1,d=b?-1:this.inputList.length,e=0,f;f=this.inputList[e];e++)if(f.name==a){if(c=e,-1!=d)break}else if(b&&f.name==b&&(d=e,-1!=c))break;goog.asserts.assert(-1!=c,'Named input "%s" not found.',a);goog.asserts.assert(-1!=d,'Reference input "%s" not found.',b);this.moveNumberedInputBefore(c,d)}};
|
||||
Blockly.Block.prototype.moveNumberedInputBefore=function(a,b){goog.asserts.assert(a!=b,"Can't move input to itself.");goog.asserts.assert(a<this.inputList.length,"Input index "+a+" out of bounds.");goog.asserts.assert(b<=this.inputList.length,"Reference input "+b+" out of bounds.");var c=this.inputList[a];this.inputList.splice(a,1);a<b&&b--;this.inputList.splice(b,0,c);this.rendered&&(this.render(),this.bumpNeighbours_())};
|
||||
Blockly.Block.prototype.removeInput=function(a,b){for(var c=0,d;d=this.inputList[c];c++)if(d.name==a){d.connection&&d.connection.targetConnection&&d.connection.targetBlock().setParent(null);d.dispose();this.inputList.splice(c,1);this.rendered&&(this.render(),this.bumpNeighbours_());return}b||goog.asserts.fail('Input "%s" not found.',a)};Blockly.Block.prototype.getInput=function(a){for(var b=0,c;c=this.inputList[b];b++)if(c.name==a)return c;return null};
|
||||
|
||||
@@ -939,7 +939,8 @@ Blockly.Block.prototype.jsonInit = function(json) {
|
||||
goog.asserts.assert(indexCount == json['args'].length,
|
||||
'Message does not reference all %s arg(s).', json['args'].length);
|
||||
// Add last dummy input if needed.
|
||||
if (elements.length && typeof elements[elements.length - 1] == 'string') {
|
||||
if (elements.length && (typeof elements[elements.length - 1] == 'string' ||
|
||||
elements[elements.length - 1]['type'].indexOf('field_') == 0)) {
|
||||
var input = {type: 'input_dummy'};
|
||||
if (json['lastDummyAlign']) {
|
||||
input['align'] = json['lastDummyAlign'];
|
||||
@@ -1016,8 +1017,8 @@ Blockly.Block.prototype.jsonInit = function(json) {
|
||||
}
|
||||
}
|
||||
|
||||
if (json['inputsInline']) {
|
||||
this.setInputsInline(true);
|
||||
if (json['inputsInline'] !== undefined) {
|
||||
this.setInputsInline(json['inputsInline']);
|
||||
}
|
||||
// Set output and previous/next connections.
|
||||
if (json['output'] !== undefined) {
|
||||
|
||||
Reference in New Issue
Block a user