added a node: smart_batch_controller.py
This commit is contained in:
+5
-2
@@ -1,8 +1,11 @@
|
||||
from .smart_resize import NODE_CLASS_MAPPINGS as A, NODE_DISPLAY_NAME_MAPPINGS as A_NAMES
|
||||
from .smart_batch_resize import NODE_CLASS_MAPPINGS as B, NODE_DISPLAY_NAME_MAPPINGS as B_NAMES
|
||||
from .smart_size_multiplier import NODE_CLASS_MAPPINGS as C, NODE_DISPLAY_NAME_MAPPINGS as C_NAMES
|
||||
from .image_to_latent_size import NODE_CLASS_MAPPINGS as D, NODE_DISPLAY_NAME_MAPPINGS as D_NAMES
|
||||
from .smart_prompt_picker import NODE_CLASS_MAPPINGS as E, NODE_DISPLAY_NAME_MAPPINGS as E_NAMES
|
||||
from .smart_batch_controller import NODE_CLASS_MAPPINGS as F, NODE_DISPLAY_NAME_MAPPINGS as F_NAMES
|
||||
|
||||
NODE_CLASS_MAPPINGS = {**A, **B, **C}
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {**A_NAMES, **B_NAMES, **C_NAMES}
|
||||
NODE_CLASS_MAPPINGS = {**A, **B, **C, **D, **E, **F}
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {**A_NAMES, **B_NAMES, **C_NAMES, **D_NAMES, **E_NAMES, **F_NAMES}
|
||||
|
||||
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"]
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
class SmartBatchController:
|
||||
"""
|
||||
Craftopia — Smart Batch Controller 🎛️
|
||||
Drives batch switching and prompt index from a single incrementing counter.
|
||||
Replaces SELECT BATCH + WELKE REGEL + Math Expression + Math Int.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"counter": ("INT", {
|
||||
"default": 1,
|
||||
"min": 1,
|
||||
"max": 99999,
|
||||
"step": 1,
|
||||
"display": "number",
|
||||
"control_after_generate": "increment",
|
||||
}),
|
||||
"batch_1_total": ("INT", {"default": 5, "min": 0, "max": 999, "step": 1, "display": "number"}),
|
||||
"batch_2_total": ("INT", {"default": 8, "min": 0, "max": 999, "step": 1, "display": "number"}),
|
||||
"batch_3_total": ("INT", {"default": 0, "min": 0, "max": 999, "step": 1, "display": "number"}),
|
||||
"batch_4_total": ("INT", {"default": 0, "min": 0, "max": 999, "step": 1, "display": "number"}),
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("INT", "INT", "INT")
|
||||
RETURN_NAMES = ("select", "prompt_index", "total_all")
|
||||
FUNCTION = "control"
|
||||
CATEGORY = "Craftopia"
|
||||
OUTPUT_NODE = True
|
||||
|
||||
def control(self, counter, batch_1_total, batch_2_total, batch_3_total, batch_4_total):
|
||||
totals = [batch_1_total, batch_2_total, batch_3_total, batch_4_total]
|
||||
|
||||
# Filter out empty batches
|
||||
active = [(i, t) for i, t in enumerate(totals) if t > 0]
|
||||
total_all = sum(t for _, t in active)
|
||||
|
||||
if total_all == 0:
|
||||
return {"ui": {"text": ["no prompts"]}, "result": (0, 0, 0)}
|
||||
|
||||
# Wrap counter within total_all (1-based counter → 0-based position)
|
||||
position = (counter - 1) % total_all
|
||||
|
||||
# Find which batch and which prompt within that batch
|
||||
cumulative = 0
|
||||
batch_index = 0
|
||||
prompt_index = 0
|
||||
|
||||
for i, t in active:
|
||||
if position < cumulative + t:
|
||||
batch_index = i # 0-based → Switch select
|
||||
prompt_index = position - cumulative # 0-based within batch
|
||||
break
|
||||
cumulative += t
|
||||
|
||||
# UI label: "B2 — 3 / 8"
|
||||
batch_number = batch_index + 1
|
||||
batch_total = totals[batch_index]
|
||||
prompt_display = prompt_index + 1 # 1-based for display
|
||||
label = f"B{batch_number} — {prompt_display} / {batch_total}"
|
||||
|
||||
# prompt_index +1 because Pose node select is 0-based but we subtract 1 via Math Int
|
||||
# Actually return 0-based so user can connect directly to Pose select
|
||||
return {"ui": {"text": [label]}, "result": (batch_index, prompt_index, total_all)}
|
||||
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"SmartBatchController": SmartBatchController,
|
||||
}
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"SmartBatchController": "Smart Batch Controller 🎛️",
|
||||
}
|
||||
Reference in New Issue
Block a user