Skip to content

Commit

Permalink
The Messenger: remove 3.8 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
alwaysintreble committed Sep 23, 2024
1 parent 2394c60 commit 84744bf
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 67 deletions.
30 changes: 15 additions & 15 deletions worlds/messenger/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import Any, ClassVar, Dict, List, Optional, Set, TextIO
from typing import Any, ClassVar, TextIO

from BaseClasses import CollectionState, Entrance, Item, ItemClassification, MultiWorld, Tutorial
from Options import Accessibility
Expand Down Expand Up @@ -120,16 +120,16 @@ class MessengerWorld(World):
required_seals: int = 0
created_seals: int = 0
total_shards: int = 0
shop_prices: Dict[str, int]
figurine_prices: Dict[str, int]
_filler_items: List[str]
starting_portals: List[str]
plando_portals: List[str]
spoiler_portal_mapping: Dict[str, str]
portal_mapping: List[int]
transitions: List[Entrance]
shop_prices: dict[str, int]
figurine_prices: dict[str, int]
_filler_items: list[str]
starting_portals: list[str]
plando_portals: list[str]
spoiler_portal_mapping: dict[str, str]
portal_mapping: list[int]
transitions: list[Entrance]
reachable_locs: int = 0
filler: Dict[str, int]
filler: dict[str, int]

def generate_early(self) -> None:
if self.options.goal == Goal.option_power_seal_hunt:
Expand Down Expand Up @@ -178,7 +178,7 @@ def create_regions(self) -> None:
for reg_name in sub_region]

