Files

84 lines
2.4 KiB
Python

MAX_TEXT_SLOTS = 32
class TextSwitchStack:
@classmethod
def INPUT_TYPES(cls):
inputs = {
"required": {
"auto_comma": (
"BOOLEAN",
{
"default": True,
"tooltip": "Append an English comma to every enabled part except the last one when needed.",
},
),
"text_count": (
[str(i) for i in range(1, MAX_TEXT_SLOTS + 1)],
{
"default": "1",
"tooltip": "Number of text slots to show and process.",
},
),
},
"optional": {},
}
for i in range(1, MAX_TEXT_SLOTS + 1):
inputs["optional"][f"enabled_{i}"] = (
"BOOLEAN",
{
"default": True,
"tooltip": f"Include text {i} in the merged output.",
},
)
inputs["optional"][f"part_{i}"] = (
"STRING",
{
"default": "",
"multiline": True,
"tooltip": f"Text part {i}.",
},
)
return inputs
RETURN_TYPES = ("STRING",)
OUTPUT_TOOLTIPS = ("All enabled text slots merged into one string.",)
FUNCTION = "merge_texts"
CATEGORY = "text"
DESCRIPTION = "Merge enabled text slots into a single string."
SEARCH_ALIASES = ["text stack", "text switch", "merge text", "concat text"]
def merge_texts(self, auto_comma=True, text_count="1", **kwargs):
try:
count = int(text_count)
except (TypeError, ValueError):
count = 1
count = max(1, min(MAX_TEXT_SLOTS, count))
texts = []
for i in range(1, count + 1):
if not kwargs.get(f"enabled_{i}", True):
continue
part = kwargs.get(f"part_{i}", "")
if part:
texts.append(part)
if auto_comma:
for i in range(len(texts) - 1):
if not texts[i].endswith(","):
texts[i] = f"{texts[i]},"
return ("\n".join(texts),)
NODE_CLASS_MAPPINGS = {
"TextSwitchStack": TextSwitchStack,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"TextSwitchStack": "Text Switch Stack",
}