Commit ca966979 authored by Neil Fraser's avatar Neil Fraser

Fix Block Factory when types are saved.

parent 0f187fc3
print("Status: 302") print("Status: 302")
print("Location: /static/apps/index.html") print("Location: /static/demos/index.html")
...@@ -45,56 +45,67 @@ Blockly.Blocks['factory_base'] = { ...@@ -45,56 +45,67 @@ Blockly.Blocks['factory_base'] = {
['↑ top connection', 'TOP'], ['↑ top connection', 'TOP'],
['↓ bottom connection', 'BOTTOM']], ['↓ bottom connection', 'BOTTOM']],
function(option) { function(option) {
var block = this.sourceBlock_; this.sourceBlock_.updateShape_(option);
var outputExists = block.getInput('OUTPUTTYPE'); });
var topExists = block.getInput('TOPTYPE'); this.appendDummyInput()
var bottomExists = block.getInput('BOTTOMTYPE'); .appendField(dropdown, 'CONNECTIONS');
this.appendValueInput('COLOUR')
.setCheck('Colour')
.appendField('colour');
/*
this.appendValueInput('TOOLTIP')
.setCheck('String')
.appendField('tooltip');
this.appendValueInput('HELP')
.setCheck('String')
.appendField('help url');
*/
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 (option == 'LEFT') {
if (!outputExists) { if (!outputExists) {
block.appendValueInput('OUTPUTTYPE') this.appendValueInput('OUTPUTTYPE')
.setCheck('Type') .setCheck('Type')
.appendField('output type'); .appendField('output type');
block.moveInputBefore('OUTPUTTYPE', 'COLOUR'); this.moveInputBefore('OUTPUTTYPE', 'COLOUR');
} }
} else if (outputExists) { } else if (outputExists) {
block.removeInput('OUTPUTTYPE'); this.removeInput('OUTPUTTYPE');
} }
if (option == 'TOP' || option == 'BOTH') { if (option == 'TOP' || option == 'BOTH') {
if (!topExists) { if (!topExists) {
block.appendValueInput('TOPTYPE') this.appendValueInput('TOPTYPE')
.setCheck('Type') .setCheck('Type')
.appendField('top type'); .appendField('top type');
block.moveInputBefore('TOPTYPE', 'COLOUR'); this.moveInputBefore('TOPTYPE', 'COLOUR');
} }
} else if (topExists) { } else if (topExists) {
block.removeInput('TOPTYPE'); this.removeInput('TOPTYPE');
} }
if (option == 'BOTTOM' || option == 'BOTH') { if (option == 'BOTTOM' || option == 'BOTH') {
if (!bottomExists) { if (!bottomExists) {
block.appendValueInput('BOTTOMTYPE') this.appendValueInput('BOTTOMTYPE')
.setCheck('Type') .setCheck('Type')
.appendField('bottom type'); .appendField('bottom type');
block.moveInputBefore('BOTTOMTYPE', 'COLOUR'); this.moveInputBefore('BOTTOMTYPE', 'COLOUR');
} }
} else if (bottomExists) { } else if (bottomExists) {
block.removeInput('BOTTOMTYPE'); this.removeInput('BOTTOMTYPE');
} }
});
this.appendDummyInput()
.appendField(dropdown, 'CONNECTIONS');
this.appendValueInput('COLOUR')
.setCheck('Colour')
.appendField('colour');
/*
this.appendValueInput('TOOLTIP')
.setCheck('String')
.appendField('tooltip');
this.appendValueInput('HELP')
.setCheck('String')
.appendField('help url');
*/
this.setTooltip('Build a custom block by plugging\n' +
'fields, inputs and other blocks here.');
} }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment