always check legal range for Range
This commit is contained in:
parent
821b0f0f92
commit
622f8f8158
25
Options.py
25
Options.py
|
@ -109,11 +109,17 @@ class Choice(Option):
|
||||||
return cls(data)
|
return cls(data)
|
||||||
return cls.from_text(str(data))
|
return cls.from_text(str(data))
|
||||||
|
|
||||||
|
|
||||||
class Range(Option):
|
class Range(Option):
|
||||||
range_start = 0
|
range_start = 0
|
||||||
range_end = 1
|
range_end = 1
|
||||||
def __init__(self, value: typing.Union[str, int]):
|
|
||||||
self.value: typing.Union[str, int] = value
|
def __init__(self, value: int):
|
||||||
|
if value < self.range_start:
|
||||||
|
raise Exception(f"{value} is lower than minimum {self.range_start} for option {self.__class__.__name__}")
|
||||||
|
elif value > self.range_end:
|
||||||
|
raise Exception(f"{value} is higher than maximum {self.range_end} for option {self.__class__.__name__}")
|
||||||
|
self.value: int = value
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_text(cls, text: str) -> Range:
|
def from_text(cls, text: str) -> Range:
|
||||||
|
@ -125,13 +131,7 @@ class Range(Option):
|
||||||
return cls(int(round(random.triangular(cls.range_start, cls.range_end, cls.range_end), 0)))
|
return cls(int(round(random.triangular(cls.range_start, cls.range_end, cls.range_end), 0)))
|
||||||
else:
|
else:
|
||||||
return cls(random.randint(cls.range_start, cls.range_end))
|
return cls(random.randint(cls.range_start, cls.range_end))
|
||||||
number = int(text)
|
return cls(int(text))
|
||||||
if number < cls.range_start:
|
|
||||||
raise Exception(f"{number} is lower than minimum {cls.range_start} for option {cls.__name__}")
|
|
||||||
elif number > cls.range_end:
|
|
||||||
raise Exception(f"{number} is higher than maximum {cls.range_end} for option {cls.__name__}")
|
|
||||||
else:
|
|
||||||
return cls(number)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_any(cls, data: typing.Any) -> Range:
|
def from_any(cls, data: typing.Any) -> Range:
|
||||||
|
@ -139,6 +139,7 @@ class Range(Option):
|
||||||
return cls(data)
|
return cls(data)
|
||||||
return cls.from_text(str(data))
|
return cls.from_text(str(data))
|
||||||
|
|
||||||
|
|
||||||
class OptionNameSet(Option):
|
class OptionNameSet(Option):
|
||||||
default = frozenset()
|
default = frozenset()
|
||||||
|
|
||||||
|
@ -172,6 +173,7 @@ class OptionDict(Option):
|
||||||
def get_option_name(self):
|
def get_option_name(self):
|
||||||
return str(self.value)
|
return str(self.value)
|
||||||
|
|
||||||
|
|
||||||
class Logic(Choice):
|
class Logic(Choice):
|
||||||
option_no_glitches = 0
|
option_no_glitches = 0
|
||||||
option_minor_glitches = 1
|
option_minor_glitches = 1
|
||||||
|
@ -207,14 +209,17 @@ class Crystals(Range):
|
||||||
range_start = 0
|
range_start = 0
|
||||||
range_end = 7
|
range_end = 7
|
||||||
|
|
||||||
|
|
||||||
class TriforcePieces(Range):
|
class TriforcePieces(Range):
|
||||||
range_start = 1
|
range_start = 1
|
||||||
range_end = 90
|
range_end = 90
|
||||||
|
|
||||||
|
|
||||||
class ShopShuffleSlots(Range):
|
class ShopShuffleSlots(Range):
|
||||||
range_start = 0
|
range_start = 0
|
||||||
range_end = 30
|
range_end = 30
|
||||||
|
|
||||||
|
|
||||||
class WorldState(Choice):
|
class WorldState(Choice):
|
||||||
option_standard = 1
|
option_standard = 1
|
||||||
option_open = 0
|
option_open = 0
|
||||||
|
@ -358,6 +363,7 @@ class Visibility(Choice):
|
||||||
option_sending = 1
|
option_sending = 1
|
||||||
default = 1
|
default = 1
|
||||||
|
|
||||||
|
|
||||||
class RecipeTime(Choice):
|
class RecipeTime(Choice):
|
||||||
option_vanilla = 0
|
option_vanilla = 0
|
||||||
option_fast = 1
|
option_fast = 1
|
||||||
|
@ -365,6 +371,7 @@ class RecipeTime(Choice):
|
||||||
option_slow = 4
|
option_slow = 4
|
||||||
option_chaos = 5
|
option_chaos = 5
|
||||||
|
|
||||||
|
|
||||||
class FactorioStartItems(OptionDict):
|
class FactorioStartItems(OptionDict):
|
||||||
default = {"burner-mining-drill": 19, "stone-furnace": 19}
|
default = {"burner-mining-drill": 19, "stone-furnace": 19}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue