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' }
|
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 */
|
/* Application Clicks Actions */
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
|
|
@ -45,13 +32,10 @@ export default class AncestrySheet extends DHHeritageSheet {
|
||||||
type: 'feature',
|
type: 'feature',
|
||||||
name: game.i18n.format('DOCUMENT.New', { type: game.i18n.localize('TYPES.Item.feature') })
|
name: game.i18n.format('DOCUMENT.New', { type: game.i18n.localize('TYPES.Item.feature') })
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.document.update({
|
await this.document.update({
|
||||||
system: {
|
system: {
|
||||||
features: [
|
features: [...this.document.system.features.map(x => x.uuid), feature.uuid],
|
||||||
...this.document.system.features.map(x => ({ ...x, value: x.value.uuid })),
|
[`${button.dataset.type}Feature`]: feature.uuid
|
||||||
{ primary: button.dataset.type === 'primary', value: feature.uuid }
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -62,9 +46,7 @@ export default class AncestrySheet extends DHHeritageSheet {
|
||||||
*/
|
*/
|
||||||
static async #editFeature(_event, button) {
|
static async #editFeature(_event, button) {
|
||||||
const target = button.closest('.feature-item');
|
const target = button.closest('.feature-item');
|
||||||
const feature = this.document.system.features.find(x =>
|
const feature = this.document.system[`${target.dataset.type}Feature`];
|
||||||
target.dataset.type === 'primary' ? x.primary : !x.primary
|
|
||||||
)?.value;
|
|
||||||
if (!feature) {
|
if (!feature) {
|
||||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.featureIsMissing'));
|
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.featureIsMissing'));
|
||||||
return;
|
return;
|
||||||
|
|
@ -80,9 +62,7 @@ export default class AncestrySheet extends DHHeritageSheet {
|
||||||
static async #removeFeature(event, button) {
|
static async #removeFeature(event, button) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
const target = button.closest('.feature-item');
|
const target = button.closest('.feature-item');
|
||||||
const feature = this.document.system.features.find(x =>
|
const feature = this.document.system[`${target.dataset.type}Feature`];
|
||||||
target.dataset.type === 'primary' ? x.primary : !x.primary
|
|
||||||
)?.value;
|
|
||||||
|
|
||||||
if (feature) {
|
if (feature) {
|
||||||
const confirmed = await foundry.applications.api.DialogV2.confirm({
|
const confirmed = await foundry.applications.api.DialogV2.confirm({
|
||||||
|
|
@ -98,9 +78,10 @@ export default class AncestrySheet extends DHHeritageSheet {
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.document.update({
|
await this.document.update({
|
||||||
'system.features': this.document.system.features
|
system: {
|
||||||
.filter(x => x.value.uuid !== feature.uuid)
|
features: this.document.system.features.filter(x => x.uuid !== feature.uuid).map(x => x.uuid),
|
||||||
.map(x => ({ ...x, value: x.value.uuid }))
|
[`${target.dataset.type}Feature`]: null
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,12 +101,19 @@ export default class AncestrySheet extends DHHeritageSheet {
|
||||||
|
|
||||||
const item = await fromUuid(data.uuid);
|
const item = await fromUuid(data.uuid);
|
||||||
if (item?.type === 'feature') {
|
if (item?.type === 'feature') {
|
||||||
await this.document.update({
|
const update = {
|
||||||
'system.features': [
|
system: {
|
||||||
...this.document.system.features.map(x => ({ ...x, value: x.value.uuid })),
|
features: [...this.document.system.features.map(x => x.uuid), item.uuid]
|
||||||
{ primary: Boolean(event.target.closest('.primary-feature')), value: 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 ForeignDocumentUUIDField from '../fields/foreignDocumentUUIDField.mjs';
|
||||||
import BaseDataItem from './base.mjs';
|
import BaseDataItem from './base.mjs';
|
||||||
|
|
||||||
|
|
@ -13,15 +14,11 @@ export default class DHAncestry extends BaseDataItem {
|
||||||
|
|
||||||
/** @inheritDoc */
|
/** @inheritDoc */
|
||||||
static defineSchema() {
|
static defineSchema() {
|
||||||
const fields = foundry.data.fields;
|
|
||||||
return {
|
return {
|
||||||
...super.defineSchema(),
|
...super.defineSchema(),
|
||||||
features: new fields.ArrayField(
|
features: new ForeignDocumentUUIDArrayField({ type: 'Item' }),
|
||||||
new fields.SchemaField({
|
primaryFeature: new ForeignDocumentUUIDField({ type: 'Item' }),
|
||||||
primary: new fields.BooleanField(),
|
secondaryFeature: new ForeignDocumentUUIDField({ type: 'Item' })
|
||||||
value: new ForeignDocumentUUIDField({ type: 'Item' })
|
|
||||||
})
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,13 @@
|
||||||
<fieldset class="one-column drop-section primary-feature">
|
<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"}} <a><i data-action="addFeature" data-type="primary" class="fa-solid fa-plus icon-button"></i></a></legend>
|
||||||
<div class="features-list">
|
<div class="features-list">
|
||||||
{{#if primaryFeature}}
|
{{#if document.system.primaryFeature}}
|
||||||
<div class="feature-item"
|
<div class="feature-item"
|
||||||
data-action="editFeature"
|
data-action="editFeature"
|
||||||
data-type="primary"
|
data-type="primary"
|
||||||
>
|
>
|
||||||
<img class="image" src="{{primaryFeature.img}}" />
|
<img class="image" src="{{document.system.primaryFeature.img}}" />
|
||||||
<span>{{primaryFeature.name}}</span>
|
<span>{{document.system.primaryFeature.name}}</span>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<a data-action="removeFeature" data-type="primary"><i class="fa-solid fa-trash"></i></a>
|
<a data-action="removeFeature" data-type="primary"><i class="fa-solid fa-trash"></i></a>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -24,13 +24,13 @@
|
||||||
<fieldset class="one-column drop-section secondary-feature">
|
<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"}} <a><i data-action="addFeature" data-type="secondary" class="fa-solid fa-plus icon-button"></i></a></legend>
|
||||||
<div class="features-list">
|
<div class="features-list">
|
||||||
{{#if secondaryFeature}}
|
{{#if document.system.secondaryFeature}}
|
||||||
<div class="feature-item"
|
<div class="feature-item"
|
||||||
data-action="editFeature"
|
data-action="editFeature"
|
||||||
data-type="secondary"
|
data-type="secondary"
|
||||||
>
|
>
|
||||||
<img class="image" src="{{secondaryFeature.img}}" />
|
<img class="image" src="{{document.system.secondaryFeature.img}}" />
|
||||||
<span>{{secondaryFeature.name}}</span>
|
<span>{{document.system.secondaryFeature.name}}</span>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<a data-action="removeFeature" data-type="secondary"><i class="fa-solid fa-trash"></i></a>
|
<a data-action="removeFeature" data-type="secondary"><i class="fa-solid fa-trash"></i></a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue