Further fix server deck JSON generation
This commit is contained in:
parent
7c999e0dfd
commit
e4819c1f26
24
server.js
24
server.js
@ -170,17 +170,14 @@ function handleUpload(res, req) {
|
|||||||
const json = JSON.parse(body);
|
const json = JSON.parse(body);
|
||||||
const deckJSON = json.json;
|
const deckJSON = json.json;
|
||||||
const cardTemplate = fs.readFileSync('template/card.json');
|
const cardTemplate = fs.readFileSync('template/card.json');
|
||||||
|
const template = JSON.parse(fs.readFileSync(`template/${deckJSON.type}/input.json`));
|
||||||
|
const cardCount = Object.entries(template.cardTypes)
|
||||||
|
.map(ct => deckJSON[ct[0]].length * (ct[1].back ? 2 : 1))
|
||||||
|
.reduce((sum, current) => sum + current, 0);
|
||||||
|
|
||||||
let deckOut = JSON.parse(fs.readFileSync('template/deck.json'));
|
let deckOut = JSON.parse(fs.readFileSync('template/deck.json'));
|
||||||
|
|
||||||
deckOut.ObjectStates[0].Nickname = deckJSON.name;
|
deckOut.ObjectStates[0].Nickname = deckJSON.name;
|
||||||
|
|
||||||
let template = JSON.parse(fs.readFileSync(`template/${deckJSON.type}/input.json`));
|
|
||||||
|
|
||||||
let cardCount = Object.entries(template.cardTypes)
|
|
||||||
.map(ct => deckJSON[ct[0]].length * (ct[1].back ? 2 : 1))
|
|
||||||
.reduce((sum, current) => sum + current, 0);
|
|
||||||
|
|
||||||
Object.assign(deckOut.ObjectStates[0].CustomDeck['1'],
|
Object.assign(deckOut.ObjectStates[0].CustomDeck['1'],
|
||||||
{NumWidth: Math.ceil(Math.sqrt(cardCount)),
|
{NumWidth: Math.ceil(Math.sqrt(cardCount)),
|
||||||
NumHeight: Math.ceil(Math.sqrt(cardCount)),
|
NumHeight: Math.ceil(Math.sqrt(cardCount)),
|
||||||
@ -195,6 +192,12 @@ function handleUpload(res, req) {
|
|||||||
Object.assign(cardOut, {Nickname: cardIn.name,
|
Object.assign(cardOut, {Nickname: cardIn.name,
|
||||||
Description: cardIn.keywords,
|
Description: cardIn.keywords,
|
||||||
CardID: index});
|
CardID: index});
|
||||||
|
|
||||||
|
for (let ii=0; ii<(cardIn.count || 1); ii++) {
|
||||||
|
deckOut.ObjectStates[0].DeckIDs.push(index);
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
|
||||||
if(cardType[1].back) {
|
if(cardType[1].back) {
|
||||||
let cardBack = JSON.parse(cardTemplate);
|
let cardBack = JSON.parse(cardTemplate);
|
||||||
Object.assign(cardBack, {Nickname: cardIn.back.name,
|
Object.assign(cardBack, {Nickname: cardIn.back.name,
|
||||||
@ -203,12 +206,9 @@ function handleUpload(res, req) {
|
|||||||
cardOut.States = {"2": cardBack};
|
cardOut.States = {"2": cardBack};
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
for (let ii=0; ii<(cardIn.count || 1); ii++) {
|
|
||||||
deckOut.ObjectStates[0].DeckIDs.push(index);
|
|
||||||
}
|
|
||||||
index++;
|
|
||||||
return cardOut;
|
return cardOut;
|
||||||
}));
|
}))
|
||||||
|
.reduce((sum, cur) => sum.concat(cur), []);
|
||||||
|
|
||||||
fs.writeFileSync(`decks/${deckJSON.name}.json`, JSON.stringify(deckOut));
|
fs.writeFileSync(`decks/${deckJSON.name}.json`, JSON.stringify(deckOut));
|
||||||
fs.writeFileSync(`decks/${deckJSON.name}.input.json`, JSON.stringify(deckJSON));
|
fs.writeFileSync(`decks/${deckJSON.name}.input.json`, JSON.stringify(deckJSON));
|
||||||
|
Loading…
Reference in New Issue
Block a user