Convert to plugin structure
This commit is contained in:
parent
b6cf75b197
commit
62e9e1ec4f
7
eons-plugin
Normal file
7
eons-plugin
Normal file
@ -0,0 +1,7 @@
|
||||
#
|
||||
# ArkhamDB Export Root File
|
||||
#
|
||||
|
||||
id = CATALOGUEID{0736ec6b-6307-4fe2-a8ed-c30d14a2c4c5:2021-8-16-21-31-54-238}
|
||||
|
||||
res://ArkhamDBExport.js
|
@ -1,7 +1,11 @@
|
||||
/*
|
||||
* ArkhamDBExport.js
|
||||
*
|
||||
* Generates a JSON file and card images for import into ArkhamDB
|
||||
*/
|
||||
|
||||
useLibrary('imageutils');
|
||||
importClass(java.io.File);
|
||||
importClass(java.io.FileWriter);
|
||||
importPackage(arkham.project);
|
||||
useLibrary('project');
|
||||
|
||||
// The resolution (in pixels per inch) of the exported images
|
||||
const RESOLUTION = 200;
|
||||
@ -12,6 +16,26 @@ const FORMAT = ImageUtils.FORMAT_JPEG;
|
||||
const pack_code = "kyo_player";
|
||||
const cycle_prefix = "43";
|
||||
|
||||
function getName() {
|
||||
return 'ArkhamDB Export';
|
||||
}
|
||||
function getDescription() {
|
||||
return 'Generates a JSON file and card images for import into ArkhamDB';
|
||||
}
|
||||
function getVersion() {
|
||||
return 1.0;
|
||||
}
|
||||
function getPluginType() {
|
||||
return arkham.plugins.Plugin.INJECTED;
|
||||
}
|
||||
|
||||
function unload() {
|
||||
unregisterAll();
|
||||
}
|
||||
|
||||
// Creates a test button during development that calls unload() to clean up.
|
||||
testProjectScript();
|
||||
|
||||
function renameSlot(slot) {
|
||||
if (slot.startsWith('1 ')) {
|
||||
return slot.slice(2);
|
||||
@ -95,29 +119,6 @@ function replaceAll(str, search, replace) {
|
||||
return str.split(search).join(replace);
|
||||
}
|
||||
|
||||
function javaIteratorToJsGenerator(java_iter) {
|
||||
while(java_iter.hasNext()) {
|
||||
yield java_iter.next();
|
||||
}
|
||||
}
|
||||
|
||||
function recurseAllChildren(parent) {
|
||||
if (parent == null || !(parent instanceof Member)) {
|
||||
error('missing parent, or parent is not a Member');
|
||||
}
|
||||
|
||||
for (let child in javaIteratorToJsGenerator(parent.iterator())) {
|
||||
if (child.isFolder()) {
|
||||
for (let sub_child in recurseAllChildren(child)) {
|
||||
yield sub_child;
|
||||
}
|
||||
}
|
||||
else {
|
||||
yield child;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function build_card(component) {
|
||||
function substitute_tags(str) {
|
||||
str = str.trim();
|
||||
@ -249,39 +250,76 @@ function exportCard(component, file) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const cards = [];
|
||||
for (let member in recurseAllChildren(Eons.getOpenProject())) {
|
||||
try {
|
||||
if (ProjectUtilities.matchExtension(member, "eon")) {
|
||||
let component = ResourceKit.getGameComponentFromFile(member.getFile());
|
||||
if (component.getFrontTemplateKey() in card_types) {
|
||||
printf("Generating JSON/PNG for '%s'...\n", member);
|
||||
let card_data = build_card(component);
|
||||
cards.push(card_data);
|
||||
|
||||
let export_dir = new File(member.parent.file, 'export');
|
||||
let target_file = new File(export_dir, card_data.code + '.' + FORMAT);
|
||||
if (!target_file.exists() || member.file.lastModified() > target_file.lastModified()) {
|
||||
printf("Image for '%s' is out of date, rebuilding...\n", member);
|
||||
export_dir.mkdir();
|
||||
exportCard(component, target_file);
|
||||
}
|
||||
function run() {
|
||||
const arkhamDBAction = JavaAdapter(TaskAction, {
|
||||
getLabel: function getLabel() {
|
||||
return 'Generate ArkhamDB Data';
|
||||
},
|
||||
getActionName: function getActionName() {
|
||||
return 'arkhamdb';
|
||||
},
|
||||
// Applies to Deck Tasks
|
||||
appliesTo: function appliesTo(project, task, member) {
|
||||
if (member != null || task == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} catch (ex) {
|
||||
println(ex);
|
||||
println('Error while processing ' + member.name + ', skipping file');
|
||||
Error.handleUncaught(ex);
|
||||
}
|
||||
const type = task.settings.get(Task.KEY_TYPE);
|
||||
if (NewTaskType.DECK_TYPE.equals(type)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
perform: function perform(project, task, member) {
|
||||
member = ProjectUtilities.simplify(project, task, member);
|
||||
Eons.setWaitCursor(true);
|
||||
try {
|
||||
this.performImpl(member);
|
||||
} catch (ex) {
|
||||
Error.handleUncaught(ex);
|
||||
} finally {
|
||||
Eons.setWaitCursor(false);
|
||||
member.synchronize();
|
||||
}
|
||||
},
|
||||
performImpl: function performImpl(member) {
|
||||
const children = member.children.filter(function (child) {
|
||||
return ProjectUtilities.matchExtension(child, 'eon');
|
||||
});
|
||||
|
||||
const cards = [];
|
||||
|
||||
for (let child of children) {
|
||||
try {
|
||||
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);
|
||||
cards.push(card_data);
|
||||
|
||||
let export_dir = new File(member.file, 'export');
|
||||
let target_file = new File(export_dir, card_data.code + '.' + FORMAT);
|
||||
if (!target_file.exists() || child.file.lastModified() > target_file.lastModified()) {
|
||||
printf("Image for '%s' is out of date, rebuilding...\n", child);
|
||||
export_dir.mkdir();
|
||||
exportCard(component, target_file);
|
||||
}
|
||||
}
|
||||
} catch (ex) {
|
||||
println(ex);
|
||||
println('Error while processing ' + child.name + ', skipping file');
|
||||
Error.handleUncaught(ex);
|
||||
}
|
||||
}
|
||||
|
||||
cards.sort(function (a, b) {
|
||||
return parseInt(a.code) - parseInt(b.code);
|
||||
});
|
||||
const file = new File(member.file, pack_code + '.json');
|
||||
printf("Writing '%s'\n", file);
|
||||
ProjectUtilities.writeTextFile(file, JSON.stringify(cards, null, 4));
|
||||
println("Done!");
|
||||
}
|
||||
});
|
||||
|
||||
ActionRegistry.register(arkhamDBAction, Actions.PRIORITY_IMPORT_EXPORT);
|
||||
}
|
||||
|
||||
cards.sort(function (a, b) {
|
||||
return parseInt(a.code) - parseInt(b.code);
|
||||
});
|
||||
const file = new File(Eons.getOpenProject().getFile(), pack_code + '.json');
|
||||
printf("Writing '%s'\n", file);
|
||||
ProjectUtilities.writeTextFile(file, JSON.stringify(cards, null, 4));
|
||||
println("Done!");
|
||||
|
||||
Eons.getOpenProject().synchronize();
|
Loading…
x
Reference in New Issue
Block a user