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

90 lines
2.8 KiB
TypeScript
Raw Normal View History

2020-12-23 18:23:26 +01:00
import { DS4ActorDataType } from "../actor/actor-data";
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 */
2020-12-23 18:23:26 +01:00
getData(): ItemSheetData<DS4ItemDataType> {
2020-12-23 16:52:20 +01:00
const data = { ...super.getData(), config: CONFIG.DS4 };
console.log(data);
return data;
}
/* -------------------------------------------- */
/** @override */
2020-12-23 18:23:26 +01:00
setPosition(options = {}): unknown {
2020-12-23 16:52:20 +01:00
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 */
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-create").click(this._onEffectCreate.bind(this));
html.find(".effect-edit").click((ev) => {
const li = $(ev.currentTarget).parents(".effect");
console.log(li.data("effectId"));
2020-12-23 18:23:26 +01:00
const effect = this.item["effects"].get(li.data("effectId")); // TODO: replace ["..."]
2020-12-23 16:52:20 +01:00
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
*/
2020-12-23 18:23:26 +01:00
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({});
}
}