Simplify makeFace by moving os.path.join inside

This commit is contained in:
Adam Goldsmith 2017-08-05 13:52:44 -04:00
parent a1859f4eff
commit a2fa5f7bce

View File

@ -72,8 +72,9 @@ def addCardToBase(svg, baseImg, baseX, cardNum):
str(int(cardNum / baseX) * CARD_HEIGHT)))
baseImg.getroot().append(svg.getroot())
def makeFace(baseImage, baseX, cardNum, base, card):
fig = makeSVG(base, card)
def makeFace(baseImage, baseX, cardNum, deckType, cardFile, card):
path = os.path.join(bundle_dir, "images", deckType, cardFile)
fig = makeSVG(path, card)
addCardToBase(fig, baseImage, baseX, cardNum)
def makeFaces(deckJson, outfile):
@ -84,49 +85,38 @@ def makeFaces(deckJson, outfile):
'version': "1.2",
'xmlns': "http://www.w3.org/2000/svg"}))
cardType = deckJson["type"]
deckType = deckJson["type"]
cardNum = 0
# Make a card for each hero character card
if cardType == "hero":
if deckType == "hero":
for card in deckJson['character']:
makeFace(baseImage, baseX, cardNum,
os.path.join("images", cardType, "charFront.svg"), card)
makeFace(baseImage, baseX, cardNum, deckType, "charFront.svg", card)
cardNum += 1
makeFace(baseImage, baseX, cardNum,
os.path.join("images", cardType, "charBack.svg"), card)
makeFace(baseImage, baseX, cardNum, deckType, "charBack.svg", card)
cardNum += 1
# Make a character and instructions card for each villain card
elif cardType == "villain":
elif deckType == "villain":
for card in deckJson['character']:
front = card["front"]
front["name"] = card["name"]
back = card["back"]
back["name"] = card["name"]
makeFace(baseImage, baseX, cardNum,
os.path.join("images", cardType, "character.svg"),
front)
makeFace(baseImage, baseX, cardNum, deckType, "character.svg", front)
cardNum += 1
makeFace(baseImage, baseX, cardNum,
os.path.join("images", cardType, "character.svg"),
back)
makeFace(baseImage, baseX, cardNum, deckType, "character.svg", back)
cardNum += 1
makeFace(baseImage, baseX, cardNum,
os.path.join("images", cardType, "instructions.svg"),
front)
makeFace(baseImage, baseX, cardNum, deckType, "instructions.svg", front)
cardNum += 1
makeFace(baseImage, baseX, cardNum,
os.path.join("images", cardType, "instructions.svg"),
back)
makeFace(baseImage, baseX, cardNum, deckType, "instructions.svg", back)
cardNum += 1
# Make a card for each card
for card in deckJson['deck']:
makeFace(baseImage, baseX, cardNum,
os.path.join("images", cardType, "card.svg"), card)
makeFace(baseImage, baseX, cardNum, deckType, "card.svg", card)
cardNum += 1
baseImage.write(outfile + ".svg")