Skip to content

Commit 492fe53

Browse files
committed
tickWireMode 함수 구조 정리
1 parent 5a5df54 commit 492fe53

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

static/work_mode.js

+18-9
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function needSwap() {
143143
return highlightedSockets[0].role === Socket.INPUT && highlightedSockets[1].role === Socket.OUTPUT;
144144
}
145145

146-
function packetProcess(connectFlag) {
146+
function packetProcess() {
147147
highlightedSockets.length = 2;
148148
let outSocket = highlightedSockets[0];
149149
let inSocket = highlightedSockets[1];
@@ -160,13 +160,22 @@ function packetProcess(connectFlag) {
160160
let inSockets = getConnectedComponent(inSocket, components, true).inSockets,
161161
inSocketIndex = inSockets.indexOf(inSocket);
162162
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();
163169
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]);
170179
}
171180
}
172181

@@ -182,7 +191,7 @@ function tickWireMode() {
182191
}
183192

184193
if (highlightedSockets[0].role === Socket.OUTPUT && highlightedSockets[1].role === Socket.INPUT) {
185-
packetProcess(true);
194+
packetConnect();
186195
}
187196
}
188197

@@ -194,7 +203,7 @@ function tickWireMode() {
194203
wirePacket = 1;
195204
}
196205

197-
packetProcess()
206+
packetHighlight();
198207
} else if (isMouseUp(0)) {
199208
highlightedSockets = [null, null];
200209
}

0 commit comments

Comments
 (0)