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: else:
def sub_encircle(match: re.Match): def sub_encircle(match: re.Match) -> str:
return encircle_symbol(match.group(1), False) 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) return encircle_symbol(Card.__ELEMENTS_MAP[match.group(1)], False)
def load_name(language: Language) -> str: 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)) return Grid((self.x * other.x, self.y * other.y))
@property @property
def x(self): def x(self) -> int:
return self[0] return self[0]
@property @property
def y(self): def y(self) -> int:
return self[1] return self[1]
@property @property
def capacity(self): def capacity(self) -> int:
# capacity of grid (reserve last space for card back) # capacity of grid (reserve last space for card back)
return self.x * self.y - 1 return self.x * self.y - 1

View file

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

View file

@ -1,5 +1,6 @@
import logging import logging
from dataclasses import replace from dataclasses import replace
from typing import Callable, Iterator
import requests import requests
import roman import roman
@ -81,7 +82,7 @@ class Opus(Cards):
return self.__number return self.__number
@property @property
def elemental_decks(self) -> list[TTSDeck]: def elemental_decks(self) -> Iterator[TTSDeck]:
if self.number in ["PR", "B"]: if self.number in ["PR", "B"]:
return [TTSDeck( return [TTSDeck(
codes=[ codes=[
@ -94,7 +95,7 @@ class Opus(Cards):
)] )]
else: else:
def element_filter(element: str): def element_filter(element: str) -> Callable[[Card], list[str]]:
return lambda card: card.elements == [element] return lambda card: card.elements == [element]
# simple cases: create lambdas for base elemental decks # 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: x[self.__language].name)
cards.sort(key=lambda x: "Multi" if len(x.elements) > 1 else x.elements[0]) cards.sort(key=lambda x: "Multi" if len(x.elements) > 1 else x.elements[0])
return [TTSDeck( # generate decks
codes=[ decks = (
card.code TTSDeck(
for card in cards codes=[
if f(card) card.code
], for card in cards
name=f"{self.name} {elem}", if f(card)
description=f"All {self.name} Cards with {elem} element in alphabetical order", ],
face_down=False, name=f"{self.name} {elem}",
) for elem, f in filters.items()] 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 PIL import Image
from .grid import Grid from .grid import Grid
@ -13,7 +15,7 @@ CARD_BACK_URL = "http://cloud-3.steamusercontent.com/ugc/948455238665576576/8506
# functions # functions
def encircle_symbol(symbol: str, negative: bool): def encircle_symbol(symbol: str, negative: bool) -> str:
symbol = symbol[0].upper() symbol = symbol[0].upper()
base_symbols: tuple[str, str] = "", "" base_symbols: tuple[str, str] = "", ""
@ -37,7 +39,7 @@ def encircle_symbol(symbol: str, negative: bool):
return chr(ord(base_symbols[1]) + symbol_num) 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 there are elements
while whole: while whole:
# get a chunk # get a chunk