mirror of
https://github.com/ldericher/fftcgtool
synced 2025-01-15 15:02:59 +00:00
preserve previously generated "face" values
This commit is contained in:
parent
10526d34e9
commit
c2f0f7f050
4 changed files with 27 additions and 12 deletions
|
@ -4,7 +4,7 @@ import re
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
from .code import Code
|
from .code import Code
|
||||||
from .language import Language
|
from .language import Language, API_LANGS
|
||||||
from .utils import encircle_symbol
|
from .utils import encircle_symbol
|
||||||
|
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ class Card:
|
||||||
|
|
||||||
content = {
|
content = {
|
||||||
language: CardContent(load_name(language), load_text(language), "")
|
language: CardContent(load_name(language), load_text(language), "")
|
||||||
for language in Language.all_api_langs()
|
for language in API_LANGS
|
||||||
}
|
}
|
||||||
|
|
||||||
return cls(
|
return cls(
|
||||||
|
|
|
@ -20,6 +20,9 @@ class CardDB:
|
||||||
|
|
||||||
return CardDB.__instance
|
return CardDB.__instance
|
||||||
|
|
||||||
|
def __contains__(self, item: Code) -> bool:
|
||||||
|
return item in self.__content
|
||||||
|
|
||||||
def __getitem__(self, code: Code) -> Card:
|
def __getitem__(self, code: Code) -> Card:
|
||||||
return self.__content[code]
|
return self.__content[code]
|
||||||
|
|
||||||
|
|
|
@ -36,9 +36,13 @@ class Language:
|
||||||
else:
|
else:
|
||||||
return "_EN"
|
return "_EN"
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def all_api_langs(cls) -> set[Language]:
|
API_LANGS = frozenset([
|
||||||
return set([
|
Language(short)
|
||||||
cls(short)
|
|
||||||
for short in ["de", "en", "es", "fr", "it", "ja"]
|
for short in ["de", "en", "es", "fr", "it", "ja"]
|
||||||
])
|
])
|
||||||
|
|
||||||
|
IMG_LANGS = frozenset([
|
||||||
|
Language(short)
|
||||||
|
for short in ["de", "en", "es", "fr", "it"]
|
||||||
|
])
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
import logging
|
import logging
|
||||||
|
from dataclasses import replace
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import roman
|
import roman
|
||||||
|
|
||||||
from .card import Card
|
from .card import Card
|
||||||
|
from .carddb import CardDB
|
||||||
from .cards import Cards
|
from .cards import Cards
|
||||||
from .language import Language
|
from .language import Language, API_LANGS
|
||||||
from .ttsdeck import TTSDeck
|
from .ttsdeck import TTSDeck
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,20 +16,21 @@ class Opus(Cards):
|
||||||
|
|
||||||
def __init__(self, opus_id: str, language: Language):
|
def __init__(self, opus_id: str, language: Language):
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
self.__language = language
|
||||||
|
|
||||||
params: dict[str, any]
|
params: dict[str, any]
|
||||||
if opus_id.isnumeric():
|
if opus_id.isnumeric():
|
||||||
name = f"Opus {opus_id} ({language.short})"
|
name = f"Opus {opus_id} ({self.__language.short})"
|
||||||
self.__number = opus_id
|
self.__number = opus_id
|
||||||
params = {"set": [f"Opus {roman.toRoman(int(opus_id)).upper()}"]}
|
params = {"set": [f"Opus {roman.toRoman(int(opus_id)).upper()}"]}
|
||||||
|
|
||||||
elif opus_id == "chaos":
|
elif opus_id == "chaos":
|
||||||
name = f"Boss Deck Chaos ({language.short})"
|
name = f"Boss Deck Chaos ({self.__language.short})"
|
||||||
self.__number = "B"
|
self.__number = "B"
|
||||||
params = {"set": ["Boss Deck Chaos"]}
|
params = {"set": ["Boss Deck Chaos"]}
|
||||||
|
|
||||||
elif opus_id == "promo":
|
elif opus_id == "promo":
|
||||||
name = f"Promo ({language.short})"
|
name = f"Promo ({self.__language.short})"
|
||||||
self.__number = "PR"
|
self.__number = "PR"
|
||||||
params = {"rarity": ["pr"]}
|
params = {"rarity": ["pr"]}
|
||||||
|
|
||||||
|
@ -49,6 +52,7 @@ class Opus(Cards):
|
||||||
|
|
||||||
# get cards from square api
|
# get cards from square api
|
||||||
req = requests.post(Opus.__SQUARE_API_URL, json=params)
|
req = requests.post(Opus.__SQUARE_API_URL, json=params)
|
||||||
|
carddb = CardDB()
|
||||||
cards = [
|
cards = [
|
||||||
Card.from_square_api_data(card_data)
|
Card.from_square_api_data(card_data)
|
||||||
for card_data in req.json()["cards"]
|
for card_data in req.json()["cards"]
|
||||||
|
@ -66,6 +70,10 @@ class Opus(Cards):
|
||||||
self.sort(key=lambda x: x.code.opus)
|
self.sort(key=lambda x: x.code.opus)
|
||||||
|
|
||||||
for card in self:
|
for card in self:
|
||||||
|
if card.code in carddb:
|
||||||
|
for lang in API_LANGS:
|
||||||
|
card[lang] = replace(card[lang], face=carddb[card.code][lang].face)
|
||||||
|
|
||||||
logger.debug(f"imported card {card}")
|
logger.debug(f"imported card {card}")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
Loading…
Reference in a new issue