Generate JSONs for all cards in project
This commit is contained in:
parent
a86390579e
commit
01a0ff0aae
@ -1,18 +1,5 @@
|
||||
// TODO: should be defined in strange eons somewhere
|
||||
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) {
|
||||
if (slot.startsWith('1 ')) {
|
||||
@ -27,7 +14,6 @@ function renameSlot(slot) {
|
||||
}
|
||||
|
||||
const tag_replacements = {
|
||||
"<fullname>": String(Component.getName()),
|
||||
"<gua>": "[guardian]",
|
||||
"<see>": "[seeker]",
|
||||
"<rog>": "[rogue]",
|
||||
@ -68,13 +54,6 @@ const tag_replacements = {
|
||||
"<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
|
||||
const card_types = {
|
||||
"AHLCG-Event-Default": "event",
|
||||
@ -97,62 +76,97 @@ function int_or_null(inp) {
|
||||
}
|
||||
}
|
||||
|
||||
var card_data = {
|
||||
code: String(code),
|
||||
deck_limit: 2, // TODO: could be derived?
|
||||
faction_code: String(Component.settings.get('CardClass')).toLowerCase(),
|
||||
flavor: substitute_tags(String(Component.settings.get('Flavor'))),
|
||||
health: int_or_null(Component.settings.get('Stamina')),
|
||||
illustrator: String(Component.settings.get('Artist')),
|
||||
is_unique: Component.settings.getBoolean('Unique'),
|
||||
name: substitute_tags(String(Component.getName())),
|
||||
pack_code: pack_code,
|
||||
position: int_or_null(Component.settings.get('CollectionNumber')),
|
||||
quantity: 2, // TODO
|
||||
//restrictions: null, // TODO
|
||||
sanity: int_or_null(Component.settings.get('Sanity')),
|
||||
skill_agility: skills["Agility"],
|
||||
skill_combat: skills["Combat"],
|
||||
skill_intellect: skills["Intellect"],
|
||||
skill_wild: skills["Wild"],
|
||||
skill_willpower: skills["Willpower"],
|
||||
// TODO: should also handle "Victory" field
|
||||
text: substitute_tags(String(
|
||||
Component.settings.get('Keywords') + '\n' + Component.settings.get('Rules'))),
|
||||
traits: substitute_tags(String(Component.settings.get('Traits'))),
|
||||
type_code: card_types[Component.getFrontTemplateKey()],
|
||||
xp: int_or_null(Component.settings.get('Level')),
|
||||
};
|
||||
function build_card(component) {
|
||||
function substitute_tags(str) {
|
||||
str = str.replace("<fullname>", String(component.getName()));
|
||||
|
||||
var raw_cost = Component.settings.get('ResourceCost');
|
||||
if (raw_cost) {
|
||||
card_data.cost = int_or_null(raw_cost);
|
||||
}
|
||||
|
||||
var raw_slot = Component.settings.get('Slot');
|
||||
if (raw_slot) {
|
||||
card_data.slot = renameSlot(String(raw_slot));
|
||||
var raw_slot2 = Component.settings.get('Slot2');
|
||||
if (raw_slot2 && raw_slot2 != 'None') {
|
||||
card_data.slot += '. ' + renameSlot(raw_slot2);
|
||||
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 = {
|
||||
code: String(code),
|
||||
deck_limit: 2, // TODO: could be derived?
|
||||
faction_code: String(component.settings.get('CardClass')).toLowerCase(),
|
||||
flavor: substitute_tags(String(component.settings.get('Flavor'))),
|
||||
health: int_or_null(component.settings.get('Stamina')),
|
||||
illustrator: String(component.settings.get('Artist')),
|
||||
is_unique: component.settings.getBoolean('Unique'),
|
||||
name: substitute_tags(String(component.getName())),
|
||||
pack_code: pack_code,
|
||||
position: int_or_null(component.settings.get('CollectionNumber')),
|
||||
quantity: 2, // TODO
|
||||
//restrictions: null, // TODO
|
||||
sanity: int_or_null(component.settings.get('Sanity')),
|
||||
skill_agility: skills["Agility"],
|
||||
skill_combat: skills["Combat"],
|
||||
skill_intellect: skills["Intellect"],
|
||||
skill_wild: skills["Wild"],
|
||||
skill_willpower: skills["Willpower"],
|
||||
// TODO: should also handle "Victory" field
|
||||
text: substitute_tags(String(
|
||||
component.settings.get('Keywords') + '\n' + component.settings.get('Rules'))),
|
||||
traits: substitute_tags(String(component.settings.get('Traits'))),
|
||||
type_code: card_types[component.getFrontTemplateKey()],
|
||||
xp: int_or_null(component.settings.get('Level')),
|
||||
};
|
||||
|
||||
var raw_cost = component.settings.get('ResourceCost');
|
||||
if (raw_cost) {
|
||||
card_data.cost = int_or_null(raw_cost);
|
||||
}
|
||||
|
||||
var raw_slot = component.settings.get('Slot');
|
||||
if (raw_slot) {
|
||||
card_data.slot = renameSlot(String(raw_slot));
|
||||
var raw_slot2 = component.settings.get('Slot2');
|
||||
if (raw_slot2 && raw_slot2 != 'None') {
|
||||
card_data.slot += '. ' + renameSlot(raw_slot2);
|
||||
}
|
||||
}
|
||||
|
||||
var subtitle = component.settings.get('Subtitle');
|
||||
if (subtitle && subtitle != '') {
|
||||
card_data.subname = subtitle;
|
||||
}
|
||||
|
||||
var faction2 = component.settings.get('CardClass2');
|
||||
if (faction2 && faction2 != 'None') {
|
||||
card_data.faction2_code = String(component.settings.get('CardClass2')).toLowerCase();
|
||||
}
|
||||
|
||||
if (card_types[component.getFrontTemplateKey()] == 'enemy') {
|
||||
// TODO: "weakness" or "basicweakness"
|
||||
card_data.subtype_code = "basicweakness";
|
||||
}
|
||||
|
||||
// TODO: parse out some keywords into their own fields
|
||||
|
||||
return card_data;
|
||||
}
|
||||
|
||||
var subtitle = Component.settings.get('Subtitle');
|
||||
if (subtitle && subtitle != '') {
|
||||
card_data.subname = subtitle;
|
||||
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);
|
||||
}
|
||||
|
||||
var faction2 = Component.settings.get('CardClass2');
|
||||
if (faction2 && faction2 != 'None') {
|
||||
card_data.faction2_code = String(Component.settings.get('CardClass2')).toLowerCase();
|
||||
}
|
||||
|
||||
if (card_types[Component.getFrontTemplateKey()] == 'enemy') {
|
||||
// TODO: "weakness" or "basicweakness"
|
||||
card_data.subtype_code = "basicweakness";
|
||||
}
|
||||
|
||||
// TODO: parse out some keywords into their own fields
|
||||
|
||||
println(JSON.stringify(card_data, null, 4));
|
||||
println(JSON.stringify(cards, null, 4));
|
||||
|
Loading…
Reference in New Issue
Block a user