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