mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-04-23 07:53:39 +02:00
Improved
This commit is contained in:
parent
28efef7951
commit
9cdfd7a27a
11 changed files with 151 additions and 69 deletions
|
|
@ -21,7 +21,8 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
|||
hasDescription: false,
|
||||
hasResource: false,
|
||||
isQuantifiable: false,
|
||||
isInventoryItem: false
|
||||
isInventoryItem: false,
|
||||
possibleItemLink: false
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -69,6 +70,20 @@ 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.possibleItemLink) {
|
||||
schema.originItemType = new fields.StringField({
|
||||
choices: CONFIG.DH.ITEM.featureTypes,
|
||||
nullable: true,
|
||||
initial: null
|
||||
});
|
||||
schema.originId = new fields.StringField({ nullable: true, initial: null });
|
||||
schema.subType = new fields.StringField({
|
||||
choices: CONFIG.DH.ITEM.featureSubTypes,
|
||||
nullable: true,
|
||||
initial: null
|
||||
});
|
||||
}
|
||||
|
||||
return schema;
|
||||
}
|
||||
|
||||
|
|
@ -137,22 +152,43 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
|||
|
||||
async _preDelete() {
|
||||
if (this.originId) {
|
||||
if (this.actor && this.actor.type === 'character') {
|
||||
const items = this.actor.items.filter(item => item.system.originId === this.parent.id);
|
||||
if (items.length > 0)
|
||||
await this.actor.deleteEmbeddedDocuments(
|
||||
'Item',
|
||||
items.map(x => x.id)
|
||||
);
|
||||
} else {
|
||||
const linkedItem = await foundry.utils.fromUuid(this.originId);
|
||||
if (linkedItem) {
|
||||
await linkedItem.update({
|
||||
'system.features': linkedItem.system.features
|
||||
.filter(x => x.uuid !== this.parent.uuid)
|
||||
.map(x => x.uuid)
|
||||
});
|
||||
if (this.parent.type === 'feature') {
|
||||
if (this.actor && this.actor.type === 'character') {
|
||||
const items = this.actor.items.filter(item => item.system.originId === this.parent.id);
|
||||
if (items.length > 0)
|
||||
await this.actor.deleteEmbeddedDocuments(
|
||||
'Item',
|
||||
items.map(x => x.id)
|
||||
);
|
||||
} else {
|
||||
const linkedItem = await foundry.utils.fromUuid(this.originId);
|
||||
if (linkedItem) {
|
||||
await linkedItem.update({
|
||||
'system.features': linkedItem.system.features
|
||||
.filter(x => x.uuid !== this.parent.uuid)
|
||||
.map(x => x.uuid)
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if (this.parent.type === 'subclass') {
|
||||
const linkedItem = await foundry.utils.fromUuid(this.originId);
|
||||
await linkedItem.update({
|
||||
'system.subclasses': linkedItem.system.subclasses
|
||||
.filter(x => x.uuid !== this.parent.uuid)
|
||||
.map(x => x.uuid)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (this.features?.length) {
|
||||
for (var feature of this.features) {
|
||||
await feature.update({
|
||||
system: {
|
||||
originItemType: null,
|
||||
originId: null,
|
||||
subType: null
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,6 +86,18 @@ export default class DHClass extends BaseDataItem {
|
|||
}
|
||||
}
|
||||
|
||||
async _preDelete() {
|
||||
for (var subclass of this.subclasses) {
|
||||
await subclass.update({
|
||||
system: {
|
||||
originItemType: null,
|
||||
originId: null,
|
||||
subType: null
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_onDelete(options, userId) {
|
||||
super._onDelete(options, userId);
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@ export default class DHFeature extends BaseDataItem {
|
|||
label: 'TYPES.Item.feature',
|
||||
type: 'feature',
|
||||
hasDescription: true,
|
||||
hasResource: true
|
||||
hasResource: true,
|
||||
possibleItemLink: true
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -17,13 +18,6 @@ export default class DHFeature extends BaseDataItem {
|
|||
const fields = foundry.data.fields;
|
||||
return {
|
||||
...super.defineSchema(),
|
||||
originItemType: new fields.StringField({
|
||||
choices: CONFIG.DH.ITEM.featureTypes,
|
||||
nullable: true,
|
||||
initial: null
|
||||
}),
|
||||
originId: new fields.StringField({ nullable: true, initial: null }),
|
||||
subType: new fields.StringField({ choices: CONFIG.DH.ITEM.featureSubTypes, nullable: true, initial: null }),
|
||||
actions: new fields.ArrayField(new ActionField())
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ export default class DHSubclass extends BaseDataItem {
|
|||
return foundry.utils.mergeObject(super.metadata, {
|
||||
label: 'TYPES.Item.subclass',
|
||||
type: 'subclass',
|
||||
hasDescription: true
|
||||
hasDescription: true,
|
||||
possibleItemLink: true
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue