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

cleanup, minor fixes

This commit is contained in:
Jörn-Michael Miehe 2021-08-18 17:38:58 +02:00
parent 8c88553d29
commit cb7b8c0620
5 changed files with 38 additions and 37 deletions

View file

@ -15,7 +15,6 @@ class Book:
# sort cards by element, then alphabetically
cards.sort(key=lambda x: x.name)
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
urls = [f"https://fftcg.cdn.sewest.net/images/cards/full/{card.code}_{language}.jpg" for card in cards]
@ -31,7 +30,7 @@ class Book:
page_images: list[Image.Image]
page_cards: Cards
for page_images, page_cards in zip(GRID.chunks(images), GRID.chunks(cards)):
for page_num, (page_images, page_cards) in enumerate(zip(GRID.chunks(images), GRID.chunks(cards))):
# create book page Image
page_image = Image.new("RGB", GRID * RESOLUTION)
logger.info(f"New image: {page_image.size[0]}x{page_image.size[1]}")
@ -49,6 +48,7 @@ class Book:
# save page
self.__pages.append({
"file_name": f"{cards.file_name}_{page_num}.jpg",
"image": page_image,
"cards": page_cards,
})
@ -56,9 +56,8 @@ class Book:
def save(self) -> None:
# save images
for i, page in enumerate(self.__pages):
fn = f"{self.__file_name}_{i}.jpg"
# save page image
page["image"].save(fn)
page["image"].save(page["file_name"])
book: dict[str, Cards]
try:
@ -69,13 +68,12 @@ class Book:
# save book
for i, page in enumerate(self.__pages):
fn = f"{self.__file_name}_{i}.jpg"
# ask for upload
face_url = input(f"Upload '{fn}' and paste URL: ")
face_url = input(f"Upload '{page['file_name']}' and paste URL: ")
for card in page["cards"]:
card.face_url = face_url
# add contents of that image
book[fn] = page["cards"]
book[page["file_name"]] = page["cards"]
# update book.yml file
with open(BOOK_YML_NAME, "w") as file:

View file

@ -41,7 +41,3 @@ class CardDB:
card.code: card
for card in cards
}
# write carddb.yml file
with open("carddb.yml", "w") as file:
yaml.dump(self.__content, file, Dumper=yaml.Dumper)

View file

@ -73,7 +73,7 @@ class Opus(Cards):
filters |= {
# light/darkness elemental deck
"Light/Darkness": lambda card: card.elements == ["Light"] or card.elements == ["Darkness"],
"Light-Darkness": lambda card: card.elements == ["Light"] or card.elements == ["Darkness"],
# multi element deck
"Multi": lambda card: len(card.elements) > 1,
}

View file

@ -11,36 +11,41 @@ class TTSDeck(Cards):
super().__init__(name)
self.__description = description
# get cards from carddb
carddb = CardDB.get()
self.extend([carddb[code] for code in codes])
def __str__(self) -> str:
face_urls = list(set([
# unique face urls used
unique_face_urls = set([
card.face_url
for card in self
]))
])
# lookup for indices of urls
self.__url_indices = {
url: i + 1
for i, url in enumerate(unique_face_urls)
}
@property
def tts_object(self) -> dict[str, any]:
# build the "CustomDeck" dictionary
custom_deck = {
str(i + 1): {
str(i): {
"NumWidth": "10",
"NumHeight": "7",
"FaceURL": url,
"BackURL": CARD_BACK_URL,
} for i, url in enumerate(face_urls)
}
custom_deck_inv = {
url: i + 1
for i, url in enumerate(face_urls)
} for url, i in self.__url_indices.items()
}
# values both in main deck and each contained card
common_dict = {
"Transform": {
"scaleX": 2.17822933,
"scaleY": 1.0,
"scaleZ": 2.17822933
},
"Locked": False,
"Grid": True,
"Snap": True,
@ -50,40 +55,42 @@ class TTSDeck(Cards):
"GridProjection": False,
}
# cards contained in deck
contained_objects = [
{
"Name": "Card",
"Nickname": card.name,
"Description": card.text,
"CardID": 100 * self.__url_indices[card.face_url] + card.index,
"CardID": 100 * custom_deck_inv[card.face_url] + card.index,
"Name": "Card",
"Hands": True,
"SidewaysCard": False,
} | common_dict for card in self
]
# extract the card ids
deck_ids = [
contained_object["CardID"]
for contained_object in contained_objects
]
json_dict = {"ObjectStates": [
# create the deck dictionary
return {"ObjectStates": [
{
"Name": "Deck",
"Nickname": self.name,
"Description": self.__description,
"Hands": False,
"SidewaysCard": False,
"DeckIDs": deck_ids,
"CustomDeck": custom_deck,
"ContainedObjects": contained_objects,
"Name": "Deck",
"Hands": False,
"SidewaysCard": False,
} | common_dict
]}
return json.dumps(json_dict, indent=2)
def save(self, file_name: str) -> None:
pass
def save(self) -> None:
# only save if the deck contains cards
if self:
with open(f"{self.file_name}.json", "w") as file:
json.dump(self.tts_object, file, indent=2)

View file

@ -49,7 +49,7 @@ def main() -> None:
# create elemental decks for opus
for deck in opus.elemental_decks:
print(deck)
deck.save()
# bye
logging.info("Done. Put the generated JSON files in your 'Saved Objects' Folder.")