Move character slot label policy
This commit is contained in:
@@ -2,6 +2,11 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any, Callable
|
||||
|
||||
try:
|
||||
from . import character_config as character_policy
|
||||
except ImportError: # Allows local smoke tests with top-level imports.
|
||||
import character_config as character_policy
|
||||
|
||||
|
||||
Choose = Callable[[Any, list[tuple[str, str, str]]], tuple[str, str, str]]
|
||||
|
||||
@@ -37,6 +42,30 @@ def cast_summary_phrase(women_count: int, men_count: int) -> str:
|
||||
return f"{women_count} {women_label}, {men_count} {men_label}, {person_count} total adults"
|
||||
|
||||
|
||||
def explicit_character_slot_label(slot: dict[str, Any]) -> str:
|
||||
label = str(slot.get("label") or "").strip().upper()
|
||||
if label in character_policy.CHARACTER_LABEL_CHOICES and label != "AUTO_CHAIN":
|
||||
return label
|
||||
return ""
|
||||
|
||||
|
||||
def character_slot_label_map(slots: list[dict[str, Any]]) -> dict[str, dict[str, Any]]:
|
||||
label_map: dict[str, dict[str, Any]] = {}
|
||||
letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
for subject_type, prefix in (("woman", "Woman"), ("man", "Man")):
|
||||
subject_slots = [slot for slot in slots if slot.get("subject_type") == subject_type]
|
||||
auto_slots = [slot for slot in subject_slots if not explicit_character_slot_label(slot)]
|
||||
for index, slot in enumerate(reversed(auto_slots)):
|
||||
if index >= len(letters):
|
||||
break
|
||||
label_map[f"{prefix} {letters[index]}"] = slot
|
||||
for slot in subject_slots:
|
||||
explicit = explicit_character_slot_label(slot)
|
||||
if explicit:
|
||||
label_map[f"{prefix} {explicit}"] = slot
|
||||
return label_map
|
||||
|
||||
|
||||
def configured_cast_context(women_count: int, men_count: int) -> dict[str, str]:
|
||||
women_count = max(0, int(women_count))
|
||||
men_count = max(0, int(men_count))
|
||||
|
||||
Reference in New Issue
Block a user