REFACTOR: remove unused methods

REFACTOR: create method on BaseActorSheet
REFACTOR: make Datamodel metadata getter
This commit is contained in:
Joaquin Pereyra 2025-07-07 01:41:05 -03:00
parent 72e6bf055c
commit 79a4c13a1b
12 changed files with 103 additions and 75 deletions

View file

@ -1,19 +1,15 @@
import DHBaseActorSheet from '../api/base-actor.mjs';
import DHActionConfig from '../../sheets-configs/action-config.mjs';
import DHAdversarySettings from '../../sheets-configs/adversary-settings.mjs';
/**@typedef {import('@client/applications/_types.mjs').ApplicationClickAction} ApplicationClickAction */
export default class AdversarySheet extends DHBaseActorSheet {
static DEFAULT_OPTIONS = {
classes: ['adversary'],
position: { width: 660, height: 766 },
actions: {
reactionRoll: this.reactionRoll,
reactionRoll: AdversarySheet.#reactionRoll,
useItem: this.useItem,
toChat: this.toChat,
attackConfigure: this.attackConfigure,
addExperience: this.addExperience,
removeExperience: this.removeExperience,
openSettings: this.openSettings
},
window: {
resizable: true
@ -51,7 +47,15 @@ export default class AdversarySheet extends DHBaseActorSheet {
return item;
}
static async reactionRoll(event) {
/* -------------------------------------------- */
/* Application Clicks Actions */
/* -------------------------------------------- */
/**
* Performs a reaction roll for an Adversary.
* @type {ApplicationClickAction}
*/
static #reactionRoll(event) {
const config = {
event: event,
title: `Reaction Roll: ${this.actor.name}`,
@ -65,18 +69,23 @@ export default class AdversarySheet extends DHBaseActorSheet {
mute: true
}
};
this.actor.diceRoll(config);
}
static async openSettings() {
await new DHAdversarySettings(this.document).render(true);
}
/**
*
* @type {ApplicationClickAction}
*/
static async useItem(event) {
const action = this.getItem(event) ?? this.actor.system.attack;
action.use(event);
}
/**
*
* @type {ApplicationClickAction}
*/
static async toChat(event, button) {
if (button?.dataset?.type === 'experience') {
const experience = this.document.system.experiences[button.dataset.uuid];
@ -103,21 +112,4 @@ export default class AdversarySheet extends DHBaseActorSheet {
}
}
static async attackConfigure(event) {
await new DHActionConfig(this.document.system.attack).render(true);
}
static async addExperience() {
const experienceId = foundry.utils.randomID();
await this.document.update({
[`system.experiences.${experienceId}`]: { id: experienceId, name: 'Experience', value: 1 }
});
}
static async removeExperience(_, button) {
await this.document.update({
[`system.experiences.-=${button.dataset.experience}`]: null
});
}
}

View file

@ -172,7 +172,8 @@ export default class CharacterSheet extends DHBaseActorSheet {
/**
* Get the set of ContextMenu options.
* @returns {import('@client/applications/ux/context-menu.mjs').ContextMenuEntry[]} The Array of context options passed to the ContextMenu instance
* @returns {import('@client/applications/ux/context-menu.mjs').ContextMenuEntry[]} - The Array of context options passed to the ContextMenu instance
* @this {CharacterSheet}
* @protected
*/
static _getContextMenuOptions() {
@ -199,7 +200,7 @@ export default class CharacterSheet extends DHBaseActorSheet {
const item = getItem(el);
return ['weapon', 'armor'].includes(item.type) && !item.system.equipped;
},
callback: CharacterSheet.toggleEquipItem.bind(this)
callback: CharacterSheet.#toggleEquipItem.bind(this)
}, {
name: 'DAGGERHEART.Sheets.PC.ContextMenu.Unequip',
icon: '<i class="fa-solid fa-hands"></i>',
@ -207,7 +208,7 @@ export default class CharacterSheet extends DHBaseActorSheet {
const item = getItem(el);
return ['weapon', 'armor'].includes(item.type) && item.system.equipped;
},
callback: CharacterSheet.toggleEquipItem.bind(this)
callback: CharacterSheet.#toggleEquipItem.bind(this)
}, {
name: 'DAGGERHEART.Sheets.PC.ContextMenu.ToLoadout',
icon: '<i class="fa-solid fa-arrow-up"></i>',

View file

@ -1,5 +1,7 @@
import DHBaseActorSheet from '../api/base-actor.mjs';
import DHCompanionSettings from '../../sheets-configs/companion-settings.mjs';
/**@typedef {import('@client/applications/_types.mjs').ApplicationClickAction} ApplicationClickAction */
export default class DhCompanionSheet extends DHBaseActorSheet {
static DEFAULT_OPTIONS = {
@ -7,9 +9,8 @@ export default class DhCompanionSheet extends DHBaseActorSheet {
position: { width: 300 },
actions: {
viewActor: this.viewActor,
openSettings: this.openSettings,
useItem: this.useItem,
toChat: this.toChat
toChat: this.toChat,
},
};
@ -30,6 +31,10 @@ export default class DhCompanionSheet extends DHBaseActorSheet {
}
};
/* -------------------------------------------- */
/* Application Clicks Actions */
/* -------------------------------------------- */
static async viewActor(_, button) {
const target = button.closest('[data-item-uuid]');
const actor = await foundry.utils.fromUuid(target.dataset.itemUuid);
@ -73,8 +78,4 @@ export default class DhCompanionSheet extends DHBaseActorSheet {
item.toChat(this.document.id);
}
}
static async openSettings() {
await new DHCompanionSettings(this.document).render(true);
}
}

View file

@ -1,22 +1,22 @@
import DHBaseActorSheet from '../api/base-actor.mjs';
import DHEnvironmentSettings from '../../sheets-configs/environment-settings.mjs';
/**@typedef {import('@client/applications/_types.mjs').ApplicationClickAction} ApplicationClickAction */
export default class DhpEnvironment extends DHBaseActorSheet {
/**@inheritdoc */
static DEFAULT_OPTIONS = {
classes: ['environment'],
position: {
width: 500
},
actions: {
addAdversary: this.addAdversary,
deleteProperty: this.deleteProperty,
openSettings: this.openSettings,
useItem: this.useItem,
toChat: this.toChat
},
dragDrop: [{ dragSelector: '.action-section .inventory-item', dropSelector: null }]
};
/**@override */
static PARTS = {
header: { template: 'systems/daggerheart/templates/sheets/actors/environment/header.hbs' },
features: { template: 'systems/daggerheart/templates/sheets/actors/environment/features.hbs' },
@ -35,30 +35,22 @@ export default class DhpEnvironment extends DHBaseActorSheet {
}
};
/* -------------------------------------------- */
getItem(element) {
const itemId = (element.target ?? element).closest('[data-item-id]').dataset.itemId,
item = this.document.items.get(itemId);
return item;
}
static async openSettings() {
await new DHEnvironmentSettings(this.document).render(true);
}
static async addAdversary() {
await this.document.update({
[`system.potentialAdversaries.${foundry.utils.randomID()}.label`]: game.i18n.localize(
'DAGGERHEART.ACTORS.Environment.newAdversary'
)
});
this.render();
}
static async deleteProperty(_, target) {
await this.document.update({ [`${target.dataset.path}.-=${target.id}`]: null });
this.render();
}
/* -------------------------------------------- */
/* Application Clicks Actions */
/* -------------------------------------------- */
/**
*
* @type {ApplicationClickAction}
*/
async viewAdversary(_, button) {
const target = button.closest('[data-item-uuid]');
const adversary = await foundry.utils.fromUuid(target.dataset.itemUuid);
@ -67,7 +59,7 @@ export default class DhpEnvironment extends DHBaseActorSheet {
return;
}
adversary.sheet.render(true);
adversary.sheet.render({ force: true });
}
static async useItem(event, button) {

View file

@ -2,6 +2,8 @@ import DHApplicationMixin from './application-mixin.mjs';
const { ActorSheetV2 } = foundry.applications.sheets;
/**@typedef {import('@client/applications/_types.mjs').ApplicationClickAction} ApplicationClickAction */
/**
* A base actor sheet extending {@link ActorSheetV2} via {@link DHApplicationMixin}
* @extends ActorSheetV2
@ -17,14 +19,36 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) {
form: {
submitOnChange: true
},
actions: {},
dragDrop: []
actions: {
openSettings: DHBaseActorSheet.#openSettings
},
dragDrop: [],
};
/**
*
*/
#settingSheet;
get settingSheet() {
const SheetClass = this.document.system.metadata.settingSheet;
return this.#settingSheet ??= SheetClass ? new SheetClass(this.document): null;
}
/**@inheritdoc */
async _prepareContext(_options) {
const context = await super._prepareContext(_options);
context.isNPC = this.document.isNPC;
return context;
}
/**
*
* @type {ApplicationClickAction}
*/
static async #openSettings() {
await this.settingSheet.render({ force: true });
}
}