1
0
Fork 0
mirror of https://github.com/ldericher/fftcgtool synced 2025-01-15 23:03:00 +00:00
fftcgtool/fftcg/ttsdeck.py

86 lines
2.2 KiB
Python
Raw Normal View History

2021-08-16 23:35:57 +00:00
import json
from .carddb import CardDB
from .code import Code
2021-08-18 11:49:34 +00:00
from .utils import CARD_BACK_URL
2021-08-16 23:35:57 +00:00
class TTSDeck(list[dict[str, any]]):
2021-08-18 11:49:34 +00:00
def __init__(self, codes: list[Code], name: str, description: str):
2021-08-17 15:37:28 +00:00
carddb = CardDB.get()
super().__init__([carddb[code] for code in codes])
2021-08-16 23:35:57 +00:00
2021-08-18 11:49:34 +00:00
self.__name = name
self.__description = description
2021-08-16 23:35:57 +00:00
def __str__(self) -> str:
face_urls = list(set([entry["file"] for entry in self]))
custom_deck = {
str(i + 1): {
"NumWidth": "10",
"NumHeight": "7",
"FaceURL": url,
2021-08-18 11:49:34 +00:00
"BackURL": CARD_BACK_URL,
2021-08-16 23:35:57 +00:00
} for i, url in enumerate(face_urls)
}
custom_deck_inv = {
url: i + 1
for i, url in enumerate(face_urls)
}
common_dict = {
"Transform": {
"scaleX": 2.17822933,
"scaleY": 1.0,
"scaleZ": 2.17822933
},
"Locked": False,
"Grid": True,
"Snap": True,
"Autoraise": True,
"Sticky": True,
"Tooltip": True,
"GridProjection": False,
}
contained_objects = [
{
"Name": "Card",
"Nickname": entry["card"].name,
"Description": entry["card"].text,
"CardID": 100 * custom_deck_inv[entry["file"]] + entry["index"],
"Hands": True,
"SidewaysCard": False,
} | common_dict for entry in self
]
deck_ids = [
contained_object["CardID"]
for contained_object in contained_objects
]
jsondict = {"ObjectStates": [
{
"Name": "Deck",
2021-08-18 11:49:34 +00:00
"Nickname": self.__name,
"Description": self.__description,
2021-08-16 23:35:57 +00:00
"Hands": False,
"SidewaysCard": False,
"DeckIDs": deck_ids,
"CustomDeck": custom_deck,
"ContainedObjects": contained_objects,
} | common_dict
]}
return json.dumps(jsondict, indent=2)
2021-08-18 11:49:34 +00:00
def save(self, file_name: str) -> None:
pass