Add Krea2 formatting and scalable scene pools
This commit is contained in:
+47
-1
@@ -202,6 +202,14 @@ def _list_from(value: Any) -> list[Any]:
|
||||
return [value]
|
||||
|
||||
|
||||
def _is_false(value: Any) -> bool:
|
||||
if isinstance(value, bool):
|
||||
return value is False
|
||||
if isinstance(value, str):
|
||||
return value.strip().lower() in ("false", "0", "no", "off")
|
||||
return False
|
||||
|
||||
|
||||
def _unique_extend(target: list[Any], additions: list[Any]) -> None:
|
||||
seen = set()
|
||||
for item in target:
|
||||
@@ -554,6 +562,24 @@ def load_category_library() -> list[dict[str, Any]]:
|
||||
return categories
|
||||
|
||||
|
||||
def load_scene_pool_library() -> dict[str, list[Any]]:
|
||||
pools: dict[str, list[Any]] = {}
|
||||
for path in _json_files():
|
||||
data = _read_json(path)
|
||||
raw_pools = data.get("scene_pools", {})
|
||||
if not raw_pools:
|
||||
continue
|
||||
if not isinstance(raw_pools, dict):
|
||||
raise ValueError(f"scene_pools in {path} must be an object")
|
||||
for name, entries in raw_pools.items():
|
||||
pool_name = str(name).strip()
|
||||
if not pool_name:
|
||||
continue
|
||||
pools.setdefault(pool_name, [])
|
||||
_unique_extend(pools[pool_name], _list_from(entries))
|
||||
return pools
|
||||
|
||||
|
||||
def _extension_targets() -> dict[str, tuple[list[Any], bool]]:
|
||||
return {
|
||||
"women_clothes": (g.WOMEN_CLOTHES, False),
|
||||
@@ -1335,7 +1361,27 @@ def _subject_context(
|
||||
|
||||
def _scene_pool(category: dict[str, Any], subcategory: dict[str, Any], item: Any, subject_type: str) -> list[Any]:
|
||||
fallback = g.GROUP_SCENES if subject_type in ("group", "configured_cast") else g.SCENES
|
||||
return _list_from(_merged_field(category, subcategory, item, "scenes", fallback))
|
||||
scene_entries: list[Any] = []
|
||||
scene_pools = load_scene_pool_library()
|
||||
item_source = item if isinstance(item, dict) else None
|
||||
if item_source is not None and _is_false(item_source.get("inherit_scenes")):
|
||||
sources = (item_source,)
|
||||
elif _is_false(subcategory.get("inherit_scenes")):
|
||||
sources = (subcategory, item_source)
|
||||
else:
|
||||
sources = (category, subcategory, item_source)
|
||||
for source in sources:
|
||||
if not isinstance(source, dict):
|
||||
continue
|
||||
if "scenes" in source:
|
||||
_unique_extend(scene_entries, _list_from(source["scenes"]))
|
||||
refs = _list_from(source.get("scene_pool")) + _list_from(source.get("scene_pools"))
|
||||
for ref in refs:
|
||||
ref_name = str(ref).strip()
|
||||
if ref_name not in scene_pools:
|
||||
raise ValueError(f"Unknown scene pool '{ref_name}'")
|
||||
_unique_extend(scene_entries, scene_pools[ref_name])
|
||||
return scene_entries or fallback
|
||||
|
||||
|
||||
def _pose_pool(category: dict[str, Any], subcategory: dict[str, Any], item: Any, subject_type: str, poses: str) -> list[Any]:
|
||||
|
||||
Reference in New Issue
Block a user