core: fix options with "random" as default value not generating (#1033)
* core: fix options with "random" as default value not generating when option is missing from the player yaml, Using this in #893 and tested there. * remove if * OptionSets default to frozenset so handle that * range had some specific instances of assuming default as a valid value so change this here to call the from_any * isinstance instead of type Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com> Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com>
This commit is contained in:
parent
4686881566
commit
267d9234e5
|
@ -455,7 +455,7 @@ def handle_option(ret: argparse.Namespace, game_weights: dict, option_key: str,
|
||||||
else:
|
else:
|
||||||
player_option.verify(AutoWorldRegister.world_types[ret.game], ret.name, plando_options)
|
player_option.verify(AutoWorldRegister.world_types[ret.game], ret.name, plando_options)
|
||||||
else:
|
else:
|
||||||
setattr(ret, option_key, option(option.default))
|
setattr(ret, option_key, option.from_any(option.default)) # call the from_any here to support default "random"
|
||||||
|
|
||||||
|
|
||||||
def roll_settings(weights: dict, plando_options: PlandoSettings = PlandoSettings.bosses):
|
def roll_settings(weights: dict, plando_options: PlandoSettings = PlandoSettings.bosses):
|
||||||
|
|
|
@ -483,7 +483,7 @@ class Range(NumericOption):
|
||||||
if text.startswith("random"):
|
if text.startswith("random"):
|
||||||
return cls.weighted_range(text)
|
return cls.weighted_range(text)
|
||||||
elif text == "default" and hasattr(cls, "default"):
|
elif text == "default" and hasattr(cls, "default"):
|
||||||
return cls(cls.default)
|
return cls.from_any(cls.default)
|
||||||
elif text == "high":
|
elif text == "high":
|
||||||
return cls(cls.range_end)
|
return cls(cls.range_end)
|
||||||
elif text == "low":
|
elif text == "low":
|
||||||
|
@ -494,7 +494,7 @@ class Range(NumericOption):
|
||||||
and text in ("true", "false"):
|
and text in ("true", "false"):
|
||||||
# these are the conditions where "true" and "false" make sense
|
# these are the conditions where "true" and "false" make sense
|
||||||
if text == "true":
|
if text == "true":
|
||||||
return cls(cls.default)
|
return cls.from_any(cls.default)
|
||||||
else: # "false"
|
else: # "false"
|
||||||
return cls(0)
|
return cls(0)
|
||||||
return cls(int(text))
|
return cls(int(text))
|
||||||
|
@ -698,10 +698,7 @@ class OptionSet(Option[typing.Set[str]], VerifyKeys):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_any(cls, data: typing.Any):
|
def from_any(cls, data: typing.Any):
|
||||||
if type(data) == list:
|
if isinstance(data, (list, set, frozenset)):
|
||||||
cls.verify_keys(data)
|
|
||||||
return cls(data)
|
|
||||||
elif type(data) == set:
|
|
||||||
cls.verify_keys(data)
|
cls.verify_keys(data)
|
||||||
return cls(data)
|
return cls(data)
|
||||||
return cls.from_text(str(data))
|
return cls.from_text(str(data))
|
||||||
|
|
Loading…
Reference in New Issue