mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
Revert "Changed so ancestry uses a single Features field"
This reverts commit 0bda6b5dbe.
This commit is contained in:
parent
0bda6b5dbe
commit
1febafd441
3 changed files with 31 additions and 46 deletions
|
|
@ -19,19 +19,6 @@ export default class AncestrySheet extends DHHeritageSheet {
|
|||
features: { template: 'systems/daggerheart/templates/sheets/items/ancestry/features.hbs' }
|
||||
};
|
||||
|
||||
async _preparePartContext(partId, context) {
|
||||
await super._preparePartContext(partId, context);
|
||||
|
||||
switch (partId) {
|
||||
case 'features':
|
||||
context.primaryFeature = this.document.system.features.find(x => x.primary)?.value;
|
||||
context.secondaryFeature = this.document.system.features.find(x => !x.primary)?.value;
|
||||
break;
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Application Clicks Actions */
|
||||
/* -------------------------------------------- */
|
||||
|
|
@ -45,13 +32,10 @@ export default class AncestrySheet extends DHHeritageSheet {
|
|||
type: 'feature',
|
||||
name: game.i18n.format('DOCUMENT.New', { type: game.i18n.localize('TYPES.Item.feature') })
|
||||
});
|
||||
|
||||
await this.document.update({
|
||||
system: {
|
||||
features: [
|
||||
...this.document.system.features.map(x => ({ ...x, value: x.value.uuid })),
|
||||
{ primary: button.dataset.type === 'primary', value: feature.uuid }
|
||||
]
|
||||
features: [...this.document.system.features.map(x => x.uuid), feature.uuid],
|
||||
[`${button.dataset.type}Feature`]: feature.uuid
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -62,9 +46,7 @@ export default class AncestrySheet extends DHHeritageSheet {
|
|||
*/
|
||||
static async #editFeature(_event, button) {
|
||||
const target = button.closest('.feature-item');
|
||||
const feature = this.document.system.features.find(x =>
|
||||
target.dataset.type === 'primary' ? x.primary : !x.primary
|
||||
)?.value;
|
||||
const feature = this.document.system[`${target.dataset.type}Feature`];
|
||||
if (!feature) {
|
||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.featureIsMissing'));
|
||||
return;
|
||||
|
|
@ -80,9 +62,7 @@ export default class AncestrySheet extends DHHeritageSheet {
|
|||
static async #removeFeature(event, button) {
|
||||
event.stopPropagation();
|
||||
const target = button.closest('.feature-item');
|
||||
const feature = this.document.system.features.find(x =>
|
||||
target.dataset.type === 'primary' ? x.primary : !x.primary
|
||||
)?.value;
|
||||
const feature = this.document.system[`${target.dataset.type}Feature`];
|
||||
|
||||
if (feature) {
|
||||
const confirmed = await foundry.applications.api.DialogV2.confirm({
|
||||
|
|
@ -98,9 +78,10 @@ export default class AncestrySheet extends DHHeritageSheet {
|
|||
}
|
||||
|
||||
await this.document.update({
|
||||
'system.features': this.document.system.features
|
||||
.filter(x => x.value.uuid !== feature.uuid)
|
||||
.map(x => ({ ...x, value: x.value.uuid }))
|
||||
system: {
|
||||
features: this.document.system.features.filter(x => x.uuid !== feature.uuid).map(x => x.uuid),
|
||||
[`${target.dataset.type}Feature`]: null
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -120,12 +101,19 @@ export default class AncestrySheet extends DHHeritageSheet {
|
|||
|
||||
const item = await fromUuid(data.uuid);
|
||||
if (item?.type === 'feature') {
|
||||
await this.document.update({
|
||||
'system.features': [
|
||||
...this.document.system.features.map(x => ({ ...x, value: x.value.uuid })),
|
||||
{ primary: Boolean(event.target.closest('.primary-feature')), value: item.uuid }
|
||||
]
|
||||
});
|
||||
const update = {
|
||||
system: {
|
||||
features: [...this.document.system.features.map(x => x.uuid), item.uuid]
|
||||
}
|
||||
};
|
||||
|
||||
if (event.target.closest('.primary-feature')) {
|
||||
update.system.primaryFeature = item.uuid;
|
||||
} else if (event.target.closest('.secondary-feature')) {
|
||||
update.system.secondaryFeature = item.uuid;
|
||||
}
|
||||
|
||||
await this.document.update(update);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
|
||||
import ForeignDocumentUUIDField from '../fields/foreignDocumentUUIDField.mjs';
|
||||
import BaseDataItem from './base.mjs';
|
||||
|
||||
|
|
@ -13,15 +14,11 @@ export default class DHAncestry extends BaseDataItem {
|
|||
|
||||
/** @inheritDoc */
|
||||
static defineSchema() {
|
||||
const fields = foundry.data.fields;
|
||||
return {
|
||||
...super.defineSchema(),
|
||||
features: new fields.ArrayField(
|
||||
new fields.SchemaField({
|
||||
primary: new fields.BooleanField(),
|
||||
value: new ForeignDocumentUUIDField({ type: 'Item' })
|
||||
})
|
||||
)
|
||||
features: new ForeignDocumentUUIDArrayField({ type: 'Item' }),
|
||||
primaryFeature: new ForeignDocumentUUIDField({ type: 'Item' }),
|
||||
secondaryFeature: new ForeignDocumentUUIDField({ type: 'Item' })
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
<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>
|
||||
<div class="features-list">
|
||||
{{#if primaryFeature}}
|
||||
{{#if document.system.primaryFeature}}
|
||||
<div class="feature-item"
|
||||
data-action="editFeature"
|
||||
data-type="primary"
|
||||
>
|
||||
<img class="image" src="{{primaryFeature.img}}" />
|
||||
<span>{{primaryFeature.name}}</span>
|
||||
<img class="image" src="{{document.system.primaryFeature.img}}" />
|
||||
<span>{{document.system.primaryFeature.name}}</span>
|
||||
<div class="controls">
|
||||
<a data-action="removeFeature" data-type="primary"><i class="fa-solid fa-trash"></i></a>
|
||||
</div>
|
||||
|
|
@ -24,13 +24,13 @@
|
|||
<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>
|
||||
<div class="features-list">
|
||||
{{#if secondaryFeature}}
|
||||
{{#if document.system.secondaryFeature}}
|
||||
<div class="feature-item"
|
||||
data-action="editFeature"
|
||||
data-type="secondary"
|
||||
>
|
||||
<img class="image" src="{{secondaryFeature.img}}" />
|
||||
<span>{{secondaryFeature.name}}</span>
|
||||
<img class="image" src="{{document.system.secondaryFeature.img}}" />
|
||||
<span>{{document.system.secondaryFeature.name}}</span>
|
||||
<div class="controls">
|
||||
<a data-action="removeFeature" data-type="secondary"><i class="fa-solid fa-trash"></i></a>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue