Fixed class/subclass drag-drop

This commit is contained in:
WBHarry 2025-07-31 16:56:56 +02:00
parent 39eb3dce69
commit 0cf9e1d17c
10 changed files with 247 additions and 28 deletions

View file

@ -5,6 +5,7 @@ export { default as DamageReductionDialog } from './damageReductionDialog.mjs';
export { default as DamageSelectionDialog } from './damageSelectionDialog.mjs';
export { default as DeathMove } from './deathMove.mjs';
export { default as Downtime } from './downtime.mjs';
export { default as MulticlassChoiceDialog } from './multiclassChoiceDialog.mjs';
export { default as OwnershipSelection } from './ownershipSelection.mjs';
export { default as ResourceDiceDialog } from './resourceDiceDialog.mjs';
export { default as ActionSelectionDialog } from './actionSelectionDialog.mjs';

View file

@ -0,0 +1,73 @@
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
export default class MulticlassChoiceDialog extends HandlebarsApplicationMixin(ApplicationV2) {
constructor(actor, multiclass, options) {
super(options);
this.actor = actor;
this.multiclass = multiclass;
this.selectedDomain = null;
}
get title() {
return game.i18n.format('DAGGERHEART.APPLICATIONS.MulticlassChoice.title', { actor: this.actor.name });
}
static DEFAULT_OPTIONS = {
classes: ['daggerheart', 'dh-style', 'dialog', 'views', 'multiclass-choice'],
position: { width: 'auto', height: 'auto' },
window: { icon: 'fa-solid fa-person-rays' },
actions: {
save: MulticlassChoiceDialog.#save,
selectDomain: MulticlassChoiceDialog.#selectDomain
}
};
static PARTS = {
application: {
id: 'multiclass-choice',
template: 'systems/daggerheart/templates/dialogs/multiclassChoice.hbs'
}
};
async _prepareContext(_options) {
const context = await super._prepareContext(_options);
context.multiclass = this.multiclass;
context.domainChoices = this.multiclass.domains.map(value => {
const domain = CONFIG.DH.DOMAIN.domains[value];
return {
value: value,
label: game.i18n.localize(domain.label),
description: game.i18n.localize(domain.description),
src: domain.src,
selected: value === this.selectedDomain,
disabled: this.actor.system.domains.includes(domain)
};
});
context.multiclassDisabled = !this.selectedDomain;
return context;
}
/** @override */
_onClose(options = {}) {
if (!options.submitted) this.move = null;
}
static async configure(actor, multiclass, options = {}) {
return new Promise(resolve => {
const app = new this(actor, multiclass, options);
app.addEventListener('close', () => resolve(app.selectedDomain), { once: true });
app.render({ force: true });
});
}
static #save() {
this.close({ submitted: true });
}
static #selectDomain(_event, button) {
this.selectedDomain = this.selectedDomain === button.dataset.domain ? null : button.dataset.domain;
this.render();
}
}

View file

@ -62,16 +62,37 @@ export default class DHClass extends BaseDataItem {
}
async _preCreate(data, options, user) {
const allowed = await super._preCreate(data, options, user);
if (allowed === false) return;
if (this.actor?.type === 'character') {
const path = data.system.isMulticlass ? 'system.multiclass.value' : 'system.class.value';
if (foundry.utils.getProperty(this.actor, path)) {
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.classAlreadySelected'));
return false;
const levelupAuto = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation).levelupAuto;
if (levelupAuto) {
const path = data.system.isMulticlass ? 'system.multiclass.value' : 'system.class.value';
if (foundry.utils.getProperty(this.actor, path)) {
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.classAlreadySelected'));
return false;
}
} else {
if (this.actor.system.class.value) {
if (this.actor.system.multiclass.value) {
ui.notifications.warn(
game.i18n.localize('DAGGERHEART.UI.Notifications.multiclassAlreadyPresent')
);
return false;
} else {
const selectedDomain =
await game.system.api.applications.dialogs.MulticlassChoiceDialog.configure(
this.actor,
this
);
if (!selectedDomain) return false;
await this.updateSource({ isMulticlass: true, domains: [selectedDomain] });
}
}
}
}
const allowed = await super._preCreate(data, options, user);
if (allowed === false) return;
}
_onCreate(data, options, userId) {

View file

@ -45,21 +45,23 @@ export default class DHSubclass extends BaseDataItem {
if (allowed === false) return;
if (this.actor?.type === 'character') {
const classData = this.actor.items.find(
x => x.type === 'class' && x.system.isMulticlass === data.system.isMulticlass
);
const subclassData = this.actor.items.find(
x => x.type === 'subclass' && x.system.isMulticlass === data.system.isMulticlass
);
if (!classData) {
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.missingClass'));
return false;
} else if (subclassData) {
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.subclassAlreadySelected'));
return false;
} else if (classData.system.subclasses.every(x => x.uuid !== (data.uuid ?? `Item.${data._id}`))) {
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.subclassNotInClass'));
return false;
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;
}
await this.updateSource({ isMulticlass: true });
}
} else {
if (!this.actor.system.class.value) {
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.missingClass'));
return false;
}
}
}
}