Formatting Changes
This commit is contained in:
parent
1b2926e547
commit
0cdb83b9b7
@ -1,5 +1,8 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Note: SVG templates are heavily based on these:
|
||||
# https://boardgamegeek.com/thread/813176/card-templates/page/1
|
||||
|
||||
import json
|
||||
import math
|
||||
import os
|
||||
@ -26,7 +29,8 @@ def setText(tree, id, text):
|
||||
element.remove(e) # clear child paragraphs
|
||||
lines = str(text).splitlines()
|
||||
for line in lines:
|
||||
etree.SubElement(element, "{http://www.w3.org/2000/svg}flowPara").text=line
|
||||
etree.SubElement(element,
|
||||
"{http://www.w3.org/2000/svg}flowPara").text=line
|
||||
else:
|
||||
element.text = str(text)
|
||||
|
||||
@ -58,9 +62,11 @@ def makeSVG(base, properties):
|
||||
|
||||
def addCardToBase(svg, baseImg, baseX, cardNum):
|
||||
for e in svg.findall('{http://www.w3.org/2000/svg}g'):
|
||||
e.set("transform", e.get("transform", "") + " translate(" + \
|
||||
str((cardNum % baseX) * CARD_WIDTH) + " " + \
|
||||
str(int(cardNum / baseX) * CARD_HEIGHT) + ")")
|
||||
e.set("transform",
|
||||
"{} translate({} {})".format(
|
||||
e.get("transform", ""),
|
||||
str((cardNum % baseX) * CARD_WIDTH),
|
||||
str(int(cardNum / baseX) * CARD_HEIGHT)))
|
||||
baseImg.getroot().append(svg.getroot())
|
||||
|
||||
def makeFace(baseImage, baseX, cardNum, base, card):
|
||||
@ -70,11 +76,10 @@ def makeFace(baseImage, baseX, cardNum, base, card):
|
||||
def makeFaces(deckJson, outfile):
|
||||
baseX = math.ceil(math.sqrt(len(deckJson['deck']) + len(deckJson['character']) * 2))
|
||||
baseImage = etree.ElementTree(
|
||||
etree.Element('svg',
|
||||
attrib={'width': str(baseX * CARD_WIDTH) + "pt",
|
||||
'height': str(baseX * CARD_HEIGHT) + "pt",
|
||||
'version': "1.2",
|
||||
'xmlns': "http://www.w3.org/2000/svg"}))
|
||||
etree.Element('svg', attrib={'width': str(baseX * CARD_WIDTH) + "pt",
|
||||
'height': str(baseX * CARD_HEIGHT) + "pt",
|
||||
'version': "1.2",
|
||||
'xmlns': "http://www.w3.org/2000/svg"}))
|
||||
|
||||
cardType = deckJson["type"]
|
||||
|
||||
@ -183,7 +188,8 @@ def makeJson(deckJson, imgWidth, outfile):
|
||||
|
||||
outJson['ObjectStates'][0]['DeckIDs'].append(cardNum)
|
||||
cardOut = makeDoubleSidedCardJson(
|
||||
cardTemplate, card['name'] + " instructions", "Front", "Back", cardNum)
|
||||
cardTemplate, card['name'] + " instructions",
|
||||
"Front", "Back", cardNum)
|
||||
outJson['ObjectStates'][0]['ContainedObjects'].append(cardOut)
|
||||
cardNum += 2
|
||||
|
||||
@ -192,7 +198,8 @@ def makeJson(deckJson, imgWidth, outfile):
|
||||
outJson['ObjectStates'][0]['DeckIDs'].append(cardNum)
|
||||
|
||||
# add a card object thing for each card, and give it a name
|
||||
cardOut = makeCardJson(cardTemplate, card['name'], card.get('keywords', ""), cardNum)
|
||||
cardOut = makeCardJson(cardTemplate, card['name'],
|
||||
card.get('keywords', ""), cardNum)
|
||||
outJson['ObjectStates'][0]['ContainedObjects'].append(cardOut)
|
||||
cardNum += 1
|
||||
|
||||
|
Reference in New Issue
Block a user