Add a customizable weight formatter function
This commit is contained in:
parent
6e2dfa1cf1
commit
44372d0a17
3 changed files with 23 additions and 7 deletions
|
|
@ -1,9 +1,9 @@
|
||||||
import { __ID__, filePath } from "../consts.mjs";
|
import { __ID__, filePath } from "../consts.mjs";
|
||||||
import { AttributeManager } from "./AttributeManager.mjs";
|
import { AttributeManager } from "./AttributeManager.mjs";
|
||||||
import { attributeSorter } from "../utils/attributeSort.mjs";
|
import { attributeSorter } from "../utils/attributeSort.mjs";
|
||||||
|
import { config } from "../config.mjs";
|
||||||
import { TAFDocumentSheetConfig } from "./TAFDocumentSheetConfig.mjs";
|
import { TAFDocumentSheetConfig } from "./TAFDocumentSheetConfig.mjs";
|
||||||
import { TAFDocumentSheetMixin } from "./mixins/TAFDocumentSheetMixin.mjs";
|
import { TAFDocumentSheetMixin } from "./mixins/TAFDocumentSheetMixin.mjs";
|
||||||
import { toPrecision } from "../utils/roundToPrecision.mjs";
|
|
||||||
|
|
||||||
const { HandlebarsApplicationMixin } = foundry.applications.api;
|
const { HandlebarsApplicationMixin } = foundry.applications.api;
|
||||||
const { ActorSheetV2 } = foundry.applications.sheets;
|
const { ActorSheetV2 } = foundry.applications.sheets;
|
||||||
|
|
@ -220,7 +220,6 @@ export class PlayerSheet extends
|
||||||
async _prepareItems(ctx) {
|
async _prepareItems(ctx) {
|
||||||
ctx.tabActive = this.tabGroups.primary === `items`;
|
ctx.tabActive = this.tabGroups.primary === `items`;
|
||||||
|
|
||||||
const weightUnit = game.settings.get(__ID__, `weightUnit`);
|
|
||||||
let totalWeight = 0;
|
let totalWeight = 0;
|
||||||
|
|
||||||
ctx.itemGroups = [];
|
ctx.itemGroups = [];
|
||||||
|
|
@ -237,24 +236,22 @@ export class PlayerSheet extends
|
||||||
ctx.itemGroups.push({
|
ctx.itemGroups.push({
|
||||||
name: groupName.titleCase(),
|
name: groupName.titleCase(),
|
||||||
items: preparedItems,
|
items: preparedItems,
|
||||||
weight: toPrecision(summedWeight, 2) + weightUnit,
|
weight: config.weightFormatter(totalWeight),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
totalWeight = toPrecision(totalWeight, 2);
|
ctx.totalWeight = config.weightFormatter(totalWeight);
|
||||||
ctx.totalWeight = totalWeight + weightUnit;
|
|
||||||
ctx.carryCapacityPercent = Math.round(totalWeight / this.actor.system.carryCapacity * 100);
|
ctx.carryCapacityPercent = Math.round(totalWeight / this.actor.system.carryCapacity * 100);
|
||||||
};
|
};
|
||||||
|
|
||||||
async _prepareItem(item) {
|
async _prepareItem(item) {
|
||||||
const weightUnit = game.settings.get(__ID__, `weightUnit`);
|
|
||||||
const ctx = {
|
const ctx = {
|
||||||
uuid: item.uuid,
|
uuid: item.uuid,
|
||||||
img: item.img,
|
img: item.img,
|
||||||
name: item.name,
|
name: item.name,
|
||||||
equipped: item.system.equipped,
|
equipped: item.system.equipped,
|
||||||
quantity: item.system.quantity,
|
quantity: item.system.quantity,
|
||||||
weight: item.system.quantifiedWeight + weightUnit,
|
weight: config.weightFormatter(item.system.quantifiedWeight),
|
||||||
isExpanded: this.#expandedItems.has(item.uuid),
|
isExpanded: this.#expandedItems.has(item.uuid),
|
||||||
canExpand: item.system.description.length > 0,
|
canExpand: item.system.description.length > 0,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
7
module/config.mjs
Normal file
7
module/config.mjs
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
import { formatWeight } from "./utils/formatWeight.mjs";
|
||||||
|
|
||||||
|
const { deepSeal } = foundry.utils;
|
||||||
|
|
||||||
|
export const config = CONFIG.TAF = deepSeal({
|
||||||
|
weightFormatter: formatWeight,
|
||||||
|
});
|
||||||
12
module/utils/formatWeight.mjs
Normal file
12
module/utils/formatWeight.mjs
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
import { __ID__ } from "../consts.mjs";
|
||||||
|
import { toPrecision } from "./roundToPrecision.mjs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats a numerical value as a weight.
|
||||||
|
*
|
||||||
|
* @param {number} weight The numerical weight to format
|
||||||
|
*/
|
||||||
|
export function formatWeight(weight) {
|
||||||
|
const unit = game.settings.get(__ID__, `weightUnit`);
|
||||||
|
return toPrecision(weight, 2) + unit;
|
||||||
|
};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue