daggerheart/module/applications/sheets-configs/adversary-settings.mjs
WBHarry effab8db0c
Some checks are pending
Project CI / build (24.x) (push) Waiting to run
[Rework] ChatMessage Damage (#2079)
* Initial rework

* Removed unneeded method

* Removed outcommented code

* Added migration

* Fixed DamageActions

* Semi-corrected reroll of one of multiple results on a die

* Code improvement

* Added aseDie.rerollResult method to specifically reroll a specific result die in a grouping

* TagTeamDialog somewhat working

* Added migration for TagTeamData

* Fix for mean tagTeamDialog.finish

* .

* Improved migration

* Internalised ChatDamageData.prepareRolls to its own constructor

* Moved DamageTypes to roll.options

* TagTeamDialog fixes to accomodate new flat damage.types structure

* Changed so all default rolls become BaseRolls to access convenience functions and getters

* .

* Fixed so that party.tagTeam now uses a declared damageRollData(ChatDamageData) field. rollData.options.damage is retired.

* Critical damage fixes

* Corrected TagTeamDialog rerender logic when selecting a roll

* Fixed so that DamageTypes are retained and joined together throughout TagTeamDialog

* Removed some remaining types.<>.roll references

* [Rework] Damage and Damage Resource split (#2094)

* Changed the label of ActionSheet damage.resources to Mark Resources

* Fix assigning includeBase

* Localize add resource

* Maybe simplify API

* Fix onRollSimple

* Handle erroring action update differently

---------

Co-authored-by: Carlos Fernandez <cfern1990@gmail.com>
2026-07-19 03:02:57 +02:00

128 lines
4.4 KiB
JavaScript

import { DHDamageData } from '../../data/fields/action/damageField.mjs';
import DHBaseActorSettings from '../sheets/api/actor-setting.mjs';
/**@typedef {import('@client/applications/_types.mjs').ApplicationClickAction} ApplicationClickAction */
export default class DHAdversarySettings extends DHBaseActorSettings {
/**@inheritdoc */
static DEFAULT_OPTIONS = {
classes: ['adversary-settings'],
position: { width: 455, height: 'auto' },
actions: {
addExperience: this.#onAddExperience,
removeExperience: this.#onRemoveExperience,
addDamage: this.#onAddDamage,
removeDamage: this.#onRemoveDamage
}
};
/**@override */
static PARTS = {
header: {
id: 'header',
template: 'systems/daggerheart/templates/sheets-settings/adversary-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'
},
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',
scrollable: ['']
}
};
/** @override */
static TABS = {
primary: {
tabs: [{ id: 'details' }, { id: 'attack' }, { id: 'experiences' }, { id: 'features' }],
initial: 'details',
labelPrefix: 'DAGGERHEART.GENERAL.Tabs'
}
};
async _prepareContext(options) {
const context = await super._prepareContext(options);
// Get feature groups. Uncategorized go to actions
const featureFormsTypes = ['passive', 'action', 'reaction'];
const features = this.document.system.features.sort((a, b) => a.sort - b.sort);
const featureGroups = featureFormsTypes.map(t => ({
featureForm: t,
label: _loc(CONFIG.DH.ITEM.featureForm[t]),
features: features.filter(f => f.system.featureForm === t)
}));
featureGroups[1].features.push(...features.filter(f => !featureFormsTypes.includes(f.system.featureForm)));
context.featureGroups = featureGroups;
return context;
}
/* -------------------------------------------- */
/**
* Adds a new experience entry to the actor.
* @type {ApplicationClickAction}
*/
static async #onAddExperience() {
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 #onRemoveExperience(_, 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}`]: _del });
}
/**
* @this DHAdversarySettings
* @type {ApplicationClickAction}
*/
static #onAddDamage() {
this.actor.update({
'system.attack.damage.main': {
...DHDamageData.schema.getInitialValue(),
applyTo: 'hitPoints',
type: 'physical'
}
});
}
/**
* @this DHAdversarySettings
* @type {ApplicationClickAction}
*/
static #onRemoveDamage() {
this.actor.update({
'system.attack.damage.main': null
});
}
}