Remove continuous value inputs from widgets

This commit is contained in:
space-nuko
2023-05-16 17:11:45 -05:00
parent 0143b6430f
commit b515ac885a

View File

@@ -89,16 +89,11 @@ export abstract class ComfyWidgetNode<T = any> extends ComfyGraphNode {
override isBackendNode = false; override isBackendNode = false;
override serialize_widgets = true; override serialize_widgets = true;
// TODO these are bad, create override methods instead
// input slots
inputIndex: number | null = null;
storeActionName: string | null = "store"; storeActionName: string | null = "store";
// output slots // output slots
outputIndex: number | null = 0; outputSlotName: string | null = "value";
changedIndex: number | null = 1; changedEventName: string | null = "changed";
displayWidget: ITextWidget; displayWidget: ITextWidget;
@@ -145,11 +140,13 @@ export abstract class ComfyWidgetNode<T = any> extends ComfyGraphNode {
// console.debug("[Widget] valueUpdated", this, value) // console.debug("[Widget] valueUpdated", this, value)
this.displayWidget.value = this.formatValue(value) this.displayWidget.value = this.formatValue(value)
if (this.outputIndex !== null && this.outputs.length >= this.outputIndex) { if (this.outputSlotName !== null) {
this.setOutputData(this.outputIndex, get(this.value)) const outputIndex = this.findOutputSlotIndexByName(this.outputSlotName)
if (outputIndex !== -1)
this.setOutputData(outputIndex, get(this.value))
} }
if (this.changedIndex !== null && this.outputs.length >= this.changedIndex && !this._noChangedEvent) { if (this.changedEventName !== null && !this._noChangedEvent) {
if (!this.delayChangedEvent) if (!this.delayChangedEvent)
this.triggerChangeEvent(get(this.value)) this.triggerChangeEvent(get(this.value))
else { else {
@@ -163,9 +160,7 @@ export abstract class ComfyWidgetNode<T = any> extends ComfyGraphNode {
private triggerChangeEvent(value: any) { private triggerChangeEvent(value: any) {
// console.debug("[Widget] trigger changed", this, value) // console.debug("[Widget] trigger changed", this, value)
const changedOutput = this.outputs[this.changedIndex] this.trigger(this.changedEventName, value)
if (changedOutput.type === BuiltInSlotType.EVENT)
this.triggerSlot(this.changedIndex, value)
} }
parseValue(value: any): T { return value as T }; parseValue(value: any): T { return value as T };
@@ -198,18 +193,10 @@ export abstract class ComfyWidgetNode<T = any> extends ComfyGraphNode {
* Logic to run if this widget can be treated as output (slider, combo, text) * Logic to run if this widget can be treated as output (slider, combo, text)
*/ */
override onExecute(param: any, options: object) { override onExecute(param: any, options: object) {
if (this.inputIndex != null) { if (this.outputSlotName != null) {
if (this.inputs.length >= this.inputIndex) { const outputIndex = this.findOutputSlotIndexByName(this.outputSlotName)
const data = this.getInputData(this.inputIndex) if (outputIndex !== -1)
if (data != null) { // TODO can "null" be a legitimate value here? this.setOutputData(outputIndex, get(this.value))
this.setValue(data)
}
}
}
if (this.outputIndex != null) {
if (this.outputs.length >= this.outputIndex) {
this.setOutputData(this.outputIndex, get(this.value))
}
} }
for (const propName in this.shownOutputProperties) { for (const propName in this.shownOutputProperties) {
const data = this.shownOutputProperties[propName] const data = this.shownOutputProperties[propName]
@@ -373,7 +360,6 @@ export class ComfySliderNode extends ComfyWidgetNode<number> {
static slotLayout: SlotLayout = { static slotLayout: SlotLayout = {
inputs: [ inputs: [
{ name: "value", type: "number" },
{ name: "store", type: BuiltInSlotType.ACTION } { name: "store", type: BuiltInSlotType.ACTION }
], ],
outputs: [ outputs: [
@@ -431,7 +417,6 @@ export class ComfyComboNode extends ComfyWidgetNode<string> {
static slotLayout: SlotLayout = { static slotLayout: SlotLayout = {
inputs: [ inputs: [
{ name: "value", type: "string" },
{ name: "store", type: BuiltInSlotType.ACTION } { name: "store", type: BuiltInSlotType.ACTION }
], ],
outputs: [ outputs: [
@@ -574,7 +559,6 @@ export class ComfyTextNode extends ComfyWidgetNode<string> {
static slotLayout: SlotLayout = { static slotLayout: SlotLayout = {
inputs: [ inputs: [
{ name: "value", type: "string" },
{ name: "store", type: BuiltInSlotType.ACTION } { name: "store", type: BuiltInSlotType.ACTION }
], ],
outputs: [ outputs: [
@@ -650,10 +634,9 @@ export class ComfyGalleryNode extends ComfyWidgetNode<ComfyBoxImageMetadata[]> {
override svelteComponentType = GalleryWidget override svelteComponentType = GalleryWidget
override defaultValue = [] override defaultValue = []
override inputIndex = null;
override saveUserState = false; override saveUserState = false;
override outputIndex = null; override outputSlotName = null;
override changedIndex = null; override changedEventName = null;
selectedFilename: string | null = null; selectedFilename: string | null = null;
@@ -727,13 +710,13 @@ export class ComfyButtonNode extends ComfyWidgetNode<boolean> {
static slotLayout: SlotLayout = { static slotLayout: SlotLayout = {
outputs: [ outputs: [
{ name: "clicked", type: BuiltInSlotType.EVENT }, { name: "clicked", type: BuiltInSlotType.EVENT },
{ name: "isClicked", type: "boolean" },
] ]
} }
override svelteComponentType = ButtonWidget; override svelteComponentType = ButtonWidget;
override defaultValue = false; override defaultValue = false;
override outputIndex = 1; override outputSlotName = null;
override changedEventName = null;
constructor(name?: string) { constructor(name?: string) {
super(name, false) super(name, false)
@@ -768,7 +751,6 @@ export class ComfyCheckboxNode extends ComfyWidgetNode<boolean> {
static slotLayout: SlotLayout = { static slotLayout: SlotLayout = {
inputs: [ inputs: [
{ name: "value", type: "boolean" },
{ name: "store", type: BuiltInSlotType.ACTION } { name: "store", type: BuiltInSlotType.ACTION }
], ],
outputs: [ outputs: [
@@ -779,7 +761,6 @@ export class ComfyCheckboxNode extends ComfyWidgetNode<boolean> {
override svelteComponentType = CheckboxWidget; override svelteComponentType = CheckboxWidget;
override defaultValue = false; override defaultValue = false;
override changedIndex = 1;
constructor(name?: string) { constructor(name?: string) {
super(name, false) super(name, false)
@@ -810,7 +791,6 @@ export class ComfyRadioNode extends ComfyWidgetNode<string> {
static slotLayout: SlotLayout = { static slotLayout: SlotLayout = {
inputs: [ inputs: [
{ name: "value", type: "string,number" },
{ name: "store", type: BuiltInSlotType.ACTION } { name: "store", type: BuiltInSlotType.ACTION }
], ],
outputs: [ outputs: [
@@ -822,7 +802,6 @@ export class ComfyRadioNode extends ComfyWidgetNode<string> {
override svelteComponentType = RadioWidget; override svelteComponentType = RadioWidget;
override defaultValue = ""; override defaultValue = "";
override changedIndex = 2;
indexWidget: INumberWidget; indexWidget: INumberWidget;
@@ -894,9 +873,6 @@ export class ComfyImageEditorNode extends ComfyWidgetNode<ComfyBoxImageMetadata[
override svelteComponentType = ImageEditorWidget; override svelteComponentType = ImageEditorWidget;
override defaultValue = []; override defaultValue = [];
override outputIndex = 0;
override inputIndex = null;
override changedIndex = 1;
override storeActionName = "store"; override storeActionName = "store";
override saveUserState = false; override saveUserState = false;