Get started on the required infrastructure for the attributes tab

This commit is contained in:
Oliver 2026-04-23 17:46:40 -06:00
parent 2c915c82e8
commit f1499d1c3d
4 changed files with 79 additions and 64 deletions

View file

@ -97,6 +97,7 @@
"toggle-item-description": "Show/Hide Item Description",
"tab-names": {
"content": "Content",
"attributes": "Attributes",
"items": "Items"
}
},

View file

@ -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,

View file

@ -1,34 +0,0 @@
{{#if hasAttributes}}
<div class="attributes">
{{#each attrs as | attr |}}
<fieldset data-attribute="{{ attr.id }}">
<legend>
{{ attr.name }}
</legend>
<div class="attr-range">
<input
type="number"
class="attr-range__value"
name="{{attr.path}}.value"
value="{{attr.value}}"
aria-label="{{localize "taf.Apps.PlayerSheet.current-value"}}"
data-tooltip="@{{ attr.id }}{{#if attr.isRange}}.value{{/if}}"
>
{{#if attr.isRange}}
<span aria-hidden="true">/</span>
<input
type="number"
class="attr-range__max"
name="{{attr.path}}.max"
value="{{attr.max}}"
aria-label="{{localize "taf.Apps.PlayerSheet.max-value"}}"
data-tooltip="@{{ attr.id }}.max"
>
{{/if}}
</div>
</fieldset>
{{/each}}
</div>
{{else}}
<template />
{{/if}}

View file

@ -0,0 +1,51 @@
{{#if hasAttributes}}
<div class="attributes">
{{#each attrs as | attr |}}
<fieldset data-foreign-uuid="{{ attr.uuid }}">
<legend>
{{ attr.name }}
</legend>
<div class="attr-range">
{{#if attr.system.isRange }}
<input
type="number"
id="{{attr.uuid}}-value"
class="attr-range__value"
data-foreign-name="system.value"
value="{{attr.system.value}}"
min="{{attr.system.min}}"
max="{{attr.system.max}}"
aria-label="{{localize "taf.Apps.PlayerSheet.current-value"}}"
data-tooltip="@{{ attr.system.key }}.value"
>
<span aria-hidden="true">/</span>
<input
type="number"
id="{{attr.uuid}}-max"
class="attr-range__max"
data-foreign-name="system.max"
value="{{attr.system.max}}"
min="{{attr.system.min}}"
aria-label="{{localize "taf.Apps.PlayerSheet.max-value"}}"
data-tooltip="@{{ attr.system.key }}.max"
>
{{else}}
<input
type="number"
id="{{attr.uuid}}-value"
class="attr-range__value"
data-foreign-name="system.value"
value="{{attr.system.value}}"
min="{{attr.system.min}}"
max="{{attr.system.max}}"
aria-label="{{localize "taf.Apps.PlayerSheet.current-value"}}"
data-tooltip="@{{ attr.system.key }}"
>
{{/if}}
</div>
</fieldset>
{{/each}}
</div>
{{else}}
<template />
{{/if}}