From d3f3708a0d6e643ec7a47f2c811efb93443b0fdb Mon Sep 17 00:00:00 2001 From: GTSuya Studio Date: Sun, 19 Nov 2023 23:25:39 -0500 Subject: [PATCH] add wildcards node --- __init__.py | 1 + gtsuya_nodes.py | 43 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/__init__.py b/__init__.py index 919b8fe..177bcd3 100644 --- a/__init__.py +++ b/__init__.py @@ -9,6 +9,7 @@ from .gtsuya_nodes import * NODE_CLASS_MAPPINGS = { "Simple Wildcards": SimpleWildcards, "Simple Wildcards (Dir.)": SimpleWildcardsDir, + "Wildcards": Wildcards, } __all__ = ['NODE_CLASS_MAPPINGS'] diff --git a/gtsuya_nodes.py b/gtsuya_nodes.py index 1b39c36..404a9c1 100644 --- a/gtsuya_nodes.py +++ b/gtsuya_nodes.py @@ -49,7 +49,7 @@ class SimpleWildcards: if not lines: myline = "" else: - myline = random.choice(lines).lower() + myline = random.choice(lines) print(myline) text = text.replace('__'+wildcard+'__',myline) @@ -82,7 +82,7 @@ class SimpleWildcardsDir: if not lines: myline = "" else: - myline = random.choice(lines).lower() + myline = random.choice(lines) print(myline) text = text.replace('__'+wildcard+'__',myline) @@ -90,8 +90,47 @@ class SimpleWildcardsDir: #---------------------------------------------------------------------------------------------------------------------------------------------------# +class Wildcards: + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "text": ("STRING", {"multiline": True}), + }, + "optional": { + "str1": ("STRING", {"forceInput": True}), + "str2": ("STRING", {"forceInput": True}), + "str3": ("STRING", {"forceInput": True}), + "str4": ("STRING", {"forceInput": True}), + "str5": ("STRING", {"forceInput": True}), + } + } + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("text",) + FUNCTION = "get_value" + CATEGORY = "gtsuya/wildcards" + + def get_value(self, text, str1=None, str2=None, str3=None, str4=None, str5=None): + + if str1: + text = text.replace('__str1__',str1) + if str2: + text = text.replace('__str2__',str2) + if str3: + text = text.replace('__str3__',str3) + if str4: + text = text.replace('__str4__',str4) + if str5: + text = text.replace('__str5__',str5) + + return (text,) + +#---------------------------------------------------------------------------------------------------------------------------------------------------# + # A dictionary that contains the friendly/humanly readable titles for the nodes NODE_DISPLAY_NAME_MAPPINGS = { "SimpleWildcards": "Simple Wildcards", "SimpleWildcardsDir": "Simple Wildcards (Dir.)", + "Wildcards": "Wildcards", }