finish actions setting tab

This commit is contained in:
moliloo 2025-07-01 00:42:34 -03:00
parent 3b159d7c0c
commit f48459114a
23 changed files with 365 additions and 175 deletions

View file

@ -28,19 +28,19 @@ export default class AdversarySheet extends DaggerheartSheet(ActorSheetV2) {
static PARTS = {
sidebar: { template: 'systems/daggerheart/templates/sheets/actors/adversary/sidebar.hbs' },
header: { template: 'systems/daggerheart/templates/sheets/actors/adversary/header.hbs' },
features: { template: 'systems/daggerheart/templates/sheets/actors/adversary/features.hbs' },
actions: { template: 'systems/daggerheart/templates/sheets/actors/adversary/actions.hbs' },
notes: { template: 'systems/daggerheart/templates/sheets/actors/adversary/notes.hbs' },
effects: { template: 'systems/daggerheart/templates/sheets/actors/adversary/effects.hbs' }
};
static TABS = {
features: {
actions: {
active: true,
cssClass: '',
group: 'primary',
id: 'features',
id: 'actions',
icon: null,
label: 'DAGGERHEART.Sheets.Adversary.Tabs.features'
label: 'DAGGERHEART.General.tabs.actions'
},
notes: {
active: false,

View file

@ -1,5 +1,7 @@
import DHActionConfig from '../../config/Action.mjs';
import DaggerheartSheet from '../daggerheart-sheet.mjs';
import DHBaseItemSheet from '../api/base-item.mjs';
import { actionsTypes } from '../../../data/_module.mjs';
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
@ -24,8 +26,11 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
},
position: { width: 455, height: 'auto' },
actions: {
addExperience: this.addExperience,
removeExperience: this.removeExperience
addExperience: this.#addExperience,
removeExperience: this.#removeExperience,
addAction: this.#addAction,
editAction: this.#editAction,
removeAction: this.#removeAction
},
form: {
handler: this.updateForm,
@ -52,9 +57,9 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
id: 'experiences',
template: 'systems/daggerheart/templates/sheets/applications/adversary-settings/experiences.hbs'
},
features: {
id: 'features',
template: 'systems/daggerheart/templates/sheets/applications/adversary-settings/features.hbs'
actions: {
id: 'actions',
template: 'systems/daggerheart/templates/sheets/applications/adversary-settings/actions.hbs'
}
};
@ -83,13 +88,13 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
icon: null,
label: 'DAGGERHEART.General.tabs.experiences'
},
features: {
actions: {
active: false,
cssClass: '',
group: 'primary',
id: 'features',
id: 'actions',
icon: null,
label: 'DAGGERHEART.General.tabs.features'
label: 'DAGGERHEART.General.tabs.actions'
}
};
@ -114,7 +119,7 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
return tabs;
}
static async addExperience() {
static async #addExperience() {
const newExperience = {
name: 'Experience',
modifier: 0
@ -123,11 +128,55 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
this.render();
}
static async removeExperience(_, target) {
static async #removeExperience(_, target) {
await this.actor.update({ [`system.experiences.-=${target.dataset.experience}`]: null });
this.render();
}
static async #addAction(_event, _button) {
const actionType = await DHBaseItemSheet.selectActionType();
if (!actionType) return;
try {
const cls = actionsTypes[actionType] ?? actionsTypes.attack,
action = new cls(
{
_id: foundry.utils.randomID(),
type: actionType,
name: game.i18n.localize(SYSTEM.ACTIONS.actionTypes[actionType].name),
...cls.getSourceConfig(this.actor)
},
{
parent: this.actor
}
);
console.log(action);
await this.actor.update({ 'system.actions': [...this.actor.system.actions, action] });
await new DHActionConfig(this.actor.system.actions[this.actor.system.actions.length - 1]).render({
force: true
});
this.render();
} catch (error) {
console.log(error);
}
}
static async #editAction(event, target) {
event.stopPropagation();
const actionIndex = target.dataset.index;
await new DHActionConfig(this.actor.system.actions[actionIndex]).render({
force: true
});
}
static async #removeAction(event, target) {
event.stopPropagation();
const actionIndex = target.dataset.index;
await this.actor.update({
'system.actions': this.actor.system.actions.filter((_, index) => index !== Number.parseInt(actionIndex))
});
this.render();
}
static async updateForm(event, _, formData) {
await this.actor.update(formData.object);
this.render();