Skip to content

Commit 73d986b

Browse files
nex3beauxqNewSoupVi
authored andcommitted
Rules: Verify the default values of Options. (ArchipelagoMW#2403)
* Verify the default values of `Option`s. Since `Option.verify()` can handle normalization of option names, this allows options to define defaults which rely on that normalization. For example, it allows a world to exclude certain locations by default. This also makes it easier to catch errors if a world author accidentally sets an invalid default. * Update Generate.py Co-authored-by: Doug Hoskisson <[email protected]> --------- Co-authored-by: Doug Hoskisson <[email protected]> Co-authored-by: NewSoupVi <[email protected]>
1 parent 8c56b1c commit 73d986b

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Generate.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -409,19 +409,19 @@ def roll_triggers(weights: dict, triggers: list) -> dict:
409409

410410

411411
def handle_option(ret: argparse.Namespace, game_weights: dict, option_key: str, option: type(Options.Option), plando_options: PlandoOptions):
412-
if option_key in game_weights:
413-
try:
412+
try:
413+
if option_key in game_weights:
414414
if not option.supports_weighting:
415415
player_option = option.from_any(game_weights[option_key])
416416
else:
417417
player_option = option.from_any(get_choice(option_key, game_weights))
418-
setattr(ret, option_key, player_option)
419-
except Exception as e:
420-
raise Options.OptionError(f"Error generating option {option_key} in {ret.game}") from e
421418
else:
422-
player_option.verify(AutoWorldRegister.world_types[ret.game], ret.name, plando_options)
419+
player_option = option.from_any(option.default) # call the from_any here to support default "random"
420+
setattr(ret, option_key, player_option)
421+
except Exception as e:
422+
raise Options.OptionError(f"Error generating option {option_key} in {ret.game}") from e
423423
else:
424-
setattr(ret, option_key, option.from_any(option.default)) # call the from_any here to support default "random"
424+
player_option.verify(AutoWorldRegister.world_types[ret.game], ret.name, plando_options)
425425

426426

427427
def roll_settings(weights: dict, plando_options: PlandoOptions = PlandoOptions.bosses):

0 commit comments

Comments
 (0)