1
0
Fork 0
mirror of https://github.com/ldericher/fftcgtool synced 2025-01-15 15:02:59 +00:00
This commit is contained in:
Jörn-Michael Miehe 2021-08-09 04:03:24 +02:00
parent 6f1b5fd422
commit 418d8f823e
6 changed files with 38 additions and 35 deletions

View file

@ -1,4 +1,5 @@
import logging
from typing import List, Tuple, Any
from PIL import Image
@ -6,7 +7,7 @@ from .cards import Cards
from .imageloader import ImageLoader
def chunks(whole: list, chunk_size):
def chunks(whole: List[Any], chunk_size) -> List:
# while there are elements
while whole:
# get a chunk
@ -22,7 +23,8 @@ class Book:
# Card back image by Aurik
__BACK_URL = "http://cloud-3.steamusercontent.com/ugc/948455238665576576/85063172B8C340602E8D6C783A457122F53F7843/"
def __init__(self, cards: Cards, grid: tuple, resolution: tuple, language: str, num_threads: int):
def __init__(self, cards: Cards, grid: Tuple[int, int], resolution: Tuple[int, int], language: str,
num_threads: int):
logger = logging.getLogger(__name__)
# sort cards by element, then alphabetically
@ -47,7 +49,7 @@ class Book:
# width, height per card
w, h = resolution
def paste_image(page: Image, index: int, image: Image):
def paste_image(page: Image, index: int, image: Image) -> None:
x, y = (index % c) * w, (index // c) * h
page.paste(image, (x, y))
@ -66,6 +68,6 @@ class Book:
self.__pages.append(page)
def save(self, filename: str):
def save(self, filename: str) -> None:
for i, page in enumerate(self.__pages):
page.save(filename.format(i))

View file

@ -1,5 +1,7 @@
import re
from typing import List, Dict, Any
class Card:
__ELEMENTS_MAP = {
@ -13,7 +15,7 @@ class Card:
'': "Darkness"
}
def __init__(self, data: dict, language: str = "EN"):
def __init__(self, data: Dict[str, Any], language: str = "EN"):
if not data:
self.__opus = "0"
self.__serial = "000"
@ -48,34 +50,34 @@ class Card:
self.__name = data[f"Name_{language}"]
self.__text = data[f"Text_{language}"]
def __str__(self):
def __str__(self) -> str:
return f"'{self.__name}' ({'/'.join(self.__elements)}, {self.code})"
# 6-048C
@property
def code(self):
def code(self) -> str:
return f"{self.__opus}-{self.__serial}{self.__rarity}"
@property
def opus(self):
def opus(self) -> str:
return self.__opus
@property
def serial(self):
def serial(self) -> int:
return int(self.__serial)
@property
def rarity(self):
def rarity(self) -> str:
return self.__rarity
@property
def name(self):
def name(self) -> str:
return self.__name
@property
def text(self):
def text(self) -> str:
return self.__text
@property
def elements(self):
def elements(self) -> List[str]:
return self.__elements

View file

@ -1,27 +1,25 @@
from typing import Dict, Any, List
import requests
from .card import Card
class Cards(list):
class Cards(List[Card]):
__API_URL = "https://fftcg.square-enix-games.com/de/get-cards"
def __init__(self, params):
def __init__(self, params: Dict[str, Any]):
list.__init__(self)
if isinstance(params, dict):
# required params:
# text
# supported params:
# [str] text, language, code, multicard="○"|"", ex_burst="○"|"", special="《S》"|""
# [array] type, element, cost, rarity, power, category_1, set
# [int] exactmatch=0|1
# required params:
# text
# supported params:
# [str] text, language, code, multicard="○"|"", ex_burst="○"|"", special="《S》"|""
# [array] type, element, cost, rarity, power, category_1, set
# [int] exactmatch=0|1
req = requests.post(Cards.__API_URL, json=params)
self.extend([Card(card_data) for card_data in req.json()["cards"]])
req = requests.post(Cards.__API_URL, json=params)
self.extend([Card(card_data) for card_data in req.json()["cards"]])
elif isinstance(params, list):
self.extend(params)
def __str__(self):
def __str__(self) -> str:
return "\n".join(str(card) for card in self)

View file

@ -2,13 +2,14 @@ import io
import logging
import queue
import threading
from typing import List, Tuple, Dict
import requests
from PIL import Image
class ImageLoader(threading.Thread):
def __init__(self, url_queue: queue.Queue, resolution: tuple, language: str):
def __init__(self, url_queue: queue.Queue, resolution: Tuple[int, int], language: str):
threading.Thread.__init__(self)
self.__queue = url_queue
@ -44,7 +45,7 @@ class ImageLoader(threading.Thread):
self.__queue.task_done()
@classmethod
def load(cls, urls: list, resolution: tuple, language: str, num_threads: int):
def load(cls, urls: List[str], resolution: Tuple[int, int], language: str, num_threads: int) -> List[Image.Image]:
url_queue = queue.Queue()
for url in urls:
url_queue.put(url)
@ -62,11 +63,11 @@ class ImageLoader(threading.Thread):
for loader in loaders:
images = {**images, **loader.images}
# sort images to match the initial "cards" list
# sort images to match the initial "urls" list
images = [images[url] for url in urls]
return images
@property
def images(self):
def images(self) -> Dict[str, Image.Image]:
return self.__images

View file

@ -51,9 +51,9 @@ class Opus(Cards):
logger.info(f"imported card {card}")
@property
def name(self):
def name(self) -> str:
return self.__name
@property
def number(self):
def number(self) -> str:
return self.__number

View file

@ -11,7 +11,7 @@ GRID = 7, 10 # default in TTsim: 7 rows, 10 columns
RESOLUTION = 429, 600 # default in TTsim: 480x670 pixels per card
def main():
def main() -> None:
# set up CLI
parser = argparse.ArgumentParser(
description='Imports FFTCG cards for TT-Sim.')