Migrate Terraria to new options API (#3414)
This commit is contained in:
parent
dfc347cd24
commit
04e9f5c47a
|
@ -1,5 +1,5 @@
|
||||||
from Options import Choice, Option, Toggle, DeathLink
|
from dataclasses import dataclass
|
||||||
import typing
|
from Options import Choice, DeathLink, PerGameCommonOptions
|
||||||
|
|
||||||
|
|
||||||
class Goal(Choice):
|
class Goal(Choice):
|
||||||
|
@ -49,9 +49,9 @@ class FillExtraChecksWith(Choice):
|
||||||
default = 1
|
default = 1
|
||||||
|
|
||||||
|
|
||||||
options: typing.Dict[str, type(Option)] = { # type: ignore
|
@dataclass
|
||||||
"goal": Goal,
|
class TerrariaOptions(PerGameCommonOptions):
|
||||||
"achievements": Achievements,
|
goal: Goal
|
||||||
"fill_extra_checks_with": FillExtraChecksWith,
|
achievements: Achievements
|
||||||
"death_link": DeathLink,
|
fill_extra_checks_with: FillExtraChecksWith
|
||||||
}
|
death_link: DeathLink
|
||||||
|
|
|
@ -25,7 +25,7 @@ from .Checks import (
|
||||||
armor_minions,
|
armor_minions,
|
||||||
accessory_minions,
|
accessory_minions,
|
||||||
)
|
)
|
||||||
from .Options import options
|
from .Options import TerrariaOptions
|
||||||
|
|
||||||
|
|
||||||
class TerrariaWeb(WebWorld):
|
class TerrariaWeb(WebWorld):
|
||||||
|
@ -49,7 +49,8 @@ class TerrariaWorld(World):
|
||||||
|
|
||||||
game = "Terraria"
|
game = "Terraria"
|
||||||
web = TerrariaWeb()
|
web = TerrariaWeb()
|
||||||
option_definitions = options
|
options_dataclass = TerrariaOptions
|
||||||
|
options: TerrariaOptions
|
||||||
|
|
||||||
# data_version is used to signal that items, locations or their names
|
# 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
|
# changed. Set this to 0 during development so other games' clients do not
|
||||||
|
@ -70,7 +71,7 @@ class TerrariaWorld(World):
|
||||||
goal_locations: Set[str]
|
goal_locations: Set[str]
|
||||||
|
|
||||||
def generate_early(self) -> None:
|
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 = {}
|
ter_goals = {}
|
||||||
goal_items = set()
|
goal_items = set()
|
||||||
for location in goal_locations:
|
for location in goal_locations:
|
||||||
|
@ -79,7 +80,7 @@ class TerrariaWorld(World):
|
||||||
ter_goals[item] = location
|
ter_goals[item] = location
|
||||||
goal_items.add(item)
|
goal_items.add(item)
|
||||||
|
|
||||||
achievements = self.multiworld.achievements[self.player].value
|
achievements = self.options.achievements.value
|
||||||
location_count = 0
|
location_count = 0
|
||||||
locations = []
|
locations = []
|
||||||
for rule, flags, _, _ in rules[:goal]:
|
for rule, flags, _, _ in rules[:goal]:
|
||||||
|
@ -89,7 +90,7 @@ class TerrariaWorld(World):
|
||||||
or (achievements < 2 and "Grindy" in flags)
|
or (achievements < 2 and "Grindy" in flags)
|
||||||
or (achievements < 3 and "Fishing" in flags)
|
or (achievements < 3 and "Fishing" in flags)
|
||||||
or (
|
or (
|
||||||
rule == "Zenith" and self.multiworld.goal[self.player].value != 11
|
rule == "Zenith" and self.options.goal.value != 11
|
||||||
) # Bad hardcoding
|
) # Bad hardcoding
|
||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
|
@ -123,7 +124,7 @@ class TerrariaWorld(World):
|
||||||
# Event
|
# Event
|
||||||
items.append(rule)
|
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 = [
|
ordered_rewards = [
|
||||||
reward
|
reward
|
||||||
for reward in labels["ordered"]
|
for reward in labels["ordered"]
|
||||||
|
@ -241,7 +242,7 @@ class TerrariaWorld(World):
|
||||||
elif condition == "calamity":
|
elif condition == "calamity":
|
||||||
return sign == self.calamity
|
return sign == self.calamity
|
||||||
elif condition == "grindy":
|
elif condition == "grindy":
|
||||||
return sign == (self.multiworld.achievements[self.player].value >= 2)
|
return sign == (self.options.achievements.value >= 2)
|
||||||
elif condition == "pickaxe":
|
elif condition == "pickaxe":
|
||||||
if type(arg) is not int:
|
if type(arg) is not int:
|
||||||
raise Exception("@pickaxe requires an integer argument")
|
raise Exception("@pickaxe requires an integer argument")
|
||||||
|
@ -340,6 +341,6 @@ class TerrariaWorld(World):
|
||||||
def fill_slot_data(self) -> Dict[str, object]:
|
def fill_slot_data(self) -> Dict[str, object]:
|
||||||
return {
|
return {
|
||||||
"goal": list(self.goal_locations),
|
"goal": list(self.goal_locations),
|
||||||
"achievements": self.multiworld.achievements[self.player].value,
|
"achievements": self.options.achievements.value,
|
||||||
"deathlink": bool(self.multiworld.death_link[self.player]),
|
"deathlink": bool(self.options.death_link),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue