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

93 lines
2.9 KiB
TypeScript
Raw Normal View History

2020-12-23 18:23:26 +01:00
import { DS4Item } from "./item";
import { DS4ItemDataType } from "./item-data";
2020-12-23 16:52:20 +01:00
/**
* Extend the basic ItemSheet with some very simple modifications
* @extends {ItemSheet}
*/
2020-12-28 15:51:00 +01:00
export class DS4ItemSheet extends ItemSheet<DS4ItemDataType, DS4Item> {
2020-12-23 16:52:20 +01:00
/** @override */
2020-12-23 18:23:26 +01:00
static get defaultOptions(): FormApplicationOptions {
2020-12-23 16:52:20 +01:00
return mergeObject(super.defaultOptions, {
width: 530,
height: 400,
classes: ["ds4", "sheet", "item"],
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }],
});
}
/** @override */
2020-12-23 18:23:26 +01:00
get template(): string {
2020-12-23 16:52:20 +01:00
const path = "systems/ds4/templates/item";
return `${path}/${this.item.data.type}-sheet.hbs`;
}
/* -------------------------------------------- */
/** @override */
getData(): ItemSheetData<DS4ItemDataType, DS4Item> {
2020-12-23 16:52:20 +01:00
const data = { ...super.getData(), config: CONFIG.DS4 };
console.log(data);
return data;
}
/* -------------------------------------------- */
/** @override */
setPosition(options: ApplicationPosition = {}): ApplicationPosition {
2020-12-23 16:52:20 +01:00
const position = super.setPosition(options);
if ("find" in this.element) {
2020-12-28 17:44:30 +01:00
const sheetBody = this.element.find(".sheet-body");
const bodyHeight = position.height - 192;
sheetBody.css("height", bodyHeight);
} else {
console.log("Failure setting position.");
}
2020-12-23 16:52:20 +01:00
return position;
}
/* -------------------------------------------- */
/** @override */
2020-12-23 18:23:26 +01:00
activateListeners(html: JQuery): void {
2020-12-23 16:52:20 +01:00
super.activateListeners(html);
if (!this.options.editable) return;
2020-12-28 18:24:13 +01:00
html.find(".effect-create").on("click", this._onEffectCreate.bind(this));
2020-12-23 16:52:20 +01:00
2020-12-28 18:24:13 +01:00
html.find(".effect-edit").on("click", (ev) => {
2020-12-23 16:52:20 +01:00
const li = $(ev.currentTarget).parents(".effect");
console.log(li.data("effectId"));
2020-12-28 18:24:13 +01:00
const effect = this.item["effects"].get(li.data("effectId")); //
2020-12-23 16:52:20 +01:00
effect.sheet.render(true);
});
2020-12-28 18:24:13 +01:00
html.find(".effect-delete").on("click", async (ev) => {
2020-12-23 16:52:20 +01:00
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
*/
2020-12-28 18:24:13 +01:00
private async _onEffectCreate(event: JQuery.ClickEvent): Promise<unknown> {
2020-12-23 16:52:20 +01:00
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({});
}
}