From d471e39b45169bd750502fb0206b1d48e1f01744 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Fri, 17 Sep 2021 15:35:35 -0400 Subject: [PATCH] Get card `quantity` from Deck's `CopiesList` --- resources/ArkhamDBExport.js | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/resources/ArkhamDBExport.js b/resources/ArkhamDBExport.js index c595142..4d58c59 100644 --- a/resources/ArkhamDBExport.js +++ b/resources/ArkhamDBExport.js @@ -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, "", 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');