From ce6dd329a80b30754d38c8d7dfe8430f9746e962 Mon Sep 17 00:00:00 2001 From: Monica Kozbial Date: Fri, 27 Mar 2020 09:29:20 -0700 Subject: [PATCH] Fix plane demo bug. (#3774) * Fix plane demo bug. --- demos/plane/blocks.js | 18 ++++++++++++------ demos/plane/plane.js | 19 +++++++++---------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/demos/plane/blocks.js b/demos/plane/blocks.js index b4b378c40..d5f80a321 100644 --- a/demos/plane/blocks.js +++ b/demos/plane/blocks.js @@ -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'); } }; diff --git a/demos/plane/plane.js b/demos/plane/plane.js index d6f02ef36..bc5cf512c 100644 --- a/demos/plane/plane.js +++ b/demos/plane/plane.js @@ -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)); }; /**