From f1499d1c3da100cdcc5f2e45a1aab7e49059653e Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 23 Apr 2026 17:46:40 -0600 Subject: [PATCH] Get started on the required infrastructure for the attributes tab --- langs/en-ca.json | 1 + module/apps/PlayerSheet.mjs | 57 ++++++++++---------- templates/PlayerSheet/attributes.hbs | 34 ------------ templates/PlayerSheet/primary-attributes.hbs | 51 ++++++++++++++++++ 4 files changed, 79 insertions(+), 64 deletions(-) delete mode 100644 templates/PlayerSheet/attributes.hbs create mode 100644 templates/PlayerSheet/primary-attributes.hbs diff --git a/langs/en-ca.json b/langs/en-ca.json index 552ca5f..b0418db 100644 --- a/langs/en-ca.json +++ b/langs/en-ca.json @@ -97,6 +97,7 @@ "toggle-item-description": "Show/Hide Item Description", "tab-names": { "content": "Content", + "attributes": "Attributes", "items": "Items" } }, diff --git a/module/apps/PlayerSheet.mjs b/module/apps/PlayerSheet.mjs index 2ae276d..9b55b93 100644 --- a/module/apps/PlayerSheet.mjs +++ b/module/apps/PlayerSheet.mjs @@ -45,9 +45,10 @@ export class PlayerSheet extends static PARTS = { header: { template: filePath(`templates/PlayerSheet/header.hbs`) }, - attributes: { template: filePath(`templates/PlayerSheet/attributes.hbs`) }, + primaryAttributes: { template: filePath(`templates/PlayerSheet/primary-attributes.hbs`) }, tabs: { template: filePath(`templates/generic/tabs.hbs`) }, content: { template: filePath(`templates/PlayerSheet/content.hbs`) }, + attributeTab: {}, items: { template: filePath(`templates/PlayerSheet/item-lists.hbs`), scrollable: [``], @@ -78,6 +79,7 @@ export class PlayerSheet extends labelPrefix: `taf.Apps.PlayerSheet.tab-names`, tabs: [ { id: `content` }, + { id: `attributes` }, { id: `items` }, ], }, @@ -104,6 +106,10 @@ export class PlayerSheet extends Logger.debug(`Asserting app "${this.id}" from tab "items" to "${initial}"`); this.tabGroups.primary = initial; }; + if (this.tabGroups.primary === `attributes` && !this.hasAttributesTab) { + Logger.debug(`Asserting app "${this.id}" from tab "attributes" to "${initial}"`); + this.tabGroups.primary = initial; + } }; /** @@ -118,6 +124,7 @@ export class PlayerSheet extends switch (tabID) { case `content`: return this.hasContentTab; case `items`: return this.hasItemsTab; + case `attributes`: return this.hasAttributesTab; }; return false; }; @@ -127,7 +134,8 @@ export class PlayerSheet extends }; get hasAttributesTab() { - return this.actor.itemTypes.attributes + return this.actor.itemTypes + .attribute .filter(attr => !attr.system.aboveTheFold) .length > 0; }; @@ -262,8 +270,12 @@ export class PlayerSheet extends async _preparePartContext(partID, ctx) { switch (partID) { - case `attributes`: { - await this._prepareAttributes(ctx); + case `primaryAttributes`: { + await this._preparePrimaryAttributes(ctx); + break; + }; + case `attributeTab`: { + await this._prepareAttributesTab(ctx); break; }; case `tabs`: { @@ -283,20 +295,15 @@ export class PlayerSheet extends return ctx; }; - async _prepareAttributes(ctx) { - ctx.hasAttributes = this.actor.system.hasAttributes; - - const attrs = []; - for (const [id, data] of Object.entries(this.actor.system.attr)) { - attrs.push({ - ...data, - id, - path: `system.attr.${id}`, - }); - }; - ctx.attrs = attrs.toSorted(attributeSorter); + async _preparePrimaryAttributes(ctx) { + const attrs = this.actor.itemTypes.attribute ?? []; + const filtered = attrs.filter(attr => attr.system.aboveTheFold); + ctx.hasAttributes = filtered.length > 0; + ctx.attrs = filtered; }; + async _prepareAttributesTab(ctx) {}; + async _prepareTabList(ctx) { ctx.tabs = await this._prepareTabs(`primary`); @@ -337,8 +344,9 @@ export class PlayerSheet extends let summedWeight = 0; for (const item of items) { - summedWeight += item.system.quantifiedWeight; - preparedItems.push(await this._prepareItem(item)); + summedWeight += item.system.quantifiedWeight ?? 0; + const data = await this._prepareItem(item); + if (data) preparedItems.push(data); }; totalWeight += summedWeight; @@ -355,18 +363,7 @@ export class PlayerSheet extends }; async _prepareItem(item) { - if (item.type !== "generic") { - return { - uuid: item.uuid, - img: item.img, - name: item.name, - equipped: false, - quantity: 0, - weight: 0, - isExpanded: false, - canExpand: false, - }; - } + if (item.type !== `generic`) { return }; const ctx = { uuid: item.uuid, img: item.img, diff --git a/templates/PlayerSheet/attributes.hbs b/templates/PlayerSheet/attributes.hbs deleted file mode 100644 index a2f0457..0000000 --- a/templates/PlayerSheet/attributes.hbs +++ /dev/null @@ -1,34 +0,0 @@ -{{#if hasAttributes}} -
- {{#each attrs as | attr |}} -
- - {{ attr.name }} - -
- - {{#if attr.isRange}} - - - {{/if}} -
-
- {{/each}} -
-{{else}} -