From 92a93d6b6d6b5c8c48fedd55c5b9c415fa8cd276 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Tue, 14 Sep 2021 13:42:28 -0400 Subject: [PATCH] Generate images for front face of each card --- strange_eons_to_arkhamdb.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/strange_eons_to_arkhamdb.js b/strange_eons_to_arkhamdb.js index 0eb9d2b..9664664 100644 --- a/strange_eons_to_arkhamdb.js +++ b/strange_eons_to_arkhamdb.js @@ -1,7 +1,13 @@ +useLibrary('imageutils'); importClass(java.io.File); importClass(java.io.FileWriter); importPackage(arkham.project); +// The resolution (in pixels per inch) of the exported images +const RESOLUTION = 300; +// The extension of the image file format to use, e.g., png, jpg +const FORMAT = ImageUtils.FORMAT_PNG; + // TODO: should be defined in strange eons somewhere const pack_code = "kyo_player"; const cycle_prefix = "42"; @@ -227,15 +233,36 @@ function build_card(component) { return ordered_card_data; } +function exportCard(component, file) { + try { + // create the sheets that will paint the faces of the component + let sheets = component.createDefaultSheets(); + if (sheets == null) return; + + // export front face + let image = sheets[0].paint(arkham.sheet.RenderTarget.EXPORT, RESOLUTION); + ImageUtils.write(image, file, FORMAT, -1, false, RESOLUTION); + } catch (ex) { + println(ex); + println('Error while making image for ' + component.getName() + ', skipping file'); + Error.handleUncaught(ex); + } +} + + const cards = []; for (let member in recurseAllChildren(Eons.getOpenProject())) { try { if (ProjectUtilities.matchExtension(member, "eon")) { - printf("Generating JSON for '%s'...\n", member); + printf("Generating JSON/PNG for '%s'...\n", member); let component = ResourceKit.getGameComponentFromFile(member.getFile()); if (component.getFrontTemplateKey() in card_types) { let card_data = build_card(component); cards.push(card_data); + + const export_dir = new File(member.parent.file, 'export'); + export_dir.mkdir(); + exportCard(component, new File(export_dir, card_data.code + '.png')); } } } catch (ex) {