Randomize seed in a hackish way

This commit is contained in:
space-nuko
2023-04-25 06:26:40 -07:00
parent 76a22c47f6
commit cd0fde0f55
8 changed files with 66 additions and 10 deletions

View File

@@ -10,5 +10,6 @@ export default class ComfyGraphNode extends LGraphNode {
*/
virtualWidgets: ComfyWidget[] = [];
onExecuting?(): void;
onExecuted?(output: any): void;
}

View 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 {}

View File

@@ -1,2 +1,3 @@
export { default as ComfyReroute } from "./ComfyReroute"
export { ComfySaveImageNode, ComfyPreviewImageNode } from "./ComfyImageNodes"
export { ComfyKSamplerNode, ComfyKSamplerAdvancedNode } from "./ComfyKSamplerNodes"