support.pyΒΆ

Part of PirateMaker.

 1"""Asset / animation helpers for the PirateMaker port."""
 2
 3from __future__ import annotations
 4
 5from pathlib import Path
 6
 7
 8def folder_frames(path: Path | str) -> list[str]:
 9    """List all PNGs in a folder, sorted, returned as absolute path strings.
10
11    Mirrors upstream `import_folder` -- one folder = one animation.
12    """
13    p = Path(path)
14    if not p.is_dir():
15        return []
16    return [str(child) for child in sorted(p.iterdir()) if child.suffix.lower() == ".png"]
17
18
19def folder_dict(path: Path | str) -> dict[str, str]:
20    """Map filename-stem -> absolute path for every PNG in a folder.
21
22    Used for the auto-tiling land-tiles dictionary (`ABCDE.png` -> path).
23    """
24    p = Path(path)
25    if not p.is_dir():
26        return {}
27    return {child.stem: str(child) for child in p.iterdir() if child.suffix.lower() == ".png"}
28
29
30def palm_subfolders(palm_dir: Path | str) -> dict[str, list[str]]:
31    """Return {name: frames} for every palm subfolder."""
32    p = Path(palm_dir)
33    return {sub.name: folder_frames(sub) for sub in p.iterdir() if sub.is_dir()}
34
35
36def player_subfolders(player_dir: Path | str) -> dict[str, list[str]]:
37    """Return {state_orientation: frames} -- e.g. 'idle_right' -> [..]"""
38    p = Path(player_dir)
39    return {sub.name: folder_frames(sub) for sub in p.iterdir() if sub.is_dir()}
40
41
42def tooth_subfolders(tooth_dir: Path | str) -> dict[str, list[str]]:
43    """Same shape as player, for tooth idle/run_left/run_right."""
44    return player_subfolders(tooth_dir)
45
46
47def shell_subfolders(shell_dir: Path | str) -> dict[str, list[str]]:
48    """Shell attack/idle frames."""
49    return player_subfolders(shell_dir)