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
|
const secondaryAncestryFeature = this.setup.secondaryAncestry?.uuid
|
||||||
? this.setup.secondaryAncestry.system.secondaryFeature
|
? this.setup.secondaryAncestry.system.secondaryFeature
|
||||||
: this.setup.primaryAncestry.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 = {
|
const ancestry = {
|
||||||
...this.setup.primaryAncestry,
|
...this.setup.primaryAncestry,
|
||||||
|
|
|
||||||
|
|
@ -229,7 +229,7 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
|
||||||
if (featureItem) {
|
if (featureItem) {
|
||||||
const feature = this.document.system.features.find(x => x?.id === featureItem.id);
|
const feature = this.document.system.features.find(x => x?.id === featureItem.id);
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,13 +30,13 @@ export default class AncestrySheet extends DHHeritageSheet {
|
||||||
static async #addFeature(_event, button) {
|
static async #addFeature(_event, button) {
|
||||||
const feature = await game.items.documentClass.create({
|
const feature = await game.items.documentClass.create({
|
||||||
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') }),
|
||||||
|
system: {
|
||||||
|
primary: button.dataset.type === 'primary'
|
||||||
|
}
|
||||||
});
|
});
|
||||||
await this.document.update({
|
await this.document.update({
|
||||||
system: {
|
'system.features': [...this.document.system.features.map(x => x.uuid), feature.uuid]
|
||||||
features: [...this.document.system.features.map(x => x.uuid), feature.uuid],
|
|
||||||
[`${button.dataset.type}Feature`]: feature.uuid
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,7 +47,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[`${target.dataset.type}Feature`];
|
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'));
|
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.featureIsMissing'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -63,8 +63,9 @@ export default class AncestrySheet extends DHHeritageSheet {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
const target = button.closest('.feature-item');
|
const target = button.closest('.feature-item');
|
||||||
const feature = this.document.system[`${target.dataset.type}Feature`];
|
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({
|
const confirmed = await foundry.applications.api.DialogV2.confirm({
|
||||||
window: {
|
window: {
|
||||||
title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', {
|
title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', {
|
||||||
|
|
@ -77,11 +78,9 @@ export default class AncestrySheet extends DHHeritageSheet {
|
||||||
if (!confirmed) return;
|
if (!confirmed) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (featureExists && target.dataset.type === 'primary') await feature.update({ 'system.primary': null });
|
||||||
await this.document.update({
|
await this.document.update({
|
||||||
system: {
|
'system.features': this.document.system.features.filter(x => x && x.uuid !== feature.uuid).map(x => x.uuid)
|
||||||
features: this.document.system.features.filter(x => x.uuid !== feature.uuid).map(x => x.uuid),
|
|
||||||
[`${target.dataset.type}Feature`]: null
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,19 +100,13 @@ 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') {
|
||||||
const update = {
|
|
||||||
system: {
|
|
||||||
features: [...this.document.system.features.map(x => x.uuid), item.uuid]
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (event.target.closest('.primary-feature')) {
|
if (event.target.closest('.primary-feature')) {
|
||||||
update.system.primaryFeature = item.uuid;
|
await item.update({ 'system.primary': true });
|
||||||
} else if (event.target.closest('.secondary-feature')) {
|
|
||||||
update.system.secondaryFeature = item.uuid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 actionPath = this.getActionPath(button.dataset.type);
|
||||||
const feature = this.document.system[actionPath].find(x => x?.id === target.dataset.featureId);
|
const feature = this.document.system[actionPath].find(x => x?.id === target.dataset.featureId);
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ export default class SubclassSheet extends DHBaseItemSheet {
|
||||||
static async editFeature(_, button) {
|
static async editFeature(_, button) {
|
||||||
const feature = this.document.system[button.dataset.type];
|
const feature = this.document.system[button.dataset.type];
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -71,7 +71,7 @@ export default class SubclassSheet extends DHBaseItemSheet {
|
||||||
if (featureItem) {
|
if (featureItem) {
|
||||||
const feature = this.document.system[featureItem.dataset.type];
|
const feature = this.document.system[featureItem.dataset.type];
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
|
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
|
||||||
import ForeignDocumentUUIDField from '../fields/foreignDocumentUUIDField.mjs';
|
|
||||||
import BaseDataItem from './base.mjs';
|
import BaseDataItem from './base.mjs';
|
||||||
|
|
||||||
export default class DHAncestry extends BaseDataItem {
|
export default class DHAncestry extends BaseDataItem {
|
||||||
|
|
@ -16,9 +15,15 @@ export default class DHAncestry extends BaseDataItem {
|
||||||
static defineSchema() {
|
static defineSchema() {
|
||||||
return {
|
return {
|
||||||
...super.defineSchema(),
|
...super.defineSchema(),
|
||||||
features: new ForeignDocumentUUIDArrayField({ type: 'Item' }),
|
features: new ForeignDocumentUUIDArrayField({ type: 'Item' })
|
||||||
primaryFeature: new ForeignDocumentUUIDField({ type: 'Item' }),
|
|
||||||
secondaryFeature: new ForeignDocumentUUIDField({ 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 }),
|
type: new fields.StringField({ choices: CONFIG.DH.ITEM.featureTypes, nullable: true, initial: null }),
|
||||||
originId: new fields.StringField({ nullable: true, initial: null }),
|
originId: new fields.StringField({ nullable: true, initial: null }),
|
||||||
identifier: new fields.StringField(),
|
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