Core: Refactor Autoworld.options to Autoworld.option_definitions (#906)
* refactor `world.options` -> `world.option_definitions` * rename world api reference * missed some self.options
This commit is contained in:
parent
8484193151
commit
81cf1508e0
|
@ -166,7 +166,7 @@ class MultiWorld():
|
|||
self.player_types[new_id] = NetUtils.SlotType.group
|
||||
self._region_cache[new_id] = {}
|
||||
world_type = AutoWorld.AutoWorldRegister.world_types[game]
|
||||
for option_key, option in world_type.options.items():
|
||||
for option_key, option in world_type.option_definitions.items():
|
||||
getattr(self, option_key)[new_id] = option(option.default)
|
||||
for option_key, option in Options.common_options.items():
|
||||
getattr(self, option_key)[new_id] = option(option.default)
|
||||
|
@ -204,7 +204,7 @@ class MultiWorld():
|
|||
for player in self.player_ids:
|
||||
self.custom_data[player] = {}
|
||||
world_type = AutoWorld.AutoWorldRegister.world_types[self.game[player]]
|
||||
for option_key in world_type.options:
|
||||
for option_key in world_type.option_definitions:
|
||||
setattr(self, option_key, getattr(args, option_key, {}))
|
||||
|
||||
self.worlds[player] = world_type(self, player)
|
||||
|
@ -1388,7 +1388,7 @@ class Spoiler():
|
|||
outfile.write('Game: %s\n' % self.world.game[player])
|
||||
for f_option, option in Options.per_game_common_options.items():
|
||||
write_option(f_option, option)
|
||||
options = self.world.worlds[player].options
|
||||
options = self.world.worlds[player].option_definitions
|
||||
if options:
|
||||
for f_option, option in options.items():
|
||||
write_option(f_option, option)
|
||||
|
|
|
@ -396,7 +396,7 @@ def roll_meta_option(option_key, game: str, category_dict: Dict) -> Any:
|
|||
return get_choice(option_key, category_dict)
|
||||
if game in AutoWorldRegister.world_types:
|
||||
game_world = AutoWorldRegister.world_types[game]
|
||||
options = ChainMap(game_world.options, Options.per_game_common_options)
|
||||
options = ChainMap(game_world.option_definitions, Options.per_game_common_options)
|
||||
if option_key in options:
|
||||
if options[option_key].supports_weighting:
|
||||
return get_choice(option_key, category_dict)
|
||||
|
@ -557,7 +557,7 @@ def roll_settings(weights: dict, plando_options: PlandoSettings = PlandoSettings
|
|||
setattr(ret, option_key, option.from_any(get_choice(option_key, weights, option.default)))
|
||||
|
||||
if ret.game in AutoWorldRegister.world_types:
|
||||
for option_key, option in world_type.options.items():
|
||||
for option_key, option in world_type.option_definitions.items():
|
||||
handle_option(ret, game_weights, option_key, option)
|
||||
for option_key, option in Options.per_game_common_options.items():
|
||||
# skip setting this option if already set from common_options, defaulting to root option
|
||||
|
|
|
@ -60,7 +60,7 @@ def create():
|
|||
|
||||
for game_name, world in AutoWorldRegister.world_types.items():
|
||||
|
||||
all_options = {**Options.per_game_common_options, **world.options}
|
||||
all_options = {**Options.per_game_common_options, **world.option_definitions}
|
||||
res = Template(open(os.path.join("WebHostLib", "templates", "options.yaml")).read()).render(
|
||||
options=all_options,
|
||||
__version__=__version__, game=game_name, yaml_dump=yaml.dump,
|
||||
|
|
|
@ -86,7 +86,7 @@ inside a World object.
|
|||
|
||||
Players provide customized settings for their World in the form of yamls.
|
||||
Those are accessible through `self.world.<option_name>[self.player]`. A dict
|
||||
of valid options has to be provided in `self.options`. Options are automatically
|
||||
of valid options has to be provided in `self.option_definitions`. Options are automatically
|
||||
added to the `World` object for easy access.
|
||||
|
||||
### World Options
|
||||
|
@ -252,7 +252,7 @@ to describe it and a `display_name` property for display on the website and in
|
|||
spoiler logs.
|
||||
|
||||
The actual name as used in the yaml is defined in a `dict[str, Option]`, that is
|
||||
assigned to the world under `self.options`.
|
||||
assigned to the world under `self.option_definitions`.
|
||||
|
||||
Common option types are `Toggle`, `DefaultOnToggle`, `Choice`, `Range`.
|
||||
For more see `Options.py` in AP's base directory.
|
||||
|
@ -328,7 +328,7 @@ from .Options import mygame_options # import the options dict
|
|||
|
||||
class MyGameWorld(World):
|
||||
#...
|
||||
options = mygame_options # assign the options dict to the world
|
||||
option_definitions = mygame_options # assign the options dict to the world
|
||||
#...
|
||||
```
|
||||
|
||||
|
@ -365,7 +365,7 @@ class MyGameLocation(Location): # or from Locations import MyGameLocation
|
|||
class MyGameWorld(World):
|
||||
"""Insert description of the world/game here."""
|
||||
game: str = "My Game" # name of the game/world
|
||||
options = mygame_options # options the player can set
|
||||
option_definitions = mygame_options # options the player can set
|
||||
topology_present: bool = True # show path to required location checks in spoiler
|
||||
remote_items: bool = False # True if all items come from the server
|
||||
remote_start_inventory: bool = False # True if start inventory comes from the server
|
||||
|
|
|
@ -16,7 +16,7 @@ class TestDungeon(unittest.TestCase):
|
|||
def setUp(self):
|
||||
self.world = MultiWorld(1)
|
||||
args = Namespace()
|
||||
for name, option in AutoWorld.AutoWorldRegister.world_types["A Link to the Past"].options.items():
|
||||
for name, option in AutoWorld.AutoWorldRegister.world_types["A Link to the Past"].option_definitions.items():
|
||||
setattr(args, name, {1: option.from_any(option.default)})
|
||||
self.world.set_options(args)
|
||||
self.world.set_default_common_options()
|
||||
|
|
|
@ -12,7 +12,7 @@ def setup_default_world(world_type) -> MultiWorld:
|
|||
world.player_name = {1: "Tester"}
|
||||
world.set_seed()
|
||||
args = Namespace()
|
||||
for name, option in world_type.options.items():
|
||||
for name, option in world_type.option_definitions.items():
|
||||
setattr(args, name, {1: option.from_any(option.default)})
|
||||
world.set_options(args)
|
||||
world.set_default_common_options()
|
||||
|
|
|
@ -16,7 +16,7 @@ class TestInverted(TestBase):
|
|||
def setUp(self):
|
||||
self.world = MultiWorld(1)
|
||||
args = Namespace()
|
||||
for name, option in AutoWorld.AutoWorldRegister.world_types["A Link to the Past"].options.items():
|
||||
for name, option in AutoWorld.AutoWorldRegister.world_types["A Link to the Past"].option_definitions.items():
|
||||
setattr(args, name, {1: option.from_any(option.default)})
|
||||
self.world.set_options(args)
|
||||
self.world.set_default_common_options()
|
||||
|
|
|
@ -17,7 +17,7 @@ class TestInvertedBombRules(unittest.TestCase):
|
|||
self.world = MultiWorld(1)
|
||||
self.world.mode[1] = "inverted"
|
||||
args = Namespace
|
||||
for name, option in AutoWorld.AutoWorldRegister.world_types["A Link to the Past"].options.items():
|
||||
for name, option in AutoWorld.AutoWorldRegister.world_types["A Link to the Past"].option_definitions.items():
|
||||
setattr(args, name, {1: option.from_any(option.default)})
|
||||
self.world.set_options(args)
|
||||
self.world.set_default_common_options()
|
||||
|
|
|
@ -17,7 +17,7 @@ class TestInvertedMinor(TestBase):
|
|||
def setUp(self):
|
||||
self.world = MultiWorld(1)
|
||||
args = Namespace()
|
||||
for name, option in AutoWorld.AutoWorldRegister.world_types["A Link to the Past"].options.items():
|
||||
for name, option in AutoWorld.AutoWorldRegister.world_types["A Link to the Past"].option_definitions.items():
|
||||
setattr(args, name, {1: option.from_any(option.default)})
|
||||
self.world.set_options(args)
|
||||
self.world.set_default_common_options()
|
||||
|
|
|
@ -18,7 +18,7 @@ class TestInvertedOWG(TestBase):
|
|||
def setUp(self):
|
||||
self.world = MultiWorld(1)
|
||||
args = Namespace()
|
||||
for name, option in AutoWorld.AutoWorldRegister.world_types["A Link to the Past"].options.items():
|
||||
for name, option in AutoWorld.AutoWorldRegister.world_types["A Link to the Past"].option_definitions.items():
|
||||
setattr(args, name, {1: option.from_any(option.default)})
|
||||
self.world.set_options(args)
|
||||
self.world.set_default_common_options()
|
||||
|
|
|
@ -17,7 +17,7 @@ class TestMinor(TestBase):
|
|||
def setUp(self):
|
||||
self.world = MultiWorld(1)
|
||||
args = Namespace()
|
||||
for name, option in AutoWorld.AutoWorldRegister.world_types["A Link to the Past"].options.items():
|
||||
for name, option in AutoWorld.AutoWorldRegister.world_types["A Link to the Past"].option_definitions.items():
|
||||
setattr(args, name, {1: option.from_any(option.default)})
|
||||
self.world.set_options(args)
|
||||
self.world.set_default_common_options()
|
||||
|
|
|
@ -18,7 +18,7 @@ class TestVanillaOWG(TestBase):
|
|||
def setUp(self):
|
||||
self.world = MultiWorld(1)
|
||||
args = Namespace()
|
||||
for name, option in AutoWorld.AutoWorldRegister.world_types["A Link to the Past"].options.items():
|
||||
for name, option in AutoWorld.AutoWorldRegister.world_types["A Link to the Past"].option_definitions.items():
|
||||
setattr(args, name, {1: option.from_any(option.default)})
|
||||
self.world.set_options(args)
|
||||
self.world.set_default_common_options()
|
||||
|
|
|
@ -16,7 +16,7 @@ class TestVanilla(TestBase):
|
|||
def setUp(self):
|
||||
self.world = MultiWorld(1)
|
||||
args = Namespace()
|
||||
for name, option in AutoWorld.AutoWorldRegister.world_types["A Link to the Past"].options.items():
|
||||
for name, option in AutoWorld.AutoWorldRegister.world_types["A Link to the Past"].option_definitions.items():
|
||||
setattr(args, name, {1: option.from_any(option.default)})
|
||||
self.world.set_options(args)
|
||||
self.world.set_default_common_options()
|
||||
|
|
|
@ -111,7 +111,7 @@ class World(metaclass=AutoWorldRegister):
|
|||
"""A World object encompasses a game's Items, Locations, Rules and additional data or functionality required.
|
||||
A Game should have its own subclass of World in which it defines the required data structures."""
|
||||
|
||||
options: Dict[str, Option[Any]] = {} # link your Options mapping
|
||||
option_definitions: Dict[str, Option[Any]] = {} # link your Options mapping
|
||||
game: str # name the game
|
||||
topology_present: bool = False # indicate if world type has any meaningful layout/pathing
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ class ALTTPWorld(World):
|
|||
Ganon!
|
||||
"""
|
||||
game: str = "A Link to the Past"
|
||||
options = alttp_options
|
||||
option_definitions = alttp_options
|
||||
topology_present = True
|
||||
item_name_groups = item_name_groups
|
||||
hint_blacklist = {"Triforce"}
|
||||
|
|
|
@ -27,7 +27,7 @@ class ChecksFinderWorld(World):
|
|||
with the mines! You win when you get all your items and beat the board!
|
||||
"""
|
||||
game: str = "ChecksFinder"
|
||||
options = checksfinder_options
|
||||
option_definitions = checksfinder_options
|
||||
topology_present = True
|
||||
web = ChecksFinderWeb()
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ class DarkSouls3World(World):
|
|||
"""
|
||||
|
||||
game: str = "Dark Souls III"
|
||||
options = dark_souls_options
|
||||
option_definitions = dark_souls_options
|
||||
topology_present: bool = True
|
||||
remote_items: bool = False
|
||||
remote_start_inventory: bool = False
|
||||
|
|
|
@ -38,7 +38,7 @@ class DKC3World(World):
|
|||
mystery of why Donkey Kong and Diddy disappeared while on vacation.
|
||||
"""
|
||||
game: str = "Donkey Kong Country 3"
|
||||
options = dkc3_options
|
||||
option_definitions = dkc3_options
|
||||
topology_present = False
|
||||
data_version = 1
|
||||
#hint_blacklist = {LocationName.rocket_rush_flag}
|
||||
|
|
|
@ -193,7 +193,7 @@ class Factorio(World):
|
|||
|
||||
return super(Factorio, self).collect_item(state, item, remove)
|
||||
|
||||
options = factorio_options
|
||||
option_definitions = factorio_options
|
||||
|
||||
@classmethod
|
||||
def stage_write_spoiler(cls, world, spoiler_handle):
|
||||
|
|
|
@ -27,7 +27,7 @@ class FF1World(World):
|
|||
Part puzzle and part speed-run, it breathes new life into one of the most influential games ever made.
|
||||
"""
|
||||
|
||||
options = ff1_options
|
||||
option_definitions = ff1_options
|
||||
game = "Final Fantasy"
|
||||
topology_present = False
|
||||
remote_items = True
|
||||
|
|
|
@ -142,7 +142,7 @@ class HKWorld(World):
|
|||
As the enigmatic Knight, you’ll traverse the depths, unravel its mysteries and conquer its evils.
|
||||
""" # from https://www.hollowknight.com
|
||||
game: str = "Hollow Knight"
|
||||
options = hollow_knight_options
|
||||
option_definitions = hollow_knight_options
|
||||
|
||||
web = HKWeb()
|
||||
|
||||
|
@ -435,7 +435,7 @@ class HKWorld(World):
|
|||
slot_data = {}
|
||||
|
||||
options = slot_data["options"] = {}
|
||||
for option_name in self.options:
|
||||
for option_name in self.option_definitions:
|
||||
option = getattr(self.world, option_name)[self.player]
|
||||
try:
|
||||
optionvalue = int(option.value)
|
||||
|
|
|
@ -49,7 +49,7 @@ class MeritousWorld(World):
|
|||
# NOTE: Remember to change this before this game goes live
|
||||
required_client_version = (0, 2, 4)
|
||||
|
||||
options = meritous_options
|
||||
option_definitions = meritous_options
|
||||
|
||||
def __init__(self, world: MultiWorld, player: int):
|
||||
super(MeritousWorld, self).__init__(world, player)
|
||||
|
|
|
@ -58,7 +58,7 @@ class MinecraftWorld(World):
|
|||
victory!
|
||||
"""
|
||||
game: str = "Minecraft"
|
||||
options = minecraft_options
|
||||
option_definitions = minecraft_options
|
||||
topology_present = True
|
||||
web = MinecraftWebWorld()
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ class OOTWorld(World):
|
|||
to rescue the Seven Sages, and then confront Ganondorf to save Hyrule!
|
||||
"""
|
||||
game: str = "Ocarina of Time"
|
||||
options: dict = oot_options
|
||||
option_definitions: dict = oot_options
|
||||
topology_present: bool = True
|
||||
item_name_to_id = {item_name: oot_data_to_ap_id(data, False) for item_name, data in item_table.items() if
|
||||
data[2] is not None}
|
||||
|
|
|
@ -17,7 +17,7 @@ class OriBlindForest(World):
|
|||
item_name_to_id = item_table
|
||||
location_name_to_id = lookup_name_to_id
|
||||
|
||||
options = options
|
||||
option_definitions = options
|
||||
|
||||
hidden = True
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ class RaftWorld(World):
|
|||
lastItemId = max(filter(lambda val: val is not None, item_name_to_id.values()))
|
||||
|
||||
location_name_to_id = locations_lookup_name_to_id
|
||||
options = raft_options
|
||||
option_definitions = raft_options
|
||||
|
||||
data_version = 2
|
||||
required_client_version = (0, 3, 4)
|
||||
|
|
|
@ -30,7 +30,7 @@ class LegacyWorld(World):
|
|||
But that's OK, because no one is perfect, and you don't have to be to succeed.
|
||||
"""
|
||||
game: str = "Rogue Legacy"
|
||||
options = legacy_options
|
||||
option_definitions = legacy_options
|
||||
topology_present = False
|
||||
data_version = 3
|
||||
required_client_version = (0, 2, 3)
|
||||
|
|
|
@ -28,7 +28,7 @@ class RiskOfRainWorld(World):
|
|||
first crash landing.
|
||||
"""
|
||||
game: str = "Risk of Rain 2"
|
||||
options = ror2_options
|
||||
option_definitions = ror2_options
|
||||
topology_present = False
|
||||
|
||||
item_name_to_id = item_table
|
||||
|
|
|
@ -49,7 +49,7 @@ class SA2BWorld(World):
|
|||
Sonic Adventure 2 Battle is an action platforming game. Play as Sonic, Tails, Knuckles, Shadow, Rogue, and Eggman across 31 stages and prevent the destruction of the earth.
|
||||
"""
|
||||
game: str = "Sonic Adventure 2 Battle"
|
||||
options = sa2b_options
|
||||
option_definitions = sa2b_options
|
||||
topology_present = False
|
||||
data_version = 2
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ class SC2WoLWorld(World):
|
|||
|
||||
item_name_to_id = {name: data.code for name, data in item_table.items()}
|
||||
location_name_to_id = {location.name: location.code for location in get_locations(None, None)}
|
||||
options = sc2wol_options
|
||||
option_definitions = sc2wol_options
|
||||
|
||||
item_name_groups = item_name_groups
|
||||
locked_locations: typing.List[str]
|
||||
|
|
|
@ -79,7 +79,7 @@ class SMWorld(World):
|
|||
game: str = "Super Metroid"
|
||||
topology_present = True
|
||||
data_version = 1
|
||||
options = sm_options
|
||||
option_definitions = sm_options
|
||||
item_names: Set[str] = frozenset(items_lookup_name_to_id)
|
||||
location_names: Set[str] = frozenset(locations_lookup_name_to_id)
|
||||
item_name_to_id = items_lookup_name_to_id
|
||||
|
@ -567,7 +567,7 @@ class SMWorld(World):
|
|||
def fill_slot_data(self):
|
||||
slot_data = {}
|
||||
if not self.world.is_race:
|
||||
for option_name in self.options:
|
||||
for option_name in self.option_definitions:
|
||||
option = getattr(self.world, option_name)[self.player]
|
||||
slot_data[option_name] = option.value
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ class SM64World(World):
|
|||
|
||||
area_connections: typing.Dict[int, int]
|
||||
|
||||
options = sm64_options
|
||||
option_definitions = sm64_options
|
||||
|
||||
def generate_early(self):
|
||||
self.topology_present = self.world.AreaRandomizer[self.player].value
|
||||
|
|
|
@ -62,7 +62,7 @@ class SMZ3World(World):
|
|||
game: str = "SMZ3"
|
||||
topology_present = False
|
||||
data_version = 2
|
||||
options = smz3_options
|
||||
option_definitions = smz3_options
|
||||
item_names: Set[str] = frozenset(TotalSMZ3Item.lookup_name_to_id)
|
||||
location_names: Set[str]
|
||||
item_name_to_id = TotalSMZ3Item.lookup_name_to_id
|
||||
|
|
|
@ -151,7 +151,7 @@ class SoEWorld(World):
|
|||
space station where the final boss must be defeated.
|
||||
"""
|
||||
game: str = "Secret of Evermore"
|
||||
options = soe_options
|
||||
option_definitions = soe_options
|
||||
topology_present = False
|
||||
remote_items = False
|
||||
data_version = 3
|
||||
|
@ -162,7 +162,7 @@ class SoEWorld(World):
|
|||
location_name_to_id, location_id_to_raw = _get_location_mapping()
|
||||
item_name_groups = _get_item_grouping()
|
||||
|
||||
trap_types = [name[12:] for name in options if name.startswith('trap_chance_')]
|
||||
trap_types = [name[12:] for name in option_definitions if name.startswith('trap_chance_')]
|
||||
|
||||
evermizer_seed: int
|
||||
connect_name: str
|
||||
|
@ -339,7 +339,7 @@ class SoEWorld(World):
|
|||
placement_file = out_base + '.txt'
|
||||
patch_file = out_base + '.apsoe'
|
||||
flags = 'l' # spoiler log
|
||||
for option_name in self.options:
|
||||
for option_name in self.option_definitions:
|
||||
option = getattr(self.world, option_name)[self.player]
|
||||
if hasattr(option, 'to_flag'):
|
||||
flags += option.to_flag()
|
||||
|
|
|
@ -27,7 +27,7 @@ class SpireWorld(World):
|
|||
immense power, and Slay the Spire!
|
||||
"""
|
||||
|
||||
options = spire_options
|
||||
option_definitions = spire_options
|
||||
game = "Slay the Spire"
|
||||
topology_present = False
|
||||
data_version = 1
|
||||
|
|
|
@ -39,7 +39,7 @@ class SubnauticaWorld(World):
|
|||
|
||||
item_name_to_id = {data["name"]: item_id for item_id, data in Items.item_table.items()}
|
||||
location_name_to_id = all_locations
|
||||
options = Options.options
|
||||
option_definitions = Options.options
|
||||
|
||||
data_version = 5
|
||||
required_client_version = (0, 3, 4)
|
||||
|
|
|
@ -40,7 +40,7 @@ class TimespinnerWorld(World):
|
|||
Travel back in time to change fate itself. Join timekeeper Lunais on her quest for revenge against the empire that killed her family.
|
||||
"""
|
||||
|
||||
options = timespinner_options
|
||||
option_definitions = timespinner_options
|
||||
game = "Timespinner"
|
||||
topology_present = True
|
||||
remote_items = False
|
||||
|
|
|
@ -41,7 +41,7 @@ class V6World(World):
|
|||
|
||||
music_map: typing.Dict[int,int]
|
||||
|
||||
options = v6_options
|
||||
option_definitions = v6_options
|
||||
|
||||
def create_regions(self):
|
||||
create_regions(self.world,self.player)
|
||||
|
|
|
@ -41,7 +41,7 @@ class WitnessWorld(World):
|
|||
static_locat = StaticWitnessLocations()
|
||||
static_items = StaticWitnessItems()
|
||||
web = WitnessWebWorld()
|
||||
options = the_witness_options
|
||||
option_definitions = the_witness_options
|
||||
|
||||
item_name_to_id = {
|
||||
name: data.code for name, data in static_items.ALL_ITEM_TABLE.items()
|
||||
|
|
Loading…
Reference in New Issue