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();

View file

@ -1,42 +1,42 @@
export const actionTypes = {
attack: {
id: 'attack',
name: 'DAGGERHEART.Actions.Types.Attack.Name',
name: 'DAGGERHEART.Actions.Types.attack.name',
icon: 'fa-swords'
},
// spellcast: {
// id: 'spellcast',
// name: 'DAGGERHEART.Actions.Types.Spellcast.Name',
// name: 'DAGGERHEART.Actions.Types.spellcast.name',
// icon: 'fa-book-sparkles'
// },
healing: {
id: 'healing',
name: 'DAGGERHEART.Actions.Types.Healing.Name',
name: 'DAGGERHEART.Actions.Types.healing.name',
icon: 'fa-kit-medical'
},
// resource: {
// id: 'resource',
// name: 'DAGGERHEART.Actions.Types.Resource.Name',
// name: 'DAGGERHEART.Actions.Types.resource.name',
// icon: 'fa-honey-pot'
// },
damage: {
id: 'damage',
name: 'DAGGERHEART.Actions.Types.Damage.Name',
name: 'DAGGERHEART.Actions.Types.damage.name',
icon: 'fa-bone-break'
},
summon: {
id: 'summon',
name: 'DAGGERHEART.Actions.Types.Summon.Name',
name: 'DAGGERHEART.Actions.Types.summon.name',
icon: 'fa-ghost'
},
effect: {
id: 'effect',
name: 'DAGGERHEART.Actions.Types.Effect.Name',
name: 'DAGGERHEART.Actions.Types.effect.name',
icon: 'fa-person-rays'
},
macro: {
id: 'macro',
name: 'DAGGERHEART.Actions.Types.Macro.Name',
name: 'DAGGERHEART.Actions.Types.macro.name',
icon: 'fa-scroll'
}
};
@ -76,7 +76,7 @@ export const damageOnSave = {
label: 'Full damage',
mod: 1
}
}
};
export const diceCompare = {
below: {
@ -104,4 +104,4 @@ export const diceCompare = {
label: 'Above',
operator: '>'
}
}
};

View file

@ -712,14 +712,14 @@ export const valueTypes = {
export const actionTypes = {
passive: {
id: 'passive',
label: 'DAGGERHEART.ActionType.Passive'
label: 'DAGGERHEART.ActionType.passive'
},
action: {
id: 'action',
label: 'DAGGERHEART.ActionType.Action'
label: 'DAGGERHEART.ActionType.action'
},
reaction: {
id: 'reaction',
label: 'DAGGERHEART.ActionType.Reaction'
label: 'DAGGERHEART.ActionType.reaction'
}
};

View file

@ -43,6 +43,7 @@ export default class DhpAdversary extends BaseDataActor {
hitPoints: resourceField(),
stress: resourceField()
}),
actions: new fields.ArrayField(new ActionField()),
attack: new ActionField({
initial: {
name: 'Attack',