Skip to content

Commit

Permalink
Migrate Terraria to new options API (ArchipelagoMW#3414)
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldom-SE authored and qwint committed Jun 24, 2024
1 parent 6b7b376 commit a93fd43
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
16 changes: 8 additions & 8 deletions worlds/terraria/Options.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from Options import Choice, Option, Toggle, DeathLink
import typing
from dataclasses import dataclass
from Options import Choice, DeathLink, PerGameCommonOptions


class Goal(Choice):
Expand Down Expand Up @@ -49,9 +49,9 @@ class FillExtraChecksWith(Choice):
default = 1


options: typing.Dict[str, type(Option)] = { # type: ignore
"goal": Goal,
"achievements": Achievements,
"fill_extra_checks_with": FillExtraChecksWith,
"death_link": DeathLink,
}
@dataclass
class TerrariaOptions(PerGameCommonOptions):
goal: Goal
achievements: Achievements
fill_extra_checks_with: FillExtraChecksWith
death_link: DeathLink
19 changes: 10 additions & 9 deletions worlds/terraria/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
armor_minions,
accessory_minions,
)
from .Options import options
from .Options import TerrariaOptions


class TerrariaWeb(WebWorld):
Expand All @@ -49,7 +49,8 @@ class TerrariaWorld(World):

game = "Terraria"
web = TerrariaWeb()
option_definitions = options
options_dataclass = TerrariaOptions
options: TerrariaOptions

# data_version is used to signal that items, locations or their names
# changed. Set this to 0 during development so other games' clients do not
Expand All @@ -70,7 +71,7 @@ class TerrariaWorld(World):
goal_locations: Set[str]

def generate_early(self) -> None:
goal, goal_locations = goals[self.multiworld.goal[self.player].value]
goal, goal_locations = goals[self.options.goal.value]
ter_goals = {}
goal_items = set()
for location in goal_locations:
Expand All @@ -79,7 +80,7 @@ def generate_early(self) -> None:
ter_goals[item] = location
goal_items.add(item)

achievements = self.multiworld.achievements[self.player].value
achievements = self.options.achievements.value
location_count = 0
locations = []
for rule, flags, _, _ in rules[:goal]:
Expand All @@ -89,7 +90,7 @@ def generate_early(self) -> None:
or (achievements < 2 and "Grindy" in flags)
or (achievements < 3 and "Fishing" in flags)
or (
rule == "Zenith" and self.multiworld.goal[self.player].value != 11
rule == "Zenith" and self.options.goal.value != 11
) # Bad hardcoding
):
continue
Expand Down Expand Up @@ -123,7 +124,7 @@ def generate_early(self) -> None:
# Event
items.append(rule)

extra_checks = self.multiworld.fill_extra_checks_with[self.player].value
extra_checks = self.options.fill_extra_checks_with.value
ordered_rewards = [
reward
for reward in labels["ordered"]
Expand Down Expand Up @@ -241,7 +242,7 @@ def check_condition(
elif condition == "calamity":
return sign == self.calamity
elif condition == "grindy":
return sign == (self.multiworld.achievements[self.player].value >= 2)
return sign == (self.options.achievements.value >= 2)
elif condition == "pickaxe":
if type(arg) is not int:
raise Exception("@pickaxe requires an integer argument")
Expand Down Expand Up @@ -340,6 +341,6 @@ def check(state: CollectionState, location=location):
def fill_slot_data(self) -> Dict[str, object]:
return {
"goal": list(self.goal_locations),
"achievements": self.multiworld.achievements[self.player].value,
"deathlink": bool(self.multiworld.death_link[self.player]),
"achievements": self.options.achievements.value,
"deathlink": bool(self.options.death_link),
}

0 comments on commit a93fd43

Please sign in to comment.