Generate: improve error message for missing game (#1857)

---------

Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com>
This commit is contained in:
Fabian Dill 2023-06-23 10:17:35 +02:00 committed by GitHub
parent f3c788d0cc
commit 78b981228a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 26 deletions

View File

@ -447,6 +447,11 @@ def roll_settings(weights: dict, plando_options: PlandoOptions = PlandoOptions.b
raise Exception(f"Option {option_key} has to be in a game's section, not on its own.") raise Exception(f"Option {option_key} has to be in a game's section, not on its own.")
ret.game = get_choice("game", weights) ret.game = get_choice("game", weights)
if ret.game not in AutoWorldRegister.world_types:
picks = Utils.get_fuzzy_results(ret.game, AutoWorldRegister.world_types, limit=1)[0]
raise Exception(f"No world found to handle game {ret.game}. Did you mean '{picks[0]}' ({picks[1]}% sure)? "
f"Check your spelling or installation of that world.")
if ret.game not in weights: if ret.game not in weights:
raise Exception(f"No game options for selected game \"{ret.game}\" found.") raise Exception(f"No game options for selected game \"{ret.game}\" found.")
@ -461,32 +466,29 @@ def roll_settings(weights: dict, plando_options: PlandoOptions = PlandoOptions.b
for option_key, option in Options.common_options.items(): for option_key, option in Options.common_options.items():
setattr(ret, option_key, option.from_any(get_choice(option_key, weights, option.default))) setattr(ret, option_key, option.from_any(get_choice(option_key, weights, option.default)))
if ret.game in AutoWorldRegister.world_types: for option_key, option in world_type.option_definitions.items():
for option_key, option in world_type.option_definitions.items(): handle_option(ret, game_weights, option_key, option, plando_options)
for option_key, option in Options.per_game_common_options.items():
# skip setting this option if already set from common_options, defaulting to root option
if option_key not in world_type.option_definitions and \
(option_key not in Options.common_options or option_key in game_weights):
handle_option(ret, game_weights, option_key, option, plando_options) handle_option(ret, game_weights, option_key, option, plando_options)
for option_key, option in Options.per_game_common_options.items(): if PlandoOptions.items in plando_options:
# skip setting this option if already set from common_options, defaulting to root option ret.plando_items = game_weights.get("plando_items", [])
if option_key not in world_type.option_definitions and \ if ret.game == "Minecraft" or ret.game == "Ocarina of Time":
(option_key not in Options.common_options or option_key in game_weights): # bad hardcoded behavior to make this work for now
handle_option(ret, game_weights, option_key, option, plando_options) ret.plando_connections = []
if PlandoOptions.items in plando_options: if PlandoOptions.connections in plando_options:
ret.plando_items = game_weights.get("plando_items", []) options = game_weights.get("plando_connections", [])
if ret.game == "Minecraft" or ret.game == "Ocarina of Time": for placement in options:
# bad hardcoded behavior to make this work for now if roll_percentage(get_choice("percentage", placement, 100)):
ret.plando_connections = [] ret.plando_connections.append(PlandoConnection(
if PlandoOptions.connections in plando_options: get_choice("entrance", placement),
options = game_weights.get("plando_connections", []) get_choice("exit", placement),
for placement in options: get_choice("direction", placement)
if roll_percentage(get_choice("percentage", placement, 100)): ))
ret.plando_connections.append(PlandoConnection( elif ret.game == "A Link to the Past":
get_choice("entrance", placement), roll_alttp_settings(ret, game_weights, plando_options)
get_choice("exit", placement),
get_choice("direction", placement)
))
elif ret.game == "A Link to the Past":
roll_alttp_settings(ret, game_weights, plando_options)
else:
raise Exception(f"Unsupported game {ret.game}")
return ret return ret

View File

@ -92,7 +92,7 @@ def roll_options(options: Dict[str, Union[dict, str]],
rolled_results[f"{filename}/{i + 1}"] = roll_settings(yaml_data, rolled_results[f"{filename}/{i + 1}"] = roll_settings(yaml_data,
plando_options=plando_options) plando_options=plando_options)
except Exception as e: except Exception as e:
results[filename] = f"Failed to generate mystery in {filename}: {e}" results[filename] = f"Failed to generate options in {filename}: {e}"
else: else:
results[filename] = True results[filename] = True
return results, rolled_results return results, rolled_results