Source code for aianim.assets
"""Dynamic asset discovery and environment inspection for AI prompts and agents."""
from pathlib import Path
from typing import Any
import handanim.stylings.color as color_module
from handanim.stylings.fonts import get_font_info, get_font_path, list_fonts
[docs]
def get_available_assets() -> dict[str, Any]:
"""Scan and return available fonts, colors, and asset files."""
repo_root = Path(__file__).resolve().parent.parent.parent
assets_dir = repo_root / "assets"
legacy_examples_assets_dir = repo_root / "examples" / "assets"
ttf_fonts = []
custom_json_fonts = []
hershey_fonts = []
# Use the renderer's registry so reported names work as font_name values.
# This also includes registered user fonts and resolves assets/fonts correctly.
for name in list_fonts():
info = get_font_info(name)
if info["type"] == "hershey":
hershey_fonts.append(name)
elif Path(get_font_path(name)).is_file():
if info["type"] == "ttf":
ttf_fonts.append(name)
elif info["type"] == "custom":
custom_json_fonts.append(name)
# Extract color names
colors = [
name
for name in dir(color_module)
if name.isupper() and not name.startswith("_") and isinstance(getattr(color_module, name), (tuple, list))
]
# Discover image / SVG assets
media_assets = []
for search_dir in (assets_dir, legacy_examples_assets_dir):
if search_dir.exists():
for p in search_dir.rglob("*"):
if p.is_file() and p.suffix.lower() in (".svg", ".png", ".jpg", ".jpeg"):
media_assets.append(str(p.relative_to(repo_root)))
return {
"fonts": {
"ttf": sorted(ttf_fonts),
"custom_json": sorted(custom_json_fonts),
"hershey": sorted(hershey_fonts),
},
"colors": sorted(colors),
"media_assets": sorted(media_assets),
}