Recursively iterate through all (supported) cards in the project

This commit is contained in:
Adam Goldsmith 2021-09-14 13:04:29 -04:00
parent fff366770a
commit c3051b19d2
1 changed files with 40 additions and 7 deletions

View File

@ -1,3 +1,5 @@
importPackage(arkham.project);
// TODO: should be defined in strange eons somewhere
const pack_code = "kyo_player";
const cycle_prefix = "42";
@ -85,6 +87,29 @@ 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();
@ -201,13 +226,21 @@ function build_card(component) {
}
const cards = [];
const member_iter = Eons.getOpenProject().iterator();
while (member_iter.hasNext()) {
const member = member_iter.next();
printf("Generating JSON for '%s'...\n", member);
const component = ResourceKit.getGameComponentFromFile(member.getFile());
const card_data = build_card(component);
cards.push(card_data);
for (let member in recurseAllChildren(Eons.getOpenProject())) {
try {
if (ProjectUtilities.matchExtension(member, "eon")) {
printf("Generating JSON 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);
}
}
} catch (ex) {
println(ex);
println('Error while processing ' + member.name + ', skipping file');
Error.handleUncaught(ex);
}
}
cards.sort(function (a, b) {