121 lines
3.1 KiB
Python
Executable file
121 lines
3.1 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
"""
|
|
Used as a tool by the Makefile.
|
|
Updates only those files whose contents are changed by changes to the given yaml
|
|
file.
|
|
"""
|
|
|
|
import sys
|
|
from textwrap import dedent
|
|
import yaml
|
|
|
|
def read_cards(filename=None):
|
|
"""
|
|
Reads the given file as yaml into card information data.
|
|
"""
|
|
if filename is not None:
|
|
with open(filename, 'r') as yaml_file:
|
|
data = yaml.load(yaml_file, Loader=yaml.FullLoader)
|
|
else:
|
|
data = yaml.load(sys.stdin, Loader=yaml.FullLoader)
|
|
|
|
return data
|
|
|
|
|
|
def card_to_tex(card, deck, rarity):
|
|
"""
|
|
Returns a card's LaTeX as a string.
|
|
"""
|
|
head = f"""\
|
|
\\documentclass{{iditacard}}
|
|
|
|
\\cardtype{{{card['type']}}}
|
|
\\rarity{{{rarity}}}
|
|
\\deck{{{deck}}}
|
|
|
|
\\begin{{document}}
|
|
\\begin{{card}}
|
|
\\art{{{card['image']}}}
|
|
"""
|
|
effect_text = "\\quad".join(card['effects'] if 'effects' in card else [])
|
|
tail = f"""\
|
|
\\name{{{card['name']}}}
|
|
\\text{{{effect_text}}}
|
|
\\flava{{{card['flavour']}}}
|
|
\\type{{{card['type']}}}
|
|
\\end{{card}}
|
|
\\end{{document}}\
|
|
"""
|
|
|
|
costs = card["costs"]
|
|
costr = ""
|
|
|
|
if 'energy' in costs and costs['energy'] != 0:
|
|
costr += f" \\energy{{{costs['energy']}}}\n"
|
|
|
|
if 'health' in costs and costs['health'] != 0:
|
|
costr += f" \\health{{{costs['health']}}}\n"
|
|
|
|
if 'risk' in costs and costs['risk'] != 0:
|
|
costr += f" \\risk{{{costs['risk']}}}\n"
|
|
|
|
return dedent(head) + costr + dedent(tail)
|
|
|
|
|
|
def leg_to_tex(leg, level):
|
|
"""
|
|
Returns a leg's LaTeX as a string.
|
|
"""
|
|
head = f"""\
|
|
\\documentclass{{iditacard}}
|
|
|
|
\\leglevel{{{level}}}
|
|
|
|
\\begin{{document}}
|
|
\\begin{{leg}}
|
|
\\legname{{{leg['name']}}}
|
|
"""
|
|
spaces = ""
|
|
for space in range(1, 11):
|
|
if str(space) in leg['spaces']:
|
|
icon = f"\\legspaceicon{{{leg['spaces'][space]}}}"
|
|
spaces += f" \\onlegspace{{{space}}}{{{icon}}}\n"
|
|
effect_text = "\\quad".join(leg['effects'] if 'effects' in leg else [])
|
|
tail = f"""\
|
|
\\legeffect{{{effect_text}}}
|
|
\\end{{leg}}
|
|
\\end{{document}}\
|
|
"""
|
|
|
|
return dedent(head) + spaces + dedent(tail)
|
|
|
|
|
|
def dump_decks_to(decks, directory):
|
|
"""
|
|
Dumps all tex from decks to the given directory.
|
|
For each deck in decks it will generate:
|
|
- a directory within the given directory with the same name
|
|
- .tex files for each card in the deck in the above directory
|
|
- .list file in the given directory with the same name as the deck
|
|
- one line in the list file for each pdf that would go into said deck
|
|
"""
|
|
return 'TODO'
|
|
|
|
# TODO: fill out dump_decks_to, create dump_legs_to and call them with the
|
|
# appropriate directory in main (using sys.argv)
|
|
#
|
|
# also write a script to extract all deck names for use in the makefile (to be
|
|
# assigned to the DECK_LIST/DECK_DEPENDENCIES variables
|
|
|
|
def main():
|
|
"""
|
|
Main entry point.
|
|
"""
|
|
cards = read_cards()
|
|
print(card_to_tex(cards['cards'][0], "thedeck", "therarity"))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|