1
0
Fork 0
mirror of https://github.com/ldericher/fftcgtool synced 2025-01-15 15:02:59 +00:00

type hints

This commit is contained in:
Jörn-Michael Miehe 2021-09-03 07:34:12 +02:00
parent c270959ed2
commit 0f176f44ea
5 changed files with 34 additions and 21 deletions

View file

@ -45,10 +45,10 @@ class Card:
)
else:
def sub_encircle(match: re.Match):
def sub_encircle(match: re.Match) -> str:
return encircle_symbol(match.group(1), False)
def sub_elements(match: re.Match):
def sub_elements(match: re.Match) -> str:
return encircle_symbol(Card.__ELEMENTS_MAP[match.group(1)], False)
def load_name(language: Language) -> str:

View file

@ -6,14 +6,14 @@ class Grid(tuple[int, int]):
return Grid((self.x * other.x, self.y * other.y))
@property
def x(self):
def x(self) -> int:
return self[0]
@property
def y(self):
def y(self) -> int:
return self[1]
@property
def capacity(self):
def capacity(self) -> int:
# capacity of grid (reserve last space for card back)
return self.x * self.y - 1

View file

@ -19,7 +19,7 @@ class Language:
object.__setattr__(self, "short", "en")
@property
def image_suffix(self):
def image_suffix(self) -> str:
# supported languages for face URLs
if self.short in ["de", "es", "fr", "it"]:
return self.short
@ -27,7 +27,7 @@ class Language:
return "eg"
@property
def key_suffix(self):
def key_suffix(self) -> str:
# supported languages for Square API
if self.short in ["de", "es", "fr", "it"]:
return f"_{self.short.upper()}"

View file

@ -1,5 +1,6 @@
import logging
from dataclasses import replace
from typing import Callable, Iterator
import requests
import roman
@ -81,7 +82,7 @@ class Opus(Cards):
return self.__number
@property
def elemental_decks(self) -> list[TTSDeck]:
def elemental_decks(self) -> Iterator[TTSDeck]:
if self.number in ["PR", "B"]:
return [TTSDeck(
codes=[
@ -94,7 +95,7 @@ class Opus(Cards):
)]
else:
def element_filter(element: str):
def element_filter(element: str) -> Callable[[Card], list[str]]:
return lambda card: card.elements == [element]
# simple cases: create lambdas for base elemental decks
@ -116,13 +117,23 @@ class Opus(Cards):
cards.sort(key=lambda x: x[self.__language].name)
cards.sort(key=lambda x: "Multi" if len(x.elements) > 1 else x.elements[0])
return [TTSDeck(
codes=[
card.code
for card in cards
if f(card)
],
name=f"{self.name} {elem}",
description=f"All {self.name} Cards with {elem} element in alphabetical order",
face_down=False,
) for elem, f in filters.items()]
# generate decks
decks = (
TTSDeck(
codes=[
card.code
for card in cards
if f(card)
],
name=f"{self.name} {elem}",
description=f"All {self.name} Cards with {elem} element in alphabetical order",
face_down=False,
) for elem, f in filters.items()
)
# Ignore empty decks
return (
deck
for deck in decks
if deck
)

View file

@ -1,3 +1,5 @@
from typing import Iterator
from PIL import Image
from .grid import Grid
@ -13,7 +15,7 @@ CARD_BACK_URL = "http://cloud-3.steamusercontent.com/ugc/948455238665576576/8506
# functions
def encircle_symbol(symbol: str, negative: bool):
def encircle_symbol(symbol: str, negative: bool) -> str:
symbol = symbol[0].upper()
base_symbols: tuple[str, str] = "", ""
@ -37,7 +39,7 @@ def encircle_symbol(symbol: str, negative: bool):
return chr(ord(base_symbols[1]) + symbol_num)
def chunks(chunk_size: int, whole: list):
def chunks(chunk_size: int, whole: list) -> Iterator[list]:
# while there are elements
while whole:
# get a chunk