[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>
This commit is contained in:
WBHarry 2025-08-01 17:16:35 +02:00 committed by GitHub
parent 263dfa69ae
commit e1d8f8784a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
49 changed files with 1205 additions and 386 deletions

View file

@ -1,4 +1,5 @@
export { default as ActionConfig } from './action-config.mjs';
export { default as CharacterSettings } from './character-settings.mjs';
export { default as AdversarySettings } from './adversary-settings.mjs';
export { default as CompanionSettings } from './companion-settings.mjs';
export { default as DowntimeConfig } from './downtimeConfig.mjs';

View file

@ -0,0 +1,143 @@
import DHBaseActorSettings from '../sheets/api/actor-setting.mjs';
/**@typedef {import('@client/applications/_types.mjs').ApplicationClickAction} ApplicationClickAction */
export default class DHCharacterSettings extends DHBaseActorSettings {
/**@inheritdoc */
static DEFAULT_OPTIONS = {
classes: ['character-settings'],
position: { width: 455, height: 'auto' },
actions: {
addExperience: DHCharacterSettings.#addExperience,
removeExperience: DHCharacterSettings.#removeExperience
},
dragDrop: [
{ dragSelector: null, dropSelector: '.tab.features' },
{ dragSelector: '.feature-item', dropSelector: null }
]
};
/**@override */
static PARTS = {
header: {
id: 'header',
template: 'systems/daggerheart/templates/sheets-settings/character-settings/header.hbs'
},
tabs: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs' },
details: {
id: 'details',
template: 'systems/daggerheart/templates/sheets-settings/character-settings/details.hbs'
},
experiences: {
id: 'experiences',
template: 'systems/daggerheart/templates/sheets-settings/character-settings/experiences.hbs'
}
};
/** @override */
static TABS = {
primary: {
tabs: [{ id: 'details' }, { id: 'experiences' }],
initial: 'details',
labelPrefix: 'DAGGERHEART.GENERAL.Tabs'
}
};
/**@inheritdoc */
async _prepareContext(options) {
const context = await super._prepareContext(options);
context.levelupAuto = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation).levelupAuto;
return context;
}
/* -------------------------------------------- */
/**
* Adds a new experience entry to the actor.
* @type {ApplicationClickAction}
*/
static async #addExperience() {
const newExperience = {
name: 'Experience',
modifier: 0
};
await this.actor.update({ [`system.experiences.${foundry.utils.randomID()}`]: newExperience });
}
/**
* Removes an experience entry from the actor.
* @type {ApplicationClickAction}
*/
static async #removeExperience(_, target) {
const experience = this.actor.system.experiences[target.dataset.experience];
const updates = {};
const relinkAchievementData = [];
const relinkSelectionData = [];
Object.keys(this.actor.system.levelData.levelups).forEach(key => {
const level = this.actor.system.levelData.levelups[key];
const achievementIncludesExp = level.achievements.experiences[target.dataset.experience];
if (achievementIncludesExp)
relinkAchievementData.push({ levelKey: key, experience: target.dataset.experience });
const selectionIndex = level.selections.findIndex(
x => x.optionKey === 'experience' && x.data[0] === target.dataset.experience
);
if (selectionIndex !== -1)
relinkSelectionData.push({ levelKey: key, selectionIndex, experience: target.dataset.experience });
});
if (relinkAchievementData.length > 0 || relinkSelectionData.length > 0) {
const confirmed = await foundry.applications.api.DialogV2.confirm({
window: {
title: game.i18n.localize('DAGGERHEART.ACTORS.Character.experienceDataRemoveConfirmation.title')
},
content: game.i18n.localize('DAGGERHEART.ACTORS.Character.experienceDataRemoveConfirmation.text')
});
if (!confirmed) return;
}
if (relinkAchievementData.length > 0) {
relinkAchievementData.forEach(data => {
updates[`system.levelData.levelups.${data.levelKey}.achievements.experiences.-=${data.experience}`] =
null;
});
} else if (relinkSelectionData.length > 0) {
relinkSelectionData.forEach(data => {
updates[`system.levelData.levelups.${data.levelKey}.selections`] = this.actor.system.levelData.levelups[
data.levelKey
].selections.reduce((acc, selection, index) => {
if (
index === data.selectionIndex &&
selection.optionKey === 'experience' &&
selection.data.includes(data.experience)
) {
acc.push({ ...selection, data: selection.data.filter(x => x !== data.experience) });
} else {
acc.push(selection);
}
return acc;
}, []);
});
} else {
const confirmed = await foundry.applications.api.DialogV2.confirm({
window: {
title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', {
type: game.i18n.localize(`DAGGERHEART.GENERAL.Experience.single`),
name: experience.name
})
},
content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', { name: experience.name })
});
if (!confirmed) return;
}
await this.actor.update({
...updates,
[`system.experiences.-=${target.dataset.experience}`]: null
});
}
}

View file

@ -10,6 +10,8 @@ export default class DHCompanionSettings extends DHBaseActorSettings {
classes: ['companion-settings'],
position: { width: 455, height: 'auto' },
actions: {
addExperience: DHCompanionSettings.#addExperience,
removeExperience: DHCompanionSettings.#removeExperience,
levelUp: DHCompanionSettings.#levelUp
}
};
@ -88,6 +90,38 @@ export default class DHCompanionSettings extends DHBaseActorSettings {
if (!value) await this.actor.updateLevel(1);
}
/**
* Adds a new experience entry to the actor.
* @type {ApplicationClickAction}
*/
static async #addExperience() {
const newExperience = {
name: 'Experience',
modifier: 0
};
await this.actor.update({ [`system.experiences.${foundry.utils.randomID()}`]: newExperience });
}
/**
* Removes an experience entry from the actor.
* @type {ApplicationClickAction}
*/
static async #removeExperience(_, target) {
const experience = this.actor.system.experiences[target.dataset.experience];
const confirmed = await foundry.applications.api.DialogV2.confirm({
window: {
title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', {
type: game.i18n.localize(`DAGGERHEART.GENERAL.Experience.single`),
name: experience.name
})
},
content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', { name: experience.name })
});
if (!confirmed) return;
await this.actor.update({ [`system.experiences.-=${target.dataset.experience}`]: null });
}
/**
* Opens the companion level-up dialog for the associated actor.
* @type {ApplicationClickAction}