From a1859f4eff96ca3e7ef3a0240222b655e62a7492 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Sat, 5 Aug 2017 13:43:06 -0400 Subject: [PATCH] Move card json template to global it is always going to be the same, so there's no point in passing it around --- SotMDeckBuilder.py | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/SotMDeckBuilder.py b/SotMDeckBuilder.py index fed6492..80406b0 100755 --- a/SotMDeckBuilder.py +++ b/SotMDeckBuilder.py @@ -19,6 +19,9 @@ else: # we are running in a normal Python environment CARD_WIDTH = 181 CARD_HEIGHT = 253 +with open(bundle_dir + "/templates/card.json") as f: + CARD_JSON_TEMPLATE = json.load(f) + def setText(tree, id, text): element = tree.find('.//*[@id="' + id + '"]') if element is None: @@ -135,8 +138,8 @@ def makeFaces(deckJson, outfile): subprocess.run(command) return baseX -def makeCardJson(template, nickname, description, cardID, outJson=None): - card = template.copy() +def makeCardJson(nickname, description, cardID, outJson=None): + card = CARD_JSON_TEMPLATE.copy() card.update({"Nickname": nickname, "Description": description, "CardID": cardID}) @@ -145,19 +148,17 @@ def makeCardJson(template, nickname, description, cardID, outJson=None): outJson['ObjectStates'][0]['ContainedObjects'].append(card) return card -def makeDoubleSidedCardJson(template, nickname, descriptionFront, +def makeDoubleSidedCardJson(nickname, descriptionFront, descriptionBack, cardID, outJson): - cardBack = makeCardJson(template, nickname, descriptionBack, cardID + 1) + cardBack = makeCardJson(nickname, descriptionBack, cardID + 1) - card = makeCardJson(template, nickname, descriptionFront, cardID, outJson) + card = makeCardJson(nickname, descriptionFront, cardID, outJson) card.update({ "States": {"2": cardBack}}) return card def makeJson(deckJson, imgWidth, outfile): with open(bundle_dir + "/templates/deck.json") as f: outJson = json.load(f) - with open(bundle_dir + "/templates/card.json") as f: - cardTemplate = json.load(f) # number of cards in x and y direction outJson['ObjectStates'][0]['CustomDeck']['1'].update( @@ -173,29 +174,27 @@ def makeJson(deckJson, imgWidth, outfile): if deckJson["type"] == "hero": for card in deckJson['character']: # character card - makeDoubleSidedCardJson( - cardTemplate, card['name'], - "Active", "Incapacitated", cardNum, outJson) + makeDoubleSidedCardJson(card['name'], "Active", + "Incapacitated", cardNum, outJson) cardNum += 2 elif deckJson["type"] == "villain": for card in deckJson['character']: # character card - makeDoubleSidedCardJson( - cardTemplate, card['name'], "Front", "Back", cardNum, outJson) + makeDoubleSidedCardJson(card['name'], "Front", "Back", + cardNum, outJson) cardNum += 2 # instructions card - makeDoubleSidedCardJson( - cardTemplate, card['name'] + " instructions", - "Front", "Back", cardNum, outJson) + makeDoubleSidedCardJson(card['name'] + " instructions", + "Front", "Back", cardNum, outJson) cardNum += 2 for card in deckJson['deck']: for i in range(0, card.get('count', 1)): # normal cards - makeCardJson(cardTemplate, card['name'], - card.get('keywords', ""), cardNum, outJson) + makeCardJson(card['name'], card.get('keywords', ""), + cardNum, outJson) cardNum += 1 with open(outfile + ".json", "w") as f: