Move card json template to global
it is always going to be the same, so there's no point in passing it around
This commit is contained in:
parent
e65990329b
commit
a1859f4eff
@ -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:
|
||||
|
Reference in New Issue
Block a user