Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
ComfyUI
Commits
5229c1f9
Commit
5229c1f9
authored
Apr 20, 2023
by
omar92
Browse files
add option on the settings to change the number of the suggestions
parent
94e9798a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
19 deletions
+42
-19
web/extensions/core/slotDefaults.js
web/extensions/core/slotDefaults.js
+42
-19
No files found.
web/extensions/core/slotDefaults.js
View file @
5229c1f9
...
@@ -4,46 +4,69 @@ import { ComfyWidgets } from "/scripts/widgets.js";
...
@@ -4,46 +4,69 @@ import { ComfyWidgets } from "/scripts/widgets.js";
app
.
registerExtension
({
app
.
registerExtension
({
name
:
"
Comfy.SlotDefaults
"
,
name
:
"
Comfy.SlotDefaults
"
,
suggestionsNumber
:
null
,
init
()
{
init
()
{
LiteGraph
.
middle_click_slot_add_default_node
=
true
;
LiteGraph
.
middle_click_slot_add_default_node
=
true
;
this
.
suggestionsNumber
=
app
.
ui
.
settings
.
addSetting
({
id
:
"
Comfy.NodeSuggestions.number
"
,
name
:
"
number of nodes suggestions
"
,
type
:
"
slider
"
,
attrs
:
{
min
:
1
,
max
:
100
,
step
:
1
,
},
defaultValue
:
5
,
onChange
:
(
newVal
,
oldVal
)
=>
{
this
.
setDefaults
(
newVal
);
}
});
},
},
slot_types_default_out
:
{},
slot_types_default_in
:
{},
async
beforeRegisterNodeDef
(
nodeType
,
nodeData
,
app
)
{
async
beforeRegisterNodeDef
(
nodeType
,
nodeData
,
app
)
{
var
nodeId
=
nodeData
.
name
;
var
nodeId
=
nodeData
.
name
;
var
inputs
=
[];
var
inputs
=
[];
//if (nodeData["input"]["optional"] != undefined) {
inputs
=
nodeData
[
"
input
"
][
"
required
"
];
//only show required inputs to reduce the mess also not logical to create node with optional inputs
// inputs = Object.assign({}, nodeData["input"]["required"], nodeData["input"]["optional"]);
//} else {
inputs
=
nodeData
[
"
input
"
][
"
required
"
];
//only show required inputs to reduce the mess also not logica to create node with optional inputs
//}
for
(
const
inputKey
in
inputs
)
{
for
(
const
inputKey
in
inputs
)
{
var
input
=
(
inputs
[
inputKey
]);
var
input
=
(
inputs
[
inputKey
]);
//make sure input[0] is a string
if
(
typeof
input
[
0
]
!==
"
string
"
)
continue
;
if
(
typeof
input
[
0
]
!==
"
string
"
)
continue
;
// for (const slotKey in inputs[inputKey]) {
var
type
=
input
[
0
]
var
type
=
input
[
0
]
if
(
type
in
ComfyWidgets
)
{
if
(
type
in
ComfyWidgets
)
{
var
customProperties
=
input
[
1
]
var
customProperties
=
input
[
1
]
//console.log(customProperties)
if
(
!
(
customProperties
?.
forceInput
))
continue
;
//ignore widgets that don't force input
if
(
!
(
customProperties
?.
forceInput
))
continue
;
//ignore widgets that don't force input
}
}
if
(
!
(
type
in
LiteGraph
.
slot_types_default_out
))
{
if
(
!
(
type
in
this
.
slot_types_default_out
))
{
LiteGraph
.
slot_types_default_out
[
type
]
=
[
"
Reroute
"
];
this
.
slot_types_default_out
[
type
]
=
[
"
Reroute
"
];
}
}
if
(
LiteGraph
.
slot_types_default_out
[
type
].
includes
(
nodeId
))
continue
;
if
(
this
.
slot_types_default_out
[
type
].
includes
(
nodeId
))
continue
;
LiteGraph
.
slot_types_default_out
[
type
].
push
(
nodeId
);
this
.
slot_types_default_out
[
type
].
push
(
nodeId
);
// }
}
}
var
outputs
=
nodeData
[
"
output
"
];
var
outputs
=
nodeData
[
"
output
"
];
for
(
const
key
in
outputs
)
{
for
(
const
key
in
outputs
)
{
var
type
=
outputs
[
key
];
var
type
=
outputs
[
key
];
if
(
!
(
type
in
LiteGraph
.
slot_types_default_in
))
{
if
(
!
(
type
in
this
.
slot_types_default_in
))
{
LiteGraph
.
slot_types_default_in
[
type
]
=
[
"
Reroute
"
];
// ["Reroute", "Primitive"]; primitive doesn't always work :'()
this
.
slot_types_default_in
[
type
]
=
[
"
Reroute
"
];
// ["Reroute", "Primitive"]; primitive doesn't always work :'()
}
}
LiteGraph
.
slot_types_default_in
[
type
].
push
(
nodeId
);
}
this
.
slot_types_default_in
[
type
].
push
(
nodeId
);
}
var
maxNum
=
this
.
suggestionsNumber
?
this
.
suggestionsNumber
.
value
:
5
;
this
.
setDefaults
(
maxNum
);
},
},
setDefaults
(
maxNum
)
{
LiteGraph
.
slot_types_default_out
=
{};
LiteGraph
.
slot_types_default_in
=
{};
for
(
const
type
in
this
.
slot_types_default_out
)
{
LiteGraph
.
slot_types_default_out
[
type
]
=
this
.
slot_types_default_out
[
type
].
slice
(
0
,
maxNum
);
}
for
(
const
type
in
this
.
slot_types_default_in
)
{
LiteGraph
.
slot_types_default_in
[
type
]
=
this
.
slot_types_default_in
[
type
].
slice
(
0
,
maxNum
);
}
}
});
});
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