mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-19 00:19:03 +01:00
Initial
This commit is contained in:
parent
42a705a870
commit
f614456e86
10 changed files with 68 additions and 90 deletions
|
|
@ -1,3 +1,4 @@
|
|||
export { default as FormulaField } from './formulaField.mjs';
|
||||
export { default as ForeignDocumentUUIDField } from './foreignDocumentUUIDField.mjs';
|
||||
export { default as ForeignDocumentUUIDArrayField } from './foreignDocumentUUIDArrayField.mjs';
|
||||
export { default as ItemLinksField } from './itemLinksField.mjs';
|
||||
|
|
|
|||
32
module/data/fields/itemLinksField.mjs
Normal file
32
module/data/fields/itemLinksField.mjs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
export default class ItemLinksField extends foundry.data.fields.TypedObjectField {
|
||||
/**
|
||||
* @param {DataFieldOptions} [options] Options which configure the behavior of the field.
|
||||
* @param {DataFieldContext} [context] Additional context which describes the field
|
||||
*/
|
||||
constructor(options, context) {
|
||||
super(
|
||||
new foundry.data.fields.StringField({
|
||||
choices: CONFIG.DH.ITEM.featureSubTypes,
|
||||
nullable: true,
|
||||
initial: null
|
||||
}),
|
||||
options,
|
||||
context
|
||||
);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
static get _defaults() {
|
||||
return mergeObject(super._defaults, { validateKey: this.validateKey });
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} [value] The candidate object to be added.
|
||||
*/
|
||||
static validateKey(value) {
|
||||
return true;
|
||||
const parsed = foundry.utils.parseUuid(value);
|
||||
if (!parsed || parsed.type !== CONFIG.Item.documentClass.documentName) return false;
|
||||
if (!foundry.packages.BasePackage.validateId(parsed.documentId)) return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -20,18 +20,10 @@ export default class DHAncestry extends BaseDataItem {
|
|||
}
|
||||
|
||||
get primaryFeature() {
|
||||
return (
|
||||
this.features.find(x => x?.system?.subType === CONFIG.DH.ITEM.featureSubTypes.primary) ??
|
||||
(this.features.filter(x => !x).length > 0 ? {} : null)
|
||||
);
|
||||
return this.features.find(x => x.system.itemLinks[this.parent.id] === CONFIG.DH.ITEM.featureSubTypes.primary);
|
||||
}
|
||||
|
||||
get secondaryFeature() {
|
||||
return (
|
||||
this.features.find(x => x?.system?.subType === CONFIG.DH.ITEM.featureSubTypes.secondary) ??
|
||||
(this.features.filter(x => !x || x.system.subType === CONFIG.DH.ITEM.featureSubTypes.primary).length > 1
|
||||
? {}
|
||||
: null)
|
||||
);
|
||||
return this.features.find(x => x.system.itemLinks[this.parent.id] === CONFIG.DH.ITEM.featureSubTypes.secondary);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
* @property {boolean} isInventoryItem- Indicates whether items of this type is a Inventory Item
|
||||
*/
|
||||
|
||||
import ItemLinksField from '../fields/itemLinksField.mjs';
|
||||
|
||||
const fields = foundry.data.fields;
|
||||
|
||||
export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
||||
|
|
@ -21,7 +23,8 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
|||
hasDescription: false,
|
||||
hasResource: false,
|
||||
isQuantifiable: false,
|
||||
isInventoryItem: false
|
||||
isInventoryItem: false,
|
||||
isItemLinkable: true
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -69,6 +72,10 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
|||
if (this.metadata.isQuantifiable)
|
||||
schema.quantity = new fields.NumberField({ integer: true, initial: 1, min: 0, required: true });
|
||||
|
||||
if (this.metadata.isItemLinkable) {
|
||||
schema.itemLinks = new ItemLinksField();
|
||||
}
|
||||
|
||||
return schema;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@ export default class DHFeature extends BaseDataItem {
|
|||
label: 'TYPES.Item.feature',
|
||||
type: 'feature',
|
||||
hasDescription: true,
|
||||
hasResource: true
|
||||
hasResource: true,
|
||||
isItemLinkable: true
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue