Initial commit
This commit is contained in:
@@ -0,0 +1 @@
|
||||
__pycache__
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
from .remember_last_seed import RememberLastSeed
|
||||
from .show_last_seed import ShowLastSeed
|
||||
from .show_last_text import ShowLastText
|
||||
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"RememberLastSeed": RememberLastSeed,
|
||||
"ShowLastSeed": ShowLastSeed,
|
||||
"ShowLastText": ShowLastText,
|
||||
}
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"ShowLastSeed": "Show Last Seed",
|
||||
"RememberLastSeed": "Remember Last Seed",
|
||||
"ShowLastText": "Show Last Text",
|
||||
}
|
||||
|
||||
WEB_DIRECTORY = "./web"
|
||||
|
||||
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"]
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
class RememberLastSeed:
|
||||
last_seed = None
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"seed": ("INT", {}),
|
||||
}
|
||||
}
|
||||
|
||||
OUTPUT_NODE = True
|
||||
RETURN_TYPES = ("INT",)
|
||||
FUNCTION = "read_seed"
|
||||
CATEGORY = "utils"
|
||||
|
||||
def read_seed(self, seed):
|
||||
ret = self.last_seed
|
||||
self.last_seed = seed
|
||||
return (ret,)
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
from server import PromptServer
|
||||
|
||||
class ShowLastSeed:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"hidden": {"node_id": "UNIQUE_ID"},
|
||||
"required": {
|
||||
"seed": ("INT", {}),
|
||||
}
|
||||
}
|
||||
|
||||
OUTPUT_NODE = True
|
||||
RETURN_TYPES = ("STRING",)
|
||||
FUNCTION = "read_seed"
|
||||
CATEGORY = "utils"
|
||||
|
||||
def read_seed(self, seed, node_id):
|
||||
PromptServer.instance.send_sync("RememberingUtils:change", {"node": node_id, "next": seed})
|
||||
return (str(seed),)
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
from server import PromptServer
|
||||
|
||||
class ShowLastText:
|
||||
last_text = None
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"hidden": {"node_id": "UNIQUE_ID"},
|
||||
"required": {
|
||||
"text": ("STRING", {}),
|
||||
}
|
||||
}
|
||||
|
||||
OUTPUT_NODE = True
|
||||
RETURN_TYPES = ("STRING",)
|
||||
FUNCTION = "read_text"
|
||||
CATEGORY = "utils"
|
||||
|
||||
def read_text(self, text, node_id):
|
||||
PromptServer.instance.send_sync("RememberingUtils:change", {"node": node_id, "next": text})
|
||||
|
||||
return (text,)
|
||||
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
import { app } from "../../scripts/app.js";
|
||||
import { api } from "../../scripts/api.js";
|
||||
|
||||
const propertiesMapping = {};
|
||||
const nodes = [];
|
||||
|
||||
function drawTextWithLineBreaks(ctx, text, x, y, maxWidth, lineHeight) {
|
||||
const words = text.split(' '); // 将文本按空格分割为单词
|
||||
let line = ''; // 当前行的文本
|
||||
let currentY = y; // 当前行的Y坐标
|
||||
|
||||
words.forEach(word => {
|
||||
const testLine = line + (line ? ' ' : '') + word; // 尝试添加单词到当前行
|
||||
const metrics = ctx.measureText(testLine); // 测量当前行宽度
|
||||
//console.log('metrics.width', metrics.width, 'maxWidth', maxWidth);
|
||||
if (metrics.width > maxWidth && line !== '') {
|
||||
// 如果当前行宽度超过了最大宽度且行不为空,则绘制当前行
|
||||
ctx.fillText(line, x, currentY);
|
||||
line = word; // 将当前单词移到下一行
|
||||
currentY += lineHeight; // 更新Y坐标
|
||||
} else {
|
||||
// 否则,将单词添加到当前行
|
||||
line = testLine;
|
||||
}
|
||||
});
|
||||
|
||||
// 绘制最后一行
|
||||
if (line) {
|
||||
ctx.fillText(line, x, currentY);
|
||||
}
|
||||
}
|
||||
|
||||
app.registerExtension({
|
||||
name: "RememberingUtils",
|
||||
async beforeRegisterNodeDef(nodeType, nodeData, app) {
|
||||
if (nodeData.python_module !== "custom_nodes.RememberingUtils") return;
|
||||
nodeType.prototype.onDrawForeground = function(ctx, graphcanvas) {
|
||||
//console.log(arguments)
|
||||
if (this.flags.collapsed) return;
|
||||
if (!this.properties.curr) return;
|
||||
ctx.save();
|
||||
ctx.font = "16px serif";
|
||||
if (typeof this.properties.curr === 'string') {
|
||||
drawTextWithLineBreaks(ctx, this.properties.curr, 10, 35, this.size[0] - 20, 16);
|
||||
} else {
|
||||
ctx.fillText(this.properties.curr, 10, 50);
|
||||
}
|
||||
ctx.restore();
|
||||
}
|
||||
nodeType.prototype.onGetInputs = function() {
|
||||
// handle the situation when node is freshly added
|
||||
const {id, properties} = this;
|
||||
propertiesMapping[id] = properties;
|
||||
node_callback(this);
|
||||
};
|
||||
api.addEventListener('RememberingUtils:change', function(data) {
|
||||
//console.log('RememberingUtils:change', data.detail)
|
||||
const id = data.detail.node;
|
||||
if (!(id in propertiesMapping)) {
|
||||
return;
|
||||
}
|
||||
const properties = propertiesMapping[id];
|
||||
properties.next = data.detail.next;
|
||||
// console.log('next', properties.next);
|
||||
});
|
||||
api.addEventListener('progress', function({detail}) {
|
||||
if (detail.value < detail.max) return;
|
||||
Object.values(propertiesMapping).forEach(v => {
|
||||
v.curr = v.next;
|
||||
})
|
||||
// console.log('propertiesMapping', propertiesMapping)
|
||||
})
|
||||
},
|
||||
async nodeCreated(node) {
|
||||
nodes.push(node);
|
||||
},
|
||||
async setup() {
|
||||
nodes.forEach(node => {
|
||||
const {id, properties} = node;
|
||||
propertiesMapping[id] = properties;
|
||||
});
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user