Changed ItemLinksField makeup

This commit is contained in:
WBHarry 2025-07-23 14:50:24 +02:00
parent 600c08cb23
commit 30f31e77dd
13 changed files with 120 additions and 96 deletions

View file

@ -20,14 +20,14 @@ export default class DHAncestry extends BaseDataItem {
}
get primaryFeature() {
return this.features.find(
x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.itemLinkFeatureTypes.primary
return this.features.find(x =>
x.system.itemLinks[CONFIG.DH.ITEM.itemLinkFeatureTypes.primary]?.has(this.parent.uuid)
);
}
get secondaryFeature() {
return this.features.find(
x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.itemLinkFeatureTypes.secondary
return this.features.find(x =>
x.system.itemLinks[CONFIG.DH.ITEM.itemLinkFeatureTypes.secondary]?.has(this.parent.uuid)
);
}
}

View file

@ -171,18 +171,18 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
);
}
if (this.metadata.isItemLinkable) {
const linkEntries = Object.entries(this.itemLinks);
for (let [uuid, type] of linkEntries) {
const item = await foundry.utils.fromUuid(uuid);
const path = CONFIG.DH.ITEM.itemLinkFeatureTypes[type] ? 'system.features' : 'system.linkedItems';
await item.update({
[path]: foundry.utils
.getProperty(item, path)
.filter(x => x.uuid !== this.parent.uuid)
.map(x => x.uuid)
});
}
}
// if (this.metadata.isItemLinkable) {
// const linkEntries = Object.entries(this.itemLinks);
// for (let [uuid, type] of linkEntries) {
// const item = await foundry.utils.fromUuid(uuid);
// const path = CONFIG.DH.ITEM.itemLinkFeatureTypes[type] ? 'system.features' : 'system.linkedItems';
// await item.update({
// [path]: foundry.utils
// .getProperty(item, path)
// .filter(x => x.uuid !== this.parent.uuid)
// .map(x => x.uuid)
// });
// }
// }
}
}

View file

@ -1,5 +1,4 @@
import BaseDataItem from './base.mjs';
import ForeignDocumentUUIDField from '../fields/foreignDocumentUUIDField.mjs';
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
export default class DHClass extends BaseDataItem {
@ -29,7 +28,7 @@ export default class DHClass extends BaseDataItem {
evasion: new fields.NumberField({ initial: 0, integer: true, label: 'DAGGERHEART.GENERAL.evasion' }),
features: new ForeignDocumentUUIDArrayField({ type: 'Item' }),
linkedItems: new ForeignDocumentUUIDArrayField({ type: 'Item' }),
subclasses: new ForeignDocumentUUIDArrayField({ type: 'Item', required: false }),
subclasses: new ForeignDocumentUUIDArrayField({ type: 'Item' }),
characterGuide: new fields.SchemaField({
suggestedTraits: new fields.SchemaField({
agility: new fields.NumberField({ initial: 0, integer: true }),
@ -45,46 +44,50 @@ export default class DHClass extends BaseDataItem {
}
get hopeFeatures() {
return this.features.filter(
x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.itemLinkFeatureTypes.hope
return this.features.filter(x =>
x.system.itemLinks[CONFIG.DH.ITEM.itemLinkFeatureTypes.hope]?.has(this.parent.uuid)
);
}
get classFeatures() {
return this.features.filter(
x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.itemLinkFeatureTypes.class
return this.features.filter(x =>
x.system.itemLinks[CONFIG.DH.ITEM.itemLinkFeatureTypes.class]?.has(this.parent.uuid)
);
}
get suggestedPrimaryWeapon() {
return this.linkedItems.find(
x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.itemLinkTypes.primaryWeapon
return this.linkedItems.find(x =>
x.system.itemLinks[CONFIG.DH.ITEM.itemLinkItemTypes.primaryWeapon]?.has(this.parent.uuid)
);
}
get suggestedSecondaryWeapon() {
return this.linkedItems.find(
x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.itemLinkTypes.secondaryWeapon
return this.linkedItems.find(x =>
x.system.itemLinks[CONFIG.DH.ITEM.itemLinkItemTypes.secondaryWeapon]?.has(this.parent.uuid)
);
}
get suggestedArmor() {
return this.linkedItems.find(x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.itemLinkTypes.armor);
return this.linkedItems.find(x =>
x.system.itemLinks[CONFIG.DH.ITEM.itemLinkItemTypes.armor]?.has(this.parent.uuid)
);
}
get take() {
return this.linkedItems.filter(x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.itemLinkTypes.take);
return this.linkedItems.filter(x =>
x.system.itemLinks[CONFIG.DH.ITEM.itemLinkItemTypes.take]?.has(this.parent.uuid)
);
}
get choiceA() {
return this.linkedItems.filter(
x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.itemLinkTypes.choiceA
return this.linkedItems.filter(x =>
x.system.itemLinks[CONFIG.DH.ITEM.itemLinkItemTypes.choiceA]?.has(this.parent.uuid)
);
}
get choiceB() {
return this.linkedItems.filter(
x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.itemLinkTypes.choiceB
return this.linkedItems.filter(x =>
x.system.itemLinks[CONFIG.DH.ITEM.itemLinkItemTypes.choiceB]?.has(this.parent.uuid)
);
}

View file

@ -30,20 +30,20 @@ export default class DHSubclass extends BaseDataItem {
}
get foundationFeatures() {
return this.features.filter(
x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.itemLinkFeatureTypes.foundation
return this.features.filter(x =>
x.system.itemLinks[CONFIG.DH.ITEM.itemLinkFeatureTypes.foundation]?.has(this.parent.uuid)
);
}
get specializationFeatures() {
return this.features.filter(
x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.itemLinkFeatureTypes.specialization
return this.features.filter(x =>
x.system.itemLinks[CONFIG.DH.ITEM.itemLinkFeatureTypes.specialization]?.has(this.parent.uuid)
);
}
get masteryFeatures() {
return this.features.filter(
x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.itemLinkFeatureTypes.mastery
return this.features.filter(x =>
x.system.itemLinks[CONFIG.DH.ITEM.itemLinkFeatureTypes.mastery]?.has(this.parent.uuid)
);
}