2021-06-26 22:02:00 +02:00
|
|
|
// SPDX-FileCopyrightText: 2021 Johannes Loher
|
|
|
|
// SPDX-FileCopyrightText: 2021 Oliver Rümpelein
|
|
|
|
// SPDX-FileCopyrightText: 2021 Gesina Schwalbe
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2021-02-05 02:35:47 +01:00
|
|
|
import { DS4 } from "../config";
|
2021-02-21 04:09:48 +01:00
|
|
|
import notifications from "../ui/notifications";
|
2021-06-30 03:53:52 +02:00
|
|
|
import { isDS4ItemDataTypePhysical } from "./item-data-source";
|
2020-12-23 18:23:26 +01:00
|
|
|
|
2020-12-23 16:52:20 +01:00
|
|
|
/**
|
2021-02-07 11:51:36 +01:00
|
|
|
* The Sheet class for DS4 Items
|
2020-12-23 16:52:20 +01:00
|
|
|
*/
|
2021-06-30 13:26:15 +02:00
|
|
|
export class DS4ItemSheet extends ItemSheet<ItemSheet.Options, DS4ItemSheetData> {
|
2020-12-23 16:52:20 +01:00
|
|
|
/** @override */
|
2021-06-30 03:53:52 +02:00
|
|
|
static get defaultOptions(): ItemSheet.Options {
|
2021-06-30 13:08:41 +02:00
|
|
|
return foundry.utils.mergeObject(super.defaultOptions, {
|
2021-02-21 05:39:12 +01:00
|
|
|
width: 540,
|
2020-12-23 16:52:20 +01:00
|
|
|
height: 400,
|
|
|
|
classes: ["ds4", "sheet", "item"],
|
|
|
|
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }],
|
2021-05-13 19:59:44 +02:00
|
|
|
scrollY: [".tab.description", ".tab.effects", ".tab.details"],
|
2020-12-23 16:52:20 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @override */
|
2020-12-23 18:23:26 +01:00
|
|
|
get template(): string {
|
2021-04-13 21:40:52 +02:00
|
|
|
const basePath = "systems/ds4/templates/sheets/item";
|
|
|
|
return `${basePath}/${this.item.data.type}-sheet.hbs`;
|
2020-12-23 16:52:20 +01:00
|
|
|
}
|
2021-06-30 13:26:15 +02:00
|
|
|
|
|
|
|
/** @override */
|
|
|
|
async getData(): Promise<DS4ItemSheetData> {
|
2021-06-30 14:24:23 +02:00
|
|
|
const data = {
|
2021-06-30 13:26:15 +02:00
|
|
|
...(await super.getData()),
|
|
|
|
config: DS4,
|
|
|
|
isOwned: this.item.isOwned,
|
|
|
|
actor: this.item.actor,
|
|
|
|
isPhysical: isDS4ItemDataTypePhysical(this.item.data.data),
|
|
|
|
};
|
2021-06-30 14:24:23 +02:00
|
|
|
return data;
|
2021-06-30 13:26:15 +02:00
|
|
|
}
|
|
|
|
|
2020-12-23 16:52:20 +01:00
|
|
|
/** @override */
|
2021-06-30 03:53:52 +02:00
|
|
|
setPosition(options: Partial<Application.Position> = {}): (Application.Position & { height: number }) | undefined {
|
2020-12-23 16:52:20 +01:00
|
|
|
const position = super.setPosition(options);
|
2021-06-30 03:53:52 +02:00
|
|
|
if (position) {
|
|
|
|
const sheetBody = this.element.find(".sheet-body");
|
|
|
|
const bodyHeight = position.height - 192;
|
|
|
|
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;
|
|
|
|
|
2021-01-07 11:55:54 +01:00
|
|
|
html.find(".effect-control").on("click", this._onManageActiveEffect.bind(this));
|
2020-12-23 16:52:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-07 11:55:54 +01:00
|
|
|
* Handle management of ActiveEffects.
|
2021-02-07 11:51:36 +01:00
|
|
|
* @param event - he originating click event
|
2020-12-23 16:52:20 +01:00
|
|
|
*/
|
2021-02-07 11:51:36 +01:00
|
|
|
protected async _onManageActiveEffect(event: JQuery.ClickEvent): Promise<unknown> {
|
2020-12-23 16:52:20 +01:00
|
|
|
event.preventDefault();
|
|
|
|
|
2021-01-07 11:55:54 +01:00
|
|
|
if (this.item.isOwned) {
|
2021-02-21 04:09:48 +01:00
|
|
|
return notifications.warn(game.i18n.localize("DS4.WarningManageActiveEffectOnOwnedItem"));
|
2021-01-07 11:55:54 +01:00
|
|
|
}
|
|
|
|
const a = event.currentTarget;
|
|
|
|
const li = $(a).parents(".effect");
|
|
|
|
|
|
|
|
switch (a.dataset["action"]) {
|
|
|
|
case "create":
|
|
|
|
return this._createActiveEffect();
|
|
|
|
case "edit":
|
2021-02-11 12:03:32 +01:00
|
|
|
const id = li.data("effectId");
|
|
|
|
const effect = this.item.effects.get(id);
|
|
|
|
if (!effect) {
|
|
|
|
throw new Error(game.i18n.format("DS4.ErrorItemDoesNotHaveEffect", { id, item: this.item.name }));
|
|
|
|
}
|
|
|
|
return effect.sheet.render(true);
|
2021-01-07 11:55:54 +01:00
|
|
|
case "delete": {
|
2021-06-30 03:53:52 +02:00
|
|
|
return this.item.deleteEmbeddedDocuments("ActiveEffect", [li.data("effectId")]);
|
2021-01-07 11:55:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new ActiveEffect for the item using default data.
|
|
|
|
*/
|
2021-06-30 03:53:52 +02:00
|
|
|
protected async _createActiveEffect(): Promise<ActiveEffect | undefined> {
|
2020-12-23 16:52:20 +01:00
|
|
|
const label = `New Effect`;
|
|
|
|
|
|
|
|
const createData = {
|
|
|
|
label: label,
|
|
|
|
changes: [],
|
|
|
|
duration: {},
|
|
|
|
transfer: true,
|
|
|
|
};
|
|
|
|
|
2021-06-30 03:53:52 +02:00
|
|
|
return ActiveEffect.create(createData, { parent: this.item });
|
2020-12-23 16:52:20 +01:00
|
|
|
}
|
|
|
|
}
|
2021-06-30 13:26:15 +02:00
|
|
|
|
|
|
|
interface DS4ItemSheetData extends ItemSheet.Data<ItemSheet.Options> {
|
|
|
|
config: typeof DS4;
|
|
|
|
isOwned: boolean;
|
|
|
|
actor: DS4ItemSheet["item"]["actor"];
|
|
|
|
isPhysical: boolean;
|
|
|
|
}
|