mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 23:49:02 +01:00
Adding features on CharacterItems now adds them on the Character and relinks
This commit is contained in:
parent
3dc4daffc3
commit
682ffc04d7
4 changed files with 37 additions and 13 deletions
|
|
@ -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'
|
||||||
? type === 'action'
|
? this.document.parent
|
||||||
? this.document.system
|
: parentIsItem && documentClass === 'Item'
|
||||||
: null
|
? type === 'action'
|
||||||
: this.document;
|
? this.document.system
|
||||||
|
: null
|
||||||
|
: 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;
|
||||||
|
|
|
||||||
|
|
@ -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({
|
|
||||||
type: 'feature',
|
let systemData = {};
|
||||||
name: cls.defaultName({ type: 'feature' })
|
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',
|
||||||
|
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,
|
||||||
|
|
|
||||||
|
|
@ -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 }
|
||||||
|
|
|
||||||
|
|
@ -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()
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue