48 lines
2.4 KiB
Python
48 lines
2.4 KiB
Python
"""Export original scripts for the optional frontend initialization smoke test.
|
|
|
|
Run from backend, after ``app.converter.analyze --dump <dump> <original>``:
|
|
python -m tests.export_renpy_runtime <original> <dump/game-name> <runtime.json>
|
|
"""
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from app.converter.archive import find_game_dir
|
|
from app.converter.compatibility import audit_ir, blocking_names, require_supported_scripts
|
|
from app.converter.pipeline import _is_engine_file, _used_screens, anchors
|
|
from app.converter.rpy_parser import RpyParser, ScriptData
|
|
from app.converter.source import read_source
|
|
from app.games.renpy_builds import identify, prepare_source, skipped_files, waive_known
|
|
|
|
|
|
def export(original: Path, dump: Path, output: Path) -> None:
|
|
build = identify(find_game_dir(original))
|
|
data = ScriptData()
|
|
sources = {p.relative_to(dump).as_posix(): prepare_source(build, p.relative_to(dump).as_posix(), read_source(p))
|
|
for p in sorted(dump.rglob("*.rpy")) if not _is_engine_file(dump, p)
|
|
and p.relative_to(dump).as_posix().lower() not in skipped_files(build)}
|
|
for source in sources.values():
|
|
data.prescan(source)
|
|
for relative, source in sources.items():
|
|
RpyParser(data, relative).parse(source)
|
|
audit_ir(data)
|
|
waive_known(data, build)
|
|
require_supported_scripts(data)
|
|
game = dict(title=original.name, resolution=data.gui.get("resolution", [1920, 1080]), entry="start",
|
|
defaults=data.defaults, init=data.init_code, images=data.images, transforms=data.transforms,
|
|
build=data.build, atl=data.atl, blocking=blocking_names(data), characters=data.characters,
|
|
channels=data.channels, screens={n: data.screens[n] for n in _used_screens(data)}, styles=data.styles,
|
|
transitions=data.transitions, audio=data.audio, files={}, ui={}, sourceLang="en", locales={})
|
|
modules = [dict(file=p, labels=labels, anchors=anchors(labels)) for p, labels in data.modules.items()]
|
|
output.parent.mkdir(parents=True, exist_ok=True)
|
|
output.write_text(json.dumps(dict(game=game, modules=modules), ensure_ascii=False), encoding="utf-8")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("original", type=Path)
|
|
parser.add_argument("dump", type=Path)
|
|
parser.add_argument("output", type=Path)
|
|
args = parser.parse_args()
|
|
export(args.original, args.dump, args.output)
|