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

View file

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

View file

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

View file

@ -2,13 +2,14 @@ import io
import logging import logging
import queue import queue
import threading import threading
from typing import List, Tuple, Dict
import requests import requests
from PIL import Image from PIL import Image
class ImageLoader(threading.Thread): 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) threading.Thread.__init__(self)
self.__queue = url_queue self.__queue = url_queue
@ -44,7 +45,7 @@ class ImageLoader(threading.Thread):
self.__queue.task_done() self.__queue.task_done()
@classmethod @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() url_queue = queue.Queue()
for url in urls: for url in urls:
url_queue.put(url) url_queue.put(url)
@ -62,11 +63,11 @@ class ImageLoader(threading.Thread):
for loader in loaders: for loader in loaders:
images = {**images, **loader.images} 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] images = [images[url] for url in urls]
return images return images
@property @property
def images(self): def images(self) -> Dict[str, Image.Image]:
return self.__images return self.__images

View file

@ -51,9 +51,9 @@ class Opus(Cards):
logger.info(f"imported card {card}") logger.info(f"imported card {card}")
@property @property
def name(self): def name(self) -> str:
return self.__name return self.__name
@property @property
def number(self): def number(self) -> str:
return self.__number 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 RESOLUTION = 429, 600 # default in TTsim: 480x670 pixels per card
def main(): def main() -> None:
# set up CLI # set up CLI
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='Imports FFTCG cards for TT-Sim.') description='Imports FFTCG cards for TT-Sim.')