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

103 lines
3.2 KiB
JavaScript
Raw Permalink Normal View History

2022-01-09 09:33:47 +01:00
import { YggdrasillUtility } from "./yggdrasill-utility.js";
/**
* Extend the basic ItemSheet with some very simple modifications
* @extends {ItemSheet}
*/
export class YggdrasillItemSheet extends ItemSheet {
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
classes: ["fvtt-yggdrasill", "sheet", "item"],
template: "systems/fvtt-yggdrasill/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 => {}
})
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() {
2022-09-21 11:42:09 +02:00
const objectData = duplicate(this.object);
2022-01-09 09:33:47 +01:00
let formData = {
title: this.title,
id: objectData.id,
type: objectData.type,
img: objectData.img,
name: objectData.name,
editable: this.isEditable,
cssClass: this.isEditable ? "editable" : "locked",
2022-09-21 11:42:09 +02:00
data: foundry.utils.deepClone(this.object.system),
2022-01-09 09:33:47 +01:00
optionsBase: YggdrasillUtility.createDirectOptionList(0, 20),
optionsNiveaux4: YggdrasillUtility.buildListOptions(1, 5),
2022-09-28 15:43:48 +02:00
description: await TextEditor.enrichHTML(this.object.system.description, {async: true}),
2022-01-09 09:33:47 +01:00
limited: this.object.limited,
options: this.options,
owner: this.document.isOwner,
isGM: game.user.isGM
}
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");
2022-01-12 09:19:08 +01:00
const item = this.object.options.actor.items.get(li.data("item-id"));
2022-01-09 09:33:47 +01:00
item.sheet.render(true);
});
// Update Inventory Item
html.find('.item-delete').click(ev => {
const li = $(ev.currentTarget).parents(".item");
2022-01-12 09:19:08 +01:00
this.object.options.actor.deleteEmbeddedDocuments( "Item", [li.data("item-id") ] ).then( this.render(true));
2022-01-09 09:33:47 +01:00
});
}
/* -------------------------------------------- */
get template()
{
let type = this.item.type;
return `systems/fvtt-yggdrasill/templates/item-${type}-sheet.html`;
}
/* -------------------------------------------- */
/** @override */
_updateObject(event, formData) {
return this.object.update(formData);
}
}