Files

68 lines
2.2 KiB
JavaScript

import { app } from "../../scripts/app.js";
const MAX_VARIATIONS = 10;
function addCanvasLabels(nodeType, labels) {
const origDraw = nodeType.prototype.onDrawForeground;
nodeType.prototype.onDrawForeground = function (ctx) {
origDraw?.call(this, ctx);
if (this.flags?.collapsed) return;
ctx.font = "10px sans-serif";
ctx.textAlign = "left";
for (const w of this.widgets ?? []) {
if (w.last_y == null || !labels[w.name]) continue;
ctx.fillStyle = "#aaa";
ctx.fillText(labels[w.name], 10, w.last_y + 6);
}
};
}
app.registerExtension({
name: "CharacterPromptManager",
async beforeRegisterNodeDef(nodeType, nodeData) {
// ── Character Prompt Manager ──
if (nodeData.name === "CharacterPromptManager") {
const origCreated = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function () {
origCreated?.apply(this, arguments);
this.badges = [];
this.title = "Character Prompt Manager";
// taller textareas (~5 lines)
for (const w of this.widgets ?? []) {
if (["base", "character", "others"].includes(w.name)) {
const orig = w.computeSize?.bind(w);
w.computeSize = (width) => {
const s = orig?.(width) ?? [width, 60];
return [s[0], Math.max(s[1], 105)];
};
}
}
this.size = this.computeSize();
};
addCanvasLabels(nodeType, {
base: "Base",
character: "Character",
others: "Others",
});
}
// ── Variation Buffer ──
if (nodeData.name === "VariationBuffer") {
const origCreated = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function () {
origCreated?.apply(this, arguments);
this.badges = [];
this.title = "Variation Buffer";
this.size = this.computeSize();
};
}
},
});