Skip to content

Commit

Permalink
remove CommonOptions.get_value (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
beauxq authored Oct 10, 2023
1 parent 130da25 commit d8fab8e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 38 deletions.
8 changes: 0 additions & 8 deletions Options.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,14 +955,6 @@ 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
6 changes: 3 additions & 3 deletions worlds/stardew_valley/test/checks/goal_checks.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from BaseClasses import MultiWorld
from .option_checks import is_setting, assert_is_setting
from .option_checks import get_stardew_options
from ... import options
from .. import SVTestBase


def is_goal(multiworld: MultiWorld, goal: int) -> bool:
return is_setting(multiworld, options.Goal.internal_name, goal)
return get_stardew_options(multiworld).goal.value == goal


def is_bottom_mines(multiworld: MultiWorld) -> bool:
Expand Down Expand Up @@ -33,7 +33,7 @@ def is_not_perfection(multiworld: MultiWorld) -> bool:


def assert_ginger_island_is_included(tester: SVTestBase, multiworld: MultiWorld):
assert_is_setting(tester, multiworld, options.ExcludeGingerIsland.internal_name, options.ExcludeGingerIsland.option_false)
tester.assertEqual(get_stardew_options(multiworld).exclude_ginger_island, options.ExcludeGingerIsland.option_false)


def assert_walnut_hunter_world_is_valid(tester: SVTestBase, multiworld: MultiWorld):
Expand Down
36 changes: 9 additions & 27 deletions worlds/stardew_valley/test/checks/option_checks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Union

from BaseClasses import MultiWorld
from .world_checks import get_all_item_names, get_all_location_names
from .. import SVTestBase
Expand All @@ -8,32 +6,16 @@
from ...strings.ap_names.transport_names import Transportation


def get_stardew_world(multiworld: MultiWorld) -> Union[StardewValleyWorld, None]:
def get_stardew_world(multiworld: MultiWorld) -> StardewValleyWorld:
for world_key in multiworld.worlds:
world = multiworld.worlds[world_key]
if isinstance(world, StardewValleyWorld):
return world
return None


def is_setting(multiworld: MultiWorld, setting_name: str, setting_value: int) -> bool:
stardew_world = get_stardew_world(multiworld)
if not stardew_world:
return False
current_value = stardew_world.options.get_value(setting_name)
return current_value == setting_value

raise ValueError("no stardew world in this multiworld")

def is_not_setting(multiworld: MultiWorld, setting_name: str, setting_value: int) -> bool:
return not is_setting(multiworld, setting_name, setting_value)


def assert_is_setting(tester: SVTestBase, multiworld: MultiWorld, setting_name: str, setting_value: int) -> bool:
stardew_world = get_stardew_world(multiworld)
if not stardew_world:
return False
current_value = stardew_world.options.get_value(setting_name)
tester.assertEqual(current_value, setting_value)
def get_stardew_options(multiworld: MultiWorld) -> options.StardewValleyOptions:
return get_stardew_world(multiworld).options


def assert_can_reach_island(tester: SVTestBase, multiworld: MultiWorld):
Expand All @@ -49,15 +31,16 @@ def assert_cannot_reach_island(tester: SVTestBase, multiworld: MultiWorld):


def assert_can_reach_island_if_should(tester: SVTestBase, multiworld: MultiWorld):
include_island = is_setting(multiworld, options.ExcludeGingerIsland.internal_name, options.ExcludeGingerIsland.option_false)
stardew_options = get_stardew_options(multiworld)
include_island = stardew_options.exclude_ginger_island.value == options.ExcludeGingerIsland.option_false
if include_island:
assert_can_reach_island(tester, multiworld)
else:
assert_cannot_reach_island(tester, multiworld)


def assert_cropsanity_same_number_items_and_locations(tester: SVTestBase, multiworld: MultiWorld):
is_cropsanity = is_setting(multiworld, options.Cropsanity.internal_name, options.Cropsanity.option_shuffled)
is_cropsanity = get_stardew_options(multiworld).cropsanity.value == options.Cropsanity.option_shuffled
if not is_cropsanity:
return

Expand All @@ -80,11 +63,10 @@ def assert_has_deluxe_scarecrow_recipe(tester: SVTestBase, multiworld: MultiWorl


def assert_festivals_give_access_to_deluxe_scarecrow(tester: SVTestBase, multiworld: MultiWorld):
has_festivals = is_not_setting(multiworld, options.FestivalLocations.internal_name, options.FestivalLocations.option_disabled)
stardew_options = get_stardew_options(multiworld)
has_festivals = stardew_options.festival_locations.value != options.FestivalLocations.option_disabled
if not has_festivals:
return

assert_all_rarecrows_exist(tester, multiworld)
assert_has_deluxe_scarecrow_recipe(tester, multiworld)


0 comments on commit d8fab8e

Please sign in to comment.