Fix Block Factory when types are saved.

This commit is contained in:
Neil Fraser
2014-11-11 14:06:02 -08:00
parent 0f187fc392
commit ca966979a4
2 changed files with 46 additions and 35 deletions

View File

@@ -1,2 +1,2 @@
print("Status: 302")
print("Location: /static/apps/index.html")
print("Location: /static/demos/index.html")

View File

@@ -45,40 +45,7 @@ Blockly.Blocks['factory_base'] = {
['↑ top connection', 'TOP'],
['↓ bottom connection', 'BOTTOM']],
function(option) {
var block = this.sourceBlock_;
var outputExists = block.getInput('OUTPUTTYPE');
var topExists = block.getInput('TOPTYPE');
var bottomExists = block.getInput('BOTTOMTYPE');
if (option == 'LEFT') {
if (!outputExists) {
block.appendValueInput('OUTPUTTYPE')
.setCheck('Type')
.appendField('output type');
block.moveInputBefore('OUTPUTTYPE', 'COLOUR');
}
} else if (outputExists) {
block.removeInput('OUTPUTTYPE');
}
if (option == 'TOP' || option == 'BOTH') {
if (!topExists) {
block.appendValueInput('TOPTYPE')
.setCheck('Type')
.appendField('top type');
block.moveInputBefore('TOPTYPE', 'COLOUR');
}
} else if (topExists) {
block.removeInput('TOPTYPE');
}
if (option == 'BOTTOM' || option == 'BOTH') {
if (!bottomExists) {
block.appendValueInput('BOTTOMTYPE')
.setCheck('Type')
.appendField('bottom type');
block.moveInputBefore('BOTTOMTYPE', 'COLOUR');
}
} else if (bottomExists) {
block.removeInput('BOTTOMTYPE');
}
this.sourceBlock_.updateShape_(option);
});
this.appendDummyInput()
.appendField(dropdown, 'CONNECTIONS');
@@ -95,6 +62,50 @@ Blockly.Blocks['factory_base'] = {
*/
this.setTooltip('Build a custom block by plugging\n' +
'fields, inputs and other blocks here.');
},
mutationToDom: function() {
var container = document.createElement('mutation');
container.setAttribute('connections', this.getFieldValue('CONNECTIONS'));
return container;
},
domToMutation: function(xmlElement) {
var connections = xmlElement.getAttribute('connections');
this.updateShape_(connections);
},
updateShape_: function(option) {
var outputExists = this.getInput('OUTPUTTYPE');
var topExists = this.getInput('TOPTYPE');
var bottomExists = this.getInput('BOTTOMTYPE');
if (option == 'LEFT') {
if (!outputExists) {
this.appendValueInput('OUTPUTTYPE')
.setCheck('Type')
.appendField('output type');
this.moveInputBefore('OUTPUTTYPE', 'COLOUR');
}
} else if (outputExists) {
this.removeInput('OUTPUTTYPE');
}
if (option == 'TOP' || option == 'BOTH') {
if (!topExists) {
this.appendValueInput('TOPTYPE')
.setCheck('Type')
.appendField('top type');
this.moveInputBefore('TOPTYPE', 'COLOUR');
}
} else if (topExists) {
this.removeInput('TOPTYPE');
}
if (option == 'BOTTOM' || option == 'BOTH') {
if (!bottomExists) {
this.appendValueInput('BOTTOMTYPE')
.setCheck('Type')
.appendField('bottom type');
this.moveInputBefore('BOTTOMTYPE', 'COLOUR');
}
} else if (bottomExists) {
this.removeInput('BOTTOMTYPE');
}
}
};