@@ -143,7 +143,7 @@ function needSwap() {
143
143
return highlightedSockets [ 0 ] . role === Socket . INPUT && highlightedSockets [ 1 ] . role === Socket . OUTPUT ;
144
144
}
145
145
146
- function packetProcess ( connectFlag ) {
146
+ function packetProcess ( ) {
147
147
highlightedSockets . length = 2 ;
148
148
let outSocket = highlightedSockets [ 0 ] ;
149
149
let inSocket = highlightedSockets [ 1 ] ;
@@ -160,13 +160,22 @@ function packetProcess(connectFlag) {
160
160
let inSockets = getConnectedComponent ( inSocket , components , true ) . inSockets ,
161
161
inSocketIndex = inSockets . indexOf ( inSocket ) ;
162
162
let maxI = Math . min ( wirePacket , outSockets . length - outSocketIndex , inSockets . length - inSocketIndex ) ;
163
+
164
+ return [ outSockets , outSocketIndex , inSockets , inSocketIndex , maxI ] ;
165
+ }
166
+
167
+ function packetConnect ( ) {
168
+ let [ outSockets , outSocketIndex , inSockets , inSocketIndex , maxI ] = packetProcess ( ) ;
163
169
for ( let i = 0 ; i < maxI ; i ++ ) {
164
- if ( connectFlag ) {
165
- connectWire ( outSockets [ outSocketIndex + i ] , inSockets [ inSocketIndex + i ] , camera ) ;
166
- } else {
167
- highlightedSockets . push ( outSockets [ outSocketIndex + i ] ) ;
168
- highlightedSockets . push ( inSockets [ inSocketIndex + i ] ) ;
169
- }
170
+ connectWire ( outSockets [ outSocketIndex + i ] , inSockets [ inSocketIndex + i ] , camera ) ;
171
+ }
172
+ }
173
+
174
+ function packetHighlight ( ) {
175
+ let [ outSockets , outSocketIndex , inSockets , inSocketIndex , maxI ] = packetProcess ( ) ;
176
+ for ( let i = 0 ; i < maxI ; i ++ ) {
177
+ highlightedSockets . push ( outSockets [ outSocketIndex + i ] ) ;
178
+ highlightedSockets . push ( inSockets [ inSocketIndex + i ] ) ;
170
179
}
171
180
}
172
181
@@ -182,7 +191,7 @@ function tickWireMode() {
182
191
}
183
192
184
193
if ( highlightedSockets [ 0 ] . role === Socket . OUTPUT && highlightedSockets [ 1 ] . role === Socket . INPUT ) {
185
- packetProcess ( true ) ;
194
+ packetConnect ( ) ;
186
195
}
187
196
}
188
197
@@ -194,7 +203,7 @@ function tickWireMode() {
194
203
wirePacket = 1 ;
195
204
}
196
205
197
- packetProcess ( )
206
+ packetHighlight ( ) ;
198
207
} else if ( isMouseUp ( 0 ) ) {
199
208
highlightedSockets = [ null , null ] ;
200
209
}
0 commit comments