"""Featured characters and living world showcase.""" from __future__ import annotations from ui import assets from world.entities import get_all_entities from world.locations import get_location_by_id from ui.avatars import render_avatar def _location_slug(entity: dict) -> str | None: loc = get_location_by_id(entity["location_id"]) return loc["slug"] if loc else None def render_featured_characters(limit: int = 6) -> str: entities = get_all_entities(limit=50) if not entities: return "" # Prioritize characters/creatures with memory and legendary/active status def score(e: dict) -> int: s = 0 if e["type"] in ("character", "creature"): s += 3 if e.get("memory_summary"): s += 2 if e["status"] == "legendary": s += 4 if e.get("tags"): s += 1 s += min(e["days_in_realm"], 10) return s featured = sorted(entities, key=score, reverse=True)[:limit] cards = [] for entity in featured: loc = get_location_by_id(entity["location_id"]) loc_name = loc["short_description"][:60] if loc else "" loc_short = loc["name"].replace("The ", "") if loc else "Unknown" slug = loc["slug"] if loc else None avatar = render_avatar(entity, size=72, location_slug=slug) status_class = f"featured-{entity['status']}" tag = entity["tags"][0] if entity.get("tags") else entity["type"] img = assets.location_image_url(slug) bg_style = f"background-image: url('{img}');" if img else "" cards.append(f""" """) return f""" """ def render_world_vignette() -> str: from world.book_of_ages import get_entries from world.events import get_active_world_event event = get_active_world_event() if event: effect = (event.get("entity_effect") or "").strip() mystery = (event.get("mystery_hook") or "").strip() chronicle = (event.get("book_of_ages_entry") or "").strip() parts = [] if effect: parts.append(f"

On the souls: {effect}

") if mystery: parts.append(f"

Whispered omen: {mystery}

") if not parts and chronicle: parts.append(f"

{chronicle}

") body = "".join(parts) if parts else ( "

The hour shifts — watch the map and chronicle for what stirs.

" ) return f"""

Ripples through the Garden

{body}
""" entries = get_entries(limit=1, entry_type="interaction") if entries: return f"""

Recently, in the Garden

{entries[0]['content']}

""" return """

You stand at the threshold

The lanterns are lit. Someone left footprints in the moss. The world has been waiting. Add something — and it will remember you.

"""