mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 15:39:02 +01:00
Made it work again the bad way \._./
This commit is contained in:
parent
8ef3578b6f
commit
34ae1f56f6
4 changed files with 33 additions and 47 deletions
|
|
@ -50,7 +50,7 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
|
|||
static DEFAULT_OPTIONS = {
|
||||
tag: 'form',
|
||||
classes: ['daggerheart', 'dialog', 'dh-style', 'character-creation'],
|
||||
position: { width: 640, height: 'auto' },
|
||||
position: { width: 700, height: 'auto' },
|
||||
actions: {
|
||||
viewCompendium: this.viewCompendium,
|
||||
viewItem: this.viewItem,
|
||||
|
|
@ -511,6 +511,7 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
|
|||
name: this.setup.ancestryName ?? this.setup.primaryAncestry.name,
|
||||
system: {
|
||||
...this.setup.primaryAncestry.system,
|
||||
features: [primaryAncestryFeature.uuid, secondaryAncestryFeature.uuid],
|
||||
primaryFeature: primaryAncestryFeature.uuid,
|
||||
secondaryFeature: secondaryAncestryFeature.uuid
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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