Randomize seed in a hackish way
This commit is contained in:
@@ -116,7 +116,7 @@ export default class ComfyAPI extends EventTarget {
|
||||
this.dispatchEvent(new CustomEvent("progress", { detail: msg.data }));
|
||||
break;
|
||||
case "executing":
|
||||
this.dispatchEvent(new CustomEvent("executing", { detail: msg.data.node }));
|
||||
this.dispatchEvent(new CustomEvent("executing", { detail: msg.data }));
|
||||
break;
|
||||
case "executed":
|
||||
this.dispatchEvent(new CustomEvent("executed", { detail: msg.data }));
|
||||
|
||||
@@ -206,6 +206,8 @@ export default class ComfyApp {
|
||||
private registerNodeTypeOverrides() {
|
||||
ComfyApp.node_type_overrides["SaveImage"] = nodes.ComfySaveImageNode;
|
||||
ComfyApp.node_type_overrides["PreviewImage"] = nodes.ComfyPreviewImageNode;
|
||||
ComfyApp.node_type_overrides["KSampler"] = nodes.ComfyKSamplerNode;
|
||||
ComfyApp.node_type_overrides["KSamplerAdvanced"] = nodes.ComfyKSamplerAdvancedNode;
|
||||
}
|
||||
|
||||
private registerWidgetTypeOverrides() {
|
||||
@@ -386,7 +388,11 @@ export default class ComfyApp {
|
||||
});
|
||||
|
||||
this.api.addEventListener("executing", ({ detail }: CustomEvent) => {
|
||||
queueState.executingUpdated(detail);
|
||||
queueState.executingUpdated(detail.node);
|
||||
const node = this.lGraph.getNodeById(detail.node) as ComfyGraphNode;
|
||||
if (node?.onExecuting) {
|
||||
node.onExecuting();
|
||||
}
|
||||
this.lGraph.setDirtyCanvas(true, false);
|
||||
});
|
||||
|
||||
|
||||
@@ -10,5 +10,6 @@ export default class ComfyGraphNode extends LGraphNode {
|
||||
*/
|
||||
virtualWidgets: ComfyWidget[] = [];
|
||||
|
||||
onExecuting?(): void;
|
||||
onExecuted?(output: any): void;
|
||||
}
|
||||
|
||||
34
src/lib/nodes/ComfyKSamplerNodes.ts
Normal file
34
src/lib/nodes/ComfyKSamplerNodes.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { get } from 'svelte/store';
|
||||
import ComfyGraphNode from "./ComfyGraphNode";
|
||||
import widgetState from "$lib/stores/widgetState"
|
||||
|
||||
/*
|
||||
* Autorefreshes seed (until bangs/main inlets are implemented)
|
||||
*/
|
||||
class ComfyBaseKSamplerNode extends ComfyGraphNode {
|
||||
constructor(title?: any) {
|
||||
super(title)
|
||||
}
|
||||
|
||||
override onExecuting() {
|
||||
console.log(this);
|
||||
const widget = widgetState.findWidgetByName(this.id, "seed")
|
||||
if (!widget)
|
||||
return;
|
||||
|
||||
// TODO cleanup&remove
|
||||
let min = widget.widget.options.min;
|
||||
let max = widget.widget.options.max;
|
||||
// limit to something that javascript can handle
|
||||
max = Math.min(1125899906842624, max);
|
||||
min = Math.max(-1125899906842624, min);
|
||||
const range = (max - min) / (widget.widget.options.step);
|
||||
const v = Math.floor(Math.floor(Math.random() * range) * (widget.widget.options.step) + min);
|
||||
|
||||
widget.widget.value = v;
|
||||
widgetState.widgetStateChanged(this.id, widget.widget);
|
||||
}
|
||||
}
|
||||
|
||||
export class ComfyKSamplerNode extends ComfyBaseKSamplerNode {}
|
||||
export class ComfyKSamplerAdvancedNode extends ComfyBaseKSamplerNode {}
|
||||
@@ -1,2 +1,3 @@
|
||||
export { default as ComfyReroute } from "./ComfyReroute"
|
||||
export { ComfySaveImageNode, ComfyPreviewImageNode } from "./ComfyImageNodes"
|
||||
export { ComfyKSamplerNode, ComfyKSamplerAdvancedNode } from "./ComfyKSamplerNodes"
|
||||
|
||||
@@ -34,7 +34,8 @@ type WidgetStateOps = {
|
||||
nodeAdded: (node: LGraphNode) => void,
|
||||
nodeRemoved: (node: LGraphNode) => void,
|
||||
configureFinished: (graph: LGraph) => void,
|
||||
widgetStateChanged: (widget: ComfyWidget<any, any>) => void,
|
||||
widgetStateChanged: (nodeId: number, widget: IWidget<any, any>) => void,
|
||||
findWidgetByName: (nodeId: number, name: string) => WidgetUIState | null,
|
||||
clear: () => void,
|
||||
}
|
||||
|
||||
@@ -78,9 +79,9 @@ function nodeRemoved(node: LGraphNode) {
|
||||
store.set(state)
|
||||
}
|
||||
|
||||
function widgetStateChanged(widget: ComfyWidget<any, any>) {
|
||||
function widgetStateChanged(nodeId: number, widget: IWidget<any, any>) {
|
||||
const state = get(store)
|
||||
const entries = state[widget.node.id]
|
||||
const entries = state[nodeId]
|
||||
if (entries) {
|
||||
let widgetState = entries.find(e => e.widget === widget);
|
||||
if (widgetState) {
|
||||
@@ -116,6 +117,15 @@ function configureFinished(graph: LGraph) {
|
||||
store.set(state)
|
||||
}
|
||||
|
||||
function findWidgetByName(nodeId: number, name: string): WidgetUIState | null {
|
||||
let state = get(store);
|
||||
|
||||
if (!(nodeId in state))
|
||||
return null;
|
||||
|
||||
return state[nodeId].find((v) => v.widget.name === name);
|
||||
}
|
||||
|
||||
const widgetStateStore: WritableWidgetStateStore =
|
||||
{
|
||||
...store,
|
||||
@@ -123,6 +133,7 @@ const widgetStateStore: WritableWidgetStateStore =
|
||||
nodeRemoved,
|
||||
widgetStateChanged,
|
||||
configureFinished,
|
||||
findWidgetByName,
|
||||
clear
|
||||
}
|
||||
export default widgetStateStore;
|
||||
|
||||
@@ -26,7 +26,7 @@ export default abstract class ComfyWidget<T = any, V = any> implements IWidget<T
|
||||
|
||||
setValue(value: V) {
|
||||
this.value = value;
|
||||
widgetState.widgetStateChanged(this);
|
||||
widgetState.widgetStateChanged(this.node.id, this);
|
||||
}
|
||||
|
||||
draw?(ctx: CanvasRenderingContext2D, node: LGraphNode, width: number, posY: number, height: number): void;
|
||||
|
||||
@@ -6,10 +6,13 @@
|
||||
let itemValue: WidgetUIStateStore | null = null;
|
||||
let option: number | null = null;
|
||||
|
||||
$: if (item && !option) {
|
||||
if (!itemValue)
|
||||
$: if (item) {
|
||||
itemValue = item.value;
|
||||
option = get(item.value)
|
||||
updateOption(); // don't react on option
|
||||
}
|
||||
|
||||
function updateOption() {
|
||||
option = get(itemValue);
|
||||
}
|
||||
|
||||
function onRelease(e: Event) {
|
||||
|
||||
Reference in New Issue
Block a user