fvtt-vadentis/modules/vadentis-item-sheet.js

120 lines
3.8 KiB
JavaScript

import { VadentisUtility } from "./vadentis-utility.js";
/**
* Extend the basic ItemSheet with some very simple modifications
* @extends {ItemSheet}
*/
export class VadentisItemSheet extends ItemSheet {
/** @override */
static get defaultOptions() {
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ["foundryvtt-vadentis", "sheet", "item"],
template: "systems/foundryvtt-vadentis/templates/item-sheet.html",
width: 550,
height: 550
//tabs: [{navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description"}]
});
}
/* -------------------------------------------- */
_getHeaderButtons() {
let buttons = super._getHeaderButtons();
// Add "Post to chat" button
// We previously restricted this to GM and editable items only. If you ever find this comment because it broke something: eh, sorry!
buttons.unshift(
{
class: "post",
icon: "fas fa-comment",
onclick: ev => {} //new RdDItem(this.item.data).postItem()
})
return buttons
}
/* -------------------------------------------- */
/** @override */
setPosition(options={}) {
const position = super.setPosition(options);
const sheetBody = this.element.find(".sheet-body");
const bodyHeight = position.height - 192;
sheetBody.css("height", bodyHeight);
return position;
}
/* -------------------------------------------- */
async getData() {
let itemData = foundry.utils.deepClone(this.object.system);
let formData = {
title: this.title,
id: this.id,
type: this.object.type,
img: this.object.img,
name: this.object.name,
editable: this.isEditable,
cssClass: this.isEditable ? "editable" : "locked",
data: itemData,
limited: this.object.limited,
options: this.options,
owner: this.document.isOwner,
isGM: game.user.isGM,
}
if (itemData.description) {
formData.description = await TextEditor.enrichHTML(this.object.system.description, { async: true })
}
if (itemData.notes) {
formData.notes = await TextEditor.enrichHTML(this.object.system.notes, { async: true })
}
if (itemData.effect) {
formData.effect = await TextEditor.enrichHTML(this.object.system.effect, { async: true })
}
if (itemData.criticaleffect) {
formData.criticaleffect = await TextEditor.enrichHTML(this.object.system.criticaleffect, { async: true })
}
if (this.object.type == 'sort') {
formData.donnees = await VadentisUtility.getDonnees();
}
if (this.object.type == 'devotion') {
formData.eglises = await VadentisUtility.getEglises();
}
console.log("ITEM DATA", formData, this);
return formData;
}
/* -------------------------------------------- */
/** @override */
activateListeners(html) {
super.activateListeners(html);
// Everything below here is only needed if the sheet is editable
if (!this.options.editable) return;
// Update Inventory Item
html.find('.item-edit').click(ev => {
const li = $(ev.currentTarget).parents(".item");
const item = this.object.options.actor.getOwnedItem(li.data("item-id"));
item.sheet.render(true);
});
// Update Inventory Item
html.find('.item-delete').click(ev => {
const li = $(ev.currentTarget).parents(".item");
this.object.options.actor.deleteOwnedItem( li.data("item-id") ).then( this.render(true));
});
}
/* -------------------------------------------- */
get template()
{
let type = this.item.type;
return `systems/foundryvtt-vadentis/templates/item-${type}-sheet.html`;
}
/* -------------------------------------------- */
/** @override */
_updateObject(event, formData) {
return this.object.update(formData);
}
}