for region in complex_regions:
region_name = region.name.replace(f"{region.parent} - ", "")
region_name = region.name.removeprefix(f"{region.parent} - ")
connection_data = CONNECTIONS[region.parent][region_name]
for exit_region in connection_data:
region.connect(self.multiworld.get_region(exit_region, self.player))
Expand All @@ -191,7 +191,7 @@ def create_items(self) -> None:
# create items that are always in the item pool
main_movement_items = ["Rope Dart", "Wingsuit"]
precollected_names = [item.name for item in self.multiworld.precollected_items[self.player]]
itempool: List[MessengerItem] = [
itempool: list[MessengerItem] = [
self.create_item(item)
for item in self.item_name_to_id
if item not in {
Expand Down Expand Up @@ -290,7 +290,7 @@ def write_spoiler_header(self, spoiler_handle: TextIO) -> None:
for portal, output in portal_info:
spoiler.set_entrance(f"{portal} Portal", output, "I can write anything I want here lmao", self.player)

def fill_slot_data(self) -> Dict[str, Any]:
def fill_slot_data(self) -> dict[str, Any]:
slot_data = {
"shop": {SHOP_ITEMS[item].internal_name: price for item, price in self.shop_prices.items()},
"figures": {FIGURINES[item].internal_name: price for item, price in self.figurine_prices.items()},
Expand All @@ -316,7 +316,7 @@ def get_filler_item_name(self) -> str:
return self._filler_items.pop(0)

def create_item(self, name: str) -> MessengerItem:
item_id: Optional[int] = self.item_name_to_id.get(name, None)
item_id: int | None = self.item_name_to_id.get(name, None)
return MessengerItem(
name,
ItemClassification.progression if item_id is None else self.get_item_classification(name),
Expand Down Expand Up @@ -351,7 +351,7 @@ def get_item_classification(self, name: str) -> ItemClassification:
return ItemClassification.filler

@classmethod
def create_group(cls, multiworld: "MultiWorld", new_player_id: int, players: Set[int]) -> World:
def create_group(cls, multiworld: "MultiWorld", new_player_id: int, players: set[int]) -> World:
group = super().create_group(multiworld, new_player_id, players)
assert isinstance(group, MessengerWorld)

Expand Down
5 changes: 2 additions & 3 deletions worlds/messenger/client_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import subprocess
import urllib.request
from shutil import which
from typing import Any, Optional
from typing import Any
from zipfile import ZipFile
from Utils import open_file

Expand All @@ -17,7 +17,7 @@
MOD_URL = "https://api.github.com/repos/alwaysintreble/TheMessengerRandomizerModAP/releases/latest"


def ask_yes_no_cancel(title: str, text: str) -> Optional[bool]:
def ask_yes_no_cancel(title: str, text: str) -> bool | None:
"""
Wrapper for tkinter.messagebox.askyesnocancel, that creates a popup dialog box with yes, no, and cancel buttons.
Expand All @@ -33,7 +33,6 @@ def ask_yes_no_cancel(title: str, text: str) -> Optional[bool]:
return ret



def launch_game(*args) -> None:
"""Check the game installation, then launch it"""
def courier_installed() -> bool:
Expand Down
8 changes: 3 additions & 5 deletions worlds/messenger/connections.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from typing import Dict, List

CONNECTIONS: Dict[str, Dict[str, List[str]]] = {
CONNECTIONS: dict[str, dict[str, list[str]]] = {
"Ninja Village": {
"Right": [
"Autumn Hills - Left",
Expand Down Expand Up @@ -640,7 +638,7 @@
},
}

RANDOMIZED_CONNECTIONS: Dict[str, str] = {
RANDOMIZED_CONNECTIONS: dict[str, str] = {
"Ninja Village - Right": "Autumn Hills - Left",
"Autumn Hills - Left": "Ninja Village - Right",
"Autumn Hills - Right": "Forlorn Temple - Left",
Expand Down Expand Up @@ -680,7 +678,7 @@
"Sunken Shrine - Left": "Howling Grotto - Bottom",
}

TRANSITIONS: List[str] = [
TRANSITIONS: list[str] = [
"Ninja Village - Right",
"Autumn Hills - Left",
"Autumn Hills - Right",
Expand Down
18 changes: 9 additions & 9 deletions worlds/messenger/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# items
# listing individual groups first for easy lookup
NOTES = [
NOTES: list[str] = [
"Key of Hope",
"Key of Chaos",
"Key of Courage",
Expand All @@ -11,7 +11,7 @@
"Key of Symbiosis",
]

PROG_ITEMS = [
PROG_ITEMS: list[str] = [
"Wingsuit",
"Rope Dart",
"Lightfoot Tabi",
Expand All @@ -28,18 +28,18 @@
"Seashell",
]

PHOBEKINS = [
PHOBEKINS: list[str] = [
"Necro",
"Pyro",
"Claustro",
"Acro",
]

USEFUL_ITEMS = [
USEFUL_ITEMS: list[str] = [
"Windmill Shuriken",
]

FILLER = {
FILLER: dict[str, int] = {
"Time Shard": 5,
"Time Shard (10)": 10,
"Time Shard (50)": 20,
Expand All @@ -48,13 +48,13 @@
"Time Shard (500)": 5,
}

TRAPS = {
TRAPS: dict[str, int] = {
"Teleport Trap": 5,
"Prophecy Trap": 10,
}

# item_name_to_id needs to be deterministic and match upstream
ALL_ITEMS = [
ALL_ITEMS: list[str] = [
*NOTES,
"Windmill Shuriken",
"Wingsuit",
Expand Down Expand Up @@ -83,7 +83,7 @@
# locations
# the names of these don't actually matter, but using the upstream's names for now
# order must be exactly the same as upstream
ALWAYS_LOCATIONS = [
ALWAYS_LOCATIONS: list[str] = [
# notes
"Sunken Shrine - Key of Love",
"Corrupted Future - Key of Courage",
Expand Down Expand Up @@ -160,7 +160,7 @@
"Elemental Skylands Seal - Fire",
]

BOSS_LOCATIONS = [
BOSS_LOCATIONS: list[str] = [
"Autumn Hills - Leaf Golem",
"Catacombs - Ruxxtin",
"Howling Grotto - Emerald Golem",
Expand Down
3 changes: 1 addition & 2 deletions worlds/messenger/options.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from dataclasses import dataclass
from typing import Dict

from schema import And, Optional, Or, Schema

Expand Down Expand Up @@ -167,7 +166,7 @@ class ShopPrices(Range):
default = 100


def planned_price(location: str) -> Dict[Optional, Or]:
def planned_price(location: str) -> dict[Optional, Or]:
return {
Optional(location): Or(
And(int, lambda n: n >= 0),
Expand Down
12 changes: 6 additions & 6 deletions worlds/messenger/portals.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from copy import deepcopy
from typing import List, TYPE_CHECKING
from typing import TYPE_CHECKING

from BaseClasses import CollectionState, PlandoOptions
from Options import PlandoConnection
Expand All @@ -8,7 +8,7 @@
from . import MessengerWorld


PORTALS = [
PORTALS: list[str] = [
"Autumn Hills",
"Riviere Turquoise",
"Howling Grotto",
Expand All @@ -18,7 +18,7 @@
]


SHOP_POINTS = {
SHOP_POINTS: dict[str, list[str]] = {
"Autumn Hills": [
"Climbing Claws",
"Hope Path",
Expand Down Expand Up @@ -113,7 +113,7 @@
}


CHECKPOINTS = {
CHECKPOINTS: dict[str, list[str]] = {
"Autumn Hills": [
"Hope Latch",
"Key of Hope",
Expand Down Expand Up @@ -186,7 +186,7 @@
}


REGION_ORDER = [
REGION_ORDER: list[str] = [
"Autumn Hills",
"Forlorn Temple",
"Catacombs",
Expand Down Expand Up @@ -228,7 +228,7 @@ def create_mapping(in_portal: str, warp: str) -> str:

return parent

def handle_planned_portals(plando_connections: List[PlandoConnection]) -> None:
def handle_planned_portals(plando_connections: list[PlandoConnection]) -> None:
"""checks the provided plando connections for portals and connects them"""
nonlocal available_portals

Expand Down
13 changes: 5 additions & 8 deletions worlds/messenger/regions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from typing import Dict, List


LOCATIONS: Dict[str, List[str]] = {
LOCATIONS: dict[str, list[str]] = {
"Ninja Village - Nest": [
"Ninja Village - Candle",
"Ninja Village - Astral Seed",
Expand Down Expand Up @@ -201,7 +198,7 @@
}


SUB_REGIONS: Dict[str, List[str]] = {
SUB_REGIONS: dict[str, list[str]] = {
"Ninja Village": [
"Right",
],
Expand Down Expand Up @@ -385,7 +382,7 @@


# order is slightly funky here for back compat
MEGA_SHARDS: Dict[str, List[str]] = {
MEGA_SHARDS: dict[str, list[str]] = {
"Autumn Hills - Lakeside Checkpoint": ["Autumn Hills Mega Shard"],
"Forlorn Temple - Outside Shop": ["Hidden Entrance Mega Shard"],
"Catacombs - Top Left": ["Catacombs Mega Shard"],
Expand Down Expand Up @@ -414,7 +411,7 @@
}


REGION_CONNECTIONS: Dict[str, Dict[str, str]] = {
REGION_CONNECTIONS: dict[str, dict[str, str]] = {
"Menu": {"Tower HQ": "Start Game"},
"Tower HQ": {
"Autumn Hills - Portal": "ToTHQ Autumn Hills Portal",
Expand All @@ -436,7 +433,7 @@


# regions that don't have sub-regions
LEVELS: List[str] = [
LEVELS: list[str] = [
"Menu",
"Tower HQ",
"The Shop",
Expand Down
8 changes: 4 additions & 4 deletions worlds/messenger/rules.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, TYPE_CHECKING
from typing import TYPE_CHECKING

from BaseClasses import CollectionState
from worlds.generic.Rules import CollectionRule, add_rule, allow_self_locking_items
Expand All @@ -12,9 +12,9 @@
class MessengerRules:
player: int
world: "MessengerWorld"
connection_rules: Dict[str, CollectionRule]
region_rules: Dict[str, CollectionRule]
location_rules: Dict[str, CollectionRule]
connection_rules: dict[str, CollectionRule]
region_rules: dict[str, CollectionRule]
location_rules: dict[str, CollectionRule]
maximum_price: int
required_seals: int

Expand Down
18 changes: 9 additions & 9 deletions worlds/messenger/shop.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import Dict, List, NamedTuple, Optional, Set, TYPE_CHECKING, Tuple, Union
from typing import NamedTuple, TYPE_CHECKING

if TYPE_CHECKING:
from . import MessengerWorld
else:
MessengerWorld = object

PROG_SHOP_ITEMS: List[str] = [
PROG_SHOP_ITEMS: list[str] = [
"Path of Resilience",
"Meditation",
"Strike of the Ninja",
Expand All @@ -14,7 +14,7 @@
"Aerobatics Warrior",
]

USEFUL_SHOP_ITEMS: List[str] = [
USEFUL_SHOP_ITEMS: list[str] = [
"Karuta Plates",
"Serendipitous Bodies",
"Kusari Jacket",
Expand All @@ -29,10 +29,10 @@ class ShopData(NamedTuple):
internal_name: str
min_price: int
max_price: int
prerequisite: Optional[Union[str, Set[str]]] = None
prerequisite: str | set[str] | None = None


SHOP_ITEMS: Dict[str, ShopData] = {
SHOP_ITEMS: dict[str, ShopData] = {
"Karuta Plates": ShopData("HP_UPGRADE_1", 20, 200),
"Serendipitous Bodies": ShopData("ENEMY_DROP_HP", 20, 300, "The Shop - Karuta Plates"),
"Path of Resilience": ShopData("DAMAGE_REDUCTION", 100, 500, "The Shop - Serendipitous Bodies"),
Expand All @@ -56,7 +56,7 @@ class ShopData(NamedTuple):
"Focused Power Sense": ShopData("POWER_SEAL_WORLD_MAP", 300, 600, "The Shop - Power Sense"),
}

FIGURINES: Dict[str, ShopData] = {
FIGURINES: dict[str, ShopData] = {
"Green Kappa Figurine": ShopData("GREEN_KAPPA", 100, 500),
"Blue Kappa Figurine": ShopData("BLUE_KAPPA", 100, 500),
"Ountarde Figurine": ShopData("OUNTARDE", 100, 500),
Expand All @@ -73,12 +73,12 @@ class ShopData(NamedTuple):
}


def shuffle_shop_prices(world: MessengerWorld) -> Tuple[Dict[str, int], Dict[str, int]]:
def shuffle_shop_prices(world: MessengerWorld) -> tuple[dict[str, int], dict[str, int]]:
shop_price_mod = world.options.shop_price.value
shop_price_planned = world.options.shop_price_plan

shop_prices: Dict[str, int] = {}
figurine_prices: Dict[str, int] = {}
shop_prices: dict[str, int] = {}
figurine_prices: dict[str, int] = {}
for item, price in shop_price_planned.value.items():
if not isinstance(price, int):
price = world.random.choices(list(price.keys()), weights=list(price.values()))[0]
Expand Down
Loading

0 comments on commit 84744bf

Please sign in to comment.