Fix plane demo bug. (#3774)

* Fix plane demo bug.
This commit is contained in:
Monica Kozbial
2020-03-27 09:29:20 -07:00
committed by GitHub
parent a9223b0b22
commit ce6dd329a8
2 changed files with 21 additions and 16 deletions

View File

@@ -35,12 +35,14 @@ Blockly.Blocks['plane_get_rows'] = {
this.setHelpUrl(Blockly.Msg['VARIABLES_GET_HELPURL']);
this.setColour(330);
this.appendDummyInput()
.appendField(Plane.getMsg('Plane_getRows'), 'title');
.appendField(Plane.getMsg('Plane_getRows')
.replace('%1', Plane.rows1st), 'title');
this.setOutput(true, 'Number');
},
customUpdate: function() {
this.setFieldValue(
Plane.getMsg('Plane_getRows').replace('%1', Plane.rows1st), 'title');
Plane.getMsg('Plane_getRows')
.replace('%1', Plane.rows1st), 'title');
}
};
@@ -55,12 +57,14 @@ Blockly.Blocks['plane_get_rows1st'] = {
this.setHelpUrl(Blockly.Msg['VARIABLES_GET_HELPURL']);
this.setColour(330);
this.appendDummyInput()
.appendField(Plane.getMsg('Plane_getRows1'), 'title');
.appendField(Plane.getMsg('Plane_getRows1')
.replace('%1', Plane.rows1st), 'title');
this.setOutput(true, 'Number');
},
customUpdate: function() {
this.setFieldValue(
Plane.getMsg('Plane_getRows1').replace('%1', Plane.rows1st), 'title');
Plane.getMsg('Plane_getRows1')
.replace('%1', Plane.rows1st), 'title');
}
};
@@ -75,12 +79,14 @@ Blockly.Blocks['plane_get_rows2nd'] = {
this.setHelpUrl(Blockly.Msg['VARIABLES_GET_HELPURL']);
this.setColour(330);
this.appendDummyInput()
.appendField(Plane.getMsg('Plane_getRows2'), 'title');
.appendField(Plane.getMsg('Plane_getRows2')
.replace('%1', Plane.rows2nd), 'title');
this.setOutput(true, 'Number');
},
customUpdate: function() {
this.setFieldValue(
Plane.getMsg('Plane_getRows2').replace('%1', Plane.rows2nd), 'title');
Plane.getMsg('Plane_getRows2')
.replace('%1', Plane.rows2nd), 'title');
}
};

View File

@@ -200,12 +200,20 @@ Plane.rows1st = 0;
Plane.rows2nd = 0;
/**
* Redraw the rows when the slider has moved.
* Redraw the rows and update blocks when the slider has moved.
* @param {number} value New slider position.
*/
Plane.sliderChange = function(value) {
var newRows = Math.round(value * 410 / 20);
Plane.redraw(newRows);
function updateBlocks(blocks) {
for (var i = 0, block; block = blocks[i]; i++) {
block.customUpdate && block.customUpdate();
}
}
updateBlocks(Plane.workspace.getAllBlocks(false), true);
updateBlocks(Plane.workspace.flyout_.workspace_.getAllBlocks(false));
};
/**
@@ -340,15 +348,6 @@ Plane.recalculate = function() {
Plane.getMsg('Plane_seats').replace(
'%1', isNaN(seats) ? '?' : seats));
Plane.setCorrect(isNaN(seats) ? null : (Plane.answer() == seats));
// Update blocks to show values.
function updateBlocks(blocks) {
for (var i = 0, block; block = blocks[i]; i++) {
block.customUpdate && block.customUpdate();
}
}
updateBlocks(Plane.workspace.getAllBlocks(false));
updateBlocks(Plane.workspace.flyout_.workspace_.getAllBlocks(false));
};
/**