Preserve location route metadata

This commit is contained in:
2026-06-27 13:21:51 +02:00
parent 63e8489fb2
commit 75a71a2df6
9 changed files with 215 additions and 24 deletions
+38 -2
View File
@@ -89,8 +89,31 @@ def _choose_pair(rng: random.Random, items: list[Any]) -> tuple[str, str]:
return _pair_from(_weighted_choice(rng, items))
def _metadata_entry(value: Any, *, slug: str = "", text: str = "") -> dict[str, Any]:
if isinstance(value, dict):
entry = dict(value)
elif isinstance(value, (list, tuple)) and len(value) == 2:
entry = {"slug": str(value[0]), "prompt": str(value[1])}
else:
entry = {"prompt": str(value or "")}
if slug:
entry["slug"] = slug
if text:
if "prompt" in entry:
entry["prompt"] = text
elif "text" in entry:
entry["text"] = text
else:
entry["prompt"] = text
return entry
def _choose_text(rng: random.Random, items: list[Any]) -> str:
item = _weighted_choice(rng, items)
return _text_from_entry(item)
def _text_from_entry(item: Any) -> str:
if isinstance(item, dict):
return str(
item.get("template")
@@ -134,13 +157,22 @@ def apply_location_config_to_legacy_row(
else:
choices = location_entries
scene_rng = seed_policy.axis_rng(seed_config, "scene", seed, row_number)
scene_slug, scene_text = _choose_pair(scene_rng, choices)
scene_choice = _weighted_choice(scene_rng, choices)
scene_slug, scene_text = _pair_from(scene_choice)
scene_entry = _metadata_entry(scene_choice, slug=scene_slug, text=scene_text)
old_slug = str(row.get("scene") or "")
old_text = legacy_scene_text_for_slug(old_slug)
row["source_scene"] = old_slug
row["source_scene_text"] = old_text
row["scene"] = scene_slug
row["scene_text"] = scene_text
row["scene_entry"] = scene_entry
row["location_theme"] = str(location_config.get("theme") or "")
row["scene_theme"] = scene_entry.get("theme", "") or (
str(location_config.get("theme") or "")
if location_config.get("apply_mode") == "replace"
else ""
)
row["location_config"] = location_config
if old_text:
row["prompt"] = str(row.get("prompt") or "").replace(f"Scene: {old_text}.", f"Scene: {scene_text}.")
@@ -178,12 +210,16 @@ def apply_composition_config_to_legacy_row(
else:
choices = composition_entries
composition_rng = seed_policy.axis_rng(seed_config, "composition", seed, row_number)
new_composition = _choose_text(composition_rng, choices)
composition_choice = _weighted_choice(composition_rng, choices)
new_composition = _text_from_entry(composition_choice)
composition_entry = _metadata_entry(composition_choice, text=new_composition)
old_composition = str(row.get("composition") or "")
old_prompt_fragment = f"Composition: vertical {old_composition}."
new_prompt_fragment = f"Composition: {row_camera.composition_prompt(new_composition)}."
row["source_composition"] = old_composition
row["composition"] = new_composition
row["composition_entry"] = composition_entry
row["composition_theme"] = str(composition_config.get("theme") or "")
row["composition_prompt"] = row_camera.composition_prompt(new_composition)
row["composition_config"] = composition_config
if old_composition: