"""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"""
{loc_short}
{entity['appearance'][:140]}…
"{entity['greeting'][:90]}{'…' if len(entity['greeting']) > 90 else ''}"{f'
{entity["memory_summary"][:100]}…
' if entity.get("memory_summary") else ''}Real inhabitants — each with their own wants, fears, and memories
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}Recently, in the Garden
{entries[0]['content']}
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.