mirror of
https://github.com/ldericher/fftcgtool
synced 2025-01-15 15:02:59 +00:00
face_url upload prompt
This commit is contained in:
parent
81122f8de8
commit
8c88553d29
7 changed files with 87 additions and 63 deletions
|
@ -15,6 +15,7 @@ class Book:
|
||||||
# sort cards by element, then alphabetically
|
# sort cards by element, then alphabetically
|
||||||
cards.sort(key=lambda x: x.name)
|
cards.sort(key=lambda x: x.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])
|
||||||
|
self.__file_name = cards.file_name
|
||||||
|
|
||||||
# all card face URLs
|
# all card face URLs
|
||||||
urls = [f"https://fftcg.cdn.sewest.net/images/cards/full/{card.code}_{language}.jpg" for card in cards]
|
urls = [f"https://fftcg.cdn.sewest.net/images/cards/full/{card.code}_{language}.jpg" for card in cards]
|
||||||
|
@ -27,6 +28,9 @@ class Book:
|
||||||
back_image = images.pop(-1)
|
back_image = images.pop(-1)
|
||||||
|
|
||||||
self.__pages = []
|
self.__pages = []
|
||||||
|
|
||||||
|
page_images: list[Image.Image]
|
||||||
|
page_cards: Cards
|
||||||
for page_images, page_cards in zip(GRID.chunks(images), GRID.chunks(cards)):
|
for page_images, page_cards in zip(GRID.chunks(images), GRID.chunks(cards)):
|
||||||
# create book page Image
|
# create book page Image
|
||||||
page_image = Image.new("RGB", GRID * RESOLUTION)
|
page_image = Image.new("RGB", GRID * RESOLUTION)
|
||||||
|
@ -39,16 +43,24 @@ class Book:
|
||||||
# paste card back in last position
|
# paste card back in last position
|
||||||
GRID.paste(page_image, GRID.capacity, back_image)
|
GRID.paste(page_image, GRID.capacity, back_image)
|
||||||
|
|
||||||
|
# set card indices
|
||||||
|
for i, card in enumerate(page_cards):
|
||||||
|
card.index = i
|
||||||
|
|
||||||
# save page
|
# save page
|
||||||
self.__pages.append({
|
self.__pages.append({
|
||||||
"image": page_image,
|
"image": page_image,
|
||||||
"cards": page_cards,
|
"cards": page_cards,
|
||||||
})
|
})
|
||||||
|
|
||||||
def save(self, file_name: str) -> None:
|
def save(self) -> None:
|
||||||
book: dict[str, dict[str, any]]
|
# save images
|
||||||
|
for i, page in enumerate(self.__pages):
|
||||||
|
fn = f"{self.__file_name}_{i}.jpg"
|
||||||
|
# save page image
|
||||||
|
page["image"].save(fn)
|
||||||
|
|
||||||
# load book.yml file
|
book: dict[str, Cards]
|
||||||
try:
|
try:
|
||||||
with open(BOOK_YML_NAME, "r") as file:
|
with open(BOOK_YML_NAME, "r") as file:
|
||||||
book = yaml.load(file, Loader=yaml.Loader)
|
book = yaml.load(file, Loader=yaml.Loader)
|
||||||
|
@ -57,11 +69,13 @@ class Book:
|
||||||
|
|
||||||
# save book
|
# save book
|
||||||
for i, page in enumerate(self.__pages):
|
for i, page in enumerate(self.__pages):
|
||||||
fn = f"{file_name}_{i}.jpg"
|
fn = f"{self.__file_name}_{i}.jpg"
|
||||||
# save page image
|
# ask for upload
|
||||||
page["image"].save(fn)
|
face_url = input(f"Upload '{fn}' and paste URL: ")
|
||||||
|
for card in page["cards"]:
|
||||||
|
card.face_url = face_url
|
||||||
# add contents of that image
|
# add contents of that image
|
||||||
book[fn] = {"cards": page["cards"]}
|
book[fn] = page["cards"]
|
||||||
|
|
||||||
# update book.yml file
|
# update book.yml file
|
||||||
with open(BOOK_YML_NAME, "w") as file:
|
with open(BOOK_YML_NAME, "w") as file:
|
||||||
|
|
|
@ -2,15 +2,11 @@ from __future__ import annotations
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import yaml
|
|
||||||
|
|
||||||
from .code import Code
|
from .code import Code
|
||||||
from .utils import encircle_symbol
|
from .utils import encircle_symbol
|
||||||
|
|
||||||
|
|
||||||
class Card(yaml.YAMLObject):
|
class Card:
|
||||||
yaml_tag = u'!Card'
|
|
||||||
|
|
||||||
__ELEMENTS_MAP = {
|
__ELEMENTS_MAP = {
|
||||||
"火": "Fire",
|
"火": "Fire",
|
||||||
"氷": "Ice",
|
"氷": "Ice",
|
||||||
|
@ -22,20 +18,23 @@ class Card(yaml.YAMLObject):
|
||||||
"闇": "Darkness"
|
"闇": "Darkness"
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, code, elements, name, text):
|
def __init__(self, code: Code, elements: list[str], name: str, text: str, face_url: str = "", index: int = 0):
|
||||||
self.__code = code
|
self.__code = code
|
||||||
self.__elements = elements
|
self.__elements = elements
|
||||||
self.__name = name
|
self.__name = name
|
||||||
self.__text = text
|
self.__text = text
|
||||||
|
|
||||||
|
self.__face_url = face_url
|
||||||
|
self.__index = index
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_data(cls, data: dict[str, any], language: str) -> Card:
|
def from_data(cls, data: dict[str, any], language: str) -> Card:
|
||||||
if not data:
|
if not data:
|
||||||
return cls(
|
return cls(
|
||||||
code=Code(""),
|
code=Code(""),
|
||||||
elements=[],
|
elements=[],
|
||||||
name=None,
|
name="",
|
||||||
text=None,
|
text="",
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -88,3 +87,19 @@ class Card(yaml.YAMLObject):
|
||||||
@property
|
@property
|
||||||
def elements(self) -> list[str]:
|
def elements(self) -> list[str]:
|
||||||
return self.__elements
|
return self.__elements
|
||||||
|
|
||||||
|
@property
|
||||||
|
def face_url(self) -> str:
|
||||||
|
return self.__face_url
|
||||||
|
|
||||||
|
@face_url.setter
|
||||||
|
def face_url(self, face_url: str) -> None:
|
||||||
|
self.__face_url = face_url
|
||||||
|
|
||||||
|
@property
|
||||||
|
def index(self) -> int:
|
||||||
|
return self.__index
|
||||||
|
|
||||||
|
@index.setter
|
||||||
|
def index(self, index: int) -> None:
|
||||||
|
self.__index = index
|
||||||
|
|
|
@ -2,6 +2,7 @@ from __future__ import annotations
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
from fftcg import Card
|
||||||
from fftcg.code import Code
|
from fftcg.code import Code
|
||||||
from fftcg.utils import BOOK_YML_NAME
|
from fftcg.utils import BOOK_YML_NAME
|
||||||
|
|
||||||
|
@ -17,10 +18,10 @@ class CardDB:
|
||||||
return CardDB.__instance
|
return CardDB.__instance
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.__content: dict[Code, dict[str, any]] = {}
|
self.__content: dict[Code, Card] = {}
|
||||||
|
|
||||||
def __getitem__(self, code: Code) -> dict[str, any]:
|
def __getitem__(self, code: Code) -> Card:
|
||||||
return self.__content[str(code)]
|
return self.__content[code]
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
# load book.yml file
|
# load book.yml file
|
||||||
|
@ -35,26 +36,12 @@ class CardDB:
|
||||||
# every card is indexable by its code
|
# every card is indexable by its code
|
||||||
self.__content.clear()
|
self.__content.clear()
|
||||||
|
|
||||||
for file_name, content in book.items():
|
for file_name, cards in book.items():
|
||||||
self.__content |= {
|
self.__content |= {
|
||||||
str(card.code): {
|
card.code: card
|
||||||
"card": card,
|
for card in cards
|
||||||
"file": file_name,
|
|
||||||
"index": i,
|
|
||||||
} for i, card in enumerate(content["cards"])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# write carddb.yml file
|
# write carddb.yml file
|
||||||
with open("carddb.yml", "w") as file:
|
with open("carddb.yml", "w") as file:
|
||||||
yaml.dump(self.__content, file, Dumper=yaml.Dumper)
|
yaml.dump(self.__content, file, Dumper=yaml.Dumper)
|
||||||
|
|
||||||
# def make_deck(self, filters):
|
|
||||||
# # filter codes by card criteria
|
|
||||||
# codes = [
|
|
||||||
# content["card"].code
|
|
||||||
# for content in self.__content.values()
|
|
||||||
# if all([f(content["card"]) for f in filters])
|
|
||||||
# ]
|
|
||||||
#
|
|
||||||
# from .ttsdeck import TTSDeck
|
|
||||||
# return TTSDeck(codes)
|
|
||||||
|
|
|
@ -14,15 +14,7 @@ class Cards(list[Card]):
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return f"[{', '.join(str(card) for card in self)}]"
|
return f"[{', '.join(str(card) for card in self)}]"
|
||||||
|
|
||||||
@property
|
def _load(self, params: dict[str, any]) -> None:
|
||||||
def name(self) -> str:
|
|
||||||
return self.__name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def file_name(self) -> str:
|
|
||||||
return self.name.lower().replace(" ", "_")
|
|
||||||
|
|
||||||
def _load(self, params: dict[str, any]):
|
|
||||||
# required params:
|
# required params:
|
||||||
# text
|
# text
|
||||||
# supported params:
|
# supported params:
|
||||||
|
@ -36,3 +28,11 @@ class Cards(list[Card]):
|
||||||
req = requests.post(Cards.__API_URL, json=params)
|
req = requests.post(Cards.__API_URL, json=params)
|
||||||
self.clear()
|
self.clear()
|
||||||
self.extend([Card.from_data(card_data, "EN") for card_data in req.json()["cards"]])
|
self.extend([Card.from_data(card_data, "EN") for card_data in req.json()["cards"]])
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self) -> str:
|
||||||
|
return self.__name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def file_name(self) -> str:
|
||||||
|
return self.name.lower().replace(" ", "_")
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import yaml
|
|
||||||
|
|
||||||
|
|
||||||
class Code(yaml.YAMLObject):
|
|
||||||
yaml_tag = u'!Code'
|
|
||||||
|
|
||||||
|
class Code:
|
||||||
__RE_NUM = re.compile(r"([0-9]+)-([0-9]+)([CRHLS])")
|
__RE_NUM = re.compile(r"([0-9]+)-([0-9]+)([CRHLS])")
|
||||||
__RE_PROMO = re.compile(r"(PR)-([0-9]+)")
|
__RE_PROMO = re.compile(r"(PR)-([0-9]+)")
|
||||||
__RE_BOSS = re.compile(r"(B)-([0-9]+)")
|
__RE_BOSS = re.compile(r"(B)-([0-9]+)")
|
||||||
|
@ -36,6 +34,12 @@ class Code(yaml.YAMLObject):
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return f"{self.__opus}-{self.__serial}{self.__rarity}"
|
return f"{self.__opus}-{self.__serial}{self.__rarity}"
|
||||||
|
|
||||||
|
def __hash__(self) -> hash:
|
||||||
|
return hash(str(self))
|
||||||
|
|
||||||
|
def __eq__(self, other: Code):
|
||||||
|
return str(self) == str(other)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def opus(self) -> str:
|
def opus(self) -> str:
|
||||||
return self.__opus
|
return self.__opus
|
||||||
|
|
|
@ -1,20 +1,24 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from .carddb import CardDB
|
from .carddb import CardDB
|
||||||
|
from .cards import Cards
|
||||||
from .code import Code
|
from .code import Code
|
||||||
from .utils import CARD_BACK_URL
|
from .utils import CARD_BACK_URL
|
||||||
|
|
||||||
|
|
||||||
class TTSDeck(list[dict[str, any]]):
|
class TTSDeck(Cards):
|
||||||
def __init__(self, codes: list[Code], name: str, description: str):
|
def __init__(self, codes: list[Code], name: str, description: str):
|
||||||
carddb = CardDB.get()
|
super().__init__(name)
|
||||||
super().__init__([carddb[code] for code in codes])
|
|
||||||
|
|
||||||
self.__name = name
|
|
||||||
self.__description = description
|
self.__description = description
|
||||||
|
|
||||||
|
carddb = CardDB.get()
|
||||||
|
self.extend([carddb[code] for code in codes])
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
face_urls = list(set([entry["file"] for entry in self]))
|
face_urls = list(set([
|
||||||
|
card.face_url
|
||||||
|
for card in self
|
||||||
|
]))
|
||||||
|
|
||||||
custom_deck = {
|
custom_deck = {
|
||||||
str(i + 1): {
|
str(i + 1): {
|
||||||
|
@ -49,14 +53,14 @@ class TTSDeck(list[dict[str, any]]):
|
||||||
contained_objects = [
|
contained_objects = [
|
||||||
{
|
{
|
||||||
"Name": "Card",
|
"Name": "Card",
|
||||||
"Nickname": entry["card"].name,
|
"Nickname": card.name,
|
||||||
"Description": entry["card"].text,
|
"Description": card.text,
|
||||||
|
|
||||||
"CardID": 100 * custom_deck_inv[entry["file"]] + entry["index"],
|
"CardID": 100 * custom_deck_inv[card.face_url] + card.index,
|
||||||
|
|
||||||
"Hands": True,
|
"Hands": True,
|
||||||
"SidewaysCard": False,
|
"SidewaysCard": False,
|
||||||
} | common_dict for entry in self
|
} | common_dict for card in self
|
||||||
]
|
]
|
||||||
|
|
||||||
deck_ids = [
|
deck_ids = [
|
||||||
|
@ -64,10 +68,10 @@ class TTSDeck(list[dict[str, any]]):
|
||||||
for contained_object in contained_objects
|
for contained_object in contained_objects
|
||||||
]
|
]
|
||||||
|
|
||||||
jsondict = {"ObjectStates": [
|
json_dict = {"ObjectStates": [
|
||||||
{
|
{
|
||||||
"Name": "Deck",
|
"Name": "Deck",
|
||||||
"Nickname": self.__name,
|
"Nickname": self.name,
|
||||||
"Description": self.__description,
|
"Description": self.__description,
|
||||||
|
|
||||||
"Hands": False,
|
"Hands": False,
|
||||||
|
@ -79,7 +83,7 @@ class TTSDeck(list[dict[str, any]]):
|
||||||
} | common_dict
|
} | common_dict
|
||||||
]}
|
]}
|
||||||
|
|
||||||
return json.dumps(jsondict, indent=2)
|
return json.dumps(json_dict, indent=2)
|
||||||
|
|
||||||
def save(self, file_name: str) -> None:
|
def save(self, file_name: str) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
2
main.py
2
main.py
|
@ -41,7 +41,7 @@ def main() -> None:
|
||||||
# main program
|
# main program
|
||||||
opus = fftcg.Opus(args.opus_id)
|
opus = fftcg.Opus(args.opus_id)
|
||||||
book = fftcg.Book(opus, "eg", args.num_threads)
|
book = fftcg.Book(opus, "eg", args.num_threads)
|
||||||
book.save(opus.file_name)
|
book.save()
|
||||||
|
|
||||||
# load the current carddb
|
# load the current carddb
|
||||||
carddb = fftcg.CardDB.get()
|
carddb = fftcg.CardDB.get()
|
||||||
|
|
Loading…
Reference in a new issue