File tree Expand file tree Collapse file tree 3 files changed +28
-2
lines changed
Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -21,3 +21,19 @@ export function stringOrEmpty(value: unknown): string {
2121export function parseSlotTypes ( type : ISlotType ) : string [ ] {
2222 return type == "" || type == "0" ? [ "*" ] : String ( type ) . toLowerCase ( ) . split ( "," )
2323}
24+
25+ /**
26+ * Creates a unique name by appending an underscore and a number to the end of the name
27+ * if it already exists.
28+ * @param name The name to make unique
29+ * @param existingNames The names that already exist. Default: an empty array
30+ * @returns The name, or a unique name if it already exists.
31+ */
32+ export function nextUniqueName ( name : string , existingNames : string [ ] = [ ] ) : string {
33+ let i = 1
34+ const baseName = name
35+ while ( existingNames . includes ( name ) ) {
36+ name = `${ baseName } _${ i ++ } `
37+ }
38+ return name
39+ }
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import type { LGraphNode } from "@/LGraphNode"
44import type { RerouteId } from "@/Reroute"
55
66import { LLink } from "@/LLink"
7+ import { nextUniqueName } from "@/strings"
78import { zeroUuid } from "@/utils/uuid"
89
910import { SubgraphInput } from "./SubgraphInput"
@@ -23,7 +24,11 @@ export class EmptySubgraphInput extends SubgraphInput {
2324 }
2425
2526 override connect ( slot : INodeInputSlot , node : LGraphNode , afterRerouteId ?: RerouteId ) : LLink | undefined {
26- const input = this . parent . subgraph . addInput ( slot . name , String ( slot . type ) )
27+ const { subgraph } = this . parent
28+ const existingNames = subgraph . inputs . map ( x => x . name )
29+
30+ const name = nextUniqueName ( slot . name , existingNames )
31+ const input = subgraph . addInput ( name , String ( slot . type ) )
2732 return input . connect ( slot , node , afterRerouteId )
2833 }
2934
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import type { LGraphNode } from "@/LGraphNode"
44import type { RerouteId } from "@/Reroute"
55
66import { LLink } from "@/LLink"
7+ import { nextUniqueName } from "@/strings"
78import { zeroUuid } from "@/utils/uuid"
89
910import { SubgraphOutput } from "./SubgraphOutput"
@@ -23,7 +24,11 @@ export class EmptySubgraphOutput extends SubgraphOutput {
2324 }
2425
2526 override connect ( slot : INodeOutputSlot , node : LGraphNode , afterRerouteId ?: RerouteId ) : LLink | undefined {
26- const output = this . parent . subgraph . addOutput ( slot . name , String ( slot . type ) )
27+ const { subgraph } = this . parent
28+ const existingNames = subgraph . outputs . map ( x => x . name )
29+
30+ const name = nextUniqueName ( slot . name , existingNames )
31+ const output = subgraph . addOutput ( name , String ( slot . type ) )
2732 return output . connect ( slot , node , afterRerouteId )
2833 }
2934
You can’t perform that action at this time.
0 commit comments