mirror of
https://github.com/justUmen/Bjornulf_custom_nodes.git
synced 2026-03-24 22:12:16 -03:00
0.39
This commit is contained in:
@@ -11,6 +11,7 @@ class WriteTextAdvanced:
|
||||
"text": ("STRING", {"multiline": True, "lines": 10}),
|
||||
},
|
||||
"optional": {
|
||||
"variables": ("STRING", {"multiline": True, "lines": 5}),
|
||||
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
|
||||
},
|
||||
}
|
||||
@@ -21,9 +22,10 @@ class WriteTextAdvanced:
|
||||
OUTPUT_NODE = True
|
||||
CATEGORY = "Bjornulf"
|
||||
|
||||
def write_text_special(self, text, seed=None):
|
||||
def write_text_special(self, text, variables="", seed=None):
|
||||
logging.info(f"Raw text: {text}")
|
||||
# If seed is not provided, generate a new one
|
||||
logging.info(f"Variables: {variables}")
|
||||
|
||||
if len(text) > 10000:
|
||||
return ("Text too large to process at once. Please split into smaller parts.",)
|
||||
|
||||
@@ -32,17 +34,30 @@ class WriteTextAdvanced:
|
||||
|
||||
random.seed(seed)
|
||||
|
||||
# Parse variables
|
||||
var_dict = {}
|
||||
for line in variables.split('\n'):
|
||||
if '=' in line:
|
||||
key, value = line.split('=', 1)
|
||||
var_dict[key.strip()] = value.strip()
|
||||
|
||||
logging.info(f"Parsed variables: {var_dict}")
|
||||
|
||||
# Replace variables
|
||||
for key, value in var_dict.items():
|
||||
text = text.replace(f"<{key}>", value)
|
||||
|
||||
# Handle random choices
|
||||
pattern = r'\{([^}]+)\}'
|
||||
|
||||
def replace_random(match):
|
||||
return random.choice(match.group(1).split('|'))
|
||||
|
||||
result = re.sub(pattern, replace_random, text)
|
||||
logging.info(f"Picked text: {result}")
|
||||
logging.info(f"Final text: {result}")
|
||||
|
||||
return (result,)
|
||||
|
||||
@classmethod
|
||||
def IS_CHANGED(s, text, seed=None):
|
||||
return (text, seed)
|
||||
|
||||
def IS_CHANGED(s, text, variables="", seed=None):
|
||||
return (text, variables, seed)
|
||||
Reference in New Issue
Block a user