From af14723e294835941b430c59387697ce8ef4032c Mon Sep 17 00:00:00 2001 From: wirytiox <79142532+wirytiox@users.noreply.github.com> Date: Sat, 15 Feb 2025 13:44:29 -0300 Subject: [PATCH] Add files via upload --- __init__.py | 1 + string_select.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 __init__.py create mode 100644 string_select.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..03bf803 --- /dev/null +++ b/__init__.py @@ -0,0 +1 @@ +from .string_select import * diff --git a/string_select.py b/string_select.py new file mode 100644 index 0000000..7a672bc --- /dev/null +++ b/string_select.py @@ -0,0 +1,53 @@ +import math + + +def wrapIndex(index, length): + if length == 0: + print("ezXY: Divide by zero error, returning 0.") + return 0,0 + + # Using modulo ensures the index won't go out of range, wrapping back to 0 instead + # math.fmod returns more predictable results when index is negative + index_mod = int(math.fmod(index, length)) + wraps = index//length + return index_mod, wraps + + +class StringFromList: + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "list_input": ("STRING", {"forceInput":True},), + "index": ("INT", {"default": 0, "min": -999, "max": 999, "step": 1}), + }, + } + + RETURN_TYPES = ("STRING", "INT", "INT",) + RETURN_NAMES = ("list item", "size", "wraps",) + + INPUT_IS_LIST = True + OUTPUT_IS_LIST = (True, False, True) + + FUNCTION = "pick" + + CATEGORY = "ezXY/utility" + + def pick(self, list_input, index): + length = len(list_input) + + wraps_list, item_list = [],[] + for i in index: + index_mod, wraps = wrapIndex(i, length) + wraps_list.append(wraps) + item_list.append(list_input[index_mod]) + + return (item_list, length, wraps_list,) + +NODE_CLASS_MAPPINGS = { + "StringFromList": StringFromList +} + +NODE_DISPLAY_NAME_MAPPINGS = { + "StringFromList": "String From List" +}