87 lines
2.2 KiB
JavaScript
87 lines
2.2 KiB
JavaScript
/**
|
|
* 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();
|
|
|
|
data.config = CONFIG.DS4;
|
|
console.log(data);
|
|
return data;
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @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;
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @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 = ActiveEffect.create(createData, this.item);
|
|
return effect.create();
|
|
}
|
|
}
|