112 lines
3.1 KiB
JavaScript
112 lines
3.1 KiB
JavaScript
|
const { HandlebarsApplicationMixin } = foundry.applications.api
|
||
|
import { SYSTEM_RDD } from "../../constants.js"
|
||
|
import { Misc } from "../../misc.js"
|
||
|
import { RdDSheetUtility } from "../../rdd-sheet-utility.js";
|
||
|
|
||
|
|
||
|
export default class RdDItemBaseSheet extends HandlebarsApplicationMixin(foundry.applications.sheets.ItemSheetV2) {
|
||
|
|
||
|
static preloadHandlebars(...templatesList) {
|
||
|
const handlebars = ["systems/foundryvtt-reve-de-dragon/templates/sheets/item/common/header.hbs"]
|
||
|
templatesList.forEach(templates =>
|
||
|
templates.forEach(t =>
|
||
|
t.handlebars().forEach(h => handlebars.push(h))
|
||
|
)
|
||
|
)
|
||
|
loadTemplates(Misc.distinct(handlebars))
|
||
|
}
|
||
|
|
||
|
static register(sheetClass) {
|
||
|
const itemType = sheetClass.ITEM_TYPE
|
||
|
Items.registerSheet(SYSTEM_RDD, sheetClass, {
|
||
|
label: Misc.typeName('Item', itemType),
|
||
|
types: [itemType],
|
||
|
makeDefault: true
|
||
|
})
|
||
|
}
|
||
|
|
||
|
static registerAll(...sheetClasses) {
|
||
|
const handlebars = ["systems/foundryvtt-reve-de-dragon/templates/sheets/item/common/header.hbs"]
|
||
|
sheetClasses.forEach(sheetClass => {
|
||
|
sheetClass.TEMPLATES.forEach(t =>
|
||
|
t.handlebars().forEach(h => handlebars.push(h))
|
||
|
)
|
||
|
const itemType = sheetClass.ITEM_TYPE
|
||
|
Items.registerSheet(SYSTEM_RDD, sheetClass, {
|
||
|
label: Misc.typeName('Item', itemType),
|
||
|
types: [itemType],
|
||
|
makeDefault: true
|
||
|
})
|
||
|
})
|
||
|
loadTemplates(Misc.distinct(handlebars))
|
||
|
}
|
||
|
|
||
|
static get ITEM_TYPE() { return undefined }
|
||
|
|
||
|
constructor(options = {}) {
|
||
|
super(options)
|
||
|
}
|
||
|
|
||
|
static get TEMPLATES() { return [] }
|
||
|
|
||
|
/** @override */
|
||
|
static DEFAULT_OPTIONS = {
|
||
|
classes: ["fvtt-rdd", "item"],
|
||
|
position: {
|
||
|
width: 600,
|
||
|
height: "auto",
|
||
|
},
|
||
|
form: {
|
||
|
submitOnChange: true,
|
||
|
},
|
||
|
window: {
|
||
|
resizable: true,
|
||
|
},
|
||
|
actions: {
|
||
|
editImage: RdDItemBaseSheet.#onEditImage,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/** @override */
|
||
|
async _prepareContext() {
|
||
|
return {
|
||
|
item: this.document,
|
||
|
options: RdDSheetUtility.getOptions(this.document, this.isEditable),
|
||
|
fields: this.document.schema.fields,
|
||
|
systemFields: this.document.system.schema.fields,
|
||
|
system: this.document.system,
|
||
|
source: this.document.toObject(),
|
||
|
isEditable: this.isEditable,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// #region Actions
|
||
|
|
||
|
/**
|
||
|
* Handle changing a Document's image.
|
||
|
*
|
||
|
* @this RdDItemBaseSheet
|
||
|
* @param {PointerEvent} event The originating click event
|
||
|
* @param {HTMLElement} target The capturing HTML element which defined a [data-action]
|
||
|
* @returns {Promise}
|
||
|
* @private
|
||
|
*/
|
||
|
static async #onEditImage(event, target) {
|
||
|
const attr = target.dataset.edit
|
||
|
const current = foundry.utils.getProperty(this.document, attr)
|
||
|
const { img } = this.document.constructor.getDefaultArtwork?.(this.document.toObject()) ?? {}
|
||
|
const fp = new FilePicker({
|
||
|
current,
|
||
|
type: "image",
|
||
|
redirectToRoot: img ? [img] : [],
|
||
|
callback: (path) => {
|
||
|
this.document.update({ [attr]: path })
|
||
|
},
|
||
|
top: this.position.top + 40,
|
||
|
left: this.position.left + 10,
|
||
|
})
|
||
|
return fp.browse()
|
||
|
}
|
||
|
// #endregion
|
||
|
}
|