Timespinner: some reformatting and type fixes

This commit is contained in:
Fabian Dill 2021-09-25 02:31:32 +02:00
parent 1cef10b309
commit 59529eba4e
2 changed files with 35 additions and 20 deletions

View File

@ -4,14 +4,16 @@ from .Options import is_option_enabled
EventId: Optional[int] = None EventId: Optional[int] = None
class LocationData(NamedTuple): class LocationData(NamedTuple):
region: str region: str
name: str name: str
code: Optional[int] code: Optional[int]
rule: Callable = lambda state: True rule: Callable = lambda state: True
def get_locations(world: MultiWorld, player: int):
location_table: Tuple[LocationData] = ( def get_locations(world: Optional[MultiWorld], player: Optional[int]):
location_table: Tuple[LocationData, ...] = (
# PresentItemLocations # PresentItemLocations
LocationData('Tutorial', 'Yo Momma 1', 1337000), LocationData('Tutorial', 'Yo Momma 1', 1337000),
LocationData('Tutorial', 'Yo Momma 2', 1337001), LocationData('Tutorial', 'Yo Momma 2', 1337001),
@ -194,7 +196,7 @@ def get_locations(world: MultiWorld, player: int):
LocationData('Ancient Pyramid (right)', 'Killed Nightmare', EventId) LocationData('Ancient Pyramid (right)', 'Killed Nightmare', EventId)
) )
downloadable_items: Tuple[LocationData] = ( downloadable_items: Tuple[LocationData, ...] = (
# DownloadTerminals # DownloadTerminals
LocationData('Libary', 'Library terminal 1', 1337157, lambda state: state.has('Tablet', player)), LocationData('Libary', 'Library terminal 1', 1337157, lambda state: state.has('Tablet', player)),
LocationData('Libary', 'Library terminal 2', 1337156, lambda state: state.has('Tablet', player)), LocationData('Libary', 'Library terminal 2', 1337156, lambda state: state.has('Tablet', player)),
@ -217,7 +219,7 @@ def get_locations(world: MultiWorld, player: int):
else: else:
return location_table return location_table
starter_progression_locations: Tuple[str] = ( starter_progression_locations: Tuple[str, ...] = (
'Starter chest 2', 'Starter chest 2',
'Starter chest 3', 'Starter chest 3',
'Starter chest 1', 'Starter chest 1',

View File

@ -1,4 +1,4 @@
from typing import Dict, List from typing import Dict, List, Set
from BaseClasses import Item, MultiWorld from BaseClasses import Item, MultiWorld
from ..AutoWorld import World from ..AutoWorld import World
from .LogicMixin import TimespinnerLogic from .LogicMixin import TimespinnerLogic
@ -8,6 +8,7 @@ from .Regions import create_regions
from .Options import is_option_enabled, timespinner_options from .Options import is_option_enabled, timespinner_options
from .PyramidKeys import get_pyramid_keys_unlock from .PyramidKeys import get_pyramid_keys_unlock
class TimespinnerWorld(World): class TimespinnerWorld(World):
options = timespinner_options options = timespinner_options
game = "Timespinner" game = "Timespinner"
@ -28,7 +29,8 @@ class TimespinnerWorld(World):
self.item_name_groups = get_item_name_groups() self.item_name_groups = get_item_name_groups()
def create_regions(self): def create_regions(self):
create_regions(self.world, self.player, get_locations(self.world, self.player), self.pyramid_keys_unlock[self.player]) create_regions(self.world, self.player, get_locations(self.world, self.player),
self.pyramid_keys_unlock[self.player])
def create_item(self, name: str) -> Item: def create_item(self, name: str) -> Item:
return create_item(name, self.player) return create_item(name, self.player)
@ -43,7 +45,8 @@ class TimespinnerWorld(World):
assign_starter_items(self.world, self.player, excluded_items, self.locked_locations[self.player]) assign_starter_items(self.world, self.player, excluded_items, self.locked_locations[self.player])
if not is_option_enabled(self.world, self.player, "QuickSeed") or not is_option_enabled(self.world, self.player, "Inverted"): if not is_option_enabled(self.world, self.player, "QuickSeed") or \
not is_option_enabled(self.world, self.player, "Inverted"):
place_first_progression_item(self.world, self.player, excluded_items, self.locked_locations[self.player]) place_first_progression_item(self.world, self.player, excluded_items, self.locked_locations[self.player])
pool = get_item_pool(self.world, self.player, excluded_items) pool = get_item_pool(self.world, self.player, excluded_items)
@ -66,10 +69,12 @@ class TimespinnerWorld(World):
return slot_data return slot_data
def create_item(name: str, player: int) -> Item: def create_item(name: str, player: int) -> Item:
data = item_table[name] data = item_table[name]
return Item(name, data.progression, data.code, player) return Item(name, data.progression, data.code, player)
def get_excluded_items_based_on_options(world: MultiWorld, player: int) -> List[str]: def get_excluded_items_based_on_options(world: MultiWorld, player: int) -> List[str]:
excluded_items = [] excluded_items = []
@ -82,6 +87,7 @@ def get_excluded_items_based_on_options(world: MultiWorld, player: int) -> List[
return excluded_items return excluded_items
def assign_starter_items(world: MultiWorld, player: int, excluded_items: List[str], locked_locations: List[str]): def assign_starter_items(world: MultiWorld, player: int, excluded_items: List[str], locked_locations: List[str]):
melee_weapon = world.random.choice(starter_melee_weapons) melee_weapon = world.random.choice(starter_melee_weapons)
spell = world.random.choice(starter_spells) spell = world.random.choice(starter_spells)
@ -98,6 +104,7 @@ def assign_starter_items(world: MultiWorld, player: int, excluded_items: List[st
locked_locations.append('Yo Momma 1') locked_locations.append('Yo Momma 1')
locked_locations.append('Yo Momma 2') locked_locations.append('Yo Momma 2')
def get_item_pool(world: MultiWorld, player: int, excluded_items: List[str]) -> List[Item]: def get_item_pool(world: MultiWorld, player: int, excluded_items: List[str]) -> List[Item]:
pool = [] pool = []
@ -109,14 +116,17 @@ def get_item_pool(world: MultiWorld, player: int, excluded_items: List[str]) ->
return pool return pool
def fill_item_pool_with_dummy_items(world: MultiWorld, player: int, locked_locations: List[str], pool: List[Item]): def fill_item_pool_with_dummy_items(world: MultiWorld, player: int, locked_locations: List[str], pool: List[Item]):
for _ in range(len(get_locations(world, player)) - len(locked_locations) - len(pool)): for _ in range(len(get_locations(world, player)) - len(locked_locations) - len(pool)):
item = create_item(world.random.choice(filler_items), player) item = create_item(world.random.choice(filler_items), player)
pool.append(item) pool.append(item)
def place_first_progression_item(world: MultiWorld, player: int, excluded_items: List[str], locked_locations: List[str]):
def place_first_progression_item(world: MultiWorld, player: int, excluded_items: List[str],
locked_locations: List[str]):
progression_item = world.random.choice(starter_progression_items) progression_item = world.random.choice(starter_progression_items)
location = world.random.choice(starter_progression_locations) location = world.random.choice(starter_progression_locations)
excluded_items.append(progression_item) excluded_items.append(progression_item)
locked_locations.append(location) locked_locations.append(location)
@ -125,6 +135,7 @@ def place_first_progression_item(world: MultiWorld, player: int, excluded_items:
world.get_location(location, player).place_locked_item(item) world.get_location(location, player).place_locked_item(item)
def update_progressive_state_based_flags(world: MultiWorld, player: int, name: str, data: Item) -> Item: def update_progressive_state_based_flags(world: MultiWorld, player: int, name: str, data: Item) -> Item:
if not data.advancement: if not data.advancement:
return data return data
@ -136,6 +147,7 @@ def update_progressive_state_based_flags(world: MultiWorld, player: int, name: s
return data return data
def setup_events(world: MultiWorld, player: int, locked_locations: List[str]): def setup_events(world: MultiWorld, player: int, locked_locations: List[str]):
for location in get_locations(world, player): for location in get_locations(world, player):
if location.code == EventId: if location.code == EventId:
@ -146,10 +158,11 @@ def setup_events(world: MultiWorld, player: int, locked_locations: List[str]):
location.place_locked_item(item) location.place_locked_item(item)
def get_item_name_groups() -> Dict[str, List[str]]:
groups: Dict[str, List[str]] = {} def get_item_name_groups() -> Dict[str, Set[str]]:
groups: Dict[str, Set[str]] = {}
for name, data in item_table.items(): for name, data in item_table.items():
groups[data.category] = [ name ] if data.category not in groups else groups[data.category] + [ name ] groups.setdefault(data.category, set()).add(name)
return groups return groups