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 # 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]
@ -31,7 +30,7 @@ class Book:
page_images: list[Image.Image] page_images: list[Image.Image]
page_cards: Cards 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 # create book page Image
page_image = Image.new("RGB", GRID * RESOLUTION) page_image = Image.new("RGB", GRID * RESOLUTION)
logger.info(f"New image: {page_image.size[0]}x{page_image.size[1]}") logger.info(f"New image: {page_image.size[0]}x{page_image.size[1]}")
@ -49,6 +48,7 @@ class Book:
# save page # save page
self.__pages.append({ self.__pages.append({
"file_name": f"{cards.file_name}_{page_num}.jpg",
"image": page_image, "image": page_image,
"cards": page_cards, "cards": page_cards,
}) })
@ -56,9 +56,8 @@ class Book:
def save(self) -> None: def save(self) -> None:
# save images # save images
for i, page in enumerate(self.__pages): for i, page in enumerate(self.__pages):
fn = f"{self.__file_name}_{i}.jpg"
# save page image # save page image
page["image"].save(fn) page["image"].save(page["file_name"])
book: dict[str, Cards] book: dict[str, Cards]
try: try:
@ -69,13 +68,12 @@ class Book:
# save book # save book
for i, page in enumerate(self.__pages): for i, page in enumerate(self.__pages):
fn = f"{self.__file_name}_{i}.jpg"
# ask for upload # 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"]: for card in page["cards"]:
card.face_url = face_url card.face_url = face_url
# add contents of that image # add contents of that image
book[fn] = page["cards"] book[page["file_name"]] = 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:

View file

@ -41,7 +41,3 @@ class CardDB:
card.code: card card.code: card
for card in cards 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 |= { filters |= {
# light/darkness elemental deck # 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 element deck
"Multi": lambda card: len(card.elements) > 1, "Multi": lambda card: len(card.elements) > 1,
} }

View file

@ -11,36 +11,41 @@ class TTSDeck(Cards):
super().__init__(name) super().__init__(name)
self.__description = description self.__description = description
# get cards from carddb
carddb = CardDB.get() carddb = CardDB.get()
self.extend([carddb[code] for code in codes]) self.extend([carddb[code] for code in codes])
def __str__(self) -> str: # unique face urls used
face_urls = list(set([ unique_face_urls = set([
card.face_url card.face_url
for card in self 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 = { custom_deck = {
str(i + 1): { str(i): {
"NumWidth": "10", "NumWidth": "10",
"NumHeight": "7", "NumHeight": "7",
"FaceURL": url, "FaceURL": url,
"BackURL": CARD_BACK_URL, "BackURL": CARD_BACK_URL,
} for i, url in enumerate(face_urls) } for url, i in self.__url_indices.items()
}
custom_deck_inv = {
url: i + 1
for i, url in enumerate(face_urls)
} }
# values both in main deck and each contained card
common_dict = { common_dict = {
"Transform": { "Transform": {
"scaleX": 2.17822933, "scaleX": 2.17822933,
"scaleY": 1.0, "scaleY": 1.0,
"scaleZ": 2.17822933 "scaleZ": 2.17822933
}, },
"Locked": False, "Locked": False,
"Grid": True, "Grid": True,
"Snap": True, "Snap": True,
@ -50,40 +55,42 @@ class TTSDeck(Cards):
"GridProjection": False, "GridProjection": False,
} }
# cards contained in deck
contained_objects = [ contained_objects = [
{ {
"Name": "Card",
"Nickname": card.name, "Nickname": card.name,
"Description": card.text, "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, "Hands": True,
"SidewaysCard": False, "SidewaysCard": False,
} | common_dict for card in self } | common_dict for card in self
] ]
# extract the card ids
deck_ids = [ deck_ids = [
contained_object["CardID"] contained_object["CardID"]
for contained_object in contained_objects for contained_object in contained_objects
] ]
json_dict = {"ObjectStates": [ # create the deck dictionary
return {"ObjectStates": [
{ {
"Name": "Deck",
"Nickname": self.name, "Nickname": self.name,
"Description": self.__description, "Description": self.__description,
"Hands": False,
"SidewaysCard": False,
"DeckIDs": deck_ids, "DeckIDs": deck_ids,
"CustomDeck": custom_deck, "CustomDeck": custom_deck,
"ContainedObjects": contained_objects, "ContainedObjects": contained_objects,
"Name": "Deck",
"Hands": False,
"SidewaysCard": False,
} | common_dict } | common_dict
]} ]}
return json.dumps(json_dict, indent=2) def save(self) -> None:
# only save if the deck contains cards
def save(self, file_name: str) -> None: if self:
pass 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 # create elemental decks for opus
for deck in opus.elemental_decks: for deck in opus.elemental_decks:
print(deck) deck.save()
# bye # bye
logging.info("Done. Put the generated JSON files in your 'Saved Objects' Folder.") logging.info("Done. Put the generated JSON files in your 'Saved Objects' Folder.")