aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2020-09-16 00:09:59 +0200
committerFlorian Fischer <florian.fl.fischer@fau.de>2020-10-18 14:28:03 +0200
commit61bf06995731b882996ec3fda65a220c0ac4d9b4 (patch)
tree4da703c7823cc2dcabf512605e3155f403d244aa /scripts
parent0eca69cca991713d98714ed45cc17aa0f742206d (diff)
downloadmuhqs-game-61bf06995731b882996ec3fda65a220c0ac4d9b4.tar.gz
muhqs-game-61bf06995731b882996ec3fda65a220c0ac4d9b4.zip
add assets support for png and jpg
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/generate_latex.py38
1 files changed, 30 insertions, 8 deletions
diff --git a/scripts/generate_latex.py b/scripts/generate_latex.py
index 5ca439a9..76c1bf58 100755
--- a/scripts/generate_latex.py
+++ b/scripts/generate_latex.py
@@ -2,6 +2,7 @@
import argparse
import configparser
import pathlib
+import os
from typing import MutableMapping
COLLECTION_TEMPLATE = \
@@ -45,18 +46,29 @@ CARD_TEMPLATE = \
\\end{{document}}
"""
+LATEX_ROOT = pathlib.Path(os.getcwd())
+ASSETS_DIR = LATEX_ROOT / 'assets'
+CARDS_DIR = LATEX_ROOT / 'cards'
+
def file_for_card(card_name: str) -> pathlib.Path:
+ """Return the corresponding latex file name for a card"""
return pathlib.Path(f'{card_name.lower().replace(" ", "_")}.tex')
def generate_card(card_name: str, card: MutableMapping):
"""Generate a standalone tikz picture with the card data"""
+ card_content = ""
+
+ card_file = file_for_card(card_name)
- print(f'# {card_name} #')
- for attr in card:
- print(f'{attr}: {card[attr]}')
+ for ext in ['.jpg', '.png']:
+ image_file = ASSETS_DIR / card_file.with_suffix(ext)
+ if image_file.exists():
+ card_content += f'\\cardbackground{{{image_file.name}}}\n'
+ break
- card_content = f'\cardtype{card["type"].capitalize()}\n'
+ card_content += f'\cardtype{card["type"].capitalize()}\n'
card_content += f'\cardtitle{{{card_name}}}\n'
+
card_content += f'\cardbuycost{{{card["buy"]}}}\n'
if card['type'] == 'unit':
@@ -70,7 +82,7 @@ def generate_card(card_name: str, card: MutableMapping):
if attack:
attack_sym = '\\faSword'
if "Range" in attack:
- attack_sym = '\\faBowArrow'
+ attack_sym = '\\ding{246}'
# stats += f'\\\\ {attack_sym}: {attack}'
stats += f'\\\\ Attack: {attack}'
@@ -102,12 +114,13 @@ def generate_card(card_name: str, card: MutableMapping):
card_content += f'\cardcontent{{{card["effect"]}}}\n'
card_content += f'\cardplaycost{{{card["play"]}}}\n'
elif card['type'] == 'equipment':
+ # card_content += f'\cardsplitcontent{{\\faRecycle: {card["durability"]}}}{{{card["effect"]}}}'
card_content += f'\cardsplitcontent{{Durability: {card["durability"]}}}{{{card["effect"]}}}'
card_content += f'\cardplaycost{{{card["play"]}}}\n'
else:
print('WARNING: unknown card type {card["type"]}!')
- with open(file_for_card(card_name), 'w') as tex_file:
+ with open(CARDS_DIR / card_file, 'w') as tex_file:
print(CARD_TEMPLATE.format(card_content), file=tex_file)
@@ -115,10 +128,19 @@ def main():
"""Generate one standalone tikz picture for each card in the input data"""
parser = argparse.ArgumentParser(description='generate latex standalone cards')
- parser.add_argument("datafile")
+ parser.add_argument('datafile', help='ini file defining the card to generate')
+ parser.add_argument('--latex-root', help='path to the latex root directory')
args = parser.parse_args()
+ if args.latex_root:
+ global LATEX_ROOT
+ LATEX_ROOT = pathlib.Path(args.latex_root)
+ global CARDS_DIR
+ CARDS_DIR = LATEX_ROOT / 'cards'
+ global ASSETS_DIR
+ ASSETS_DIR = LATEX_ROOT / 'assets'
+
data = configparser.ConfigParser()
data.read(args.datafile)
@@ -133,7 +155,7 @@ def main():
collection_inputs += f'\\vspace{{5mm}}\n\n'
collection_path = pathlib.Path(args.datafile)
- with open(f'{collection_path.stem}.tex', 'w') as collection_file:
+ with open(LATEX_ROOT / f'{collection_path.stem}.tex', 'w') as collection_file:
print(COLLECTION_TEMPLATE.format(collection_inputs), file=collection_file)
if __name__ == '__main__':