Use registry for connection checker

This commit is contained in:
Rachel Fenichel
2020-07-17 10:51:39 -06:00
parent 70812ae97d
commit 98b436031c
3 changed files with 13 additions and 1 deletions

View File

@@ -13,6 +13,8 @@
goog.provide('Blockly.ConnectionChecker');
goog.require('Blockly.registry');
goog.requireType('Blockly.Connection');
goog.requireType('Blockly.IConnectionChecker');
@@ -278,3 +280,6 @@ Blockly.ConnectionChecker.prototype.canConnectToPrevious_ = function(a, b) {
// marker is in the middle of a stack, it won't work.
return !targetBlock.getPreviousBlock();
};
Blockly.registry.register(Blockly.registry.Type.CONNECTION_CHECKER,
Blockly.registry.DEFAULT, Blockly.ConnectionChecker);

View File

@@ -15,6 +15,7 @@ goog.provide('Blockly.registry');
goog.requireType('Blockly.blockRendering.Renderer');
goog.requireType('Blockly.Field');
goog.requireType('Blockly.IConnectionChecker');
goog.requireType('Blockly.IToolbox');
goog.requireType('Blockly.Theme');
goog.requireType('Blockly.utils.toolbox');
@@ -70,6 +71,10 @@ Blockly.registry.Type.TOOLBOX = new Blockly.registry.Type('toolbox');
/** @type {!Blockly.registry.Type<Blockly.Theme>} */
Blockly.registry.Type.THEME = new Blockly.registry.Type('theme');
/** @type {!Blockly.registry.Type<Blockly.IConnectionChecker>} */
Blockly.registry.Type.CONNECTION_CHECKER =
new Blockly.registry.Type('connectionChecker');
/**
* Registers a class based on a type and name.
* @param {string|Blockly.registry.Type<T>} type The type of the plugin.

View File

@@ -44,11 +44,13 @@ Blockly.Workspace = function(opt_options) {
/** @type {number} */
this.toolboxPosition = this.options.toolboxPosition;
var connectionCheckerClass = Blockly.registry.getClassFromOptions(
Blockly.registry.Type.CONNECTION_CHECKER, this.options);
/**
* An object that encapsulates logic for safety, type, and dragging checks.
* @type {!Blockly.IConnectionChecker}
*/
this.connectionChecker = new Blockly.ConnectionChecker();
this.connectionChecker = new connectionCheckerClass(this);
/**
* @type {!Array.<!Blockly.Block>}