Mi2dRPGamEng/scripts/reimport_textures.py

53 lines
1.7 KiB
Python

#!/usr/bin/env python3
"""Copies finished art from the artist staging directory (see export_blank_textures.py) into
resources/textures/, where the game actually loads textures from at runtime - overwriting
whatever placeholder/checker art (engine/placeholder_textures.py) or earlier import currently
sits at each path.
Usage:
python scripts/reimport_textures.py [--src art_wip]
"""
from __future__ import annotations
import argparse
import shutil
from pathlib import Path
ROOT_DIR = Path(__file__).resolve().parent.parent
DEFAULT_SRC_DIR = ROOT_DIR / "art_wip"
TEXTURES_DIR = ROOT_DIR / "resources" / "textures"
def reimport_textures(src_dir: Path, textures_dir: Path) -> int:
"""Copies every file under src_dir to the same relative path under textures_dir,
overwriting anything already there. Returns how many files were copied.
"""
count = 0
for path in sorted(src_dir.rglob("*")):
if not path.is_file():
continue
relative_path = path.relative_to(src_dir)
dest = textures_dir / relative_path
dest.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(path, dest)
count += 1
return count
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"--src", type=Path, default=DEFAULT_SRC_DIR, help=f"artist staging directory (default: {DEFAULT_SRC_DIR})"
)
args = parser.parse_args()
if not args.src.exists():
raise SystemExit(f"No staging directory at {args.src} - run export_blank_textures.py first.")
count = reimport_textures(args.src, TEXTURES_DIR)
print(f"Imported {count} texture(s) into {TEXTURES_DIR}")
if __name__ == "__main__":
main()