From 230d9d993e706b13cd2d5f81dd9e3d1c09d0835f Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Tue, 3 Aug 2021 19:03:41 +0200 Subject: [PATCH] clean up some spoiler display names --- BaseClasses.py | 2 +- Options.py | 24 ++++++++++++++++++------ worlds/factorio/__init__.py | 8 +++++--- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/BaseClasses.py b/BaseClasses.py index 4321909d..e3aaaa19 100644 --- a/BaseClasses.py +++ b/BaseClasses.py @@ -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): diff --git a/Options.py b/Options.py index 64841843..0404604c 100644 --- a/Options.py +++ b/Options.py @@ -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 diff --git a/worlds/factorio/__init__.py b/worlds/factorio/__init__.py index 59a9b678..3742758c 100644 --- a/worlds/factorio/__init__.py +++ b/worlds/factorio/__init__.py @@ -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: