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');
|
useLibrary('imageutils');
|
||||||
importClass(java.io.File);
|
useLibrary('project');
|
||||||
importClass(java.io.FileWriter);
|
|
||||||
importPackage(arkham.project);
|
|
||||||
|
|
||||||
// The resolution (in pixels per inch) of the exported images
|
// The resolution (in pixels per inch) of the exported images
|
||||||
const RESOLUTION = 200;
|
const RESOLUTION = 200;
|
||||||
@ -12,6 +16,26 @@ const FORMAT = ImageUtils.FORMAT_JPEG;
|
|||||||
const pack_code = "kyo_player";
|
const pack_code = "kyo_player";
|
||||||
const cycle_prefix = "43";
|
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) {
|
function renameSlot(slot) {
|
||||||
if (slot.startsWith('1 ')) {
|
if (slot.startsWith('1 ')) {
|
||||||
return slot.slice(2);
|
return slot.slice(2);
|
||||||
@ -95,29 +119,6 @@ function replaceAll(str, search, replace) {
|
|||||||
return str.split(search).join(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 build_card(component) {
|
||||||
function substitute_tags(str) {
|
function substitute_tags(str) {
|
||||||
str = str.trim();
|
str = str.trim();
|
||||||
@ -249,39 +250,76 @@ function exportCard(component, file) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function run() {
|
||||||
const cards = [];
|
const arkhamDBAction = JavaAdapter(TaskAction, {
|
||||||
for (let member in recurseAllChildren(Eons.getOpenProject())) {
|
getLabel: function getLabel() {
|
||||||
try {
|
return 'Generate ArkhamDB Data';
|
||||||
if (ProjectUtilities.matchExtension(member, "eon")) {
|
},
|
||||||
let component = ResourceKit.getGameComponentFromFile(member.getFile());
|
getActionName: function getActionName() {
|
||||||
if (component.getFrontTemplateKey() in card_types) {
|
return 'arkhamdb';
|
||||||
printf("Generating JSON/PNG for '%s'...\n", member);
|
},
|
||||||
let card_data = build_card(component);
|
// Applies to Deck Tasks
|
||||||
cards.push(card_data);
|
appliesTo: function appliesTo(project, task, member) {
|
||||||
|
if (member != null || task == null) {
|
||||||
let export_dir = new File(member.parent.file, 'export');
|
return false;
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
const type = task.settings.get(Task.KEY_TYPE);
|
||||||
} catch (ex) {
|
if (NewTaskType.DECK_TYPE.equals(type)) {
|
||||||
println(ex);
|
return true;
|
||||||
println('Error while processing ' + member.name + ', skipping file');
|
}
|
||||||
Error.handleUncaught(ex);
|
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