Partially fix server side deck generation for heros/villains
This commit is contained in:
parent
32e4bedc59
commit
9d7b375994
48
server.js
48
server.js
@ -93,7 +93,7 @@ const server = http.createServer((req, res) => {
|
|||||||
sendFile(res, `decks/${deckName}.input.json`, 'application/json');
|
sendFile(res, `decks/${deckName}.input.json`, 'application/json');
|
||||||
break;
|
break;
|
||||||
case 'upload':
|
case 'upload':
|
||||||
handleUpload(res, req, deckName);
|
handleUpload(res, req);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
send404(res, uri);
|
send404(res, uri);
|
||||||
@ -174,23 +174,41 @@ function handleUpload(res, req) {
|
|||||||
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(deckJSON.deck.length)),
|
{NumWidth: Math.ceil(Math.sqrt(cardCount)),
|
||||||
NumHeight: Math.ceil(Math.sqrt(deckJSON.deck.length)),
|
NumHeight: Math.ceil(Math.sqrt(cardCount)),
|
||||||
FaceURL: "deck.png",
|
FaceURL: `http://${req.headers.host}/deck/${deckJSON.name}/deck.png`,
|
||||||
BackURL: "http://cloud-3.steamusercontent.com/ugc/156906385556221451/CE2C3AFE1759790CB0B532FFD636D05A99EC91F4/"});
|
BackURL: "http://cloud-3.steamusercontent.com/ugc/156906385556221451/CE2C3AFE1759790CB0B532FFD636D05A99EC91F4/"});
|
||||||
|
|
||||||
deckOut.ObjectStates[0].CustomDeck['1'].ContainedObjects =
|
let index = 100;
|
||||||
deckJSON.deck.map((cardIn, index) => {
|
deckOut.ObjectStates[0].ContainedObjects =
|
||||||
let cardOut = JSON.parse(cardTemplate);
|
Object.entries(template.cardTypes).map(
|
||||||
Object.assign(cardOut, {Nickname: cardIn.name,
|
cardType => deckJSON[cardType[0]].map(cardIn => {
|
||||||
Description: cardIn.keywords,
|
let cardOut = JSON.parse(cardTemplate);
|
||||||
CardID: 100 + index});
|
Object.assign(cardOut, {Nickname: cardIn.name,
|
||||||
for (let ii=0; ii<(cardIn.count || 1); ii++) {
|
Description: cardIn.keywords,
|
||||||
deckOut.ObjectStates[0].DeckIDs.push(100 + index);
|
CardID: index});
|
||||||
}
|
if(cardType[1].back) {
|
||||||
return cardOut;
|
let cardBack = JSON.parse(cardTemplate);
|
||||||
});
|
Object.assign(cardBack, {Nickname: cardIn.back.name,
|
||||||
|
Description: cardIn.back.keywords,
|
||||||
|
CardID: index});
|
||||||
|
cardOut.States = {"2": cardBack};
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
for (let ii=0; ii<(cardIn.count || 1); ii++) {
|
||||||
|
deckOut.ObjectStates[0].DeckIDs.push(index);
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
return cardOut;
|
||||||
|
}));
|
||||||
|
|
||||||
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