diff --git a/README.md b/README.md index 261eaa9..323389f 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ The files should end in `.txt` and each value should be on it's own line. - `prefix(STRING)`: The prefix to use - `suffix(STRING)`: The suffix to use - `regex(STRING)`: If provided this will be used to filter the input files. +- `temp_override(STRING)`: If not blank then overrides the output. +- `output_blank_ratio(FLOAT)`: A number between 0 and 1 to determine if the output should be blank. Not used if temp_override is set. ### outputs diff --git a/wildcard.py b/wildcard.py index a222b62..60303b7 100644 --- a/wildcard.py +++ b/wildcard.py @@ -56,6 +56,14 @@ class SimpleWildcard: "STRING", {"default": ".*"}, ), + "temp_override": ( + "STRING", + {"default": ""}, + ), + "output_blank_ratio": ( + "FLOAT", + {"default": 0.0, "min": 0.0, "max": 1.0, "step": 0.05}, + ), "output_text": ( "STRING", {"multiline": True, "dynamicPrompts": False, "default": ""}, @@ -69,21 +77,32 @@ class SimpleWildcard: OUTPUT_NODE = True def func(self, *args, **kwargs): + if kwargs["temp_override"] != "": + return { + "ui": {"output_text": kwargs["temp_override"]}, + "result": (kwargs["temp_override"],), + } + + rng = random.Random(kwargs["seed"]) + if rng.random() < kwargs["output_blank_ratio"]: + return { + "ui": {"output_text": ""}, + "result": ("",), + } + output_text = kwargs["input_text"] - - items = get_items_for_wildcard_path(kwargs["input_files"]) - if kwargs["regex"] != "*" or kwargs["regex"] != "": - regex = re.compile(kwargs["regex"], re.IGNORECASE) - items = list(items | where(regex.match)) - - has_items = len(items) > 0 wildcard_mode_enabled = kwargs["input_text"] == "*" should_apply_weight = kwargs["weight"] != 1 if wildcard_mode_enabled: + items = get_items_for_wildcard_path(kwargs["input_files"]) + if kwargs["regex"] != "*" or kwargs["regex"] != "": + regex = re.compile(kwargs["regex"], re.IGNORECASE) + items = list(items | where(regex.match)) + + has_items = len(items) > 0 if has_items: - random.seed(kwargs["seed"]) - output_text = random.choice(items) + output_text = rng.choice(items) else: output_text = ""