Adding features on CharacterItems now adds them on the Character and relinks

This commit is contained in:
WBHarry 2025-07-31 18:47:22 +02:00
parent 3dc4daffc3
commit 682ffc04d7
4 changed files with 37 additions and 13 deletions

View file

@ -413,17 +413,29 @@ export default function DHApplicationMixin(Base) {
const { documentClass, type, inVault, disabled } = target.dataset; const { documentClass, type, inVault, disabled } = target.dataset;
const parentIsItem = this.document.documentName === 'Item'; const parentIsItem = this.document.documentName === 'Item';
const parent = const parent =
parentIsItem && documentClass === 'Item' this.document.parent?.type === 'character'
? this.document.parent
: parentIsItem && documentClass === 'Item'
? type === 'action' ? type === 'action'
? this.document.system ? this.document.system
: null : null
: this.document; : this.document;
let systemData = {};
if (parent?.type === 'character' && type === 'feature') {
systemData = {
originItemType: this.document.type,
originId: this.document.id,
identifier: this.document.system.isMulticlass ? 'multiclass' : null
};
}
const cls = const cls =
type === 'action' ? game.system.api.models.actions.actionsTypes.base : getDocumentClass(documentClass); type === 'action' ? game.system.api.models.actions.actionsTypes.base : getDocumentClass(documentClass);
const data = { const data = {
name: cls.defaultName({ type, parent }), name: cls.defaultName({ type, parent }),
type type,
system: systemData
}; };
if (inVault) data['system.inVault'] = true; if (inVault) data['system.inVault'] = true;
if (disabled) data.disabled = true; if (disabled) data.disabled = true;

View file

@ -150,10 +150,24 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
static async #addFeature(_, target) { static async #addFeature(_, target) {
const { type } = target.dataset; const { type } = target.dataset;
const cls = foundry.documents.Item.implementation; const cls = foundry.documents.Item.implementation;
const item = await cls.create({
let systemData = {};
if (this.document.parent?.type === 'character') {
systemData = {
originItemType: this.document.type,
originId: this.document.id,
identifier: this.document.system.isMulticlass ? 'multiclass' : null
};
}
const item = await cls.create(
{
type: 'feature', type: 'feature',
name: cls.defaultName({ type: 'feature' }) name: cls.defaultName({ type: 'feature' }),
}); system: systemData
},
{ parent: this.document.parent?.type === 'character' ? this.document.parent : undefined }
);
await this.document.update({ await this.document.update({
'system.features': [...this.document.system.features, { type, item }].map(x => ({ 'system.features': [...this.document.system.features, { type, item }].map(x => ({
...x, ...x,

View file

@ -134,8 +134,7 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
system: { system: {
originItemType: this.parent.type, originItemType: this.parent.type,
originId: data._id, originId: data._id,
identifier: this.isMulticlass ? 'multiclass' : null, identifier: this.isMulticlass ? 'multiclass' : null
subType: feature.item ? feature.type : undefined
} }
}, },
{ inplace: false } { inplace: false }

View file

@ -23,7 +23,6 @@ export default class DHFeature extends BaseDataItem {
nullable: true, nullable: true,
initial: null initial: null
}), }),
subType: new fields.StringField({ choices: CONFIG.DH.ITEM.featureSubTypes, 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()
}; };