Add in a way to see if the randomly selected sprite is actually valid… (#16)

* Add in a way to see if the randomly selected sprite is actually valid, and warn if it isn't, per yaml file.

* clean up code a bit, and import one less thing.
This commit is contained in:
CaitSith2 2020-01-25 16:37:29 -08:00 committed by Fabian Dill
parent 94759fd1c4
commit 4b4a27992c
1 changed files with 6 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import random
import urllib.request
import urllib.parse
import functools
import os
import ModuleUpdate
@ -16,6 +17,7 @@ try:
except ImportError:
from yaml import Loader
from Rom import get_sprite_from_name
from EntranceRandomizer import parse_arguments
from Main import main as ERmain
@ -88,7 +90,7 @@ def main():
path = getattr(args, f'p{player}') if getattr(args, f'p{player}') else args.weights
if path:
try:
settings = settings_cache[path] if settings_cache[path] else roll_settings(weights_cache[path])
settings = settings_cache[path] if settings_cache[path] else roll_settings(weights_cache[path], path)
for k, v in vars(settings).items():
if v is not None:
getattr(erargs, k)[player] = v
@ -121,7 +123,7 @@ def interpret_on_off(value):
def convert_to_on_off(value):
return {True: "on", False: "off"}.get(value, value)
def roll_settings(weights):
def roll_settings(weights, path):
def get_choice(option, root=weights):
if option not in root:
return None
@ -228,6 +230,8 @@ def roll_settings(weights):
if 'rom' in weights:
romweights = weights['rom']
ret.sprite = get_choice('sprite', romweights)
if ret.sprite is not None and not os.path.isfile(ret.sprite) and not get_sprite_from_name(ret.sprite):
logging.Logger('').warning(f"Warning: In yaml file \"{path}\", The choson sprite, \"{ret.sprite}\" does not exist.")
ret.disablemusic = get_choice('disablemusic', romweights)
ret.extendedmsu = get_choice('extendedmsu', romweights)
ret.quickswap = get_choice('quickswap', romweights)