mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-18 16:09:03 +01:00
Changed ItemLinksField makeup
This commit is contained in:
parent
600c08cb23
commit
30f31e77dd
13 changed files with 120 additions and 96 deletions
|
|
@ -4,15 +4,7 @@ export default class ItemLinksField extends foundry.data.fields.TypedObjectField
|
|||
* @param {DataFieldContext} [context] Additional context which describes the field
|
||||
*/
|
||||
constructor(options, context) {
|
||||
super(
|
||||
new foundry.data.fields.StringField({
|
||||
choices: CONFIG.DH.ITEM.itemLinkTypes,
|
||||
nullable: true,
|
||||
initial: null
|
||||
}),
|
||||
options,
|
||||
context
|
||||
);
|
||||
super(new foundry.data.fields.SetField(new foundry.data.fields.DocumentUUIDField()), options, context);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
|
|
@ -24,15 +16,6 @@ export default class ItemLinksField extends foundry.data.fields.TypedObjectField
|
|||
* @param {Object} [value] The candidate object to be added.
|
||||
*/
|
||||
static validateKey(value) {
|
||||
const parsed = foundry.utils.parseUuid(value);
|
||||
if (!parsed || parsed.type !== foundry.documents.Item.documentName) return false;
|
||||
if (!foundry.data.validators.isValidId(parsed.documentId)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**@inheritdoc */
|
||||
_cast(value) {
|
||||
value = super._cast(value);
|
||||
return foundry.utils.flattenObject(value);
|
||||
return Boolean(CONFIG.DH.ITEM.itemLinkTypes[value]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue