fix(item-sheet): enable image editing via file picker

This commit is contained in:
Alexander Minges 2025-07-16 22:33:34 +02:00
parent e30ce8947e
commit e9c223731d
Signed by: Athemis
GPG key ID: 31FBDEF92DDB162B
2 changed files with 18 additions and 1 deletions

View file

@ -32,6 +32,7 @@ export class DS4ItemSheet extends foundry.applications.api.HandlebarsApplication
deleteEffect: DS4ItemSheet.prototype._onDeleteEffect, deleteEffect: DS4ItemSheet.prototype._onDeleteEffect,
deleteeffect: DS4ItemSheet.prototype._onDeleteEffect, deleteeffect: DS4ItemSheet.prototype._onDeleteEffect,
changeTab: DS4ItemSheet.prototype._onChangeTab, changeTab: DS4ItemSheet.prototype._onChangeTab,
editImage: DS4ItemSheet.prototype._onEditImage,
}, },
}; };
@ -250,7 +251,23 @@ export class DS4ItemSheet extends foundry.applications.api.HandlebarsApplication
} }
} }
/**
* Handle editing the items's image
* @param {Event} event - The triggering event
* @param {HTMLElement} target - The target element
*/
async _onEditImage(event, target) {
const field = target.dataset.field || "img";
const current = foundry.utils.getProperty(this.item, field);
const fp = new foundry.applications.apps.FilePicker({
type: "image",
current: current,
callback: (path) => this.item.update({ [field]: path })
});
console.log("Editing image...");
return fp.browse();
}
/** @override */ /** @override */
async _onRender(context, options) { async _onRender(context, options) {

View file

@ -5,7 +5,7 @@ SPDX-License-Identifier: MIT
--}} --}}
<header class="ds4-item-header"> <header class="ds4-item-header">
<img class="ds4-item-header__img" src="{{data.img}}" data-edit="img" alt="{{localize 'DS4.ItemImageAltText'}}" <img class="ds4-item-header__img" src="{{data.img}}" data-action="editImage" alt="{{localize 'DS4.ItemImageAltText'}}"
title="{{data.name}}" /> title="{{data.name}}" />
<div class="ds4-item-header__data"> <div class="ds4-item-header__data">
<h2 class="ds4-item-header__type">{{lookup config.i18n.itemTypes item.type}}</h2> <h2 class="ds4-item-header__type">{{lookup config.i18n.itemTypes item.type}}</h2>