Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
ardublockly
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
ardublockly
Commits
7db8ce94
Commit
7db8ce94
authored
Sep 29, 2015
by
Neil Fraser
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor simplifications to connections.
parent
34914674
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
17 deletions
+20
-17
core/connection.js
core/connection.js
+20
-17
No files found.
core/connection.js
View file @
7db8ce94
...
...
@@ -42,8 +42,10 @@ Blockly.Connection = function(source, type) {
/** @type {number} */
this
.
type
=
type
;
// Shortcut for the databases for this connection's workspace.
this
.
dbList_
=
source
.
workspace
.
connectionDBList
;
this
.
hidden_
=
!
this
.
dbList_
;
this
.
db_
=
source
.
workspace
.
connectionDBList
[
type
];
this
.
dbOpposite_
=
source
.
workspace
.
connectionDBList
[
Blockly
.
OPPOSITE_TYPE
[
type
]];
this
.
hidden_
=
!
this
.
db_
;
};
/**
...
...
@@ -88,7 +90,7 @@ Blockly.Connection.prototype.dispose = function() {
throw
'
Disconnect connection before disposing of it.
'
;
}
if
(
this
.
inDB_
)
{
this
.
db
List_
[
this
.
type
]
.
removeConnection_
(
this
);
this
.
db
_
.
removeConnection_
(
this
);
}
if
(
Blockly
.
highlightedConnection_
==
this
)
{
Blockly
.
highlightedConnection_
=
null
;
...
...
@@ -96,6 +98,8 @@ Blockly.Connection.prototype.dispose = function() {
if
(
Blockly
.
localConnection_
==
this
)
{
Blockly
.
localConnection_
=
null
;
}
this
.
db_
=
null
;
this
.
dbOpposite_
=
null
;
};
/**
...
...
@@ -242,8 +246,8 @@ Blockly.Connection.prototype.connect = function(otherConnection) {
*/
Blockly
.
Connection
.
singleConnection_
=
function
(
block
,
orphanBlock
)
{
var
connection
=
false
;
for
(
var
x
=
0
;
x
<
block
.
inputList
.
length
;
x
++
)
{
var
thisConnection
=
block
.
inputList
[
x
].
connection
;
for
(
var
i
=
0
;
i
<
block
.
inputList
.
length
;
i
++
)
{
var
thisConnection
=
block
.
inputList
[
i
].
connection
;
if
(
thisConnection
&&
thisConnection
.
type
==
Blockly
.
INPUT_VALUE
&&
orphanBlock
.
outputConnection
.
checkType_
(
thisConnection
))
{
if
(
connection
)
{
...
...
@@ -351,13 +355,13 @@ Blockly.Connection.prototype.bumpAwayFrom_ = function(staticConnection) {
Blockly
.
Connection
.
prototype
.
moveTo
=
function
(
x
,
y
)
{
// Remove it from its old location in the database (if already present)
if
(
this
.
inDB_
)
{
this
.
db
List_
[
this
.
type
]
.
removeConnection_
(
this
);
this
.
db
_
.
removeConnection_
(
this
);
}
this
.
x_
=
x
;
this
.
y_
=
y
;
// Insert it into its new location in the database.
if
(
!
this
.
hidden_
)
{
this
.
db
List_
[
this
.
type
]
.
addConnection_
(
this
);
this
.
db
_
.
addConnection_
(
this
);
}
};
...
...
@@ -441,8 +445,7 @@ Blockly.Connection.prototype.closest = function(maxLimit, dx, dy) {
return
{
connection
:
null
,
radius
:
maxLimit
};
}
// Determine the opposite type of connection.
var
oppositeType
=
Blockly
.
OPPOSITE_TYPE
[
this
.
type
];
var
db
=
this
.
dbList_
[
oppositeType
];
var
db
=
this
.
dbOpposite_
;
// Since this connection is probably being dragged, add the delta.
var
currentX
=
this
.
x_
+
dx
;
...
...
@@ -560,8 +563,8 @@ Blockly.Connection.prototype.checkType_ = function(otherConnection) {
return
true
;
}
// Find any intersection in the check lists.
for
(
var
x
=
0
;
x
<
this
.
check_
.
length
;
x
++
)
{
if
(
otherConnection
.
check_
.
indexOf
(
this
.
check_
[
x
])
!=
-
1
)
{
for
(
var
i
=
0
;
i
<
this
.
check_
.
length
;
i
++
)
{
if
(
otherConnection
.
check_
.
indexOf
(
this
.
check_
[
i
])
!=
-
1
)
{
return
true
;
}
}
...
...
@@ -608,8 +611,7 @@ Blockly.Connection.prototype.setCheck = function(check) {
*/
Blockly
.
Connection
.
prototype
.
neighbours_
=
function
(
maxLimit
)
{
// Determine the opposite type of connection.
var
oppositeType
=
Blockly
.
OPPOSITE_TYPE
[
this
.
type
];
var
db
=
this
.
dbList_
[
oppositeType
];
var
db
=
this
.
dbOpposite_
;
var
currentX
=
this
.
x_
;
var
currentY
=
this
.
y_
;
...
...
@@ -668,9 +670,9 @@ Blockly.Connection.prototype.neighbours_ = function(maxLimit) {
Blockly
.
Connection
.
prototype
.
setHidden
=
function
(
hidden
)
{
this
.
hidden_
=
hidden
;
if
(
hidden
&&
this
.
inDB_
)
{
this
.
db
List_
[
this
.
type
]
.
removeConnection_
(
this
);
this
.
db
_
.
removeConnection_
(
this
);
}
else
if
(
!
hidden
&&
!
this
.
inDB_
)
{
this
.
db
List_
[
this
.
type
]
.
addConnection_
(
this
);
this
.
db
_
.
addConnection_
(
this
);
}
};
...
...
@@ -692,8 +694,8 @@ Blockly.Connection.prototype.hideAll = function() {
}
// Close all bubbles of all children.
var
icons
=
block
.
getIcons
();
for
(
var
x
=
0
;
x
<
icons
.
length
;
x
++
)
{
icons
[
x
].
setVisible
(
false
);
for
(
var
i
=
0
;
i
<
icons
.
length
;
i
++
)
{
icons
[
i
].
setVisible
(
false
);
}
}
}
...
...
@@ -799,6 +801,7 @@ Blockly.ConnectionDB.prototype.removeConnection_ = function(connection) {
}
connection
.
inDB_
=
false
;
// Find the connection using a binary search.
// About 10% faster than a linear search using indexOf.
var
pointerMin
=
0
;
var
pointerMax
=
this
.
length
-
2
;
var
pointerMid
=
pointerMax
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment