* Determines the slot index to connect to when attempting to connect by type. * @param findInputs If true, searches for an input. Otherwise, an output. * @param node The node at the other end of the connection. * @param slotType The type of slot at the other end of the connection. * @pa
(
findInputs: boolean,
node: LGraphNode,
slotType: ISlotType,
options?: ConnectByTypeOptions,
)
| 2344 | * @see {connectByTypeOutput} |
| 2345 | */ |
| 2346 | findConnectByTypeSlot( |
| 2347 | findInputs: boolean, |
| 2348 | node: LGraphNode, |
| 2349 | slotType: ISlotType, |
| 2350 | options?: ConnectByTypeOptions, |
| 2351 | ): number | undefined { |
| 2352 | // LEGACY: Old options names |
| 2353 | if (options && typeof options === "object") { |
| 2354 | if ("firstFreeIfInputGeneralInCase" in options) options.wildcardToTyped = !!options.firstFreeIfInputGeneralInCase |
| 2355 | if ("firstFreeIfOutputGeneralInCase" in options) options.wildcardToTyped = !!options.firstFreeIfOutputGeneralInCase |
| 2356 | if ("generalTypeInCase" in options) options.typedToWildcard = !!options.generalTypeInCase |
| 2357 | } |
| 2358 | const optsDef: ConnectByTypeOptions = { |
| 2359 | createEventInCase: true, |
| 2360 | wildcardToTyped: true, |
| 2361 | typedToWildcard: true, |
| 2362 | } |
| 2363 | const opts = Object.assign(optsDef, options) |
| 2364 | |
| 2365 | if (!this.graph) throw new NullGraphError() |
| 2366 | |
| 2367 | if (node && typeof node === "number") { |
| 2368 | const nodeById = this.graph.getNodeById(node) |
| 2369 | if (!nodeById) return |
| 2370 | |
| 2371 | node = nodeById |
| 2372 | } |
| 2373 | const slot = node.findSlotByType(findInputs, slotType, false, true) |
| 2374 | if (slot >= 0 && slot !== null) return slot |
| 2375 | |
| 2376 | // TODO: Remove or reimpl. events. WILL CREATE THE onTrigger IN SLOT |
| 2377 | if (opts.createEventInCase && slotType == LiteGraph.EVENT) { |
| 2378 | if (findInputs) return -1 |
| 2379 | if (LiteGraph.do_add_triggers_slots) return node.addOnExecutedOutput() |
| 2380 | } |
| 2381 | |
| 2382 | // connect to the first general output slot if not found a specific type and |
| 2383 | if (opts.typedToWildcard) { |
| 2384 | const generalSlot = node.findSlotByType(findInputs, 0, false, true, true) |
| 2385 | if (generalSlot >= 0) return generalSlot |
| 2386 | } |
| 2387 | // connect to the first free input slot if not found a specific type and this output is general |
| 2388 | if ( |
| 2389 | opts.wildcardToTyped && |
| 2390 | (slotType == 0 || slotType == "*" || slotType == "") |
| 2391 | ) { |
| 2392 | const opt = { typesNotAccepted: [LiteGraph.EVENT] } |
| 2393 | const nonEventSlot = findInputs |
| 2394 | ? node.findInputSlotFree(opt) |
| 2395 | : node.findOutputSlotFree(opt) |
| 2396 | if (nonEventSlot >= 0) return nonEventSlot |
| 2397 | } |
| 2398 | } |
| 2399 | |
| 2400 | /** |
| 2401 | * Finds the first free output slot with any of the comma-delimited types in {@link type}. |
no test coverage detected