Skip to content
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
23 changes: 11 additions & 12 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
before_generate_basic, after_generate_basic, \
before_fill_slot_data, after_fill_slot_data, before_write_spoiler, \
before_extend_hint_information, after_extend_hint_information, \
after_collect_item, after_remove_item, before_generate_early
from .hooks.Data import hook_interpret_slot_data
after_collect_item, after_remove_item, before_generate_early, hook_interpret_slot_data

class ManualWorld(World):
__doc__ = world_description
Expand Down Expand Up @@ -68,23 +67,17 @@ class ManualWorld(World):
victory_names = victory_names

# UT (the universal-est of trackers) can now generate without a YAML
ut_can_gen_without_yaml = False # Temporary disable until we fix the bugs with it
ut_can_gen_without_yaml = True

def get_filler_item_name(self) -> str:
return hook_get_filler_item_name(self, self.multiworld, self.player) or self.filler_item_name

def interpret_slot_data(self, slot_data: dict[str, Any]):
def interpret_slot_data(self, slot_data: dict[str, Any]) -> dict[str, Any]:
#this is called by tools like UT
if not slot_data:
return False
return {}

regen = False
for key, value in slot_data.items():
if key in self.options_dataclass.type_hints:
getattr(self.options, key).value = value
regen = True

regen = hook_interpret_slot_data(self, self.player, slot_data) or regen
regen = hook_interpret_slot_data(self, self.player, slot_data) or slot_data
return regen

@classmethod
Expand All @@ -93,6 +86,12 @@ def stage_assert_generate(cls, multiworld) -> None:

def generate_early(self) -> None:
before_generate_early(self, self.multiworld, self.player)
if hasattr(self.multiworld, "re_gen_passthrough"):
slot_data = self.multiworld.re_gen_passthrough.get(self.game, {})
if slot_data:
for key, value in slot_data.items():
if hasattr(self.options, key):
getattr(self.options, key).value = value

def create_regions(self):
before_create_regions(self, self.multiworld, self.player)
Expand Down
6 changes: 0 additions & 6 deletions src/hooks/Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,3 @@ def after_load_option_file(option_table: dict) -> dict:
# for more info check https://github.com/ArchipelagoMW/Archipelago/blob/main/docs/world%20api.md#webworld-class
def after_load_meta_file(meta_table: dict) -> dict:
return meta_table

# called when an external tool (eg Universal Tracker) ask for slot data to be read
# use this if you want to restore more data
# return True if you want to trigger a regeneration if you changed anything
def hook_interpret_slot_data(world, player: int, slot_data: dict[str, any]) -> dict | bool:
return False
8 changes: 8 additions & 0 deletions src/hooks/World.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Object classes from AP core, to represent an entire MultiWorld and this individual World that's part of it
from typing import Any
from worlds.AutoWorld import World
from BaseClasses import MultiWorld, CollectionState, Item

Expand Down Expand Up @@ -190,3 +191,10 @@ def before_extend_hint_information(hint_data: dict[int, dict[int, str]], world:

def after_extend_hint_information(hint_data: dict[int, dict[int, str]], world: World, multiworld: MultiWorld, player: int) -> None:
pass

def hook_interpret_slot_data(world: World, player: int, slot_data: dict[str, Any]) -> dict[str, Any]:
"""
Called when Universal Tracker wants to perform a fake generation
Use this if you want to use or modify the slot_data for passed into re_gen_passthrough
"""
return slot_data