Check for ROMs at beginning of generation (#475)

This commit is contained in:
espeon65536 2022-04-29 20:37:28 -05:00 committed by GitHub
parent e8579771a5
commit 894a30b9bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 37 additions and 0 deletions

View File

@ -93,6 +93,8 @@ def main(args, seed=None, baked_server_options: Optional[Dict[str, object]] = No
f"Location IDs: {min(cls.location_id_to_name):{numlength}} - "
f"{max(cls.location_id_to_name):{numlength}}")
AutoWorld.call_stage(world, "assert_generate")
AutoWorld.call_all(world, "generate_early")
logger.info('')

View File

@ -426,6 +426,9 @@ In addition, the following methods can be implemented and attributes can be set
* `required_client_version: Tuple(int, int, int)`
Client version as tuple of 3 ints to make sure the client is compatible to
this world (e.g. implements all required features) when connecting.
* `assert_generate(cls, world)` is a class method called at the start of
generation to check the existence of prerequisite files, usually a ROM for
games which require one.
#### generate_early

View File

@ -171,6 +171,12 @@ class World(metaclass=AutoWorldRegister):
# can also be implemented as a classmethod and called "stage_<original_name>",
# in that case the MultiWorld object is passed as an argument and it gets called once for the entire multiworld.
# An example of this can be found in alttp as stage_pre_fill
@classmethod
def assert_generate(cls) -> None:
"""Checks that a game is capable of generating, usually checks for some base file like a ROM.
Not run for unittests since they don't produce output"""
pass
def generate_early(self) -> None:
pass

View File

@ -56,6 +56,12 @@ class ALTTPWorld(World):
self.has_progressive_bows = False
super(ALTTPWorld, self).__init__(*args, **kwargs)
@classmethod
def stage_assert_generate(cls, world):
rom_file = get_base_rom_path()
if not os.path.exists(rom_file):
raise FileNotFoundError(rom_file)
def generate_early(self):
player = self.player
world = self.world

View File

@ -89,6 +89,10 @@ class OOTWorld(World):
self.hint_data_available = threading.Event()
super(OOTWorld, self).__init__(world, player)
@classmethod
def stage_assert_generate(cls, world: MultiWorld):
rom = Rom(file=get_options()['oot_options']['rom_file'])
def generate_early(self):
# Player name MUST be at most 16 bytes ascii-encoded, otherwise won't write to ROM correctly
if len(bytes(self.world.get_player_name(self.player), 'ascii')) > 16:

View File

@ -83,6 +83,12 @@ class SMWorld(World):
self.rom_name_available_event = threading.Event()
super().__init__(world, player)
@classmethod
def stage_assert_generate(cls, world):
rom_file = get_base_rom_path()
if not os.path.exists(rom_file):
raise FileNotFoundError(rom_file)
def generate_early(self):
Logic.factory('vanilla')

View File

@ -60,6 +60,10 @@ class SMZ3World(World):
self.unreachable = []
super().__init__(world, player)
@classmethod
def stage_assert_generate(cls, world):
base_combined_rom = get_base_rom_bytes()
def generate_early(self):
config = Config({})
config.GameMode = GameMode.Multiworld

View File

@ -175,6 +175,12 @@ class SoEWorld(World):
res.trap = item.type == pyevermizer.CHECK_TRAP
return res
@classmethod
def stage_assert_generate(cls, world):
rom_file = get_base_rom_path()
if not os.path.exists(rom_file):
raise FileNotFoundError(rom_file)
def create_regions(self):
# TODO: generate *some* regions from locations' requirements?
r = Region('Menu', RegionType.Generic, 'Menu', self.player, self.world)