-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateJsonCards.js
More file actions
81 lines (74 loc) · 2.28 KB
/
createJsonCards.js
File metadata and controls
81 lines (74 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* eslint-disable camelcase */
const fs = require("fs");
const configs = require("./config");
const rulings = require("./json/pt/rulings");
function createImageData(card, expansion) {
return {
id: card.id,
house: card.house,
normal: card.front_image,
zoom:
configs.zoom +
"/media/" +
expansion.lang +
"/" +
expansion.name +
"/" +
(card.house === null ? "" : card.house.replace(" ", "") + "-") +
card.card_number +
(card.card_type === "Creature1" ? "-1" : "") +
(card.card_type === "Creature2" ? "-2" : "") +
".png"
};
}
function setupCard(card) {
delete card.id;
delete card.house;
delete card.front_image;
if (card.rarity === "Evil Twin") card.card_title += " (GM)";
if (card.card_type === "Creature1") card.card_type = "Gigantic Creature";
return card;
}
function createCards(cards, expansion) {
const path = "./cards/" + expansion.lang + "/" + expansion.name + "/";
let lastCard = {};
cards.forEach(card => {
if (lastCard.card_number === card.card_number) {
lastCard.houses.push(createImageData(card, expansion));
} else {
if (lastCard.card_number !== undefined) {
fs.writeFileSync(
path + lastCard.card_number + ".json",
JSON.stringify(setupCard(lastCard))
);
}
lastCard = card;
lastCard.houses = [];
lastCard.houses.push(createImageData(card, expansion));
lastCard.rules = rulings.filter(rule => rule.cards.includes(card.id));
}
});
if (lastCard.card_number !== undefined) {
fs.writeFileSync(
path + lastCard.card_number + ".json",
JSON.stringify(setupCard(lastCard))
);
}
}
configs.expansion.forEach(expansion => {
console.log("Loading cards from " + expansion.longname + "...");
const cardsFolder = "./json/" + expansion.lang + "/" + expansion.name + "/";
const cards = fs.readdirSync(cardsFolder);
console.log("Setup to processing " + cards.length + " cards...");
const set = [];
cards.forEach(file => {
let card = JSON.parse(fs.readFileSync(cardsFolder + file).toString());
set.push(card);
});
set.sort((c1, c2) =>
String(c1.card_number)
.concat(c1.card_type)
.localeCompare(String(c2.card_number).concat(c2.card_type))
);
createCards(set, expansion);
});