Added field_label_serializable. (#2399)

This commit is contained in:
Beka Westberg
2019-04-24 10:43:09 -07:00
committed by RoboErikG
parent 71d7809c8d
commit ce816b93bf
10 changed files with 235 additions and 65 deletions

View File

@@ -244,13 +244,33 @@ Blockly.Blocks['field_static'] = {
// Text value.
init: function() {
this.setColour(160);
this.appendDummyInput()
this.appendDummyInput('FIRST')
.appendField('text')
.appendField(new Blockly.FieldTextInput(''), 'TEXT');
this.setPreviousStatement(true, 'Field');
this.setNextStatement(true, 'Field');
this.setTooltip('Static text that serves as a label.');
this.setHelpUrl('https://www.youtube.com/watch?v=s2_xaEvcVI0#t=88');
},
};
Blockly.Blocks['field_label_serializable'] = {
// Text value that is saved to XML.
init: function() {
this.setColour(160);
this.appendDummyInput('FIRST')
.appendField('text')
.appendField(new Blockly.FieldTextInput(''), 'TEXT')
.appendField(',')
.appendField(new Blockly.FieldTextInput('NAME'), 'FIELDNAME');
this.setPreviousStatement(true, 'Field');
this.setNextStatement(true, 'Field');
this.setTooltip('Static text that serves as a label, and is saved to' +
' XML. Use only if you want to modify this label at runtime.');
this.setHelpUrl('https://www.youtube.com/watch?v=s2_xaEvcVI0#t=88');
},
onchange: function() {
fieldNameCheck(this);
}
};

View File

@@ -406,6 +406,12 @@ FactoryUtils.getFieldsJs_ = function(block) {
// Result: 'hello'
fields.push(JSON.stringify(block.getFieldValue('TEXT')));
break;
case 'field_label_serializable':
// Result: new Blockly.FieldLabelSerializable('Hello'), 'GREET'
fields.push('new Blockly.FieldLabelSerializable(' +
JSON.stringify(block.getFieldValue('TEXT')) + '), ' +
JSON.stringify(block.getFieldValue('FIELDNAME')));
break;
case 'field_input':
// Result: new Blockly.FieldTextInput('Hello'), 'GREET'
fields.push('new Blockly.FieldTextInput(' +
@@ -511,6 +517,13 @@ FactoryUtils.getFieldsJson_ = function(block) {
// Result: 'hello'
fields.push(block.getFieldValue('TEXT'));
break;
case 'field_label_serializable':
fields.push({
type: block.type,
name: block.getFieldValue('FIELDNAME'),
text: block.getFieldValue('TEXT')
});
break;
case 'field_input':
fields.push({
type: block.type,

View File

@@ -421,6 +421,7 @@
</category>
<category name="Field">
<block type="field_static"></block>
<block type="field_label_serializable"></block>
<block type="field_input"></block>
<block type="field_number"></block>
<block type="field_angle"></block>