improved importer to detect attack features and actions

This commit is contained in:
CPTN Cosmo 2026-01-24 11:21:05 +01:00
parent bbf4ecbc87
commit 74f123ecf2
No known key found for this signature in database
4 changed files with 304 additions and 61 deletions

View file

@ -49,6 +49,27 @@ export class DHImporterApp extends HandlebarsApplicationMixin(ApplicationV2) {
};
}
_onRender(context, options) {
super._onRender(context, options);
// Bind File Pickers
this.element.querySelectorAll("img[data-edit]").forEach(img => {
img.addEventListener("click", ev => {
const field = img.dataset.edit;
const fp = new FilePicker({
type: "image",
current: img.getAttribute("src"),
callback: path => {
img.src = path;
const input = this.element.querySelector(`input[name='${field}']`);
if (input) input.value = path;
}
});
fp.browse();
});
});
}
static async onParse(event, target) {
const form = this.element;
const text = form.querySelector("textarea[name='text']").value;
@ -89,12 +110,40 @@ export class DHImporterApp extends HandlebarsApplicationMixin(ApplicationV2) {
const formData = new foundry.applications.ux.FormDataExtended(this.element).object;
for (const actor of this.parsedData) {
// Update Actor Image
if (formData[`img.${actor.name}`]) {
actor.img = formData[`img.${actor.name}`];
actor.prototypeToken.texture.src = formData[`img.${actor.name}`];
}
// Update Attack Image
if (formData[`attackImg.${actor.name}`]) {
actor.system.attack.img = formData[`attackImg.${actor.name}`];
}
// Open Sheet Flag
if (formData[`openSheet.${actor.name}`]) {
actor.openSheet = true;
}
actor.useFeatures = {};
for (const item of actor.items) {
const key = `useFeatures.${actor.name}.${item.name}`;
if (formData[key]) {
actor.useFeatures[item.name] = formData[key];
}
// Update Item Image
const itemImgKey = `itemImg.${actor.name}.${item.name}`;
if (formData[itemImgKey]) {
item.img = formData[itemImgKey];
// Also update embedded action image if present
if (item.system.actions) {
for (const actionId in item.system.actions) {
item.system.actions[actionId].img = formData[itemImgKey];
}
}
}
}
}