refactor(clew): inline object dump predicates

This commit is contained in:
2026-09-07 18:16:55 -04:00
parent 246d7d5d0e
commit 8e5ae23fd2

View File

@@ -84,15 +84,7 @@ def extract_game_files(game_root: Path, output_path: Path) -> None:
shutil.copy2(item, destination)
def is_game_root(path: Path) -> bool:
return (
(path / "game").is_dir()
and (path / "renpy").is_dir()
and (path / "lib" / "linux-x86_64" / "python").is_file()
)
def walk_directory(root: Path, predicate) -> list[Path]:
def matching_paths(root: Path, predicate) -> list[Path]:
matches = []
for current, _directories, files in os.walk(root):
current_path = Path(current)
@@ -105,10 +97,6 @@ def walk_directory(root: Path, predicate) -> list[Path]:
return sorted(matches)
def is_compiled_script(path: Path) -> bool:
return path.is_file() and path.suffix.lower() in {".rpyc", ".rpymc"}
def object_dump_output_path(output_root: Path, extracted_root: Path, game_root: Path, script: Path) -> Path:
namespace = game_root.relative_to(extracted_root)
relative_script = script.relative_to(game_root)
@@ -134,13 +122,23 @@ def run_renpy_object_dump(game_root: Path, script: Path, output: Path) -> None:
def dump_renpy_objects(output_root: Path, extracted_root: Path, overwrite: bool) -> None:
game_roots = walk_directory(extracted_root, is_game_root)
game_roots = matching_paths(
extracted_root,
lambda path: (
(path / "game").is_dir()
and (path / "renpy").is_dir()
and (path / "lib" / "linux-x86_64" / "python").is_file()
),
)
if not game_roots:
LOG.warning("no Ren'Py game roots found under %s", extracted_root)
return
for game_root in game_roots:
scripts = walk_directory(game_root / "game", is_compiled_script)
scripts = matching_paths(
game_root / "game",
lambda path: path.is_file() and path.suffix.lower() in {".rpyc", ".rpymc"},
)
LOG.info("found %d compiled Ren'Py scripts under %s", len(scripts), game_root)
total = len(scripts)
for index, script in enumerate(scripts, start=1):