Skip to content

Commit

Permalink
Changed option handling to @DataClass.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrks committed Jun 15, 2024
1 parent 0354315 commit 593c5a1
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 46 deletions.
114 changes: 74 additions & 40 deletions worlds/ladx/Options.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os.path
import typing
import logging
from Options import Choice, Option, Toggle, DefaultOnToggle, Range, FreeText
from dataclasses import dataclass
from Options import Choice, Option, Toggle, DefaultOnToggle, Range, FreeText, DeathLink, OptionGroup, PerGameCommonOptions
from collections import defaultdict
import Utils

Expand Down Expand Up @@ -461,44 +462,77 @@ class AdditionalWarpPoints(DefaultOffToggle):
[On] (requires warp improvements) Adds a warp point at Crazy Tracy's house (the Mambo teleport spot) and Eagle's Tower
[Off] No change
"""

ladx_option_groups = [
OptionGroup("Goal Options", [
Goal,
InstrumentCount,
]),
OptionGroup("Shuffles", [
ShuffleInstruments,
ShuffleNightmareKeys,
ShuffleSmallKeys,
ShuffleMaps,
ShuffleCompasses,
ShuffleStoneBeaks
]),
OptionGroup("Warp Points", [
WarpImprovements,
AdditionalWarpPoints,
]),
OptionGroup("Experimental", [
DungeonShuffle,
EntranceShuffle
]),
OptionGroup("Visuals & Sound", [
LinkPalette,
Palette,
TextShuffle,
APTitleScreen,
GfxMod,
Music,
MusicChangeCondition
]),
OptionGroup("Miscellaneous", [
TradeQuest,
Rooster,
TrendyGame,
NagMessages,
BootsControls
])
]

@dataclass
class LinksAwakeningOptions(PerGameCommonOptions):
death_link: DeathLink
logic: Logic

links_awakening_options: typing.Dict[str, typing.Type[Option]] = {
'logic': Logic,
# 'heartpiece': DefaultOnToggle, # description='Includes heart pieces in the item pool'),
# 'seashells': DefaultOnToggle, # description='Randomizes the secret sea shells hiding in the ground/trees. (chest are always randomized)'),
# 'heartcontainers': DefaultOnToggle, # description='Includes boss heart container drops in the item pool'),
# 'instruments': DefaultOffToggle, # description='Instruments are placed on random locations, dungeon goal will just contain a random item.'),
'tradequest': TradeQuest, # description='Trade quest items are randomized, each NPC takes its normal trade quest item, but gives a random item'),
# 'witch': DefaultOnToggle, # description='Adds both the toadstool and the reward for giving the toadstool to the witch to the item pool'),
'rooster': Rooster, # description='Adds the rooster to the item pool. Without this option, the rooster spot is still a check giving an item. But you will never find the rooster. Any rooster spot is accessible without rooster by other means.'),
# 'boomerang': Boomerang,
# 'randomstartlocation': DefaultOffToggle, # 'Randomize where your starting house is located'),
'experimental_dungeon_shuffle': DungeonShuffle, # 'Randomizes the dungeon that each dungeon entrance leads to'),
'experimental_entrance_shuffle': EntranceShuffle,
# 'bossshuffle': BossShuffle,
# 'minibossshuffle': BossShuffle,
'goal': Goal,
'instrument_count': InstrumentCount,
# 'itempool': ItemPool,
# 'bowwow': Bowwow,
# 'overworld': Overworld,
'link_palette': LinkPalette,
'warp_improvements': WarpImprovements,
'additional_warp_points': AdditionalWarpPoints,
'trendy_game': TrendyGame,
'gfxmod': GfxMod,
'palette': Palette,
'text_shuffle': TextShuffle,
'shuffle_nightmare_keys': ShuffleNightmareKeys,
'shuffle_small_keys': ShuffleSmallKeys,
'shuffle_maps': ShuffleMaps,
'shuffle_compasses': ShuffleCompasses,
'shuffle_stone_beaks': ShuffleStoneBeaks,
'music': Music,
'shuffle_instruments': ShuffleInstruments,
'music_change_condition': MusicChangeCondition,
'nag_messages': NagMessages,
'ap_title_screen': APTitleScreen,
'boots_controls': BootsControls,
}
goal: Goal
instrument_count: InstrumentCount

shuffle_instruments: ShuffleInstruments
shuffle_nightmare_keys: ShuffleNightmareKeys
shuffle_small_keys: ShuffleSmallKeys
shuffle_maps: ShuffleMaps
shuffle_compasses: ShuffleCompasses
shuffle_stone_beaks: ShuffleStoneBeaks

warp_improvements: WarpImprovements
additional_warp_points: AdditionalWarpPoints

experimental_dungeon_shuffle: DungeonShuffle # 'Randomizes the dungeon that each dungeon entrance leads to'),
experimental_entrance_shuffle: EntranceShuffle

link_palette: LinkPalette
palette: Palette
text_shuffle: TextShuffle
ap_title_screen: APTitleScreen
gfxmod: GfxMod
music: Music
music_change_condition: MusicChangeCondition

tradequest: TradeQuest # description='Trade quest items are randomized, each NPC takes its normal trade quest item, but gives a random item'),
rooster: Rooster # description='Adds the rooster to the item pool. Without this option, the rooster spot is still a check giving an item. But you will never find the rooster. Any rooster spot is accessible without rooster by other means.'),
trendy_game: TrendyGame
nag_messages: NagMessages
boots_controls: BootsControls
14 changes: 8 additions & 6 deletions worlds/ladx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from .LADXR.worldSetup import WorldSetup as LADXRWorldSetup
from .Locations import (LinksAwakeningLocation, LinksAwakeningRegion,
create_regions_from_ladxr, get_locations_to_id)
from .Options import DungeonItemShuffle, links_awakening_options, ShuffleInstruments
from .Options import DungeonItemShuffle, LinksAwakeningOptions, ladx_option_groups, ShuffleInstruments
from .Rom import LADXDeltaPatch

DEVELOPER_MODE = False
Expand Down Expand Up @@ -64,7 +64,7 @@ class LinksAwakeningWebWorld(WebWorld):
["zig"]
)]
theme = "dirt"

option_groups = ladx_option_groups

class LinksAwakeningWorld(World):
"""
Expand All @@ -74,7 +74,8 @@ class LinksAwakeningWorld(World):
game = LINKS_AWAKENING # name of the game/world
web = LinksAwakeningWebWorld()

