Generate JSONs for all cards in project

This commit is contained in:
Adam Goldsmith 2021-09-08 14:22:37 -04:00
parent a86390579e
commit 01a0ff0aae

View File

@ -1,18 +1,5 @@
// TODO: should be defined in strange eons somewhere // TODO: should be defined in strange eons somewhere
const pack_code = "420"; const pack_code = "420";
var code = pack_code + Component.settings.get('CollectionNumber');
var skills = {
Agility: 0,
Intellect: 0,
Combat: 0,
Willpower: 0,
Wild: 0,
None: 0,
};
for (var i = 1; i<=6; i++) {
skills[Component.settings.get('Skill' + i)] += 1;
}
function renameSlot(slot) { function renameSlot(slot) {
if (slot.startsWith('1 ')) { if (slot.startsWith('1 ')) {
@ -27,7 +14,6 @@ function renameSlot(slot) {
} }
const tag_replacements = { const tag_replacements = {
"<fullname>": String(Component.getName()),
"<gua>": "[guardian]", "<gua>": "[guardian]",
"<see>": "[seeker]", "<see>": "[seeker]",
"<rog>": "[rogue]", "<rog>": "[rogue]",
@ -68,13 +54,6 @@ const tag_replacements = {
"<svs>": "", // Small vertical spacer "<svs>": "", // Small vertical spacer
}; };
function substitute_tags(str) {
for (tag in tag_replacements) {
str = str.replace(tag, tag_replacements[tag]);
}
return str;
}
// TODO: handle investigator cards // TODO: handle investigator cards
const card_types = { const card_types = {
"AHLCG-Event-Default": "event", "AHLCG-Event-Default": "event",
@ -97,20 +76,44 @@ function int_or_null(inp) {
} }
} }
function build_card(component) {
function substitute_tags(str) {
str = str.replace("<fullname>", String(component.getName()));
for (tag in tag_replacements) {
str = str.replace(tag, tag_replacements[tag]);
}
return str;
}
var code = pack_code + component.settings.get('CollectionNumber');
var skills = {
Agility: 0,
Intellect: 0,
Combat: 0,
Willpower: 0,
Wild: 0,
None: 0,
};
for (var i = 1; i<=6; i++) {
skills[component.settings.get('Skill' + i)] += 1;
}
var card_data = { var card_data = {
code: String(code), code: String(code),
deck_limit: 2, // TODO: could be derived? deck_limit: 2, // TODO: could be derived?
faction_code: String(Component.settings.get('CardClass')).toLowerCase(), faction_code: String(component.settings.get('CardClass')).toLowerCase(),
flavor: substitute_tags(String(Component.settings.get('Flavor'))), flavor: substitute_tags(String(component.settings.get('Flavor'))),
health: int_or_null(Component.settings.get('Stamina')), health: int_or_null(component.settings.get('Stamina')),
illustrator: String(Component.settings.get('Artist')), illustrator: String(component.settings.get('Artist')),
is_unique: Component.settings.getBoolean('Unique'), is_unique: component.settings.getBoolean('Unique'),
name: substitute_tags(String(Component.getName())), name: substitute_tags(String(component.getName())),
pack_code: pack_code, pack_code: pack_code,
position: int_or_null(Component.settings.get('CollectionNumber')), position: int_or_null(component.settings.get('CollectionNumber')),
quantity: 2, // TODO quantity: 2, // TODO
//restrictions: null, // TODO //restrictions: null, // TODO
sanity: int_or_null(Component.settings.get('Sanity')), sanity: int_or_null(component.settings.get('Sanity')),
skill_agility: skills["Agility"], skill_agility: skills["Agility"],
skill_combat: skills["Combat"], skill_combat: skills["Combat"],
skill_intellect: skills["Intellect"], skill_intellect: skills["Intellect"],
@ -118,41 +121,52 @@ var card_data = {
skill_willpower: skills["Willpower"], skill_willpower: skills["Willpower"],
// TODO: should also handle "Victory" field // TODO: should also handle "Victory" field
text: substitute_tags(String( text: substitute_tags(String(
Component.settings.get('Keywords') + '\n' + Component.settings.get('Rules'))), component.settings.get('Keywords') + '\n' + component.settings.get('Rules'))),
traits: substitute_tags(String(Component.settings.get('Traits'))), traits: substitute_tags(String(component.settings.get('Traits'))),
type_code: card_types[Component.getFrontTemplateKey()], type_code: card_types[component.getFrontTemplateKey()],
xp: int_or_null(Component.settings.get('Level')), xp: int_or_null(component.settings.get('Level')),
}; };
var raw_cost = Component.settings.get('ResourceCost'); var raw_cost = component.settings.get('ResourceCost');
if (raw_cost) { if (raw_cost) {
card_data.cost = int_or_null(raw_cost); card_data.cost = int_or_null(raw_cost);
} }
var raw_slot = Component.settings.get('Slot'); var raw_slot = component.settings.get('Slot');
if (raw_slot) { if (raw_slot) {
card_data.slot = renameSlot(String(raw_slot)); card_data.slot = renameSlot(String(raw_slot));
var raw_slot2 = Component.settings.get('Slot2'); var raw_slot2 = component.settings.get('Slot2');
if (raw_slot2 && raw_slot2 != 'None') { if (raw_slot2 && raw_slot2 != 'None') {
card_data.slot += '. ' + renameSlot(raw_slot2); card_data.slot += '. ' + renameSlot(raw_slot2);
} }
} }
var subtitle = Component.settings.get('Subtitle'); var subtitle = component.settings.get('Subtitle');
if (subtitle && subtitle != '') { if (subtitle && subtitle != '') {
card_data.subname = subtitle; card_data.subname = subtitle;
} }
var faction2 = Component.settings.get('CardClass2'); var faction2 = component.settings.get('CardClass2');
if (faction2 && faction2 != 'None') { if (faction2 && faction2 != 'None') {
card_data.faction2_code = String(Component.settings.get('CardClass2')).toLowerCase(); card_data.faction2_code = String(component.settings.get('CardClass2')).toLowerCase();
} }
if (card_types[Component.getFrontTemplateKey()] == 'enemy') { if (card_types[component.getFrontTemplateKey()] == 'enemy') {
// TODO: "weakness" or "basicweakness" // TODO: "weakness" or "basicweakness"
card_data.subtype_code = "basicweakness"; card_data.subtype_code = "basicweakness";
} }
// TODO: parse out some keywords into their own fields // TODO: parse out some keywords into their own fields
println(JSON.stringify(card_data, null, 4)); return card_data;
}
var cards = [];
var member_iter = Eons.getOpenProject().iterator();
while (member_iter.hasNext()) {
var member = member_iter.next();
var component = ResourceKit.getGameComponentFromFile(member.getFile());
var card_data = build_card(component);
cards.push(card_data);
}
println(JSON.stringify(cards, null, 4));