A bad merge left Git conflict markers in __init__.py, breaking import (SyntaxError) for anyone cloning the repo. Resolved by keeping the Region Variant import + registration; no other changes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
132 lines
4.7 KiB
Python
132 lines
4.7 KiB
Python
"""
|
|
ComfyUI-Momo-Nodes
|
|
Custom nodes for ComfyUI by Momo.
|
|
"""
|
|
|
|
import os
|
|
import logging
|
|
import folder_paths
|
|
|
|
logger = logging.getLogger("MomoNodes")
|
|
|
|
# ─────────────────────────────────────────────
|
|
# Node imports from nodes/ directory
|
|
# ─────────────────────────────────────────────
|
|
|
|
# Each module in nodes/ exports its node classes.
|
|
# We import them here and register them in NODE_CONFIG.
|
|
|
|
try:
|
|
from .nodes.rgb_mask_editor import RGBMaskEditor, RGBMaskSplitter
|
|
except ImportError as e:
|
|
logger.warning(f"MomoNodes: RGB Mask Editor nodes could not be imported. Error: {e}")
|
|
RGBMaskEditor = None
|
|
RGBMaskSplitter = None
|
|
|
|
try:
|
|
from .nodes.conditioning_mask_combine_dynamic import ConditioningMaskCombineDynamic
|
|
except ImportError as e:
|
|
logger.warning(f"MomoNodes: ConditioningMaskCombineDynamic could not be imported. Error: {e}")
|
|
ConditioningMaskCombineDynamic = None
|
|
|
|
try:
|
|
from .nodes.region_variant import RegionSelectNode, RegionStitchNode
|
|
except ImportError as e:
|
|
logger.warning(f"MomoNodes: Region Variant nodes could not be imported. Error: {e}")
|
|
RegionSelectNode = None
|
|
RegionStitchNode = None
|
|
|
|
# ─────────────────────────────────────────────
|
|
# NODE_CONFIG: central registry
|
|
# ─────────────────────────────────────────────
|
|
# Format: "InternalName": { "class": NodeClass, "name": "Display Name" }
|
|
# The "name" field is optional — if omitted, InternalName is used as display name.
|
|
|
|
NODE_CONFIG = {}
|
|
|
|
# ── RGB Mask Editor ──
|
|
if RGBMaskEditor is not None:
|
|
NODE_CONFIG["RGBMaskEditor"] = {
|
|
"class": RGBMaskEditor,
|
|
"name": "RGB Mask Editor ✏️",
|
|
}
|
|
|
|
if RGBMaskSplitter is not None:
|
|
NODE_CONFIG["RGBMaskSplitter"] = {
|
|
"class": RGBMaskSplitter,
|
|
"name": "RGB Mask Splitter 🔀",
|
|
}
|
|
|
|
# ── Conditioning Mask Combine (dynamic) ──
|
|
if ConditioningMaskCombineDynamic is not None:
|
|
NODE_CONFIG["ConditioningMaskCombineDynamic"] = {
|
|
"class": ConditioningMaskCombineDynamic,
|
|
"name": "Conditioning Mask Combine (dynamic) 🎭",
|
|
}
|
|
|
|
# ── Region Variant (crop region + prompt / stitch variant back) ──
|
|
if RegionSelectNode is not None:
|
|
NODE_CONFIG["RegionSelect"] = {
|
|
"class": RegionSelectNode,
|
|
"name": "Region Select ✂️",
|
|
}
|
|
|
|
if RegionStitchNode is not None:
|
|
NODE_CONFIG["RegionStitch"] = {
|
|
"class": RegionStitchNode,
|
|
"name": "Region Stitch 🧩",
|
|
}
|
|
|
|
# ── Add future nodes here ──
|
|
# Example:
|
|
# try:
|
|
# from .nodes.my_new_node import MyNewNode
|
|
# except ImportError as e:
|
|
# logger.warning(f"MomoNodes: MyNewNode could not be imported. Error: {e}")
|
|
# MyNewNode = None
|
|
#
|
|
# if MyNewNode is not None:
|
|
# NODE_CONFIG["MyNewNode"] = {
|
|
# "class": MyNewNode,
|
|
# "name": "My New Node 🚀",
|
|
# }
|
|
|
|
|
|
# ─────────────────────────────────────────────
|
|
# Generate mappings for ComfyUI
|
|
# ─────────────────────────────────────────────
|
|
|
|
def generate_node_mappings(config):
|
|
"""Generate NODE_CLASS_MAPPINGS and NODE_DISPLAY_NAME_MAPPINGS from NODE_CONFIG."""
|
|
class_mappings = {}
|
|
display_mappings = {}
|
|
|
|
for node_id, info in config.items():
|
|
if info.get("class") is not None:
|
|
class_mappings[node_id] = info["class"]
|
|
display_mappings[node_id] = info.get("name", node_id)
|
|
|
|
return class_mappings, display_mappings
|
|
|
|
|
|
NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS = generate_node_mappings(NODE_CONFIG)
|
|
|
|
# ─────────────────────────────────────────────
|
|
# Web extensions directory (JS files)
|
|
# ─────────────────────────────────────────────
|
|
|
|
WEB_DIRECTORY = "./js"
|
|
|
|
# ─────────────────────────────────────────────
|
|
# Exports
|
|
# ─────────────────────────────────────────────
|
|
|
|
__all__ = [
|
|
"NODE_CLASS_MAPPINGS",
|
|
"NODE_DISPLAY_NAME_MAPPINGS",
|
|
"WEB_DIRECTORY",
|
|
]
|
|
|
|
total = len(NODE_CLASS_MAPPINGS)
|
|
logger.info(f"MomoNodes: Loaded {total} node{'s' if total != 1 else ''}.")
|