From ab76d9e91de3cc14c2a7b46742e1208867078824 Mon Sep 17 00:00:00 2001 From: WBHarry <89362246+WBHarry@users.noreply.github.com> Date: Sat, 16 Aug 2025 01:56:17 +0200 Subject: [PATCH] [Fix] 940 Character Import (#962) * Changed Class/Multiclass to simple getters to avoid having to keep them up to date * Corrected variable --- module/data/actor/character.mjs | 34 +++++++++++++++++++++++---------- module/data/item/class.mjs | 15 --------------- module/data/item/feature.mjs | 8 +++----- module/data/item/subclass.mjs | 20 ------------------- 4 files changed, 27 insertions(+), 50 deletions(-) diff --git a/module/data/actor/character.mjs b/module/data/actor/character.mjs index 71b734cd..45dfcfc8 100644 --- a/module/data/actor/character.mjs +++ b/module/data/actor/character.mjs @@ -93,14 +93,6 @@ export default class DhCharacter extends BaseDataActor { faith: new fields.StringField({}) }) }), - class: new fields.SchemaField({ - value: new ForeignDocumentUUIDField({ type: 'Item', nullable: true }), - subclass: new ForeignDocumentUUIDField({ type: 'Item', nullable: true }) - }), - multiclass: new fields.SchemaField({ - value: new ForeignDocumentUUIDField({ type: 'Item', nullable: true }), - subclass: new ForeignDocumentUUIDField({ type: 'Item', nullable: true }) - }), attack: new ActionField({ initial: { name: 'Unarmed Attack', @@ -314,6 +306,26 @@ export default class DhCharacter extends BaseDataActor { return this.parent.items.find(x => x.type === 'community') ?? null; } + get class() { + const value = this.parent.items.find(x => x.type === 'class' && !x.system.isMulticlass); + const subclass = this.parent.items.find(x => x.type === 'subclass' && !x.system.isMulticlass); + + return { + value, + subclass + }; + } + + get multiclass() { + const value = this.parent.items.find(x => x.type === 'Class' && x.system.isMulticlass); + const subclass = this.parent.items.find(x => x.type === 'subclass' && x.system.isMulticlass); + + return { + value, + subclass + }; + } + get features() { return this.parent.items.filter(x => x.type === 'feature') ?? []; } @@ -323,7 +335,8 @@ export default class DhCharacter extends BaseDataActor { } get needsCharacterSetup() { - return !(this.class.value || this.class.subclass || this.ancestry || this.community); + const { value: classValue, subclass } = this.class; + return !(classValue || subclass || this.ancestry || this.community); } get spellcastModifierTrait() { @@ -347,7 +360,8 @@ export default class DhCharacter extends BaseDataActor { get domains() { const classDomains = this.class.value ? this.class.value.system.domains : []; - const multiclassDomains = this.multiclass.value ? this.multiclass.value.system.domains : []; + const multiclass = this.multiclass.value; + const multiclassDomains = multiclass ? multiclass.system.domains : []; return [...classDomains, ...multiclassDomains]; } diff --git a/module/data/item/class.mjs b/module/data/item/class.mjs index 45e8b4ab..5e92d2fc 100644 --- a/module/data/item/class.mjs +++ b/module/data/item/class.mjs @@ -102,26 +102,11 @@ export default class DHClass extends BaseDataItem { if (allowed === false) return; } - _onCreate(data, options, userId) { - super._onCreate(data, options, userId); - - if (userId !== game.user.id) return; - - if (options.parent?.type === 'character') { - const path = `system.${data.system.isMulticlass ? 'multiclass.value' : 'class.value'}`; - options.parent.update({ [path]: `${options.parent.uuid}.Item.${data._id}` }); - } - } - _onDelete(options, userId) { super._onDelete(options, userId); if (options.parent?.type === 'character') { const path = `system.${this.isMulticlass ? 'multiclass' : 'class'}`; - options.parent.update({ - [`${path}.value`]: null - }); - foundry.utils.getProperty(options.parent, `${path}.subclass`)?.delete(); } } diff --git a/module/data/item/feature.mjs b/module/data/item/feature.mjs index 1ca32660..13c1d149 100644 --- a/module/data/item/feature.mjs +++ b/module/data/item/feature.mjs @@ -42,11 +42,9 @@ export default class DHFeature extends BaseDataItem { traitValue = this.actor.system.traits[this.actor.items.get(this.originId).system.spellcastingTrait]?.value ?? 0; } else { - const subclass = - this.actor.system.multiclass.value?.id === this.originId - ? this.actor.system.multiclass.subclass - : this.actor.system.class.subclass; - traitValue = this.actor.system.traits[subclass.system.spellcastingTrait]?.value ?? 0; + const { value: multiclass, subclass } = this.actor.system.multiclass; + const selectedSubclass = multiclass?.id === this.originId ? subclass : this.actor.system.class.subclass; + traitValue = this.actor.system.traits[selectedSubclass.system.spellcastingTrait]?.value ?? 0; } } diff --git a/module/data/item/subclass.mjs b/module/data/item/subclass.mjs index 7ace8109..46b83753 100644 --- a/module/data/item/subclass.mjs +++ b/module/data/item/subclass.mjs @@ -88,24 +88,4 @@ export default class DHSubclass extends BaseDataItem { const allowed = await super._preCreate(data, options, user); if (allowed === false) return; } - - _onCreate(data, options, userId) { - super._onCreate(data, options, userId); - - if (userId !== game.user.id) return; - - if (options.parent?.type === 'character') { - const path = `system.${data.system.isMulticlass ? 'multiclass.subclass' : 'class.subclass'}`; - options.parent.update({ [path]: `${options.parent.uuid}.Item.${data._id}` }); - } - } - - _onDelete(options, userId) { - super._onDelete(options, userId); - - if (options.parent?.type === 'character') { - const path = `system.${this.isMulticlass ? 'multiclass.subclass' : 'class.subclass'}`; - options.parent.update({ [path]: null }); - } - } }