clean up some spoiler display names

This commit is contained in:
Fabian Dill 2021-08-03 19:03:41 +02:00
parent d1c83ffc09
commit 230d9d993e
3 changed files with 24 additions and 10 deletions

View File

@ -1298,7 +1298,7 @@ class Spoiler():
for f_option, option in options.items():
res = getattr(self.world, f_option)[player]
displayname = getattr(option, "displayname", f_option)
outfile.write(f'{displayname+":":33}{bool_to_text(res) if type(res) == Options.Toggle else res.get_option_name()}\n')
outfile.write(f'{displayname + ":":33}{res.get_option_name()}\n')
if player in self.world.get_game_players("A Link to the Past"):
for team in range(self.world.teams):

View File

@ -7,6 +7,7 @@ class AssembleOptions(type):
def __new__(mcs, name, bases, attrs):
options = attrs["options"] = {}
name_lookup = attrs["name_lookup"] = {}
# merge parent class options
for base in bases:
if hasattr(base, "options"):
options.update(base.options)
@ -30,24 +31,32 @@ class AssembleOptions(type):
attrs["__init__"] = validate_decorator(attrs["__init__"])
return super(AssembleOptions, mcs).__new__(mcs, name, bases, attrs)
class Option(metaclass=AssembleOptions):
value: int
name_lookup: typing.Dict[int, str]
default = 0
def __repr__(self):
# convert option_name_long into Name Long as displayname, otherwise name_long is the result.
# Handled in get_option_name()
autodisplayname = False
def __repr__(self) -> str:
return f"{self.__class__.__name__}({self.get_option_name()})"
def __hash__(self):
return hash(self.value)
def get_option_name(self):
return self.name_lookup[self.value]
def get_option_name(self) -> str:
if self.autodisplayname:
return self.name_lookup[self.value].replace("_", " ").title()
else:
return self.name_lookup[self.value]
def __int__(self):
def __int__(self) -> int:
return self.value
def __bool__(self):
def __bool__(self) -> bool:
return bool(self.value)
@classmethod
@ -96,12 +105,15 @@ class Toggle(Option):
return int(self.value)
def get_option_name(self):
return bool(self.value)
return ["No", "Yes"][int(self.value)]
class DefaultOnToggle(Toggle):
default = 1
class Choice(Option):
autodisplayname = True
def __init__(self, value: int):
self.value: int = value

View File

@ -1,3 +1,5 @@
import collections
from ..AutoWorld import World
from BaseClasses import Region, Entrance, Location, Item
@ -28,14 +30,14 @@ class Factorio(World):
data_version = 3
def generate_basic(self):
want_progressives = {}
want_progressives = collections.defaultdict(lambda: self.world.progressive[self.player].
want_progressives(self.world.random))
skip_silo = self.world.silo[self.player].value == Silo.option_spawn
for tech_name in base_tech_table:
if skip_silo and tech_name == "rocket-silo":
continue
progressive_item_name = tech_to_progressive_lookup.get(tech_name, tech_name)
want_progressive = want_progressives.setdefault(progressive_item_name,
self.world.progressive[self.player].want_progressives(self.world.random))
want_progressive = want_progressives[progressive_item_name]
item_name = progressive_item_name if want_progressive else tech_name
tech_item = self.create_item(item_name)
if tech_name in self.static_nodes: