Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/mars_patcher/cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import argparse
import copy
import json
import typing

from mars_patcher.auto_generated_types import MarsSchema
from mars_patcher.patcher import patch, validate_patch_data


Expand All @@ -18,11 +15,9 @@ def main() -> None:
with open(args.patch_data_path, encoding="utf-8") as f:
patch_data = json.load(f)

validate_patch_data(patch_data)

patch(
args.rom_path,
args.out_path,
typing.cast(MarsSchema, copy.copy(patch_data)),
validate_patch_data(patch_data),
lambda message, progress: print(message),
)
11 changes: 7 additions & 4 deletions src/mars_patcher/patcher.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json
from typing import Callable
import typing
from os import PathLike
from typing import Callable, Union

from jsonschema import validate

Expand Down Expand Up @@ -33,7 +35,7 @@
from mars_patcher.text import write_seed_hash


def validate_patch_data(patch_data: dict) -> None:
def validate_patch_data(patch_data: dict) -> MarsSchema:
"""
Validates whether the specified patch_data satisfies the schema for it.

Expand All @@ -43,11 +45,12 @@ def validate_patch_data(patch_data: dict) -> None:
with open(get_data_path("schema.json")) as f:
schema = json.load(f)
validate(patch_data, schema)
return typing.cast(MarsSchema, patch_data)


def patch(
input_path: str,
output_path: str,
input_path: Union[str, PathLike[str]],
output_path: Union[str, PathLike[str]],
patch_data: MarsSchema,
status_update: Callable[[str, float], None],
) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/mars_patcher/rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Rom:
},
}

def __init__(self, path: str):
def __init__(self, path: Union[str, PathLike[str]]):
# Read file
with open(path, "rb") as f:
self.data = bytearray(f.read())
Expand Down