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

108 lines
3.3 KiB
TypeScript
Raw Normal View History

2020-12-23 18:23:26 +01:00
import { DS4Item } from "./item";
import { DS4ItemDataType, isDS4ItemDataTypePhysical } from "./item-data";
2020-12-23 18:23:26 +01:00
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> {
const data = {
...super.getData(),
config: CONFIG.DS4,
isOwned: this.item.isOwned,
actor: this.item.actor,
isPhysical: isDS4ItemDataTypePhysical(this.item.data.data),
};
2020-12-23 16:52:20 +01:00
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;
html.find(".effect-control").on("click", this._onManageActiveEffect.bind(this));
2020-12-23 16:52:20 +01:00
}
/**
* Handle management of ActiveEffects.
2020-12-23 16:52:20 +01:00
* @param {Event} event The originating click event
*/
private async _onManageActiveEffect(event: JQuery.ClickEvent): Promise<unknown> {
2020-12-23 16:52:20 +01:00
event.preventDefault();
if (this.item.isOwned) {
2021-01-07 12:04:25 +01:00
return ui.notifications.warn(game.i18n.localize("DS4.WarningManageActiveEffectOnOwnedItem"));
}
const a = event.currentTarget;
const li = $(a).parents(".effect");
switch (a.dataset["action"]) {
case "create":
return this._createActiveEffect();
case "edit":
const effect = this.item.effects.get(li.data("effectId"));
return effect.sheet.render(true);
case "delete": {
return this.item.deleteEmbeddedEntity("ActiveEffect", li.data("effectId"));
}
}
}
/**
* Create a new ActiveEffect for the item using default data.
*/
private async _createActiveEffect(): Promise<unknown> {
2020-12-23 16:52:20 +01:00
const label = `New Effect`;
const createData = {
label: label,
changes: [],
duration: {},
transfer: true,
};
const effect = await ActiveEffect.create(createData, this.item);
return effect.create({});
}
}