From 642e73773c1474344e7ca1eb6506db02b32abf4a Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Sun, 23 Mar 2025 08:53:42 +1100 Subject: [PATCH] [CodeHealth] Improve legibility of renderingBoxColor (#832) Drastically reduces the cognitive complexity of `LGraphNode.renderingBoxColor` by impl. early returns. --- src/LGraphNode.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/LGraphNode.ts b/src/LGraphNode.ts index d55fcf67d..203c128d8 100644 --- a/src/LGraphNode.ts +++ b/src/LGraphNode.ts @@ -223,20 +223,18 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { /** The box color used to render the node. */ get renderingBoxColor(): string { - const mode = this.mode ?? LGraphEventMode.ALWAYS - let colState = LiteGraph.node_box_coloured_by_mode && LiteGraph.NODE_MODES_COLORS[mode] - ? LiteGraph.NODE_MODES_COLORS[mode] - : undefined + if (this.boxcolor) return this.boxcolor if (LiteGraph.node_box_coloured_when_on) { - colState = this.action_triggered - ? "#FFF" - : (this.execute_triggered - ? "#AAA" - : colState) + if (this.action_triggered) return "#FFF" + if (this.execute_triggered) return "#AAA" } - return this.boxcolor || colState || LiteGraph.NODE_DEFAULT_BOXCOLOR + if (LiteGraph.node_box_coloured_by_mode) { + const modeColour = LiteGraph.NODE_MODES_COLORS[this.mode ?? LGraphEventMode.ALWAYS] + if (modeColour) return modeColour + } + return LiteGraph.NODE_DEFAULT_BOXCOLOR } /** @inheritdoc {@link IColorable.setColorOption} */