Feature(Item) now has subtype instead of primary as a field

This commit is contained in:
WBHarry 2025-07-11 14:18:19 +02:00
parent e9967a27ca
commit e2ca4506cd
5 changed files with 28 additions and 10 deletions

View file

@ -32,7 +32,7 @@ export default class AncestrySheet extends DHHeritageSheet {
type: 'feature',
name: game.i18n.format('DOCUMENT.New', { type: game.i18n.localize('TYPES.Item.feature') }),
system: {
primary: button.dataset.type === 'primary'
subType: button.dataset.type
}
});
await this.document.update({
@ -100,9 +100,8 @@ export default class AncestrySheet extends DHHeritageSheet {
const item = await fromUuid(data.uuid);
if (item?.type === 'feature') {
if (event.target.closest('.primary-feature')) {
await item.update({ 'system.primary': true });
}
const subType = event.target.closest('.primary-feature') ? 'primary' : 'secondary';
await item.update({ 'system.subType': subType });
await this.document.update({
'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid]

View file

@ -1320,6 +1320,11 @@ export const featureTypes = {
}
};
export const featureSubTypes = {
primary: 'primary',
secondary: 'secondary'
};
export const actionTypes = {
passive: {
id: 'passive',

View file

@ -20,10 +20,18 @@ export default class DHAncestry extends BaseDataItem {
}
get primaryFeature() {
return this.features.find(x => x?.system?.primary) ?? (this.features.length > 0 ? {} : null);
return (
this.features.find(x => x?.system?.subType === CONFIG.DH.ITEM.featureSubTypes.primary) ??
(this.features.filter(x => !x).length > 0 ? {} : null)
);
}
get secondaryFeature() {
return this.features.find(x => !x?.system?.primary);
return (
this.features.find(x => x?.system?.subType === CONFIG.DH.ITEM.featureSubTypes.secondary) ??
(this.features.filter(x => !x || x.system.subType === CONFIG.DH.ITEM.featureSubTypes.primary).length > 1
? {}
: null)
);
}
}

View file

@ -17,10 +17,10 @@ export default class DHFeature extends BaseDataItem {
return {
...super.defineSchema(),
type: new fields.StringField({ choices: CONFIG.DH.ITEM.featureTypes, nullable: true, initial: null }),
subType: new fields.StringField({ choices: CONFIG.DH.ITEM.featureSubTypes, nullable: true, initial: null }),
originId: new fields.StringField({ nullable: true, initial: null }),
identifier: new fields.StringField(),
actions: new fields.ArrayField(new ActionField()),
primary: new fields.BooleanField({ nullable: true, initial: null })
actions: new fields.ArrayField(new ActionField())
};
}
}

View file

@ -4,7 +4,10 @@
data-group='{{tabs.features.group}}'
>
<fieldset class="one-column drop-section primary-feature">
<legend>{{localize "DAGGERHEART.ITEMS.Ancestry.primaryFeature"}} <a><i data-action="addFeature" data-type="primary" class="fa-solid fa-plus icon-button"></i></a></legend>
<legend>
{{localize "DAGGERHEART.ITEMS.Ancestry.primaryFeature"}}
{{#unless document.system.primaryFeature}}<a><i data-action="addFeature" data-type="primary" class="fa-solid fa-plus icon-button"></i></a>{{/unless}}
</legend>
<div class="features-list">
{{#if document.system.primaryFeature}}
<div class="feature-item"
@ -22,7 +25,10 @@
</fieldset>
<fieldset class="one-column drop-section secondary-feature">
<legend>{{localize "DAGGERHEART.ITEMS.Ancestry.secondaryFeature"}} <a><i data-action="addFeature" data-type="secondary" class="fa-solid fa-plus icon-button"></i></a></legend>
<legend>
{{localize "DAGGERHEART.ITEMS.Ancestry.secondaryFeature"}}
{{#unless document.system.secondaryFeature}}<a><i data-action="addFeature" data-type="secondary" class="fa-solid fa-plus icon-button"></i></a>{{/unless}}
</legend>
<div class="features-list">
{{#if document.system.secondaryFeature}}
<div class="feature-item"