option_definitions = links_awakening_options # options the player can set
options_dataclass = LinksAwakeningOptions
options: LinksAwakeningOptions # options the player can set
settings: typing.ClassVar[LinksAwakeningSettings]
topology_present = True # show path to required location checks in spoiler

Expand Down Expand Up @@ -114,7 +115,7 @@ class LinksAwakeningWorld(World):

def convert_ap_options_to_ladxr_logic(self):
self.player_options = {
option: getattr(self.multiworld, option)[self.player] for option in self.option_definitions
option: getattr(self.options, option) for option in dir(self.options) if not option.startswith("__") and option != "as_dict" # it's easier to also exclude the collection in the dict as using that [dir(self.options) is a list of elements]
}

self.laxdr_options = LADXRSettings(self.player_options)
Expand Down Expand Up @@ -215,7 +216,8 @@ def create_items(self) -> None:
else:
item = self.create_item(item_name)

if not self.multiworld.tradequest[self.player] and isinstance(item.item_data, TradeItemData):
if not self.player_options["tradequest"] and isinstance(item.item_data, TradeItemData):
#if not self.multiworld.tradequest[self.player] and isinstance(item.item_data, TradeItemData):
location = self.multiworld.get_location(item.item_data.vanilla_location, self.player)
location.place_locked_item(item)
location.show_in_spoiler = False
Expand Down Expand Up @@ -476,7 +478,7 @@ def generate_output(self, output_directory: str):
self.multi_key,
self.multiworld.seed_name,
self.ladxr_logic,
rnd=self.multiworld.per_slot_randoms[self.player],
rnd=self.random,
player_name=name_for_rom,
player_names=all_names,
player_id = self.player,
Expand Down

0 comments on commit 593c5a1

Please sign in to comment.