Attribute Item Subtype #76
4 changed files with 79 additions and 64 deletions
|
|
@ -97,6 +97,7 @@
|
||||||
"toggle-item-description": "Show/Hide Item Description",
|
"toggle-item-description": "Show/Hide Item Description",
|
||||||
"tab-names": {
|
"tab-names": {
|
||||||
"content": "Content",
|
"content": "Content",
|
||||||
|
"attributes": "Attributes",
|
||||||
"items": "Items"
|
"items": "Items"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,10 @@ export class PlayerSheet extends
|
||||||
|
|
||||||
static PARTS = {
|
static PARTS = {
|
||||||
header: { template: filePath(`templates/PlayerSheet/header.hbs`) },
|
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`) },
|
tabs: { template: filePath(`templates/generic/tabs.hbs`) },
|
||||||
content: { template: filePath(`templates/PlayerSheet/content.hbs`) },
|
content: { template: filePath(`templates/PlayerSheet/content.hbs`) },
|
||||||
|
attributeTab: {},
|
||||||
items: {
|
items: {
|
||||||
template: filePath(`templates/PlayerSheet/item-lists.hbs`),
|
template: filePath(`templates/PlayerSheet/item-lists.hbs`),
|
||||||
scrollable: [``],
|
scrollable: [``],
|
||||||
|
|
@ -78,6 +79,7 @@ export class PlayerSheet extends
|
||||||
labelPrefix: `taf.Apps.PlayerSheet.tab-names`,
|
labelPrefix: `taf.Apps.PlayerSheet.tab-names`,
|
||||||
tabs: [
|
tabs: [
|
||||||
{ id: `content` },
|
{ id: `content` },
|
||||||
|
{ id: `attributes` },
|
||||||
{ id: `items` },
|
{ id: `items` },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
@ -104,6 +106,10 @@ export class PlayerSheet extends
|
||||||
Logger.debug(`Asserting app "${this.id}" from tab "items" to "${initial}"`);
|
Logger.debug(`Asserting app "${this.id}" from tab "items" to "${initial}"`);
|
||||||
this.tabGroups.primary = 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) {
|
switch (tabID) {
|
||||||
case `content`: return this.hasContentTab;
|
case `content`: return this.hasContentTab;
|
||||||
case `items`: return this.hasItemsTab;
|
case `items`: return this.hasItemsTab;
|
||||||
|
case `attributes`: return this.hasAttributesTab;
|
||||||
};
|
};
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
@ -127,7 +134,8 @@ export class PlayerSheet extends
|
||||||
};
|
};
|
||||||
|
|
||||||
get hasAttributesTab() {
|
get hasAttributesTab() {
|
||||||
return this.actor.itemTypes.attributes
|
return this.actor.itemTypes
|
||||||
|
.attribute
|
||||||
.filter(attr => !attr.system.aboveTheFold)
|
.filter(attr => !attr.system.aboveTheFold)
|
||||||
.length > 0;
|
.length > 0;
|
||||||
};
|
};
|
||||||
|
|
@ -262,8 +270,12 @@ export class PlayerSheet extends
|
||||||
|
|
||||||
async _preparePartContext(partID, ctx) {
|
async _preparePartContext(partID, ctx) {
|
||||||
switch (partID) {
|
switch (partID) {
|
||||||
case `attributes`: {
|
case `primaryAttributes`: {
|
||||||
await this._prepareAttributes(ctx);
|
await this._preparePrimaryAttributes(ctx);
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
case `attributeTab`: {
|
||||||
|
await this._prepareAttributesTab(ctx);
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
case `tabs`: {
|
case `tabs`: {
|
||||||
|
|
@ -283,20 +295,15 @@ export class PlayerSheet extends
|
||||||
return ctx;
|
return ctx;
|
||||||
};
|
};
|
||||||
|
|
||||||
async _prepareAttributes(ctx) {
|
async _preparePrimaryAttributes(ctx) {
|
||||||
ctx.hasAttributes = this.actor.system.hasAttributes;
|
const attrs = this.actor.itemTypes.attribute ?? [];
|
||||||
|
const filtered = attrs.filter(attr => attr.system.aboveTheFold);
|
||||||
const attrs = [];
|
ctx.hasAttributes = filtered.length > 0;
|
||||||
for (const [id, data] of Object.entries(this.actor.system.attr)) {
|
ctx.attrs = filtered;
|
||||||
attrs.push({
|
|
||||||
...data,
|
|
||||||
id,
|
|
||||||
path: `system.attr.${id}`,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
ctx.attrs = attrs.toSorted(attributeSorter);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async _prepareAttributesTab(ctx) {};
|
||||||
|
|
||||||
async _prepareTabList(ctx) {
|
async _prepareTabList(ctx) {
|
||||||
ctx.tabs = await this._prepareTabs(`primary`);
|
ctx.tabs = await this._prepareTabs(`primary`);
|
||||||
|
|
||||||
|
|
@ -337,8 +344,9 @@ export class PlayerSheet extends
|
||||||
|
|
||||||
let summedWeight = 0;
|
let summedWeight = 0;
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
summedWeight += item.system.quantifiedWeight;
|
summedWeight += item.system.quantifiedWeight ?? 0;
|
||||||
preparedItems.push(await this._prepareItem(item));
|
const data = await this._prepareItem(item);
|
||||||
|
if (data) preparedItems.push(data);
|
||||||
};
|
};
|
||||||
totalWeight += summedWeight;
|
totalWeight += summedWeight;
|
||||||
|
|
||||||
|
|
@ -355,18 +363,7 @@ export class PlayerSheet extends
|
||||||
};
|
};
|
||||||
|
|
||||||
async _prepareItem(item) {
|
async _prepareItem(item) {
|
||||||
if (item.type !== "generic") {
|
if (item.type !== `generic`) { return };
|
||||||
return {
|
|
||||||
uuid: item.uuid,
|
|
||||||
img: item.img,
|
|
||||||
name: item.name,
|
|
||||||
equipped: false,
|
|
||||||
quantity: 0,
|
|
||||||
weight: 0,
|
|
||||||
isExpanded: false,
|
|
||||||
canExpand: false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
const ctx = {
|
const ctx = {
|
||||||
uuid: item.uuid,
|
uuid: item.uuid,
|
||||||
img: item.img,
|
img: item.img,
|
||||||
|
|
|
||||||
|
|
@ -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}}
|
|
||||||
51
templates/PlayerSheet/primary-attributes.hbs
Normal file
51
templates/PlayerSheet/primary-attributes.hbs
Normal 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}}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue