mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 15:39:02 +01:00
Refactor features creations
This commit is contained in:
parent
a9a6e8b1d9
commit
e2b0c206d2
1 changed files with 10 additions and 36 deletions
|
|
@ -124,43 +124,17 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
|||
}
|
||||
|
||||
if (this.actor && this.actor.type === 'character' && this.features) {
|
||||
/* Actions won't get created during createEmbeddedDocuments because they need the parent to be the newly created feature.
|
||||
If this can be fixed somehow, we can just create all at the same time instead of one by one.
|
||||
*/
|
||||
for (let listFeature of this.features) {
|
||||
const feature = listFeature.item ?? listFeature;
|
||||
const [doc] = await this.actor.createEmbeddedDocuments('Item', [
|
||||
{
|
||||
...feature,
|
||||
effects: feature.effects.map(x => x.toObject()),
|
||||
system: {
|
||||
...feature.system,
|
||||
originItemType: this.parent.type,
|
||||
originId: data._id,
|
||||
identifier: feature.identifier,
|
||||
subType: feature.item ? feature.type : undefined
|
||||
}
|
||||
for (let f of this.features) {
|
||||
const feature = f.item ?? f;
|
||||
const createData = foundry.utils.mergeObject(feature.toObject(), {
|
||||
system: {
|
||||
originItemType: this.parent.type,
|
||||
originId: data._id,
|
||||
identifier: feature.identifier,
|
||||
subType: feature.item ? feature.type : undefined
|
||||
}
|
||||
]);
|
||||
|
||||
const actions = feature.system.actions.reduce((acc, oldAction) => {
|
||||
const cls = game.system.api.models.actions.actionsTypes[oldAction.type];
|
||||
const action = new cls(
|
||||
{
|
||||
...oldAction.toObject(),
|
||||
...cls.getSourceConfig(doc)
|
||||
},
|
||||
{
|
||||
parent: doc
|
||||
}
|
||||
);
|
||||
|
||||
acc[action.id] = action.toObject();
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
await doc.updateSource({ 'system.actions': actions });
|
||||
}, { inplace: false });
|
||||
await this.actor.createEmbeddedDocuments('Item', [createData]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue