Skip to content

FF1: Switching Options System #3302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions worlds/ff1/Options.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Dict
from dataclasses import dataclass

from Options import OptionDict
from Options import OptionDict, PerGameCommonOptions


class Locations(OptionDict):
Expand All @@ -18,8 +18,8 @@ class Rules(OptionDict):
display_name = "rules"


ff1_options: Dict[str, OptionDict] = {
"locations": Locations,
"items": Items,
"rules": Rules
}
@dataclass
class FF1Options(PerGameCommonOptions):
locations: Locations
items: Items
rules: Rules
23 changes: 10 additions & 13 deletions worlds/ff1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from BaseClasses import Item, Location, MultiWorld, Tutorial, ItemClassification
from .Items import ItemData, FF1Items, FF1_STARTER_ITEMS, FF1_PROGRESSION_LIST, FF1_BRIDGE
from .Locations import EventId, FF1Locations, generate_rule, CHAOS_TERMINATED_EVENT
from .Options import ff1_options
from .Options import FF1Options
from ..AutoWorld import World, WebWorld


Expand Down Expand Up @@ -34,7 +34,8 @@ class FF1World(World):
Part puzzle and part speed-run, it breathes new life into one of the most influential games ever made.
"""

option_definitions = ff1_options
options: FF1Options
options_dataclass = FF1Options
settings: typing.ClassVar[FF1Settings]
settings_key = "ffr_options"
game = "Final Fantasy"
Expand All @@ -58,20 +59,20 @@ def __init__(self, world: MultiWorld, player: int):
def stage_assert_generate(cls, multiworld: MultiWorld) -> None:
# Fail generation if there are no items in the pool
for player in multiworld.get_game_players(cls.game):
options = get_options(multiworld, 'items', player)
assert options,\
items = multiworld.worlds[player].options.items.value
assert items, \
f"FFR settings submitted with no key items ({multiworld.get_player_name(player)}). Please ensure you " \
f"generated the settings using finalfantasyrandomizer.com AND enabled the AP flag"

def create_regions(self):
locations = get_options(self.multiworld, 'locations', self.player)
rules = get_options(self.multiworld, 'rules', self.player)
locations = self.options.locations.value
rules = self.options.rules.value
menu_region = self.ff1_locations.create_menu_region(self.player, locations, rules, self.multiworld)
terminated_event = Location(self.player, CHAOS_TERMINATED_EVENT, EventId, menu_region)
terminated_item = Item(CHAOS_TERMINATED_EVENT, ItemClassification.progression, EventId, self.player)
terminated_event.place_locked_item(terminated_item)

items = get_options(self.multiworld, 'items', self.player)
items = self.options.items.value
goal_rule = generate_rule([[name for name in items.keys() if name in FF1_PROGRESSION_LIST and name != "Shard"]],
self.player)
terminated_event.access_rule = goal_rule
Expand All @@ -93,7 +94,7 @@ def set_rules(self):
self.multiworld.completion_condition[self.player] = lambda state: state.has(CHAOS_TERMINATED_EVENT, self.player)

def create_items(self):
items = get_options(self.multiworld, 'items', self.player)
items = self.options.items.value
if FF1_BRIDGE in items.keys():
self._place_locked_item_in_sphere0(FF1_BRIDGE)
if items:
Expand All @@ -109,7 +110,7 @@ def create_items(self):

def _place_locked_item_in_sphere0(self, progression_item: str):
if progression_item:
rules = get_options(self.multiworld, 'rules', self.player)
rules = self.options.rules.value
sphere_0_locations = [name for name, rules in rules.items()
if rules and len(rules[0]) == 0 and name not in self.locked_locations]
if sphere_0_locations:
Expand All @@ -126,7 +127,3 @@ def fill_slot_data(self) -> Dict[str, object]:

def get_filler_item_name(self) -> str:
return self.multiworld.random.choice(["Heal", "Pure", "Soft", "Tent", "Cabin", "House"])


def get_options(world: MultiWorld, name: str, player: int):
return getattr(world, name, None)[player].value
Loading