Add tooltips for attributes, traits, and combat values

This commit is contained in:
Johannes Loher 2021-02-16 23:23:18 +01:00
parent 38a3437267
commit 9104237261
6 changed files with 56 additions and 16 deletions

View file

@ -1,3 +1,4 @@
import { ModifiableMaybeData } from "../../common/common-data";
import { DS4 } from "../../config";
import { DS4Item } from "../../item/item";
import { DS4ItemData } from "../../item/item-data";
@ -50,7 +51,7 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Data<DS4Actor>> {
*/
async getData(): Promise<ActorSheet.Data<DS4Actor>> {
const data = {
...(await super.getData()),
...this._addTooltipsToData(await super.getData()),
// Add the localization config to the data:
config: DS4,
// Add the items explicitly sorted by type to the data:
@ -59,6 +60,26 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Data<DS4Actor>> {
return data;
}
protected _addTooltipsToData(data: ActorSheet.Data<DS4Actor>): ActorSheet.Data<DS4Actor> {
const valueGroups = [data.data.attributes, data.data.traits, data.data.combatValues];
valueGroups.forEach((valueGroup) => {
Object.values(valueGroup).forEach(
(attribute: ModifiableMaybeData<number | null> & { tooltip?: string }) => {
attribute.tooltip = this._getTooltipForValue(attribute);
},
);
});
return data;
}
protected _getTooltipForValue(value: ModifiableMaybeData<number | null>): string {
return `${value.base ?? 0} (${game.i18n.localize("DS4.TooltipBaseValue")}) + ${
value.mod ?? 0
} (${game.i18n.localize("DS4.TooltipModifier")}) ${game.i18n.localize("DS4.TooltipEffects")} ${
value.total ?? 0
}`;
}
/** @override */
activateListeners(html: JQuery): void {
super.activateListeners(html);