Get card `quantity` from Deck's `CopiesList`

This commit is contained in:
Adam Goldsmith 2021-09-17 15:35:35 -04:00
parent 011962af33
commit d471e39b45
1 changed files with 25 additions and 3 deletions

View File

@ -8,6 +8,7 @@ useLibrary('imageutils');
useLibrary('project');
useLibrary('uilayout');
useLibrary('uicontrols');
importClass(arkham.project.CopiesList);
// The resolution (in pixels per inch) of the exported images
const RESOLUTION = 200;
@ -117,7 +118,7 @@ function replaceAll(str, search, replace) {
return str.split(search).join(replace);
}
function build_card(component, pack_code, cycle_prefix) {
function build_card(component, pack_code, cycle_prefix, copies) {
function substitute_tags(str) {
str = str.trim();
str = replaceAll(str, "<fullname>", String(component.getName()));
@ -139,7 +140,7 @@ function build_card(component, pack_code, cycle_prefix) {
name: substitute_tags(String(component.getName())),
pack_code: String(pack_code),
position: int_or_null(component.settings.get('CollectionNumber')),
quantity: 2, // TODO
quantity: copies,
//restrictions: null, // TODO
// TODO: should also handle "Victory" field
text: substitute_tags(String(
@ -248,6 +249,18 @@ function exportCard(component, file) {
}
}
// Hack to override the default return value of 1
function copyCount(copies_list, name) {
const entries = copies_list.getListEntries().map(function (x) {
return String(x);
});
if (entries.indexOf(String(name)) == -1) {
return 2;
} else {
return copies_list.getCopyCount(name);
}
}
function settingsDialog() {
const pack_code_field = textField("", 15);
const cycle_prefix_field = textField("", 3);
@ -301,6 +314,14 @@ function run() {
}
},
performImpl: function performImpl(member, pack_code, cycle_prefix) {
let copies_list;
try {
copies_list = new CopiesList(member);
} catch (ex) {
copies_list = new CopiesList();
warn("unable to read copies list, using card count of 2 for all files", ex);
}
const children = member.children.filter(function (child) {
return ProjectUtilities.matchExtension(child, 'eon');
});
@ -312,7 +333,8 @@ function run() {
let component = ResourceKit.getGameComponentFromFile(child.file);
if (component.getFrontTemplateKey() in card_types) {
printf("Generating JSON/PNG for '%s'...\n", child);
let card_data = build_card(component, pack_code, cycle_prefix);
let copies = copyCount(copies_list, child.baseName);
let card_data = build_card(component, pack_code, cycle_prefix, copies);
cards.push(card_data);
let export_dir = new File(member.file, 'export');