Various fixes/features

This commit is contained in:
space-nuko
2023-05-17 20:17:00 -05:00
parent fe3efe1154
commit ab54f771b1
22 changed files with 186 additions and 66 deletions

View File

@@ -59,7 +59,7 @@ LiteGraph.registerNodeType({
class: ComfyQueueEvents,
title: "Comfy.QueueEvents",
desc: "Triggers a 'bang' event when a prompt is queued.",
type: "actions/queue_events"
type: "events/queue_events"
})
export interface ComfyStoreImagesActionProperties extends ComfyGraphNodeProperties {
@@ -469,7 +469,7 @@ export class ComfySetNodeModeAdvancedAction extends ComfyGraphNode {
}
private getModeChanges(action: TagAction, enable: boolean, nodeChanges: Record<string, NodeMode>, widgetChanges: Record<DragItemID, boolean>) {
for (const node of this.graph._nodes) {
for (const node of this.graph.iterateNodesInOrderRecursive()) {
if ("tags" in node.properties) {
const comfyNode = node as ComfyGraphNode;
const hasTag = comfyNode.properties.tags.indexOf(action.tag) != -1;
@@ -482,9 +482,6 @@ export class ComfySetNodeModeAdvancedAction extends ComfyGraphNode {
newMode = NodeMode.NEVER;
}
nodeChanges[node.id] = newMode
node.changeMode(newMode);
if ("notifyPropsChanged" in node)
(node as ComfyWidgetNode).notifyPropsChanged();
}
}
}
@@ -530,8 +527,7 @@ export class ComfySetNodeModeAdvancedAction extends ComfyGraphNode {
}
for (const [nodeId, newMode] of Object.entries(nodeChanges)) {
// NOTE: Only applies to this subgraph, not parent/child graphs.
this.graph.getNodeById(nodeId).changeMode(newMode);
this.graph.getNodeByIdRecursive(nodeId).changeMode(newMode);
}
const layout = get(layoutState);

View File

@@ -5,7 +5,7 @@ import { comfyFileToAnnotatedFilepath, type ComfyBoxImageMetadata } from "$lib/u
export default class ComfyPickImageNode extends ComfyGraphNode {
static slotLayout: SlotLayout = {
inputs: [
{ name: "images", type: "COMFYBOX_IMAGES" },
{ name: "images", type: "COMFYBOX_IMAGES,COMFYBOX_IMAGE" },
],
outputs: [
{ name: "image", type: "COMFYBOX_IMAGE" },
@@ -35,9 +35,13 @@ export default class ComfyPickImageNode extends ComfyGraphNode {
_path: string | null = null;
_index: number = 0;
private setValue(value: ComfyBoxImageMetadata[] | null) {
private setValue(value: ComfyBoxImageMetadata[] | ComfyBoxImageMetadata | null) {
if (value != null && !Array.isArray(value)) {
value = [value]
this._index = 0;
}
const changed = this._value != value;
this._value = value;
this._value = value as ComfyBoxImageMetadata[];
if (changed) {
if (value && value[this._index] != null) {
this._image = value[this._index]
@@ -55,6 +59,7 @@ export default class ComfyPickImageNode extends ComfyGraphNode {
this.widthWidget.value = 0
this.heightWidget.value = 0
}
console.log("SET", value, this._image, this._path)
}
}

View File

@@ -9,7 +9,8 @@ export interface ComfyValueControlProperties extends ComfyGraphNodeProperties {
action: "fixed" | "increment" | "decrement" | "randomize",
min: number,
max: number,
step: number
step: number,
ignoreStepWhenRandom: boolean
}
const INT_MAX = 1125899906842624;
@@ -21,7 +22,8 @@ export default class ComfyValueControl extends ComfyGraphNode {
action: "fixed",
min: -INT_MAX,
max: INT_MAX,
step: 1
step: 1,
ignoreStepWhenRandom: false
}
static slotLayout: SlotLayout = {
@@ -61,15 +63,11 @@ export default class ComfyValueControl extends ComfyGraphNode {
}
override onExecute() {
this.setProperty("action", this.getInputData(2) || "fixed")
this.setProperty("min", this.getInputData(3))
this.setProperty("max", this.getInputData(4))
this.setProperty("step", this.getInputData(5) || 1)
if (this._aboutToChange > 0) {
this._aboutToChange -= 1;
if (this._aboutToChange <= 0) {
const value = this._aboutToChangeValue;
console.warn("ABOUTTOCHANGE", value)
this._aboutToChange = 0;
this._aboutToChangeValue = null;
this.triggerSlot(1, value)
@@ -82,8 +80,26 @@ export default class ComfyValueControl extends ComfyGraphNode {
if (typeof v !== "number")
return
let min = this.properties.min
let max = this.properties.max
let action_ = this.getInputData(2);
if (action_ == null)
action_ = "fixed"
let min = this.getInputData(3);
if (min == null)
min = -INT_MAX
let max = this.getInputData(4);
if (max == null)
max = INT_MAX
let step = this.getInputData(5);
if (step == null)
step = 1
this.setProperty("action", action_)
this.setProperty("min", min)
this.setProperty("max", max)
this.setProperty("step", step)
min = this.properties.min
max = this.properties.max
if (min == null) min = -INT_MAX
if (max == null) max = INT_MAX
@@ -103,7 +119,8 @@ export default class ComfyValueControl extends ComfyGraphNode {
v -= this.properties.step;
break;
case "randomize":
v = Math.floor(Math.random() * range) * (this.properties.step) + min;
const step = this.properties.ignoreStepWhenRandom ? 1 : this.properties.step
v = Math.floor(Math.random() * range) * step + min;
default:
break;
}

View File

@@ -113,12 +113,16 @@ export default class ComfyComboNode extends ComfyWidgetNode<string> {
const comfyInput = input as IComfyInputSlot;
const otherProps = comfyInput.config;
console.warn("CHECK COMBO CONNECTION", otherProps, thisProps)
// Ensure combo options match
if (!(otherProps.values instanceof Array))
return false;
if (thisProps.values.find((v, i) => otherProps.values.indexOf(v) === -1))
return false;
console.warn("PASSED")
return true;
}

View File

@@ -72,6 +72,9 @@ export default class ComfyGalleryNode extends ComfyWidgetNode<ComfyBoxImageMetad
}
override parseValue(param: any): ComfyBoxImageMetadata[] {
if (param == null)
return []
const meta = parseWhateverIntoImageMetadata(param) || [];
console.debug("[ComfyGalleryNode] Received output!", param)
@@ -81,6 +84,7 @@ export default class ComfyGalleryNode extends ComfyWidgetNode<ComfyBoxImageMetad
return currentValue.concat(meta)
}
else {
this.notifyPropsChanged();
return meta;
}
}

View File

@@ -27,6 +27,7 @@ export default class ComfyImageUploadNode extends ComfyWidgetNode<ComfyBoxImageM
override svelteComponentType = ImageUploadWidget;
override defaultValue = [];
override outputSlotName = "images";
override storeActionName = "store";
override saveUserState = false;

View File

@@ -16,6 +16,7 @@ export default class ComfyTextNode extends ComfyWidgetNode<string> {
static slotLayout: SlotLayout = {
inputs: [
{ name: "value", type: "string" },
{ name: "store", type: BuiltInSlotType.ACTION }
],
outputs: [
@@ -24,6 +25,7 @@ export default class ComfyTextNode extends ComfyWidgetNode<string> {
]
}
override inputSlotName = "value";
override svelteComponentType = TextWidget
override defaultValue = "";

View File

@@ -73,12 +73,14 @@ export default abstract class ComfyWidgetNode<T = any> extends ComfyGraphNode {
// shownInputProperties: string[] = []
/** Names of properties to add as outputs */
private shownOutputProperties: Record<string, { type: string, index: number }> = {}
private shownOutputProperties: Record<string, { type: string, outputName: string }> = {}
outputProperties: { name: string, type: string }[] = []
override isBackendNode = false;
override serialize_widgets = true;
// input slots
inputSlotName: string | null = "value";
storeActionName: string | null = "store";
// output slots
@@ -105,15 +107,16 @@ export default abstract class ComfyWidgetNode<T = any> extends ComfyGraphNode {
}
addPropertyAsOutput(propertyName: string, type: string) {
if (this.shownOutputProperties["@" + propertyName])
if (this.shownOutputProperties[propertyName])
return;
if (!(propertyName in this.properties)) {
throw `No property named ${propertyName} found!`
}
this.shownOutputProperties["@" + propertyName] = { type, index: this.outputs.length }
this.addOutput("@" + propertyName, type)
const outputName = "@" + propertyName;
this.shownOutputProperties[propertyName] = { type, outputName }
this.addOutput(outputName, type)
}
formatValue(value: any): string {
@@ -174,8 +177,11 @@ export default abstract class ComfyWidgetNode<T = any> extends ComfyGraphNode {
override onPropertyChanged(property: string, value: any, prevValue?: any) {
if (this.shownOutputProperties != null) {
const data = this.shownOutputProperties[property]
if (data)
this.setOutputData(data.index, value)
if (data) {
const index = this.findOutputSlotIndexByName(data.outputName)
if (index !== -1)
this.setOutputData(index, value)
}
}
}
@@ -183,6 +189,15 @@ export default abstract class ComfyWidgetNode<T = any> extends ComfyGraphNode {
* Logic to run if this widget can be treated as output (slider, combo, text)
*/
override onExecute(param: any, options: object) {
if (this.inputSlotName != null) {
const inputIndex = this.findInputSlotIndexByName(this.inputSlotName)
if (inputIndex !== -1) {
const data = this.getInputData(inputIndex)
if (data != null) { // TODO can "null" be a legitimate value here?
this.setValue(data)
}
}
}
if (this.outputSlotName != null) {
const outputIndex = this.findOutputSlotIndexByName(this.outputSlotName)
if (outputIndex !== -1)
@@ -190,7 +205,9 @@ export default abstract class ComfyWidgetNode<T = any> extends ComfyGraphNode {
}
for (const propName in this.shownOutputProperties) {
const data = this.shownOutputProperties[propName]
this.setOutputData(data.index, this.properties[propName])
const index = this.findOutputSlotIndexByName(data.outputName)
if (index !== -1)
this.setOutputData(index, this.properties[propName])
}
// Fire a pending change event after one full step of the graph has