Skip to content

Commit 7ef6d62

Browse files
author
Mateo Mongour
committed
Refactor version check into its own function, add IncompatiblePatchError
1 parent a4d86ae commit 7ef6d62

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

Patch.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
ModuleUpdate.update()
1010

1111
from worlds.Files import AutoPatchRegister, APAutoPatchInterface
12-
from worlds.AutoWorld import AutoWorldRegister
13-
from Utils import messagebox
1412

1513

1614
class RomMeta(TypedDict):
@@ -19,18 +17,16 @@ class RomMeta(TypedDict):
1917
player_name: str
2018

2119

20+
class IncompatiblePatchError(Exception):
21+
pass
22+
23+
2224
def create_rom_file(patch_file: str) -> Tuple[RomMeta, str]:
2325
auto_handler = AutoPatchRegister.get_handler(patch_file)
2426
if auto_handler:
2527
handler: APAutoPatchInterface = auto_handler(patch_file)
2628
handler.read()
27-
game_version = AutoWorldRegister.world_types[handler.game].world_version if handler.game else None
28-
if game_version and handler.world_version and game_version != handler.world_version:
29-
info_msg = "This patch was generated with " \
30-
f"{handler.game} version {handler.world_version.as_simple_string()}, " \
31-
f"but its currently installed version is {game_version.as_simple_string()}. " \
32-
"You may encounter errors while patching or connecting."
33-
messagebox("APWorld version mismatch", info_msg, False)
29+
handler.verify_version()
3430
target = os.path.splitext(patch_file)[0]+handler.result_file_ending
3531
handler.patch(target)
3632
return {"server": handler.server,

worlds/Files.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,22 @@ class APAutoPatchInterface(APPatch, abc.ABC, metaclass=AutoPatchRegister):
288288
def patch(self, target: str) -> None:
289289
""" create the output file with the file name `target` """
290290

291+
def verify_version(self) -> None:
292+
"""
293+
Verify compatibility between a game's currently installed
294+
world version and the version used for generation.
295+
Warns the user or raises an IncompatiblePatchError if the versions are too different.
296+
"""
297+
from Utils import messagebox
298+
from .AutoWorld import AutoWorldRegister
299+
game_version = AutoWorldRegister.world_types[self.game].world_version if self.game else None
300+
if game_version and self.world_version and game_version != self.world_version:
301+
info_msg = "This patch was generated with " \
302+
f"{self.game} version {self.world_version.as_simple_string()}, " \
303+
f"but its currently installed version is {game_version.as_simple_string()}. " \
304+
"You may encounter errors while patching or connecting."
305+
messagebox("APWorld version mismatch", info_msg, False)
306+
291307

292308
class APProcedurePatch(APAutoPatchInterface):
293309
"""

0 commit comments

Comments
 (0)