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)
|
||||
return baseX
|
||||
|
||||
def makeCardJson(template, nickname, description, cardID):
|
||||
def makeCardJson(template, nickname, description, cardID, outJson=None):
|
||||
card = template.copy()
|
||||
card.update({"Nickname": nickname,
|
||||
"Description": description,
|
||||
"CardID": cardID})
|
||||
if outJson is not None:
|
||||
outJson['ObjectStates'][0]['DeckIDs'].append(cardID)
|
||||
outJson['ObjectStates'][0]['ContainedObjects'].append(card)
|
||||
return card
|
||||
|
||||
def makeDoubleSidedCardJson(template, nickname, descriptionFront,
|
||||
descriptionBack, cardID):
|
||||
descriptionBack, cardID, outJson):
|
||||
cardBack = makeCardJson(template, nickname, descriptionBack, cardID + 1)
|
||||
|
||||
card = template.copy()
|
||||
card.update({"Nickname": nickname,
|
||||
"Description": descriptionFront,
|
||||
"CardID": cardID,
|
||||
"States": {"2": cardBack}})
|
||||
card = makeCardJson(template, nickname, descriptionFront, cardID, outJson)
|
||||
card.update({ "States": {"2": cardBack}})
|
||||
return card
|
||||
|
||||
def makeJson(deckJson, imgWidth, outfile):
|
||||
@ -172,35 +172,30 @@ def makeJson(deckJson, imgWidth, outfile):
|
||||
|
||||
if deckJson["type"] == "hero":
|
||||
for card in deckJson['character']:
|
||||
outJson['ObjectStates'][0]['DeckIDs'].append(cardNum)
|
||||
cardOut = makeDoubleSidedCardJson(
|
||||
cardTemplate, card['name'], "Active", "Incapacitated", cardNum)
|
||||
outJson['ObjectStates'][0]['ContainedObjects'].append(cardOut)
|
||||
# character card
|
||||
makeDoubleSidedCardJson(
|
||||
cardTemplate, card['name'],
|
||||
"Active", "Incapacitated", cardNum, outJson)
|
||||
cardNum += 2
|
||||
|
||||
elif deckJson["type"] == "villain":
|
||||
for card in deckJson['character']:
|
||||
outJson['ObjectStates'][0]['DeckIDs'].append(cardNum)
|
||||
cardOut = makeDoubleSidedCardJson(
|
||||
cardTemplate, card['name'], "Front", "Back", cardNum)
|
||||
outJson['ObjectStates'][0]['ContainedObjects'].append(cardOut)
|
||||
# character card
|
||||
makeDoubleSidedCardJson(
|
||||
cardTemplate, card['name'], "Front", "Back", cardNum, outJson)
|
||||
cardNum += 2
|
||||
|
||||
outJson['ObjectStates'][0]['DeckIDs'].append(cardNum)
|
||||
cardOut = makeDoubleSidedCardJson(
|
||||
cardTemplate, card['name'] + " instructions",
|
||||
"Front", "Back", cardNum)
|
||||
outJson['ObjectStates'][0]['ContainedObjects'].append(cardOut)
|
||||
# instructions card
|
||||
makeDoubleSidedCardJson(
|
||||
cardTemplate, card['name'] + " instructions",
|
||||
"Front", "Back", cardNum, outJson)
|
||||
cardNum += 2
|
||||
|
||||
for card in deckJson['deck']:
|
||||
for i in range(0, card.get('count', 1)):
|
||||
outJson['ObjectStates'][0]['DeckIDs'].append(cardNum)
|
||||
|
||||
# add a card object thing for each card, and give it a name
|
||||
cardOut = makeCardJson(cardTemplate, card['name'],
|
||||
card.get('keywords', ""), cardNum)
|
||||
outJson['ObjectStates'][0]['ContainedObjects'].append(cardOut)
|
||||
# normal cards
|
||||
makeCardJson(cardTemplate, card['name'],
|
||||
card.get('keywords', ""), cardNum, outJson)
|
||||
cardNum += 1
|
||||
|
||||
with open(outfile + ".json", "w") as f:
|
||||
|
Reference in New Issue
Block a user