mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 07:36:26 +01:00
Changed so that Feature(Item) has a primary field
This commit is contained in:
parent
34ae1f56f6
commit
e9967a27ca
7 changed files with 29 additions and 32 deletions
|
|
@ -503,8 +503,6 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
|
|||
const secondaryAncestryFeature = this.setup.secondaryAncestry?.uuid
|
||||
? this.setup.secondaryAncestry.system.secondaryFeature
|
||||
: this.setup.primaryAncestry.system.secondaryFeature;
|
||||
// const primaryFeature = await this.character.createEmbeddedDocuments('Item', [primaryAncestryFeature]);
|
||||
// const secondaryFeature = await this.character.createEmbeddedDocuments('Item', [secondaryAncestryFeature]);
|
||||
|
||||
const ancestry = {
|
||||
...this.setup.primaryAncestry,
|
||||
|
|
|
|||
|
|
@ -229,7 +229,7 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
|
|||
if (featureItem) {
|
||||
const feature = this.document.system.features.find(x => x?.id === featureItem.id);
|
||||
if (!feature) {
|
||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.notifications.featureIsMissing'));
|
||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.featureIsMissing'));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,13 +30,13 @@ export default class AncestrySheet extends DHHeritageSheet {
|
|||
static async #addFeature(_event, button) {
|
||||
const feature = await game.items.documentClass.create({
|
||||
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') }),
|
||||
system: {
|
||||
primary: button.dataset.type === 'primary'
|
||||
}
|
||||
});
|
||||
await this.document.update({
|
||||
system: {
|
||||
features: [...this.document.system.features.map(x => x.uuid), feature.uuid],
|
||||
[`${button.dataset.type}Feature`]: feature.uuid
|
||||
}
|
||||
'system.features': [...this.document.system.features.map(x => x.uuid), feature.uuid]
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ export default class AncestrySheet extends DHHeritageSheet {
|
|||
static async #editFeature(_event, button) {
|
||||
const target = button.closest('.feature-item');
|
||||
const feature = this.document.system[`${target.dataset.type}Feature`];
|
||||
if (!feature) {
|
||||
if (!feature || Object.keys(feature).length === 0) {
|
||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.featureIsMissing'));
|
||||
return;
|
||||
}
|
||||
|
|
@ -63,8 +63,9 @@ export default class AncestrySheet extends DHHeritageSheet {
|
|||
event.stopPropagation();
|
||||
const target = button.closest('.feature-item');
|
||||
const feature = this.document.system[`${target.dataset.type}Feature`];
|
||||
const featureExists = feature && Object.keys(feature).length > 0;
|
||||
|
||||
if (feature) {
|
||||
if (featureExists) {
|
||||
const confirmed = await foundry.applications.api.DialogV2.confirm({
|
||||
window: {
|
||||
title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', {
|
||||
|
|
@ -77,11 +78,9 @@ export default class AncestrySheet extends DHHeritageSheet {
|
|||
if (!confirmed) return;
|
||||
}
|
||||
|
||||
if (featureExists && target.dataset.type === 'primary') await feature.update({ 'system.primary': null });
|
||||
await this.document.update({
|
||||
system: {
|
||||
features: this.document.system.features.filter(x => x.uuid !== feature.uuid).map(x => x.uuid),
|
||||
[`${target.dataset.type}Feature`]: null
|
||||
}
|
||||
'system.features': this.document.system.features.filter(x => x && x.uuid !== feature.uuid).map(x => x.uuid)
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -101,19 +100,13 @@ export default class AncestrySheet extends DHHeritageSheet {
|
|||
|
||||
const item = await fromUuid(data.uuid);
|
||||
if (item?.type === 'feature') {
|
||||
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 item.update({ 'system.primary': true });
|
||||
}
|
||||
|
||||
await this.document.update(update);
|
||||
await this.document.update({
|
||||
'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -190,7 +190,7 @@ export default class ClassSheet extends DHBaseItemSheet {
|
|||
const actionPath = this.getActionPath(button.dataset.type);
|
||||
const feature = this.document.system[actionPath].find(x => x?.id === target.dataset.featureId);
|
||||
if (!feature) {
|
||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.notifications.featureIsMissing'));
|
||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.featureIsMissing'));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ export default class SubclassSheet extends DHBaseItemSheet {
|
|||
static async editFeature(_, button) {
|
||||
const feature = this.document.system[button.dataset.type];
|
||||
if (!feature) {
|
||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.notifications.featureIsMissing'));
|
||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.featureIsMissing'));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ export default class SubclassSheet extends DHBaseItemSheet {
|
|||
if (featureItem) {
|
||||
const feature = this.document.system[featureItem.dataset.type];
|
||||
if (!feature) {
|
||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.notifications.featureIsMissing'));
|
||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.featureIsMissing'));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
|
||||
import ForeignDocumentUUIDField from '../fields/foreignDocumentUUIDField.mjs';
|
||||
import BaseDataItem from './base.mjs';
|
||||
|
||||
export default class DHAncestry extends BaseDataItem {
|
||||
|
|
@ -16,9 +15,15 @@ export default class DHAncestry extends BaseDataItem {
|
|||
static defineSchema() {
|
||||
return {
|
||||
...super.defineSchema(),
|
||||
features: new ForeignDocumentUUIDArrayField({ type: 'Item' }),
|
||||
primaryFeature: new ForeignDocumentUUIDField({ type: 'Item' }),
|
||||
secondaryFeature: new ForeignDocumentUUIDField({ type: 'Item' })
|
||||
features: new ForeignDocumentUUIDArrayField({ type: 'Item' })
|
||||
};
|
||||
}
|
||||
|
||||
get primaryFeature() {
|
||||
return this.features.find(x => x?.system?.primary) ?? (this.features.length > 0 ? {} : null);
|
||||
}
|
||||
|
||||
get secondaryFeature() {
|
||||
return this.features.find(x => !x?.system?.primary);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@ export default class DHFeature extends BaseDataItem {
|
|||
type: new fields.StringField({ choices: CONFIG.DH.ITEM.featureTypes, nullable: true, initial: null }),
|
||||
originId: new fields.StringField({ nullable: true, initial: null }),
|
||||
identifier: new fields.StringField(),
|
||||
actions: new fields.ArrayField(new ActionField())
|
||||
actions: new fields.ArrayField(new ActionField()),
|
||||
primary: new fields.BooleanField({ nullable: true, initial: null })
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue