support.pyΒΆ

Part of Clear Code Zelda.

 1"""Asset loading helpers: counterparts to the upstream ``support.py``."""
 2
 3from __future__ import annotations
 4
 5import csv
 6from pathlib import Path
 7
 8from settings import ASSET_ROOT
 9
10
11def import_csv_layout(path: Path) -> list[list[str]]:
12    """Load a Tiled-style CSV layout. Cells are kept as strings (``"-1"`` = empty)."""
13    with open(path, newline="") as f:
14        return [list(row) for row in csv.reader(f, delimiter=",")]
15
16
17def import_folder(rel_path: str) -> list[str]:
18    """Return sorted absolute paths of every image in ``graphics/<rel_path>/``."""
19    folder = ASSET_ROOT / "graphics" / rel_path
20    if not folder.is_dir():
21        return []
22    files = [str(p) for p in folder.iterdir() if p.suffix.lower() in (".png", ".jpg", ".jpeg")]
23    files.sort()
24    return files