From e7f411d5e23a9771fd58fa8bda8fd74c0dbb4d94 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Sat, 18 Sep 2021 01:26:15 -0400 Subject: [PATCH] Use the copies file to determine how many of each card to make Currently hardcoded to use a default of 2 per card, should be a setting at some point --- resources/TTSDeck.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/resources/TTSDeck.js b/resources/TTSDeck.js index be74b47..e292216 100644 --- a/resources/TTSDeck.js +++ b/resources/TTSDeck.js @@ -8,6 +8,7 @@ useLibrary('project'); useLibrary('imageutils'); useLibrary('uilayout'); +importClass(arkham.project.CopiesList); // The resolution (in pixels per inch) of the exported images const RESOLUTION = 200; @@ -121,6 +122,18 @@ function makeSavedObjectJSON(objects, save_name) { }; } +// 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 run() { const ttsDeckAction = JavaAdapter(TaskAction, { getLabel: function getLabel() { @@ -152,6 +165,14 @@ function run() { } }, performImpl: function performImpl(member) { + let copies_list; + try { + copies_list = new CopiesList(member); + } catch (ex) { + copies_list = new CopiesList(); + alert("unable to read copies list, using card count of 2 for all files", true); + } + const children = member.getChildren(); const cards = children.filter(function (child) { if (ProjectUtilities.matchExtension(child, 'eon')) { @@ -177,8 +198,11 @@ function run() { try { let component = ResourceKit.getGameComponentFromFile(card.file); let sheets = component.createDefaultSheets(); + let copies = copyCount(copies_list, card.baseName); - card_jsons.push(makeCardJSON(100 + index, component.getName())); + for (let ii = 0; ii < copies; ii++) { + card_jsons.push(makeCardJSON(100 + index, component.getName())); + } // export front face // TODO: handle two-sided cards