compress the mf (#1267)

This commit is contained in:
NotSoToothless
2026-05-24 19:44:12 -07:00
committed by GitHub
parent 99a43e398e
commit 9c6ca3bcd7
7 changed files with 50 additions and 41 deletions
+12 -4
View File
@@ -532,7 +532,11 @@ def _clean_map_key(raw: str) -> str:
def _load_json_file(path: Path) -> dict | None:
try:
return json.loads(path.read_text())
import gzip as _gzip
raw = path.read_bytes()
if path.suffix == ".gz":
raw = _gzip.decompress(raw)
return json.loads(raw)
except Exception as e:
print(f" Failed to parse {path.name}: {e}")
return None
@@ -3279,8 +3283,12 @@ def _convert_local_replay_to_render_dict(replay: dict[str, Any]) -> dict[str, An
def load_gob_file(replay_path: Path) -> dict[str, Any]:
"""Load a replay .json file and normalize it for render/export routines."""
data = json.loads(replay_path.read_text(encoding="utf-8"))
"""Load a replay .json or .json.gz file and normalize it for render/export routines."""
import gzip as _gzip
raw = replay_path.read_bytes()
if replay_path.suffix == ".gz":
raw = _gzip.decompress(raw)
data = json.loads(raw.decode("utf-8"))
if isinstance(data, dict) and {"Players", "Entities", "Mission"}.issubset(data.keys()):
return data
if isinstance(data, dict):
@@ -3585,7 +3593,7 @@ def main():
if args.replay:
replay_path = Path(args.replay)
else:
candidates = sorted(REPLAYS_DIR.glob("*/replay_data.json"))
candidates = sorted(REPLAYS_DIR.glob("*/replay_data.json.gz"))
if not candidates:
candidates = sorted(REPLAYS_DIR.glob("*.json"))
if not candidates: