ds4/src/module/item/item-sheet.ts

86 lines
2.5 KiB
TypeScript
Raw Normal View History

2020-12-23 16:52:20 +01:00
/**
* Extend the basic ItemSheet with some very simple modifications
* @extends {ItemSheet}
*/
export class DS4ItemSheet extends ItemSheet {
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
width: 530,
height: 400,
classes: ["ds4", "sheet", "item"],
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }],
});
}
/** @override */
get template() {
const path = "systems/ds4/templates/item";
return `${path}/${this.item.data.type}-sheet.hbs`;
}
/* -------------------------------------------- */
/** @override */
getData() {
const data = { ...super.getData(), config: CONFIG.DS4 };
console.log(data);
return data;
}
/* -------------------------------------------- */
/** @override */
setPosition(options = {}) {
const position = super.setPosition(options);
const sheetBody = (this.element as JQuery).find(".sheet-body"); // TODO: Why is the cast necessary?
const bodyHeight = position.height - 192;
2020-12-23 17:09:02 +01:00
sheetBody.css("height", bodyHeight);
2020-12-23 16:52:20 +01:00
return position;
}
/* -------------------------------------------- */
/** @override */
activateListeners(html) {
super.activateListeners(html);
if (!this.options.editable) return;
html.find(".effect-create").click(this._onEffectCreate.bind(this));
html.find(".effect-edit").click((ev) => {
const li = $(ev.currentTarget).parents(".effect");
console.log(li.data("effectId"));
const effect = this.item.effects.get(li.data("effectId"));
effect.sheet.render(true);
});
html.find(".effect-delete").click(async (ev) => {
const li = $(ev.currentTarget).parents(".effect");
await this.item.deleteEmbeddedEntity("ActiveEffect", li.data("effectId"));
});
}
/**
* Handle creating a new ActiveEffect for the item using initial data defined in the HTML dataset
* @param {Event} event The originating click event
* @private
*/
async _onEffectCreate(event) {
event.preventDefault();
const label = `New Effect`;
const createData = {
label: label,
changes: [],
duration: {},
transfer: true,
};
const effect = await ActiveEffect.create(createData, this.item);
return effect.create({});
}
}