2021-02-05 02:35:47 +01:00
|
|
|
import { DS4 } from "../config";
|
2020-12-23 18:23:26 +01:00
|
|
|
import { DS4Item } from "./item";
|
2021-01-26 03:55:18 +01:00
|
|
|
import { 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
|
|
|
|
*/
|
2021-02-07 11:15:37 +01:00
|
|
|
// TODO(types): Remove first generic parameter once https://github.com/League-of-Foundry-Developers/foundry-vtt-types/pull/273 is merged
|
2021-01-26 03:55:18 +01:00
|
|
|
export class DS4ItemSheet extends ItemSheet<unknown, DS4Item> {
|
2020-12-23 16:52:20 +01:00
|
|
|
/** @override */
|
2021-01-26 03:55:18 +01:00
|
|
|
static get defaultOptions(): BaseEntitySheet.Options {
|
|
|
|
const superDefaultOptions = super.defaultOptions;
|
|
|
|
return mergeObject(superDefaultOptions, {
|
2020-12-23 16:52:20 +01:00
|
|
|
width: 530,
|
|
|
|
height: 400,
|
|
|
|
classes: ["ds4", "sheet", "item"],
|
|
|
|
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }],
|
2021-01-19 03:31:40 +01:00
|
|
|
scrollY: [".sheet-body"],
|
2021-01-26 03:55:18 +01:00
|
|
|
template: superDefaultOptions.template,
|
|
|
|
viewPermission: superDefaultOptions.viewPermission,
|
|
|
|
closeOnSubmit: superDefaultOptions.closeOnSubmit,
|
|
|
|
submitOnChange: superDefaultOptions.submitOnChange,
|
|
|
|
submitOnClose: superDefaultOptions.submitOnClose,
|
|
|
|
editable: superDefaultOptions.editable,
|
|
|
|
baseApplication: superDefaultOptions.baseApplication,
|
|
|
|
top: superDefaultOptions.top,
|
|
|
|
left: superDefaultOptions.left,
|
|
|
|
popOut: superDefaultOptions.popOut,
|
|
|
|
minimizable: superDefaultOptions.minimizable,
|
|
|
|
resizable: superDefaultOptions.resizable,
|
|
|
|
id: superDefaultOptions.id,
|
|
|
|
dragDrop: superDefaultOptions.dragDrop,
|
|
|
|
filters: superDefaultOptions.filters,
|
|
|
|
title: superDefaultOptions.title,
|
2020-12-23 16:52:20 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @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 */
|
2021-01-26 03:55:18 +01:00
|
|
|
getData(): ItemSheet.Data<DS4Item> {
|
2021-01-06 16:10:56 +01:00
|
|
|
const data = {
|
|
|
|
...super.getData(),
|
2021-02-05 02:35:47 +01:00
|
|
|
config: DS4,
|
2021-01-06 16:10:56 +01:00
|
|
|
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 */
|
2021-01-26 03:55:18 +01:00
|
|
|
setPosition(options: Partial<Application.Position> = {}): Application.Position {
|
2020-12-23 16:52:20 +01:00
|
|
|
const position = super.setPosition(options);
|
2020-12-28 17:34:40 +01:00
|
|
|
if ("find" in this.element) {
|
2020-12-28 17:44:30 +01:00
|
|
|
const sheetBody = this.element.find(".sheet-body");
|
2021-01-26 21:25:43 +01:00
|
|
|
const bodyHeight = position.height - 192;
|
2020-12-28 17:34:40 +01:00
|
|
|
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;
|
|
|
|
|
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:15:37 +01:00
|
|
|
* @param event The originating click event
|
2020-12-23 16:52:20 +01:00
|
|
|
*/
|
2021-01-07 11:55:54 +01:00
|
|
|
private 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-01-07 12:04:25 +01:00
|
|
|
return ui.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-01-29 16:17:31 +01:00
|
|
|
const effect = this.item.effects.get(li.data("effectId"));
|
2021-01-07 11:55:54 +01:00
|
|
|
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.
|
|
|
|
*/
|
2021-01-29 16:17:31 +01:00
|
|
|
private async _createActiveEffect(): Promise<ActiveEffect.Data> {
|
2020-12-23 16:52:20 +01:00
|
|
|
const label = `New Effect`;
|
|
|
|
|
|
|
|
const createData = {
|
|
|
|
label: label,
|
|
|
|
changes: [],
|
|
|
|
duration: {},
|
|
|
|
transfer: true,
|
|
|
|
};
|
|
|
|
|
2021-02-04 17:28:55 +01:00
|
|
|
const effect = ActiveEffect.create(createData, this.item);
|
2020-12-23 16:52:20 +01:00
|
|
|
return effect.create({});
|
|
|
|
}
|
|
|
|
}
|