1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
#!/usr/bin/env python3
import argparse
import configparser
import pathlib
import os
from typing import MutableMapping
COLLECTION_TEMPLATE = \
"""\\documentclass[a4paper,landscape]{{article}}
% Ränder des Dokuments anpassen
\\usepackage[margin=6mm,top=5mm]{{geometry}}
% Pakete dazuladen
\\input{{libs.tex}}
% Farbdefinitionen laden
\\input{{colors.tex}}
% \card-Commands laden
\\input{{tikzcards.tex}}
\\usepackage{{standalone}}
\\begin{{document}}
\\begin{{center}}
\\pagestyle{{empty}}
{0}
\\end{{center}}
\\end{{document}}
"""
CARD_TEMPLATE = \
"""\\documentclass[]{{standalone}}
% Pakete dazuladen
\\input{{libs.tex}}
% Farbdefinitionen laden
\\input{{colors.tex}}
% \card-Commands laden
\\input{{tikzcards.tex}}
\\begin{{document}}
\\begin{{tikzpicture}}
{0}
\\cardborder
\\end{{tikzpicture}}
\\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)
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'\cardtitle{{{card_name}}}\n'
card_content += f'\cardbuycost{{{card["buy"]}}}\n'
if card['type'] == 'unit':
health = card['health']
movement = card['movement']
# stats = f'\\faHeart: {health}\\\\ \\faShoePrints: {movement}'
stats = f'Health: {health}\\\\ Movement: {movement}'
attack = card.get('attack', None)
if attack:
attack_sym = '\\faSword'
if "Range" in attack:
attack_sym = '\\ding{246}'
# stats += f'\\\\ {attack_sym}: {attack}'
stats += f'\\\\ Attack: {attack}'
if 'effect' in card or 'full_action' in card:
ability_block = ""
effect = card.get('effect', None)
if effect:
ability_block += f'Effect: {effect}'
full_action = card.get('full_action', None)
if full_action:
if ability_block:
ability_block += '\\\\ '
ability_block += f'\\faRotateRight: {full_action}'
card_content += f'\cardsplitcontent{{{stats}}}{{{ability_block}}}'
else:
card_content += f'\cardcontent{{{stats}}}'
card_content += '\n'
card_content += f'\cardplaycost{{{card["upkeep"]}}}'
elif card['type'] == 'spell':
card_content += f'\cardcontent{{{card["effect"]}}}\n'
card_content += f'\cardplaycost{{{card["play"]}}}'
elif card['type'] == 'artifact':
card_content += f'\cardcontent{{{card["effect"]}}}\n'
card_content += f'\cardplaycost{{{card["play"]}}}'
elif card['type'] == 'equipment':
# card_content += f'\cardsplitcontent{{\\faRecycle: {card["durability"]}}}{{{card["effect"]}}}'
card_content += f'\cardsplitcontent{{Durability: {card["durability"]}}}{{{card["effect"]}}}\n'
card_content += f'\cardplaycost{{{card["play"]}}}'
else:
print('WARNING: unknown card type {card["type"]}!')
with open(CARDS_DIR / card_file, 'w') as tex_file:
print(CARD_TEMPLATE.format(card_content), file=tex_file)
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', 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)
collection_inputs = ""
cards = [card for card in data if card != 'DEFAULT']
for i, card in enumerate(cards):
generate_card(card, data[card])
collection_inputs += f'\\input{{cards/{file_for_card(card)}}}\n'
if i == 0 or i % 4 < 3:
collection_inputs += f'\\hspace{{5mm}}\n'
else:
collection_inputs += f'\\vspace{{5mm}}\n\n'
collection_path = pathlib.Path(args.datafile)
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__':
main()
|