mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-11 19:25:21 +01:00
* 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>
143 lines
5.5 KiB
JavaScript
143 lines
5.5 KiB
JavaScript
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
|
|
});
|
|
}
|
|
}
|