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_WIDTH = 181
|
||||||
CARD_HEIGHT = 253
|
CARD_HEIGHT = 253
|
||||||
|
|
||||||
|
with open(bundle_dir + "/templates/card.json") as f:
|
||||||
|
CARD_JSON_TEMPLATE = json.load(f)
|
||||||
|
|
||||||
def setText(tree, id, text):
|
def setText(tree, id, text):
|
||||||
element = tree.find('.//*[@id="' + id + '"]')
|
element = tree.find('.//*[@id="' + id + '"]')
|
||||||
if element is None:
|
if element is None:
|
||||||
@ -135,8 +138,8 @@ def makeFaces(deckJson, outfile):
|
|||||||
subprocess.run(command)
|
subprocess.run(command)
|
||||||
return baseX
|
return baseX
|
||||||
|
|
||||||
def makeCardJson(template, nickname, description, cardID, outJson=None):
|
def makeCardJson(nickname, description, cardID, outJson=None):
|
||||||
card = template.copy()
|
card = CARD_JSON_TEMPLATE.copy()
|
||||||
card.update({"Nickname": nickname,
|
card.update({"Nickname": nickname,
|
||||||
"Description": description,
|
"Description": description,
|
||||||
"CardID": cardID})
|
"CardID": cardID})
|
||||||
@ -145,19 +148,17 @@ def makeCardJson(template, nickname, description, cardID, outJson=None):
|
|||||||
outJson['ObjectStates'][0]['ContainedObjects'].append(card)
|
outJson['ObjectStates'][0]['ContainedObjects'].append(card)
|
||||||
return card
|
return card
|
||||||
|
|
||||||
def makeDoubleSidedCardJson(template, nickname, descriptionFront,
|
def makeDoubleSidedCardJson(nickname, descriptionFront,
|
||||||
descriptionBack, cardID, outJson):
|
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}})
|
card.update({ "States": {"2": cardBack}})
|
||||||
return card
|
return card
|
||||||
|
|
||||||
def makeJson(deckJson, imgWidth, outfile):
|
def makeJson(deckJson, imgWidth, outfile):
|
||||||
with open(bundle_dir + "/templates/deck.json") as f:
|
with open(bundle_dir + "/templates/deck.json") as f:
|
||||||
outJson = json.load(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
|
# number of cards in x and y direction
|
||||||
outJson['ObjectStates'][0]['CustomDeck']['1'].update(
|
outJson['ObjectStates'][0]['CustomDeck']['1'].update(
|
||||||
@ -173,29 +174,27 @@ def makeJson(deckJson, imgWidth, outfile):
|
|||||||
if deckJson["type"] == "hero":
|
if deckJson["type"] == "hero":
|
||||||
for card in deckJson['character']:
|
for card in deckJson['character']:
|
||||||
# character card
|
# character card
|
||||||
makeDoubleSidedCardJson(
|
makeDoubleSidedCardJson(card['name'], "Active",
|
||||||
cardTemplate, card['name'],
|
"Incapacitated", cardNum, outJson)
|
||||||
"Active", "Incapacitated", cardNum, outJson)
|
|
||||||
cardNum += 2
|
cardNum += 2
|
||||||
|
|
||||||
elif deckJson["type"] == "villain":
|
elif deckJson["type"] == "villain":
|
||||||
for card in deckJson['character']:
|
for card in deckJson['character']:
|
||||||
# character card
|
# character card
|
||||||
makeDoubleSidedCardJson(
|
makeDoubleSidedCardJson(card['name'], "Front", "Back",
|
||||||
cardTemplate, card['name'], "Front", "Back", cardNum, outJson)
|
cardNum, outJson)
|
||||||
cardNum += 2
|
cardNum += 2
|
||||||
|
|
||||||
# instructions card
|
# instructions card
|
||||||
makeDoubleSidedCardJson(
|
makeDoubleSidedCardJson(card['name'] + " instructions",
|
||||||
cardTemplate, card['name'] + " instructions",
|
"Front", "Back", cardNum, outJson)
|
||||||
"Front", "Back", cardNum, outJson)
|
|
||||||
cardNum += 2
|
cardNum += 2
|
||||||
|
|
||||||
for card in deckJson['deck']:
|
for card in deckJson['deck']:
|
||||||
for i in range(0, card.get('count', 1)):
|
for i in range(0, card.get('count', 1)):
|
||||||
# normal cards
|
# normal cards
|
||||||
makeCardJson(cardTemplate, card['name'],
|
makeCardJson(card['name'], card.get('keywords', ""),
|
||||||
card.get('keywords', ""), cardNum, outJson)
|
cardNum, outJson)
|
||||||
cardNum += 1
|
cardNum += 1
|
||||||
|
|
||||||
with open(outfile + ".json", "w") as f:
|
with open(outfile + ".json", "w") as f:
|
||||||
|
Reference in New Issue
Block a user