foundryvtt-shadows-over-sol/module/item-sheet.js

114 lines
3.8 KiB
JavaScript
Raw Permalink Normal View History

2021-01-18 16:11:27 +01:00
import { SoSUtility } from "./sos-utility.js";
/**
* Extend the basic ItemSheet with some very simple modifications
* @extends {ItemSheet}
*/
export class SoSItemSheet extends ItemSheet {
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
classes: ["foundryvtt-shadows-over-sol", "sheet", "item"],
template: "systems/foundryvtt-shadows-over-sol/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() {
2022-07-13 08:11:00 +02:00
const objectData = this.object
2021-05-22 23:42:53 +02: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-07-13 08:11:00 +02:00
data: foundry.utils.deepClone(this.object.system),
effects: this.object.effects.map(e => foundry.utils.deepClone(e.system)),
2021-05-22 23:42:53 +02:00
limited: this.object.limited,
options: this.options,
2022-09-28 15:53:50 +02:00
owner: this.document.isOwner,
description: await TextEditor.enrichHTML(this.object.system.description, {async: true}),
2021-05-22 23:42:53 +02:00
};
formData.isGM = game.user.isGM;
if ( objectData.type == 'skillexperience') {
2022-07-13 08:11:00 +02:00
formData.skillList = await SoSUtility.loadCompendiumNames("foundryvtt-shadows-over-sol.skills")
2021-03-12 20:57:41 +01:00
}
2021-05-22 23:42:53 +02:00
if ( objectData.type == 'skill' && this.object.options?.actor) {
2022-07-13 08:11:00 +02:00
formData.skillExperienceList = this.object.options.actor.getSkillExperience( objectData.name )
2021-03-12 20:57:41 +01:00
}
2022-09-28 15:53:50 +02:00
if ( objectData.type == 'geneline') {
formData.weakness = await TextEditor.enrichHTML(this.object.system.weakness, {async: true})
}
if ( objectData.type == 'malady') {
formData.notes = await TextEditor.enrichHTML(this.object.system.notes, {async: true})
}
2021-05-22 23:42:53 +02:00
return formData;
2021-01-18 16:11:27 +01:00
}
/* -------------------------------------------- */
/** @override */
activateListeners(html) {
super.activateListeners(html);
// Everything below here is only needed if the sheet is editable
if (!this.options.editable) return;
2021-03-12 20:57:41 +01:00
// 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));
});
2021-01-18 16:11:27 +01:00
}
/* -------------------------------------------- */
get template()
{
let type = this.item.type;
return `systems/foundryvtt-shadows-over-sol/templates/item-${type}-sheet.html`;
}
/* -------------------------------------------- */
/** @override */
_updateObject(event, formData) {
return this.object.update(formData);
}
}