diff --git a/__init__.py b/__init__.py index c3cb656..468275a 100644 --- a/__init__.py +++ b/__init__.py @@ -3,20 +3,22 @@ from .layered_infinite_zoom import LayeredInfiniteZoom from .replicate_Flux_Pro_Ultra import ReplicateAPI_flux_1_1_pro_ultra from .replicate_Flux_Fill import ReplicateAPI_flux_fill_pro from .iframe_view import IframeView - +from .queue_counter_reset import DynamicQueueCounter WEB_DIRECTORY = "./js" NODE_CLASS_MAPPINGS = { "LayeredInfiniteZoom": LayeredInfiniteZoom, "ReplicateAPI_flux_1_1_pro_ultra": ReplicateAPI_flux_1_1_pro_ultra, "ReplicateAPI_flux_fill_pro": ReplicateAPI_flux_fill_pro, - "IframeView": IframeView + "IframeView": IframeView, + "DynamicQueueCounter": DynamicQueueCounter } NODE_DISPLAY_NAME_MAPPINGS = { "LayeredInfiniteZoom": "Layered Infinite Zoom", "ReplicateAPI_flux_1_1_pro_ultra": "Replicate flux 1.1 pro ultra", "ReplicateAPI_flux_fill_pro": "Replicate flux fill pro", - "IframeView": "Iframe View" + "IframeView": "Iframe View", + "DynamicQueueCounter": "Dynamic Queue Counter" } __all__ = [ diff --git a/__pycache__/__init__.cpython-312.pyc b/__pycache__/__init__.cpython-312.pyc index 03eebb9..929978e 100644 Binary files a/__pycache__/__init__.cpython-312.pyc and b/__pycache__/__init__.cpython-312.pyc differ diff --git a/__pycache__/queue_counter_reset.cpython-312.pyc b/__pycache__/queue_counter_reset.cpython-312.pyc new file mode 100644 index 0000000..7408de1 Binary files /dev/null and b/__pycache__/queue_counter_reset.cpython-312.pyc differ diff --git a/queue_counter_reset.py b/queue_counter_reset.py new file mode 100644 index 0000000..a12b514 --- /dev/null +++ b/queue_counter_reset.py @@ -0,0 +1,67 @@ +# Define a global counter variable that persists across executions. +global_counter = 0 + +class DynamicQueueCounter: + # This flag informs ComfyUI that this node should always run. + ALWAYS_RUN = True + + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + # Widget shows start as 0, but we subtract 1 internally. + "start": ("FLOAT", {"default": 0.0}), + # Widget shows stop as 3, but we subtract 1.5 internally. + "stop": ("FLOAT", {"default": 3.0}), + "step": ("FLOAT", {"default": 1.0}), + } + } + + RETURN_TYPES = ("FLOAT", "INT", "STRING") + RETURN_NAMES = ("FLOAT", "INT", "Info") + FUNCTION = "node" + CATEGORY = "custom.number" + + @classmethod + def IS_CHANGED(cls, **kwargs): + # Always return NaN so that ComfyUI re-runs this node each prompt. + return float("NaN") + + def node(self, start, stop, step): + # Adjust widget values internally. + internal_start = float(start) - 1.0 + internal_stop = float(stop) - 1.5 + + # Initialize the counter on first run. + if not hasattr(self, "counter"): + self.counter = internal_start + print("SimpleNumberCounter: Initialized counter =", self.counter) + + current = self.counter + + # If no step, do not change the counter. + if step == 0: + info = f"Output: {current}. Step is 0, counter remains unchanged." + return float(current), int(current), info + + # Determine the counting mode based on internal_start vs internal_stop. + if internal_start < internal_stop: # Increment mode + next_value = self.counter + step + if next_value >= internal_stop: + output = internal_stop + # Reset to the internal start after outputting the stop value. + self.counter = internal_start + else: + output = self.counter + self.counter = next_value + else: # Decrement mode + next_value = self.counter - step + if next_value <= internal_stop: + output = internal_stop + self.counter = internal_start + else: + output = self.counter + self.counter = next_value + + info = f"Output: {output}. Next will be {self.counter}." + return float(output), int(output), info \ No newline at end of file