Make AktorSheet#getData compile
This commit is contained in:
parent
d85d335799
commit
8a939e84a1
2 changed files with 49 additions and 44 deletions
|
@ -9,15 +9,14 @@ import { ModifiableDataBaseTotal } from "../../common/common-data";
|
||||||
import { DS4 } from "../../config";
|
import { DS4 } from "../../config";
|
||||||
import { getCanvas } from "../../helpers";
|
import { getCanvas } from "../../helpers";
|
||||||
import { DS4Item } from "../../item/item";
|
import { DS4Item } from "../../item/item";
|
||||||
import { getDS4Settings } from "../../settings";
|
import { DS4Settings, getDS4Settings } from "../../settings";
|
||||||
import notifications from "../../ui/notifications";
|
import notifications from "../../ui/notifications";
|
||||||
import { DS4Actor } from "../actor";
|
|
||||||
import { isCheck } from "../actor-data-properties";
|
import { isCheck } from "../actor-data-properties";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base Sheet class for all DS4 Actors
|
* The base Sheet class for all DS4 Actors
|
||||||
*/
|
*/
|
||||||
export class DS4ActorSheet extends ActorSheet<ActorSheet.Options> {
|
export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetData> {
|
||||||
/** @override */
|
/** @override */
|
||||||
static get defaultOptions(): ActorSheet.Options {
|
static get defaultOptions(): ActorSheet.Options {
|
||||||
// TODO: Improve
|
// TODO: Improve
|
||||||
|
@ -50,41 +49,41 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options> {
|
||||||
return `${basePath}/${this.actor.data.type}-sheet.hbs`;
|
return `${basePath}/${this.actor.data.type}-sheet.hbs`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * This method returns the data for the template of the actor sheet.
|
* This method returns the data for the template of the actor sheet.
|
||||||
// * It explicitly adds the items of the object sorted by type in the
|
* It explicitly adds the items of the object sorted by type in the
|
||||||
// * object itemsByType.
|
* object itemsByType.
|
||||||
// * @returns The data fed to the template of the actor sheet
|
* @returns The data fed to the template of the actor sheet
|
||||||
// */
|
*/
|
||||||
// async getData(): Promise<ActorSheet.Data<DS4Actor>> {
|
async getData(): Promise<DS4ActorSheetData> {
|
||||||
// const itemsByType = Object.fromEntries(
|
const itemsByType = Object.fromEntries(
|
||||||
// Object.entries(this.actor.itemTypes).map(([itemType, items]) => {
|
Object.entries(this.actor.itemTypes).map(([itemType, items]) => {
|
||||||
// return [itemType, items.map((item) => item.data).sort((a, b) => (a.sort || 0) - (b.sort || 0))];
|
return [itemType, items.map((item) => item.data).sort((a, b) => (a.sort || 0) - (b.sort || 0))];
|
||||||
// }),
|
}),
|
||||||
// );
|
);
|
||||||
// const data = {
|
const data = {
|
||||||
// ...this._addTooltipsToData(await super.getData()),
|
...this.addTooltipsToData(await super.getData()),
|
||||||
// // Add the localization config to the data:
|
// Add the localization config to the data:
|
||||||
// config: DS4,
|
config: DS4,
|
||||||
// // Add the items explicitly sorted by type to the data:
|
// Add the items explicitly sorted by type to the data:
|
||||||
// itemsByType,
|
itemsByType,
|
||||||
// settings: getDS4Settings(),
|
settings: getDS4Settings(),
|
||||||
// };
|
};
|
||||||
// return data;
|
return data;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// protected _addTooltipsToData(data: ActorSheet.Data<DS4Actor>): ActorSheet.Data<DS4Actor> {
|
protected addTooltipsToData(data: ActorSheet.Data): ActorSheet.Data {
|
||||||
// const valueGroups = [data.data.attributes, data.data.traits, data.data.combatValues];
|
const valueGroups = [data.data.data.attributes, data.data.data.traits, data.data.data.combatValues];
|
||||||
|
|
||||||
// valueGroups.forEach((valueGroup) => {
|
valueGroups.forEach((valueGroup) => {
|
||||||
// Object.values(valueGroup).forEach((attribute: ModifiableDataBaseTotal<number> & { tooltip?: string }) => {
|
Object.values(valueGroup).forEach((attribute: ModifiableDataBaseTotal<number> & { tooltip?: string }) => {
|
||||||
// attribute.tooltip = this._getTooltipForValue(attribute);
|
attribute.tooltip = this.getTooltipForValue(attribute);
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
// return data;
|
return data;
|
||||||
// }
|
}
|
||||||
|
|
||||||
protected _getTooltipForValue(value: ModifiableDataBaseTotal<number>): string {
|
protected getTooltipForValue(value: ModifiableDataBaseTotal<number>): string {
|
||||||
return `${value.base} (${game.i18n.localize("DS4.TooltipBaseValue")}) + ${value.mod} (${game.i18n.localize(
|
return `${value.base} (${game.i18n.localize("DS4.TooltipBaseValue")}) + ${value.mod} (${game.i18n.localize(
|
||||||
"DS4.TooltipModifier",
|
"DS4.TooltipModifier",
|
||||||
)}) ➞ ${game.i18n.localize("DS4.TooltipEffects")} ➞ ${value.total}`;
|
)}) ➞ ${game.i18n.localize("DS4.TooltipEffects")} ➞ ${value.total}`;
|
||||||
|
@ -98,7 +97,7 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options> {
|
||||||
if (!this.options.editable) return;
|
if (!this.options.editable) return;
|
||||||
|
|
||||||
// Add Inventory Item
|
// Add Inventory Item
|
||||||
html.find(".item-create").on("click", this._onItemCreate.bind(this));
|
html.find(".item-create").on("click", this.onItemCreate.bind(this));
|
||||||
|
|
||||||
// Update Inventory Item
|
// Update Inventory Item
|
||||||
html.find(".item-edit").on("click", (ev) => {
|
html.find(".item-edit").on("click", (ev) => {
|
||||||
|
@ -121,18 +120,18 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options> {
|
||||||
li.slideUp(200, () => this.render(false));
|
li.slideUp(200, () => this.render(false));
|
||||||
});
|
});
|
||||||
|
|
||||||
html.find(".item-change").on("change", this._onItemChange.bind(this));
|
html.find(".item-change").on("change", this.onItemChange.bind(this));
|
||||||
|
|
||||||
html.find(".rollable-item").on("click", this._onRollItem.bind(this));
|
html.find(".rollable-item").on("click", this.onRollItem.bind(this));
|
||||||
|
|
||||||
html.find(".rollable-check").on("click", this._onRollCheck.bind(this));
|
html.find(".rollable-check").on("click", this.onRollCheck.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle creating a new Owned Item for the actor using initial data defined in the HTML dataset
|
* Handle creating a new Owned Item for the actor using initial data defined in the HTML dataset
|
||||||
* @param event - The originating click event
|
* @param event - The originating click event
|
||||||
*/
|
*/
|
||||||
protected _onItemCreate(event: JQuery.ClickEvent): void {
|
protected onItemCreate(event: JQuery.ClickEvent): void {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const header = event.currentTarget;
|
const header = event.currentTarget;
|
||||||
|
|
||||||
|
@ -155,7 +154,7 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options> {
|
||||||
* Assumes the item property is given as the value of the HTML element property 'data-property'.
|
* Assumes the item property is given as the value of the HTML element property 'data-property'.
|
||||||
* @param ev - The originating change event
|
* @param ev - The originating change event
|
||||||
*/
|
*/
|
||||||
protected _onItemChange(ev: JQuery.ChangeEvent): void {
|
protected onItemChange(ev: JQuery.ChangeEvent): void {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
const el: HTMLFormElement = $(ev.currentTarget).get(0);
|
const el: HTMLFormElement = $(ev.currentTarget).get(0);
|
||||||
const id = $(ev.currentTarget).parents(".item").data("itemId");
|
const id = $(ev.currentTarget).parents(".item").data("itemId");
|
||||||
|
@ -236,7 +235,7 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options> {
|
||||||
* Handle clickable item rolls.
|
* Handle clickable item rolls.
|
||||||
* @param event - The originating click event
|
* @param event - The originating click event
|
||||||
*/
|
*/
|
||||||
protected _onRollItem(event: JQuery.ClickEvent): void {
|
protected onRollItem(event: JQuery.ClickEvent): void {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const id = $(event.currentTarget).parents(".item").data("itemId");
|
const id = $(event.currentTarget).parents(".item").data("itemId");
|
||||||
const item = this.actor.getEmbeddedDocument("Item", id, { strict: true }) as DS4Item; // TODO: improve in upstream types
|
const item = this.actor.getEmbeddedDocument("Item", id, { strict: true }) as DS4Item; // TODO: improve in upstream types
|
||||||
|
@ -247,7 +246,7 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options> {
|
||||||
* Handle clickable check rolls.
|
* Handle clickable check rolls.
|
||||||
* @param event - The originating click event
|
* @param event - The originating click event
|
||||||
*/
|
*/
|
||||||
protected _onRollCheck(event: JQuery.ClickEvent): void {
|
protected onRollCheck(event: JQuery.ClickEvent): void {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const check = event.currentTarget.dataset["check"];
|
const check = event.currentTarget.dataset["check"];
|
||||||
this.actor.rollCheck(check).catch((e) => notifications.error(e, { log: true }));
|
this.actor.rollCheck(check).catch((e) => notifications.error(e, { log: true }));
|
||||||
|
@ -291,3 +290,9 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options> {
|
||||||
return super._onDropItem(event, data);
|
return super._onDropItem(event, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface DS4ActorSheetData extends ActorSheet.Data<ActorSheet.Options> {
|
||||||
|
config: typeof DS4;
|
||||||
|
itemsByType: Record<string, foundry.data.ItemData[]>;
|
||||||
|
settings: DS4Settings;
|
||||||
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ export function registerSystemSettings(): void {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DS4Settings {
|
export interface DS4Settings {
|
||||||
systemMigrationVersion: number;
|
systemMigrationVersion: number;
|
||||||
useSlayingDiceForAutomatedChecks: boolean;
|
useSlayingDiceForAutomatedChecks: boolean;
|
||||||
showSlayerPoints: boolean;
|
showSlayerPoints: boolean;
|
||||||
|
|
Loading…
Reference in a new issue