[Refactor] Remove redundant code (#1001)

Removes redundant code. After being refactored out of LGraphCanvas, the
class methods were being passed their own properties as params.
This commit is contained in:
filtered
2025-05-03 04:06:23 +10:00
committed by GitHub
parent b838a70ed2
commit 9dcc3bf39a
9 changed files with 53 additions and 61 deletions

View File

@@ -3374,35 +3374,34 @@ export class LGraphNode implements Positionable, IPinnable, IColorable {
}: DrawWidgetsOptions): void {
if (!this.widgets) return
const width = this.size[0]
const widgets = this.widgets
const nodeWidth = this.size[0]
const { widgets } = this
const H = LiteGraph.NODE_WIDGET_HEIGHT
const show_text = !lowQuality
const showText = !lowQuality
ctx.save()
ctx.globalAlpha = editorAlpha
const { margin } = BaseWidget
for (const w of widgets) {
if (!this.isWidgetVisible(w)) continue
for (const widget of widgets) {
if (!this.isWidgetVisible(widget)) continue
const y = w.y
const outline_color = w.advanced ? LiteGraph.WIDGET_ADVANCED_OUTLINE_COLOR : LiteGraph.WIDGET_OUTLINE_COLOR
const { y } = widget
const outlineColour = widget.advanced ? LiteGraph.WIDGET_ADVANCED_OUTLINE_COLOR : LiteGraph.WIDGET_OUTLINE_COLOR
w.last_y = y
widget.last_y = y
// Disable widget if it is disabled or if the value is passed from socket connection.
w.computedDisabled = w.disabled || this.getSlotFromWidget(w)?.link != null
widget.computedDisabled = widget.disabled || this.getSlotFromWidget(widget)?.link != null
ctx.strokeStyle = outline_color
ctx.strokeStyle = outlineColour
ctx.fillStyle = "#222"
ctx.textAlign = "left"
if (w.computedDisabled) ctx.globalAlpha *= 0.5
const widget_width = w.width || width
if (widget.computedDisabled) ctx.globalAlpha *= 0.5
const width = widget.width || nodeWidth
const WidgetClass: typeof WIDGET_TYPE_MAP[string] = WIDGET_TYPE_MAP[w.type]
const WidgetClass: typeof WIDGET_TYPE_MAP[string] = WIDGET_TYPE_MAP[widget.type]
if (WidgetClass) {
toClass(WidgetClass, w).drawWidget(ctx, { y, width: widget_width, show_text, margin })
toClass(WidgetClass, widget).drawWidget(ctx, { width, showText })
} else {
w.draw?.(ctx, this, widget_width, y, H, lowQuality)
widget.draw?.(ctx, this, width, y, H, lowQuality)
}
ctx.globalAlpha = editorAlpha
}