daggerheart/module/data/item/subclass.mjs
WBHarry e1d8f8784a
[Feature] Manual Character Editing (#490)
* Initial

* Added Character-Settings

* Finalized Character-Settings

* Hide CharacterSetup if any part is done manually

* Fixed class/subclass drag-drop

* Fixed relinking of Features from items created on Character

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

* Made suggested items inactive in the Class sheet if rendered from inside a Character

* Added hope to CharacterSetting

* add style to textarea element, add spellcasting and domain class into char sheet and move rest buttons to another place

* Fixed characterCreation experience description

---------

Co-authored-by: moliloo <dev.murilobrito@gmail.com>
2025-08-01 12:16:35 -03:00

107 lines
4 KiB
JavaScript

import ItemLinkFields from '../fields/itemLinkFields.mjs';
import BaseDataItem from './base.mjs';
export default class DHSubclass extends BaseDataItem {
/** @inheritDoc */
static get metadata() {
return foundry.utils.mergeObject(super.metadata, {
label: 'TYPES.Item.subclass',
type: 'subclass',
hasDescription: true
});
}
/** @inheritDoc */
static defineSchema() {
const fields = foundry.data.fields;
return {
...super.defineSchema(),
spellcastingTrait: new fields.StringField({
choices: CONFIG.DH.ACTOR.abilities,
integer: false,
nullable: true,
initial: null
}),
features: new ItemLinkFields(),
featureState: new fields.NumberField({ required: true, initial: 1, min: 1 }),
isMulticlass: new fields.BooleanField({ initial: false })
};
}
get foundationFeatures() {
return this.features.filter(x => x.type === CONFIG.DH.ITEM.featureSubTypes.foundation).map(x => x.item);
}
get specializationFeatures() {
return this.features.filter(x => x.type === CONFIG.DH.ITEM.featureSubTypes.specialization).map(x => x.item);
}
get masteryFeatures() {
return this.features.filter(x => x.type === CONFIG.DH.ITEM.featureSubTypes.mastery).map(x => x.item);
}
async _preCreate(data, options, user) {
if (this.actor?.type === 'character') {
if (this.actor.system.class.subclass) {
if (this.actor.system.multiclass.subclass) {
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.subclassesAlreadyPresent'));
return false;
} else {
if (!this.actor.system.multiclass.value) {
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.missingMulticlass'));
return false;
}
if (
this.actor.system.multiclass.value.system.subclasses.every(
x => x.uuid !== (data.uuid ?? `Item.${data._id}`)
)
) {
ui.notifications.error(
game.i18n.localize('DAGGERHEART.UI.Notifications.subclassNotInMulticlass')
);
return false;
}
await this.updateSource({ isMulticlass: true });
}
} else {
if (!this.actor.system.class.value) {
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.missingClass'));
return false;
}
if (
this.actor.system.class.value.system.subclasses.every(
x => x.uuid !== (data.uuid ?? `Item.${data._id}`)
)
) {
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.subclassNotInClass'));
return false;
}
}
}
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 });
}
}
}