mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-18 07:59:03 +01:00
Finalized Character-Settings
This commit is contained in:
parent
2faa5e5460
commit
d9a0decbda
16 changed files with 130 additions and 42 deletions
|
|
@ -73,18 +73,23 @@ export default class DHCharacterSettings extends DHBaseActorSettings {
|
|||
const experience = this.actor.system.experiences[target.dataset.experience];
|
||||
const updates = {};
|
||||
|
||||
const relinkData = Object.keys(this.actor.system.levelData.levelups).reduce((acc, key) => {
|
||||
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)
|
||||
acc.push({ levelKey: key, selectionIndex, experience: target.dataset.experience });
|
||||
relinkSelectionData.push({ levelKey: key, selectionIndex, experience: target.dataset.experience });
|
||||
});
|
||||
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
if (relinkData.length > 0) {
|
||||
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')
|
||||
|
|
@ -92,8 +97,15 @@ export default class DHCharacterSettings extends DHBaseActorSettings {
|
|||
content: game.i18n.localize('DAGGERHEART.ACTORS.Character.experienceDataRemoveConfirmation.text')
|
||||
});
|
||||
if (!confirmed) return;
|
||||
}
|
||||
|
||||
relinkData.forEach(data => {
|
||||
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) => {
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,12 @@ export default class DhCharacter extends BaseDataActor {
|
|||
return {
|
||||
...super.defineSchema(),
|
||||
resources: new fields.SchemaField({
|
||||
hitPoints: resourceField(0, 'DAGGERHEART.GENERAL.HitPoints.plural', true),
|
||||
hitPoints: resourceField(
|
||||
0,
|
||||
'DAGGERHEART.GENERAL.HitPoints.plural',
|
||||
true,
|
||||
'DAGGERHEART.ACTORS.Character.maxHPBonus'
|
||||
),
|
||||
stress: resourceField(6, 'DAGGERHEART.GENERAL.stress', true),
|
||||
hope: resourceField(6, 'DAGGERHEART.GENERAL.hope')
|
||||
}),
|
||||
|
|
@ -505,7 +510,7 @@ export default class DhCharacter extends BaseDataActor {
|
|||
}
|
||||
|
||||
prepareBaseData() {
|
||||
this.evasion = this.class.value?.system?.evasion ?? 0;
|
||||
this.evasion += this.class.value?.system?.evasion ?? 0;
|
||||
|
||||
const currentLevel = this.levelData.level.current;
|
||||
const currentTier =
|
||||
|
|
|
|||
|
|
@ -6,13 +6,14 @@ const attributeField = label =>
|
|||
tierMarked: new fields.BooleanField({ initial: false })
|
||||
});
|
||||
|
||||
const resourceField = (max = 0, label, reverse = false) =>
|
||||
const resourceField = (max = 0, label, reverse = false, maxLabel) =>
|
||||
new fields.SchemaField({
|
||||
value: new fields.NumberField({ initial: 0, min: 0, integer: true, label }),
|
||||
max: new fields.NumberField({
|
||||
initial: max,
|
||||
integer: true,
|
||||
label: game.i18n.format('DAGGERHEART.GENERAL.maxWithThing', { thing: game.i18n.localize(label) })
|
||||
label:
|
||||
maxLabel ?? game.i18n.format('DAGGERHEART.GENERAL.maxWithThing', { thing: game.i18n.localize(label) })
|
||||
}),
|
||||
isReversed: new fields.BooleanField({ initial: reverse })
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue