Skip to content

Commit

Permalink
fix afterChange may override other extensions (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
SunriseFox authored Feb 25, 2024
1 parent e1b1729 commit a07b2fd
Showing 1 changed file with 23 additions and 27 deletions.
50 changes: 23 additions & 27 deletions extensions/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,45 +184,40 @@ function colorPositiveNegative(app) {
* Colors
*/
let afterChange;
let colorModeValue;
function invokeAfterChange() {
switch (colorModeValue) {
case 1:
uncolor(app);
break;
case 2:
rainbowify(app);
break;
case 3:
colorByType(app);
break;
default:
break;
}
if (getPosNegValue()) {
colorPositiveNegative(app);
}
return afterChange?.apply(this, arguments);
}

function setColorMode(value, app) {
colorModeValue = value;
switch (value) {
case 1:
app.graph.afterChange = function () {
uncolor(app);
if (getPosNegValue()) {
colorPositiveNegative(app);
}
return afterChange?.apply(this, arguments);
};
uncolor(app);
break;
case 2:
app.graph.afterChange = function () {
rainbowify(app);
if (getPosNegValue()) {
colorPositiveNegative(app);
}
return afterChange?.apply(this, arguments);
};
rainbowify(app);
break;
case 3:
app.graph.afterChange = function () {
colorByType(app);
if (getPosNegValue()) {
colorPositiveNegative(app);
}
return afterChange?.apply(this, arguments);
};
colorByType(app);
break;
default:
app.graph.afterChange = function () {
if (getPosNegValue()) {
colorPositiveNegative(app);
}
return afterChange?.apply(this, arguments);
};
app.graph._nodes.forEach((node) => {
node.bgcolor = node._bgcolor ?? node.bgcolor;
node.color = node._color ?? node.color;
Expand Down Expand Up @@ -275,6 +270,7 @@ app.registerExtension({
},
async init(app) {
afterChange = app.graph.afterChange;
app.graph.afterChange = invokeAfterChange;
const onMenuNodeColors = LGraphCanvas.onMenuNodeColors;
LGraphCanvas.onMenuNodeColors = function (value, options, e, menu, node) {
const response = onMenuNodeColors.apply(this, arguments);
Expand Down

0 comments on commit a07b2fd

Please sign in to comment.