mirror of
https://github.com/ldericher/fftcgtool
synced 2025-01-15 06:53:00 +00:00
"Opus" and "Card" classes
This commit is contained in:
parent
cd115e2f9e
commit
e6f9494786
4 changed files with 54 additions and 100 deletions
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -5,19 +5,28 @@ class Card:
|
|||
def __init__(self, data):
|
||||
code_match = re.match(r'([0-9]+)-([0-9]+)([CRHLSB])', data["Code"])
|
||||
if code_match:
|
||||
self._opus, self._serial, self._rarity = code_match.groups()
|
||||
self.__opus, self.__serial, self.__rarity = code_match.groups()
|
||||
|
||||
else:
|
||||
self._opus = "PR"
|
||||
self._serial = re.match(r'PR-([0-9]+)', data["Code"]).group(1)
|
||||
self._rarity = "P"
|
||||
code_match = re.match(r'PR-([0-9]+)', data["Code"])
|
||||
if code_match:
|
||||
self.__opus = "PR"
|
||||
self.__serial = code_match.group(1)
|
||||
self.__rarity = "P"
|
||||
|
||||
self._name = data["Name_EN"]
|
||||
self._element = data["Element"]
|
||||
else:
|
||||
code_match = re.match(r'B-([0-9]+)', data["Code"])
|
||||
if code_match:
|
||||
self.__opus = "B"
|
||||
self.__serial = code_match.group(1)
|
||||
self.__rarity = "B"
|
||||
|
||||
self.__name = data["Name_EN"]
|
||||
self.__element = data["Element"]
|
||||
|
||||
def __str__(self):
|
||||
return f"'{self._name}' ({self._element}, {self.get_id()})"
|
||||
return f"'{self.__name}' ({self.__element}, {self.get_id()})"
|
||||
|
||||
# 6-048C
|
||||
def get_id(self):
|
||||
return f"{self._opus}-{self._serial}{self._rarity}"
|
||||
return f"{self.__opus}-{self.__serial}{self.__rarity}"
|
||||
|
|
9
fftcg/opus.py
Normal file
9
fftcg/opus.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from .card import Card
|
||||
|
||||
|
||||
class Opus:
|
||||
def __init__(self, data):
|
||||
self.__cards = [Card(card_data) for card_data in data]
|
||||
|
||||
def __str__(self):
|
||||
return "\n".join(str(card) for card in self.__cards)
|
114
main.py
Executable file → Normal file
114
main.py
Executable file → Normal file
|
@ -1,96 +1,26 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import requests
|
||||
|
||||
from opus import Opus
|
||||
|
||||
# constants
|
||||
GRID = 7, 10 # default in TTsim: 7 rows, 10 columns
|
||||
RESO = 429, 600 # default in TTsim: 480x670 pixels per card
|
||||
FURL = "https://ffdecks.com/api/cards/basic" # FFDecks API URL
|
||||
|
||||
def main():
|
||||
# Setup CLI
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Imports FFTCG cards for TT-Sim.')
|
||||
|
||||
parser.add_argument(
|
||||
'opusid',
|
||||
default="7",
|
||||
metavar="OpusID",
|
||||
nargs="?",
|
||||
help='the Opus to import')
|
||||
|
||||
parser.add_argument(
|
||||
'-n', '--num_threads',
|
||||
type=int,
|
||||
default=20,
|
||||
metavar="COUNT",
|
||||
help='maximum number of concurrent requests')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
# Setup logging
|
||||
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(threadName)s %(message)s')
|
||||
|
||||
# Fetch and parse card database from ffdecks API
|
||||
ffdecks_raw = requests.get(FURL)
|
||||
ffdecks = json.loads(ffdecks_raw.content.decode("utf-8"))
|
||||
|
||||
# Load an Opus
|
||||
opus_data = (card_data for card_data in ffdecks["cards"] if card_data["serial_number"].startswith(args.opusid))
|
||||
myOpus = Opus(opus_data)
|
||||
|
||||
# output directory
|
||||
if not os.path.exists("out"):
|
||||
os.mkdir("out")
|
||||
os.chdir("out")
|
||||
|
||||
# compose custom deck images
|
||||
faceurls = []
|
||||
for i, image in enumerate(myOpus.get_images(GRID, RESO, args.num_threads)):
|
||||
filename = "opus_{}_{}.jpg".format(args.opusid, i)
|
||||
image.save(filename)
|
||||
# ask for upload
|
||||
iurl = input("Upload '{}' and paste URL: ".format(filename))
|
||||
if not iurl:
|
||||
# add local file (maybe upload to steam cloud in cloud manager)
|
||||
logging.warn("Using local file for '{}'.".format(filename))
|
||||
iurl = "file://" + os.path.abspath(filename)
|
||||
faceurls.append(iurl)
|
||||
|
||||
# Build json for element decks
|
||||
elementaldecks = [
|
||||
["Fire"],
|
||||
["Water"],
|
||||
["Lightning"],
|
||||
["Ice"],
|
||||
["Wind"],
|
||||
["Earth"],
|
||||
["Light", "Dark"],
|
||||
["Multi"]
|
||||
]
|
||||
for i, elements in enumerate(elementaldecks):
|
||||
json_filename = "opus_{}_{}.json".format(args.opusid, "_".join(elements))
|
||||
with open(json_filename, "w") as json_file:
|
||||
cardfilter = lambda card: card._element in elements
|
||||
json_data = myOpus.get_json(args.opusid, "/".join(elements), GRID, cardfilter, faceurls)
|
||||
json_file.write(json_data)
|
||||
|
||||
json_filename = "fullopus_{}.json".format(args.opusid)
|
||||
with open(json_filename, "w") as json_file:
|
||||
cardfilter = lambda card: True
|
||||
json_data = myOpus.get_json(args.opusid, "full", GRID, cardfilter, faceurls)
|
||||
json_file.write(json_data)
|
||||
|
||||
# Bye
|
||||
logging.info("Done. Put the generated JSON files in your 'Saved Objects' Folder.")
|
||||
logging.info("Thanks for using fftcgtool!")
|
||||
from fftcg.opus import Opus
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
def print_hi(name):
|
||||
# supported params:
|
||||
# [str] language, text,
|
||||
# [array] type, element, cost, rarity, power, category_1, set
|
||||
# [str] multicard="○"|"", ex_burst="○"|"", code, special="《S》"|""
|
||||
# [int] exactmatch=0|1
|
||||
params = {
|
||||
"language": "de",
|
||||
"text": "",
|
||||
"element": ["fire"],
|
||||
# "set": ["Opus XIV"],
|
||||
}
|
||||
|
||||
opus_json = requests.post(url="https://fftcg.square-enix-games.com/de/get-cards", json=params).json()
|
||||
|
||||
opus = Opus(opus_json["cards"])
|
||||
print(opus)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print_hi('PyCharm')
|
||||
|
|
Loading…
Reference in a new issue