Generate images for front face of each card

This commit is contained in:
Adam Goldsmith 2021-09-14 13:42:28 -04:00
parent ad4e082012
commit 92a93d6b6d

View File

@ -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) {