refactor: convert to ECMAScript where necessary
Also drop @league-of-foundry-developers/foundry-vtt-types.
This commit is contained in:
parent
df4538f6ed
commit
6277e27056
69 changed files with 1077 additions and 1679 deletions
|
@ -3,21 +3,28 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
export class DS4ActiveEffectConfig extends ActiveEffectConfig {
|
||||
static override get defaultOptions(): DocumentSheetOptions {
|
||||
/** @override */
|
||||
static get defaultOptions() {
|
||||
return foundry.utils.mergeObject(super.defaultOptions, {
|
||||
template: "systems/ds4/templates/sheets/active-effect/active-effect-config.hbs",
|
||||
});
|
||||
}
|
||||
|
||||
override activateListeners(html: JQuery<HTMLElement>): void {
|
||||
/**
|
||||
* @override
|
||||
* @param {JQuery} html
|
||||
*/
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
const checkbox = html[0]?.querySelector<HTMLInputElement>(
|
||||
'input[name="flags.ds4.itemEffectConfig.applyToItems"]',
|
||||
);
|
||||
checkbox?.addEventListener("change", () => this.toggleItemEffectConfig(checkbox.checked));
|
||||
const checkbox = html[0]?.querySelector('input[name="flags.ds4.itemEffectConfig.applyToItems"]');
|
||||
checkbox?.addEventListener("change", () => this.#toggleItemEffectConfig(checkbox.checked));
|
||||
}
|
||||
|
||||
private toggleItemEffectConfig(active: boolean) {
|
||||
/**
|
||||
* Toggle the visibility of the item effect config section
|
||||
* @param {boolean} active The target state
|
||||
*/
|
||||
#toggleItemEffectConfig(active) {
|
||||
const elements = this.element[0]?.querySelectorAll(".ds4-item-effect-config");
|
||||
elements?.forEach((element) => {
|
||||
if (active) {
|
|
@ -13,15 +13,12 @@ import { notifications } from "../../ui/notifications";
|
|||
import { enforce, getCanvas, getGame } from "../../utils/utils";
|
||||
import { disableOverriddenFields } from "../sheet-helpers";
|
||||
|
||||
import type { ModifiableDataBaseTotal } from "../../documents/common/common-data";
|
||||
import type { DS4Settings } from "../../settings";
|
||||
import type { DS4Item } from "../../documents/item/item";
|
||||
|
||||
/**
|
||||
* The base sheet class for all {@link DS4Actor}s.
|
||||
*/
|
||||
export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetData> {
|
||||
static override get defaultOptions(): ActorSheet.Options {
|
||||
export class DS4ActorSheet extends ActorSheet {
|
||||
/** @override */
|
||||
static get defaultOptions() {
|
||||
return foundry.utils.mergeObject(super.defaultOptions, {
|
||||
classes: ["sheet", "ds4-actor-sheet"],
|
||||
height: 635,
|
||||
|
@ -36,13 +33,15 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
|
|||
});
|
||||
}
|
||||
|
||||
override get template(): string {
|
||||
/** @override */
|
||||
get template() {
|
||||
const basePath = "systems/ds4/templates/sheets/actor";
|
||||
if (!getGame().user?.isGM && this.actor.limited) return `${basePath}/limited-sheet.hbs`;
|
||||
return `${basePath}/${this.actor.data.type}-sheet.hbs`;
|
||||
}
|
||||
|
||||
override async getData(): Promise<DS4ActorSheetData> {
|
||||
/** @override */
|
||||
async getData(options) {
|
||||
const itemsByType = Object.fromEntries(
|
||||
Object.entries(this.actor.itemTypes).map(([itemType, items]) => {
|
||||
return [itemType, items.map((item) => item.data).sort((a, b) => (a.sort || 0) - (b.sort || 0))];
|
||||
|
@ -60,7 +59,7 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
|
|||
const enrichedEffects = await Promise.all(enrichedEffectPromises);
|
||||
|
||||
const data = {
|
||||
...this.addTooltipsToData(await super.getData()),
|
||||
...this.addTooltipsToData(await super.getData(options)),
|
||||
config: DS4,
|
||||
itemsByType,
|
||||
enrichedEffects,
|
||||
|
@ -71,12 +70,14 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
|
|||
|
||||
/**
|
||||
* Adds tooltips to the attributes, traits, and combatValues of the actor data of the given {@link ActorSheet.Data}.
|
||||
* @param {object} data
|
||||
* @protected
|
||||
*/
|
||||
protected addTooltipsToData(data: ActorSheet.Data): ActorSheet.Data {
|
||||
addTooltipsToData(data) {
|
||||
const valueGroups = [data.data.data.attributes, data.data.data.traits, data.data.data.combatValues];
|
||||
|
||||
valueGroups.forEach((valueGroup) => {
|
||||
Object.values(valueGroup).forEach((attribute: ModifiableDataBaseTotal<number> & { tooltip?: string }) => {
|
||||
Object.values(valueGroup).forEach((attribute) => {
|
||||
attribute.tooltip = this.getTooltipForValue(attribute);
|
||||
});
|
||||
});
|
||||
|
@ -85,8 +86,11 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
|
|||
|
||||
/**
|
||||
* Generates a tooltip for a given attribute, trait, or combatValue.
|
||||
* @param {import("../../documents/common/common-data").ModifiableDataBaseTotal<number>} value The value to get a tooltip for
|
||||
* @returns {string} The tooltip
|
||||
* @protected
|
||||
*/
|
||||
protected getTooltipForValue(value: ModifiableDataBaseTotal<number>): string {
|
||||
getTooltipForValue(value) {
|
||||
return `${value.base} (${getGame().i18n.localize("DS4.TooltipBaseValue")}) + ${
|
||||
value.mod
|
||||
} (${getGame().i18n.localize("DS4.TooltipModifier")}) ➞ ${getGame().i18n.localize("DS4.TooltipEffects")} ➞ ${
|
||||
|
@ -94,7 +98,11 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
|
|||
}`;
|
||||
}
|
||||
|
||||
override activateListeners(html: JQuery): void {
|
||||
/**
|
||||
* @param {JQuery} html
|
||||
* @override
|
||||
*/
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
if (!this.options.editable) return;
|
||||
|
@ -123,9 +131,10 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
|
|||
/**
|
||||
* Handles a click on an element of this sheet to control an embedded item of the actor corresponding to this sheet.
|
||||
*
|
||||
* @param event - The originating click event
|
||||
* @param {JQuery.ClickEvent} event The originating click event
|
||||
* @protected
|
||||
*/
|
||||
protected onControlItem(event: JQuery.ClickEvent): void {
|
||||
onControlItem(event) {
|
||||
event.preventDefault();
|
||||
const a = event.currentTarget;
|
||||
switch (a.dataset["action"]) {
|
||||
|
@ -141,9 +150,10 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
|
|||
/**
|
||||
* Creates a new embedded item using the initial data defined in the HTML dataset of the clicked element.
|
||||
*
|
||||
* @param event - The originating click event
|
||||
* @param {JQuery.ClickEvent} event The originating click event
|
||||
* @protected
|
||||
*/
|
||||
protected onCreateItem(event: JQuery.ClickEvent): void {
|
||||
onCreateItem(event) {
|
||||
const { type, ...data } = foundry.utils.deepClone(event.currentTarget.dataset);
|
||||
const name = getGame().i18n.localize(`DS4.New${type.capitalize()}Name`);
|
||||
const itemData = {
|
||||
|
@ -157,9 +167,10 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
|
|||
/**
|
||||
* Opens the sheet of the embedded item corresponding to the clicked element.
|
||||
*
|
||||
* @param event - The originating click event
|
||||
* @param {JQuery.ClickEvent} event The originating click event
|
||||
* @protected
|
||||
*/
|
||||
protected onEditItem(event: JQuery.ClickEvent): void {
|
||||
onEditItem(event) {
|
||||
const id = $(event.currentTarget)
|
||||
.parents(embeddedDocumentListEntryProperties.Item.selector)
|
||||
.data(embeddedDocumentListEntryProperties.Item.idDataAttribute);
|
||||
|
@ -172,9 +183,10 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
|
|||
/**
|
||||
* Deletes the embedded item corresponding to the clicked element.
|
||||
*
|
||||
* @param event - The originating click event
|
||||
* @param {JQuery.ClickEvent} event The originating click event
|
||||
* @protected
|
||||
*/
|
||||
protected onDeleteItem(event: JQuery.ClickEvent): void {
|
||||
onDeleteItem(event) {
|
||||
const li = $(event.currentTarget).parents(embeddedDocumentListEntryProperties.Item.selector);
|
||||
this.actor.deleteEmbeddedDocuments("Item", [li.data(embeddedDocumentListEntryProperties.Item.idDataAttribute)]);
|
||||
li.slideUp(200, () => this.render(false));
|
||||
|
@ -184,9 +196,10 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
|
|||
* Applies a change to a property of an embedded item depending on the `data-property` attribute of the
|
||||
* {@link HTMLInputElement} that has been changed and its new value.
|
||||
*
|
||||
* @param event - The originating change event
|
||||
* @param {JQuery.ClickEvent} event The originating click event
|
||||
* @protected
|
||||
*/
|
||||
protected onChangeItem(event: JQuery.ChangeEvent): void {
|
||||
onChangeItem(event) {
|
||||
return this.onChangeEmbeddedDocument(event, "Item");
|
||||
}
|
||||
|
||||
|
@ -194,9 +207,10 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
|
|||
* Handles a click on an element of this sheet to control an embedded effect of the actor corresponding to this
|
||||
* sheet.
|
||||
*
|
||||
* @param event - The originating click event
|
||||
* @param {JQuery.ClickEvent} event The originating click event
|
||||
* @protected
|
||||
*/
|
||||
protected onControlEffect(event: JQuery.ClickEvent): void {
|
||||
onControlEffect(event) {
|
||||
event.preventDefault();
|
||||
const a = event.currentTarget;
|
||||
switch (a.dataset["action"]) {
|
||||
|
@ -212,18 +226,20 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
|
|||
/**
|
||||
* Creates a new embedded effect.
|
||||
*
|
||||
* @param event - The originating click event
|
||||
* @param {JQuery.ClickEvent} event The originating click event
|
||||
* @protected
|
||||
*/
|
||||
protected onCreateEffect(): void {
|
||||
onCreateEffect() {
|
||||
DS4ActiveEffect.createDefault(this.actor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the sheet of the embedded effect corresponding to the clicked element.
|
||||
*
|
||||
* @param event - The originating click event
|
||||
* @param {JQuery.ClickEvent} event The originating click event
|
||||
* @protected
|
||||
*/
|
||||
protected onEditEffect(event: JQuery.ClickEvent): void {
|
||||
onEditEffect(event) {
|
||||
const id = $(event.currentTarget)
|
||||
.parents(embeddedDocumentListEntryProperties.ActiveEffect.selector)
|
||||
.data(embeddedDocumentListEntryProperties.ActiveEffect.idDataAttribute);
|
||||
|
@ -235,9 +251,10 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
|
|||
/**
|
||||
* Deletes the embedded item corresponding to the clicked element.
|
||||
*
|
||||
* @param event - The originating click event
|
||||
* @param {JQuery.ClickEvent} event The originating click event
|
||||
* @protected
|
||||
*/
|
||||
protected onDeleteEffect(event: JQuery.ClickEvent): void {
|
||||
onDeleteEffect(event) {
|
||||
const li = $(event.currentTarget).parents(embeddedDocumentListEntryProperties.ActiveEffect.selector);
|
||||
const id = li.data(embeddedDocumentListEntryProperties.ActiveEffect.idDataAttribute);
|
||||
this.actor.deleteEmbeddedDocuments("ActiveEffect", [id]);
|
||||
|
@ -248,9 +265,10 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
|
|||
* Applies a change to a property of an embedded effect depending on the `data-property` attribute of the
|
||||
* {@link HTMLInputElement} that has been changed and its new value.
|
||||
*
|
||||
* @param event - The originating change event
|
||||
* @param {JQuery.ClickEvent} event The originating click event
|
||||
* @protected
|
||||
*/
|
||||
protected onChangeEffect(event: JQuery.ChangeEvent): void {
|
||||
onChangeEffect(event) {
|
||||
return this.onChangeEmbeddedDocument(event, "ActiveEffect");
|
||||
}
|
||||
|
||||
|
@ -258,10 +276,11 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
|
|||
* Applies a change to a property of an embedded document of the actor belonging to this sheet. The change depends
|
||||
* on the `data-property` attribute of the {@link HTMLInputElement} that has been changed and its new value.
|
||||
*
|
||||
* @param event - The originating change event
|
||||
* @param documentName - The name of the embedded document to be changed.
|
||||
* @param {JQuery.ChangeEvent} event The originating click event
|
||||
* @param {"Item" | "ActiveEffect"} documentName The name of the embedded document to be changed.
|
||||
* @protected
|
||||
*/
|
||||
protected onChangeEmbeddedDocument(event: JQuery.ChangeEvent, documentName: "Item" | "ActiveEffect"): void {
|
||||
onChangeEmbeddedDocument(event, documentName) {
|
||||
event.preventDefault();
|
||||
const element = $(event.currentTarget).get(0);
|
||||
enforce(element instanceof HTMLInputElement);
|
||||
|
@ -284,17 +303,19 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
|
|||
* - text input: `string`
|
||||
* - number: `number`
|
||||
*
|
||||
* @param element - The input element to parse the value from
|
||||
* @param {HTMLInputElement} element The input element to parse the value from
|
||||
* @returns {boolean | string | number} The parsed data
|
||||
* @protected
|
||||
*/
|
||||
protected parseValue(element: HTMLInputElement): boolean | string | number {
|
||||
parseValue(element) {
|
||||
switch (element.type) {
|
||||
case "checkbox": {
|
||||
const inverted = Boolean(element.dataset["inverted"]);
|
||||
const value: boolean = element.checked;
|
||||
const value = element.checked;
|
||||
return inverted ? !value : value;
|
||||
}
|
||||
case "text": {
|
||||
const value: string = element.value;
|
||||
const value = element.value;
|
||||
return value;
|
||||
}
|
||||
case "number": {
|
||||
|
@ -311,9 +332,10 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
|
|||
|
||||
/**
|
||||
* Handle clickable item rolls.
|
||||
* @param event - The originating click event
|
||||
* @param {JQuery.ClickEvent} event The originating click event
|
||||
* @protected
|
||||
*/
|
||||
protected onRollItem(event: JQuery.ClickEvent): void {
|
||||
onRollItem(event) {
|
||||
event.preventDefault();
|
||||
const id = $(event.currentTarget)
|
||||
.parents(embeddedDocumentListEntryProperties.Item.selector)
|
||||
|
@ -325,17 +347,22 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
|
|||
|
||||
/**
|
||||
* Handle clickable check rolls.
|
||||
* @param event - The originating click event
|
||||
* @param {JQuery.ClickEvent} event The originating click event
|
||||
* @protected
|
||||
*/
|
||||
protected onRollCheck(event: JQuery.ClickEvent): void {
|
||||
onRollCheck(event) {
|
||||
event.preventDefault();
|
||||
event.currentTarget.blur();
|
||||
const check = event.currentTarget.dataset["check"];
|
||||
this.actor.rollCheck(check).catch((e) => notifications.error(e, { log: true }));
|
||||
}
|
||||
|
||||
override _onDragStart(event: DragEvent): void {
|
||||
const target = event.currentTarget as HTMLElement;
|
||||
/**
|
||||
* @param {DragEvent} event
|
||||
* @override
|
||||
*/
|
||||
_onDragStart(event) {
|
||||
const target = event.currentTarget;
|
||||
if (!(target instanceof HTMLElement)) return super._onDragStart(event);
|
||||
|
||||
const check = target.dataset.check;
|
||||
|
@ -356,9 +383,10 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
|
|||
|
||||
/**
|
||||
* Sort items according to the item list header that has been clicked.
|
||||
* @param event - The originating click event
|
||||
* @param {JQuery.ClickEvent} event The originating click event
|
||||
* @protected
|
||||
*/
|
||||
protected onSortItems(event: JQuery.ClickEvent<unknown, unknown, HTMLElement>): void {
|
||||
onSortItems(event) {
|
||||
event.preventDefault();
|
||||
const target = event.currentTarget;
|
||||
const type = target.parentElement?.dataset["type"];
|
||||
|
@ -369,26 +397,28 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
|
|||
const items = this.actor.items.filter((item) => item.type === type);
|
||||
items.sort((a, b) => a.data.sort - b.data.sort);
|
||||
|
||||
const sortFunction =
|
||||
(invert: boolean) =>
|
||||
(a: DS4Item, b: DS4Item): number => {
|
||||
/**
|
||||
* @param {boolean} invert Whether or not to inverse the sort order
|
||||
* @returns {(a: import("../../documents/item/item").DS4Item, b: import("../../documents/item/item").DS4Item) => number} A function for sorting items
|
||||
*/
|
||||
const sortFunction = (invert) => (a, b) => {
|
||||
const propertyA = getProperty(a.data, dataPath);
|
||||
const propertyB = getProperty(b.data, dataPath);
|
||||
const comparison =
|
||||
typeof propertyA === "string" || typeof propertyB === "string"
|
||||
? compareAsStrings(propertyA, propertyB, invert)
|
||||
: compareAsNumbers(propertyA, propertyB, invert);
|
||||
|
||||
if (comparison === 0 && dataPath2 !== undefined) {
|
||||
const propertyA = getProperty(a.data, dataPath);
|
||||
const propertyB = getProperty(b.data, dataPath);
|
||||
const comparison =
|
||||
typeof propertyA === "string" || typeof propertyB === "string"
|
||||
? compareAsStrings(propertyA, propertyB, invert)
|
||||
: compareAsNumbers(propertyA, propertyB, invert);
|
||||
return typeof propertyA === "string" || typeof propertyB === "string"
|
||||
? compareAsStrings(propertyA, propertyB, invert)
|
||||
: compareAsNumbers(propertyA, propertyB, invert);
|
||||
}
|
||||
|
||||
if (comparison === 0 && dataPath2 !== undefined) {
|
||||
const propertyA = getProperty(a.data, dataPath);
|
||||
const propertyB = getProperty(b.data, dataPath);
|
||||
return typeof propertyA === "string" || typeof propertyB === "string"
|
||||
? compareAsStrings(propertyA, propertyB, invert)
|
||||
: compareAsNumbers(propertyA, propertyB, invert);
|
||||
}
|
||||
|
||||
return comparison;
|
||||
};
|
||||
return comparison;
|
||||
};
|
||||
|
||||
const sortedItems = [...items].sort(sortFunction(false));
|
||||
const wasSortedAlready = !sortedItems.find((item, index) => item !== items[index]);
|
||||
|
@ -405,7 +435,12 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
|
|||
this.actor.updateEmbeddedDocuments("Item", updates);
|
||||
}
|
||||
|
||||
protected override async _onDropItem(event: DragEvent, data: ActorSheet.DropData.Item): Promise<unknown> {
|
||||
/**
|
||||
* @param {DragEvent} event
|
||||
* @param {object} data
|
||||
* @override
|
||||
*/
|
||||
async _onDropItem(event, data) {
|
||||
const item = await Item.fromDropData(data);
|
||||
if (item && !this.actor.canOwnItemType(item.data.type)) {
|
||||
notifications.warn(
|
||||
|
@ -422,19 +457,6 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
|
|||
}
|
||||
}
|
||||
|
||||
interface DS4ActorSheetData extends ActorSheet.Data {
|
||||
config: typeof DS4;
|
||||
itemsByType: Record<string, foundry.data.ItemData[]>;
|
||||
enrichedEffects: EnrichedActiveEffectDataSource[];
|
||||
settings: DS4Settings;
|
||||
}
|
||||
|
||||
type ActiveEffectDataSource = foundry.data.ActiveEffectData["_source"];
|
||||
|
||||
interface EnrichedActiveEffectDataSource extends ActiveEffectDataSource {
|
||||
sourceName: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* This object contains information about specific properties embedded document list entries for each different type.
|
||||
*/
|
||||
|
@ -449,10 +471,24 @@ const embeddedDocumentListEntryProperties = Object.freeze({
|
|||
},
|
||||
});
|
||||
|
||||
const compareAsStrings = (a: { toString(): string }, b: { toString(): string }, invert: boolean): number => {
|
||||
/**
|
||||
* Compare two stringifiables as strings.
|
||||
* @param {{ toString(): string }} a The thing to compare with
|
||||
* @param {{ toString(): string }} b The thing to compare
|
||||
* @param {boolean} invert Should the comparison be inverted?
|
||||
* @return {number} A number that indicates the result of the comparison
|
||||
*/
|
||||
const compareAsStrings = (a, b, invert) => {
|
||||
return invert ? b.toString().localeCompare(a.toString()) : a.toString().localeCompare(b.toString());
|
||||
};
|
||||
|
||||
const compareAsNumbers = (a: number, b: number, invert: boolean): number => {
|
||||
/**
|
||||
* Compare two number.
|
||||
* @param {number} a The number to compare with
|
||||
* @param {number} b The number to compare
|
||||
* @param {boolean} invert Should the comparison be inverted?
|
||||
* @return {number} A number that indicates the result of the comparison
|
||||
*/
|
||||
const compareAsNumbers = (a, b, invert) => {
|
||||
return invert ? b - a : a - b;
|
||||
};
|
|
@ -8,7 +8,7 @@ import { DS4ActorSheet } from "./base-sheet";
|
|||
* The Sheet class for DS4 Character Actors
|
||||
*/
|
||||
export class DS4CharacterActorSheet extends DS4ActorSheet {
|
||||
static override get defaultOptions(): ActorSheet.Options {
|
||||
static get defaultOptions() {
|
||||
return foundry.utils.mergeObject(super.defaultOptions, {
|
||||
classes: ["sheet", "ds4-actor-sheet", "ds4-character-sheet"],
|
||||
});
|
|
@ -8,7 +8,7 @@ import { DS4ActorSheet } from "./base-sheet";
|
|||
* The Sheet class for DS4 Creature Actors
|
||||
*/
|
||||
export class DS4CreatureActorSheet extends DS4ActorSheet {
|
||||
static override get defaultOptions(): ActorSheet.Options {
|
||||
static get defaultOptions() {
|
||||
return foundry.utils.mergeObject(super.defaultOptions, {
|
||||
classes: ["sheet", "ds4-actor-sheet", "ds4-creature-sheet"],
|
||||
});
|
|
@ -2,18 +2,20 @@
|
|||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/**
|
||||
* @typedef {DialogOptions} DialogWithListenersOptions
|
||||
* @property {(html: JQuery, app: DialogWithListeners) => void} [activateAdditionalListeners] An optional function to attach additional listeners to the dialog
|
||||
*/
|
||||
|
||||
/**
|
||||
* A simple extension to the {@link Dialog} class that allows attaching additional listeners.
|
||||
*/
|
||||
export class DialogWithListeners extends Dialog<DialogWithListenersOptions> {
|
||||
override activateListeners(html: JQuery): void {
|
||||
export class DialogWithListeners extends Dialog {
|
||||
/** @override */
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
if (this.options.activateAdditionalListeners !== undefined) {
|
||||
this.options.activateAdditionalListeners(html, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface DialogWithListenersOptions extends DialogOptions {
|
||||
activateAdditionalListeners?: ((html: JQuery, app: DialogWithListeners) => void) | undefined;
|
||||
}
|
|
@ -14,8 +14,9 @@ import { disableOverriddenFields } from "./sheet-helpers";
|
|||
/**
|
||||
* The Sheet class for DS4 Items
|
||||
*/
|
||||
export class DS4ItemSheet extends ItemSheet<ItemSheet.Options, DS4ItemSheetData> {
|
||||
static override get defaultOptions(): ItemSheet.Options {
|
||||
export class DS4ItemSheet extends ItemSheet {
|
||||
/** @override */
|
||||
static get defaultOptions() {
|
||||
return foundry.utils.mergeObject(super.defaultOptions, {
|
||||
classes: ["sheet", "ds4-item-sheet"],
|
||||
height: 400,
|
||||
|
@ -25,12 +26,14 @@ export class DS4ItemSheet extends ItemSheet<ItemSheet.Options, DS4ItemSheetData>
|
|||
});
|
||||
}
|
||||
|
||||
override get template(): string {
|
||||
/** @override */
|
||||
get template() {
|
||||
const basePath = "systems/ds4/templates/sheets/item";
|
||||
return `${basePath}/${this.item.data.type}-sheet.hbs`;
|
||||
}
|
||||
|
||||
override async getData(): Promise<DS4ItemSheetData> {
|
||||
/** @override */
|
||||
async getData() {
|
||||
const data = {
|
||||
...(await super.getData()),
|
||||
config: DS4,
|
||||
|
@ -41,7 +44,8 @@ export class DS4ItemSheet extends ItemSheet<ItemSheet.Options, DS4ItemSheetData>
|
|||
return data;
|
||||
}
|
||||
|
||||
override _getSubmitData(updateData = {}) {
|
||||
/** @override */
|
||||
_getSubmitData(updateData = {}) {
|
||||
const data = super._getSubmitData(updateData);
|
||||
// Prevent submitting overridden values
|
||||
const overrides = foundry.utils.flattenObject(this.item.overrides);
|
||||
|
@ -51,9 +55,8 @@ export class DS4ItemSheet extends ItemSheet<ItemSheet.Options, DS4ItemSheetData>
|
|||
return data;
|
||||
}
|
||||
|
||||
override setPosition(
|
||||
options: Partial<Application.Position> = {},
|
||||
): (Application.Position & { height: number }) | void {
|
||||
/** @override */
|
||||
setPosition(options = {}) {
|
||||
const position = super.setPosition(options);
|
||||
if (position) {
|
||||
const sheetBody = this.element.find(".sheet-body");
|
||||
|
@ -64,7 +67,11 @@ export class DS4ItemSheet extends ItemSheet<ItemSheet.Options, DS4ItemSheetData>
|
|||
return position;
|
||||
}
|
||||
|
||||
override activateListeners(html: JQuery): void {
|
||||
/**
|
||||
* @override
|
||||
* @param {JQuery} html
|
||||
*/
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
if (!this.options.editable) return;
|
||||
|
@ -78,9 +85,10 @@ export class DS4ItemSheet extends ItemSheet<ItemSheet.Options, DS4ItemSheetData>
|
|||
* Handles a click on an element of this sheet to control an embedded effect of the item corresponding to this
|
||||
* sheet.
|
||||
*
|
||||
* @param event - The originating click event
|
||||
* @param {JQuery.ClickEvent} event The originating click event
|
||||
* @protected
|
||||
*/
|
||||
protected onControlEffect(event: JQuery.ClickEvent): void {
|
||||
onControlEffect(event) {
|
||||
event.preventDefault();
|
||||
if (this.item.isOwned) {
|
||||
return notifications.warn(getGame().i18n.localize("DS4.WarningManageActiveEffectOnOwnedItem"));
|
||||
|
@ -98,17 +106,19 @@ export class DS4ItemSheet extends ItemSheet<ItemSheet.Options, DS4ItemSheetData>
|
|||
|
||||
/**
|
||||
* Creates a new embedded effect.
|
||||
* @protected
|
||||
*/
|
||||
protected onCreateEffect(): void {
|
||||
onCreateEffect() {
|
||||
DS4ActiveEffect.createDefault(this.item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the sheet of the embedded effect corresponding to the clicked element.
|
||||
*
|
||||
* @param event - The originating click event
|
||||
* @param {JQuery.ClickEvent} event The originating click event
|
||||
* @porotected
|
||||
*/
|
||||
protected onEditEffect(event: JQuery.ClickEvent): void {
|
||||
onEditEffect(event) {
|
||||
const id = $(event.currentTarget)
|
||||
.parents(embeddedDocumentListEntryProperties.ActiveEffect.selector)
|
||||
.data(embeddedDocumentListEntryProperties.ActiveEffect.idDataAttribute);
|
||||
|
@ -120,9 +130,10 @@ export class DS4ItemSheet extends ItemSheet<ItemSheet.Options, DS4ItemSheetData>
|
|||
/**
|
||||
* Deletes the embedded item corresponding to the clicked element.
|
||||
*
|
||||
* @param event - The originating click event
|
||||
* @param {JQuery.ClickEvent} event The originating click event
|
||||
* @protected
|
||||
*/
|
||||
protected onDeleteEffect(event: JQuery.ClickEvent): void {
|
||||
onDeleteEffect(event) {
|
||||
const li = $(event.currentTarget).parents(embeddedDocumentListEntryProperties.ActiveEffect.selector);
|
||||
const id = li.data(embeddedDocumentListEntryProperties.ActiveEffect.idDataAttribute);
|
||||
this.item.deleteEmbeddedDocuments("ActiveEffect", [id]);
|
||||
|
@ -130,13 +141,6 @@ export class DS4ItemSheet extends ItemSheet<ItemSheet.Options, DS4ItemSheetData>
|
|||
}
|
||||
}
|
||||
|
||||
interface DS4ItemSheetData extends ItemSheet.Data<ItemSheet.Options> {
|
||||
config: typeof DS4;
|
||||
isOwned: boolean;
|
||||
actor: DS4ItemSheet["item"]["actor"];
|
||||
isPhysical: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* This object contains information about specific properties embedded document list entries for each different type.
|
||||
*/
|
|
@ -4,11 +4,13 @@
|
|||
|
||||
import { getGame } from "../utils/utils";
|
||||
|
||||
export function disableOverriddenFields(
|
||||
form: HTMLElement | null,
|
||||
overrides: Record<string, unknown>,
|
||||
selector: (key: string) => string,
|
||||
): void {
|
||||
/**
|
||||
* Disable elements in the given form that match the selector returned for overridden properties.
|
||||
* @param {HTMLElement | null} form The form in which to disable fields
|
||||
* @param {Record<string, unknown>} overrides The set of overrides of the underlying document
|
||||
* @param {(key: string) => string} selector A function that generates a selector, based on a property key
|
||||
*/
|
||||
export function disableOverriddenFields(form, overrides, selector) {
|
||||
const inputs = ["INPUT", "SELECT", "TEXTAREA", "BUTTON"];
|
||||
const titleAddition = `(${getGame().i18n.localize("DS4.TooltipNotEditableDueToEffects")})`;
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue