Simplify card json creation by moving outJson changes to makeCardJson
This commit is contained in:
parent
0cdb83b9b7
commit
e65990329b
@ -135,22 +135,22 @@ def makeFaces(deckJson, outfile):
|
|||||||
subprocess.run(command)
|
subprocess.run(command)
|
||||||
return baseX
|
return baseX
|
||||||
|
|
||||||
def makeCardJson(template, nickname, description, cardID):
|
def makeCardJson(template, nickname, description, cardID, outJson=None):
|
||||||
card = template.copy()
|
card = template.copy()
|
||||||
card.update({"Nickname": nickname,
|
card.update({"Nickname": nickname,
|
||||||
"Description": description,
|
"Description": description,
|
||||||
"CardID": cardID})
|
"CardID": cardID})
|
||||||
|
if outJson is not None:
|
||||||
|
outJson['ObjectStates'][0]['DeckIDs'].append(cardID)
|
||||||
|
outJson['ObjectStates'][0]['ContainedObjects'].append(card)
|
||||||
return card
|
return card
|
||||||
|
|
||||||
def makeDoubleSidedCardJson(template, nickname, descriptionFront,
|
def makeDoubleSidedCardJson(template, nickname, descriptionFront,
|
||||||
descriptionBack, cardID):
|
descriptionBack, cardID, outJson):
|
||||||
cardBack = makeCardJson(template, nickname, descriptionBack, cardID + 1)
|
cardBack = makeCardJson(template, nickname, descriptionBack, cardID + 1)
|
||||||
|
|
||||||
card = template.copy()
|
card = makeCardJson(template, nickname, descriptionFront, cardID, outJson)
|
||||||
card.update({"Nickname": nickname,
|
card.update({ "States": {"2": cardBack}})
|
||||||
"Description": descriptionFront,
|
|
||||||
"CardID": cardID,
|
|
||||||
"States": {"2": cardBack}})
|
|
||||||
return card
|
return card
|
||||||
|
|
||||||
def makeJson(deckJson, imgWidth, outfile):
|
def makeJson(deckJson, imgWidth, outfile):
|
||||||
@ -172,35 +172,30 @@ def makeJson(deckJson, imgWidth, outfile):
|
|||||||
|
|
||||||
if deckJson["type"] == "hero":
|
if deckJson["type"] == "hero":
|
||||||
for card in deckJson['character']:
|
for card in deckJson['character']:
|
||||||
outJson['ObjectStates'][0]['DeckIDs'].append(cardNum)
|
# character card
|
||||||
cardOut = makeDoubleSidedCardJson(
|
makeDoubleSidedCardJson(
|
||||||
cardTemplate, card['name'], "Active", "Incapacitated", cardNum)
|
cardTemplate, card['name'],
|
||||||
outJson['ObjectStates'][0]['ContainedObjects'].append(cardOut)
|
"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']:
|
||||||
outJson['ObjectStates'][0]['DeckIDs'].append(cardNum)
|
# character card
|
||||||
cardOut = makeDoubleSidedCardJson(
|
makeDoubleSidedCardJson(
|
||||||
cardTemplate, card['name'], "Front", "Back", cardNum)
|
cardTemplate, card['name'], "Front", "Back", cardNum, outJson)
|
||||||
outJson['ObjectStates'][0]['ContainedObjects'].append(cardOut)
|
|
||||||
cardNum += 2
|
cardNum += 2
|
||||||
|
|
||||||
outJson['ObjectStates'][0]['DeckIDs'].append(cardNum)
|
# instructions card
|
||||||
cardOut = makeDoubleSidedCardJson(
|
makeDoubleSidedCardJson(
|
||||||
cardTemplate, card['name'] + " instructions",
|
cardTemplate, card['name'] + " instructions",
|
||||||
"Front", "Back", cardNum)
|
"Front", "Back", cardNum, outJson)
|
||||||
outJson['ObjectStates'][0]['ContainedObjects'].append(cardOut)
|
|
||||||
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)):
|
||||||
outJson['ObjectStates'][0]['DeckIDs'].append(cardNum)
|
# normal cards
|
||||||
|
makeCardJson(cardTemplate, card['name'],
|
||||||
# add a card object thing for each card, and give it a name
|
card.get('keywords', ""), cardNum, outJson)
|
||||||
cardOut = makeCardJson(cardTemplate, card['name'],
|
|
||||||
card.get('keywords', ""), cardNum)
|
|
||||||
outJson['ObjectStates'][0]['ContainedObjects'].append(cardOut)
|
|
||||||
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