[Fix] Itemlink Redux Revengeance (#399)

* Small random fixes

* Added use of ItemLinkFields

* Multiclass levelup fixes

* Fixed our onCreate methods unintentionally being run on all clients

* Remade apps handling

* Added for all class items and subclass

* Restored foreignDocumentUuidField

* Improved

* PR fxies

* Fixed tooltip enrichment

* .

* Reverted silly change
This commit is contained in:
WBHarry 2025-07-26 00:37:30 +02:00 committed by GitHub
parent fcba5041e9
commit 2a4777f1a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
61 changed files with 648 additions and 489 deletions

View file

@ -8,7 +8,8 @@
* @property {boolean} isInventoryItem- Indicates whether items of this type is a Inventory Item
*/
import { ActionsField } from "../fields/actionField.mjs";
import { addLinkedItemsDiff, updateLinkedItemApps } from '../../helpers/utils.mjs';
import { ActionsField } from '../fields/actionField.mjs';
const fields = foundry.data.fields;
@ -72,8 +73,7 @@ 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.hasActions)
schema.actions = new ActionsField()
if (this.metadata.hasActions) schema.actions = new ActionsField();
return schema;
}
@ -124,18 +124,21 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
}
}
_onCreate(data) {
_onCreate(data, _, userId) {
if (userId !== game.user.id) return;
if (!this.actor || this.actor.type !== 'character' || !this.features) return;
this.actor.createEmbeddedDocuments(
'Item',
this.features.map(feature => ({
...feature,
...(feature.item ?? feature),
system: {
...feature.system,
...(feature.item?.system ?? feature.system),
originItemType: this.parent.type,
originId: data._id,
identifier: feature.identifier
identifier: feature.identifier,
subType: feature.item ? feature.type : undefined
}
}))
);
@ -151,4 +154,17 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
items.map(x => x.id)
);
}
async _preUpdate(changed, options, userId) {
const allowed = await super._preUpdate(changed, options, userId);
if (allowed === false) return false;
addLinkedItemsDiff(changed.system?.features, this.features, options);
}
_onUpdate(changed, options, userId) {
super._onUpdate(changed, options, userId);
updateLinkedItemApps(options, this.parent.sheet);
}
}