Added randomness to bumping per Issue #2011

This commit is contained in:
Beka Westberg
2018-12-02 12:34:34 -08:00
parent 3cbb137b4f
commit 1b2ec7230c
2 changed files with 9 additions and 2 deletions

View File

@@ -68,6 +68,11 @@ Blockly.INSERTION_MARKER_COLOUR = '#000000';
*/
Blockly.BUMP_DELAY = 250;
/**
* Maximum randomness in workspace units for bumping a block.
*/
Blockly.BUMP_RANDOMNESS = 10;
/**
* Number of characters to truncate a collapsed block to.
*/

View File

@@ -97,8 +97,10 @@ Blockly.RenderedConnection.prototype.bumpAwayFrom_ = function(staticConnection)
// Raise it to the top for extra visibility.
var selected = Blockly.selected == rootBlock;
selected || rootBlock.addSelect();
var dx = (staticConnection.x_ + Blockly.SNAP_RADIUS) - this.x_;
var dy = (staticConnection.y_ + Blockly.SNAP_RADIUS) - this.y_;
var dx = (staticConnection.x_ + Blockly.SNAP_RADIUS +
Math.floor(Math.random() * Blockly.BUMP_RANDOMNESS)) - this.x_;
var dy = (staticConnection.y_ + Blockly.SNAP_RADIUS +
Math.floor(Math.random() * Blockly.BUMP_RANDOMNESS)) - this.y_;
if (reverse) {
// When reversing a bump due to an uneditable block, bump up.
dy = -dy;