Added Character-Settings

This commit is contained in:
WBHarry 2025-07-31 04:12:35 +02:00
parent 798cf8c761
commit 8555b7a044
17 changed files with 258 additions and 58 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

@ -7,7 +7,10 @@ export default class DHCharacterSettings extends DHBaseActorSettings {
static DEFAULT_OPTIONS = {
classes: ['character-settings'],
position: { width: 455, height: 'auto' },
actions: {},
actions: {
addExperience: DHCharacterSettings.#addExperience,
removeExperience: DHCharacterSettings.#removeExperience
},
dragDrop: [
{ dragSelector: null, dropSelector: '.tab.features' },
{ dragSelector: '.feature-item', dropSelector: null }
@ -18,33 +21,111 @@ export default class DHCharacterSettings extends DHBaseActorSettings {
static PARTS = {
header: {
id: 'header',
template: 'systems/daggerheart/templates/sheets-settings/adversary-settings/header.hbs'
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/adversary-settings/details.hbs'
},
attack: {
id: 'attack',
template: 'systems/daggerheart/templates/sheets-settings/adversary-settings/attack.hbs'
template: 'systems/daggerheart/templates/sheets-settings/character-settings/details.hbs'
},
experiences: {
id: 'experiences',
template: 'systems/daggerheart/templates/sheets-settings/adversary-settings/experiences.hbs'
},
features: {
id: 'features',
template: 'systems/daggerheart/templates/sheets-settings/adversary-settings/features.hbs'
template: 'systems/daggerheart/templates/sheets-settings/character-settings/experiences.hbs'
}
};
/** @override */
static TABS = {
primary: {
tabs: [{ id: 'details' }, { id: 'attack' }, { id: 'experiences' }, { id: 'features' }],
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 relinkData = Object.keys(this.actor.system.levelData.levelups).reduce((acc, key) => {
const level = this.actor.system.levelData.levelups[key];
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 });
return acc;
}, []);
if (relinkData.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;
relinkData.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

@ -25,7 +25,6 @@ export default class CharacterSheet extends DHBaseActorSheet {
toggleEquipItem: CharacterSheet.#toggleEquipItem,
toggleResourceDice: CharacterSheet.#toggleResourceDice,
handleResourceDice: CharacterSheet.#handleResourceDice,
openConfig: CharacterSheet.#openConfig,
useDowntime: this.useDowntime
},
window: {
@ -717,20 +716,14 @@ export default class CharacterSheet extends DHBaseActorSheet {
});
}
/**
* Open the character config sheet.
* @type {ApplicationClickAction}
*/
static async #openConfig() {}
/**
* Open the downtime application.
* @type {ApplicationClickAction}
*/
static useDowntime(_, button) {
new game.system.api.applications.dialogs.Downtime(this.document, button.dataset.type === 'shortRest').render(
true
);
new game.system.api.applications.dialogs.Downtime(this.document, button.dataset.type === 'shortRest').render({
force: true
});
}
async _onDragStart(event) {

View file

@ -87,7 +87,8 @@ export default class DhpAdversary extends BaseDataActor {
experiences: new fields.TypedObjectField(
new fields.SchemaField({
name: new fields.StringField(),
value: new fields.NumberField({ required: true, integer: true, initial: 1 })
value: new fields.NumberField({ required: true, integer: true, initial: 1 }),
description: new fields.StringField()
})
),
bonuses: new fields.SchemaField({

View file

@ -4,6 +4,7 @@ import DhLevelData from '../levelData.mjs';
import BaseDataActor from './base.mjs';
import { attributeField, resourceField, stressDamageReductionRule, bonusField } from '../fields/actorField.mjs';
import { ActionField } from '../fields/actionField.mjs';
import DHCharacterSettings from '../../applications/sheets-configs/character-settings.mjs';
export default class DhCharacter extends BaseDataActor {
static LOCALIZATION_PREFIXES = ['DAGGERHEART.ACTORS.Character'];
@ -12,6 +13,7 @@ export default class DhCharacter extends BaseDataActor {
return foundry.utils.mergeObject(super.metadata, {
label: 'TYPES.Actor.character',
type: 'character',
settingSheet: DHCharacterSettings,
isNPC: false
});
}
@ -56,7 +58,8 @@ export default class DhCharacter extends BaseDataActor {
experiences: new fields.TypedObjectField(
new fields.SchemaField({
name: new fields.StringField(),
value: new fields.NumberField({ integer: true, initial: 0 })
value: new fields.NumberField({ integer: true, initial: 0 }),
description: new fields.StringField()
})
),
gold: new fields.SchemaField({
@ -538,9 +541,9 @@ export default class DhCharacter extends BaseDataActor {
this.proficiency += selection.value;
break;
case 'experience':
Object.keys(this.experiences).forEach(key => {
const experience = this.experiences[key];
experience.value += selection.value;
selection.data.forEach(id => {
const experience = this.experiences[id];
if (experience) experience.value += selection.value;
});
break;
}
@ -568,7 +571,7 @@ export default class DhCharacter extends BaseDataActor {
this.attack.roll.trait = this.rules.attack.roll.trait ?? this.attack.roll.trait;
this.resources.armor = {
value: this.armor.system.marks.value,
value: this.armor?.system?.marks?.value ?? 0,
max: this.armorScore,
isReversed: true
};

View file

@ -9,7 +9,11 @@ const attributeField = label =>
const resourceField = (max = 0, label, reverse = false) =>
new fields.SchemaField({
value: new fields.NumberField({ initial: 0, min: 0, integer: true, label }),
max: new fields.NumberField({ initial: max, integer: true }),
max: new fields.NumberField({
initial: max,
integer: true,
label: game.i18n.format('DAGGERHEART.GENERAL.maxWithThing', { thing: game.i18n.localize(label) })
}),
isReversed: new fields.BooleanField({ initial: reverse })
});