Skip to content

Commit

Permalink
- Use .items(), get option name more directly, fix slot data content
Browse files Browse the repository at this point in the history
  • Loading branch information
agilbert1412 committed Oct 10, 2023
1 parent c38cce9 commit b0f7671
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
8 changes: 8 additions & 0 deletions Options.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,14 @@ def as_dict(self, *option_names: str, casing: str = "snake") -> typing.Dict[str,
raise ValueError(f"{option_name} not found in {tuple(type(self).type_hints)}")
return option_results

def get_value(self, option_name: str) -> typing.Any:
"""
Returns the value of a given option
:param option_name: names of the option to return the value of
"""
return getattr(self, option_name).value


class LocalItems(ItemSet):
"""Forces these items to be in their native world."""
Expand Down
8 changes: 3 additions & 5 deletions worlds/stardew_valley/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,10 @@ def fill_slot_data(self) -> Dict[str, Any]:
key, value = self.modified_bundles[bundle_key].to_pair()
modified_bundles[key] = value

excluded_options = [BundleRandomization, BundlePrice,
NumberOfMovementBuffs, NumberOfLuckBuffs]
included_option_names: List[str] = [option_name for option_name in self.options_dataclass.type_hints if option_name not in excluded_options]
excluded_options = [BundleRandomization, BundlePrice, NumberOfMovementBuffs, NumberOfLuckBuffs]
excluded_option_names = [option.internal_name for option in excluded_options]
included_option_names: List[str] = [option_name for option_name in self.options_dataclass.type_hints if option_name not in excluded_option_names]
slot_data = self.options.as_dict(*included_option_names)
for option in excluded_options:
slot_data.pop(option.internal_name)
slot_data.update({
"seed": self.multiworld.per_slot_randoms[self.player].randrange(1000000000), # Seed should be max 9 digits
"randomized_entrances": self.randomized_entrances,
Expand Down
12 changes: 4 additions & 8 deletions worlds/stardew_valley/test/TestOptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ def get_option_choices(option) -> Dict[str, int]:
class TestGenerateDynamicOptions(SVTestBase):
def test_given_special_range_when_generate_then_basic_checks(self):
options = self.world.options_dataclass.type_hints
for option_name in options:
option = options[option_name]
for option_name, option in options.items():
if not isinstance(option, SpecialRange):
continue
for value in option.special_range_names:
Expand All @@ -64,8 +63,7 @@ def test_given_special_range_when_generate_then_basic_checks(self):
def test_given_choice_when_generate_then_basic_checks(self):
seed = int(random() * pow(10, 18) - 1)
options = self.world.options_dataclass.type_hints
for option_name in options:
option = options[option_name]
for option_name, option in options.items():
if not option.options:
continue
for value in option.options:
Expand Down Expand Up @@ -152,8 +150,7 @@ def test_given_progressive_when_generate_then_tool_upgrades_are_locations(self):
class TestGenerateAllOptionsWithExcludeGingerIsland(SVTestBase):
def test_given_special_range_when_generate_exclude_ginger_island(self):
options = self.world.options_dataclass.type_hints
for option_name in options:
option = options[option_name]
for option_name, option in options.items():
if not isinstance(option, SpecialRange) or option_name == ExcludeGingerIsland.internal_name:
continue
for value in option.special_range_names:
Expand All @@ -166,8 +163,7 @@ def test_given_special_range_when_generate_exclude_ginger_island(self):
def test_given_choice_when_generate_exclude_ginger_island(self):
seed = int(random() * pow(10, 18) - 1)
options = self.world.options_dataclass.type_hints
for option_name in options:
option = options[option_name]
for option_name, option in options.items():
if not option.options or option_name == ExcludeGingerIsland.internal_name:
continue
for value in option.options:
Expand Down
4 changes: 2 additions & 2 deletions worlds/stardew_valley/test/checks/option_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def is_setting(multiworld: MultiWorld, setting_name: str, setting_value: int) ->
stardew_world = get_stardew_world(multiworld)
if not stardew_world:
return False
current_value = stardew_world.options.as_dict(setting_name)[setting_name]
current_value = stardew_world.options.get_value(setting_name)
return current_value == setting_value


Expand All @@ -32,7 +32,7 @@ def assert_is_setting(tester: SVTestBase, multiworld: MultiWorld, setting_name:
stardew_world = get_stardew_world(multiworld)
if not stardew_world:
return False
current_value = stardew_world.options.as_dict(setting_name)[setting_name]
current_value = stardew_world.options.get_value(setting_name)
tester.assertEqual(current_value, setting_value)


Expand Down

0 comments on commit b0f7671

Please sign in to comment.