From 3eaf69f5587c4ab16cf0337a7e67cde742cae2d0 Mon Sep 17 00:00:00 2001 From: Alexander Minges Date: Mon, 28 Jul 2025 21:55:06 +0200 Subject: [PATCH] fix: remove duplicate action handlers and improve template action generation - Remove duplicate action handlers (edititem, deleteitem, createitem, etc.) from DS4ActorSheet and DS4ItemSheet - Fix editImage method reference from static to prototype in DS4ActorSheet - Add capitalize helper to handlebars-helpers.ts for dynamic action name generation - Update control-button-group.hbs and add-button.hbs templates to use concat and capitalize helpers - Ensure consistent camelCase naming for all action handlers (editItem, deleteItem, createItem, etc.) This resolves action handler conflicts and improves maintainability by using dynamic template generation instead of hardcoded conditional logic. --- src/apps/actor/base-sheet.js | 9 +-------- src/apps/item-sheet.js | 3 --- src/handlebars/handlebars-helpers.ts | 5 +++++ templates/sheets/shared/components/add-button.hbs | 2 +- .../sheets/shared/components/control-button-group.hbs | 4 ++-- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/apps/actor/base-sheet.js b/src/apps/actor/base-sheet.js index 55e2163a..fabdb67d 100644 --- a/src/apps/actor/base-sheet.js +++ b/src/apps/actor/base-sheet.js @@ -41,14 +41,7 @@ export class DS4ActorSheet extends foundry.applications.api.HandlebarsApplicatio changeEffect: DS4ActorSheet.prototype._onChangeEffect, sortItems: DS4ActorSheet.prototype._onSortItems, changeTab: DS4ActorSheet.prototype._onChangeTab, - edititem: DS4ActorSheet.prototype._onEditItem, - deleteitem: DS4ActorSheet.prototype._onDeleteItem, - createitem: DS4ActorSheet.prototype._onCreateItem, - editeffect: DS4ActorSheet.prototype._onEditEffect, - deleteeffect: DS4ActorSheet.prototype._onDeleteEffect, - createeffect: DS4ActorSheet.prototype._onCreateEffect, - editImage: DS4ActorSheet._onEditImage, - + editImage: DS4ActorSheet.prototype._onEditImage, }, }; diff --git a/src/apps/item-sheet.js b/src/apps/item-sheet.js index 004b3ab9..5a05dfb4 100644 --- a/src/apps/item-sheet.js +++ b/src/apps/item-sheet.js @@ -26,11 +26,8 @@ export class DS4ItemSheet extends foundry.applications.api.HandlebarsApplication actions: { controlEffect: DS4ItemSheet.prototype._onControlEffect, createEffect: DS4ItemSheet.prototype._onCreateEffect, - createeffect: DS4ItemSheet.prototype._onCreateEffect, editEffect: DS4ItemSheet.prototype._onEditEffect, - editeffect: DS4ItemSheet.prototype._onEditEffect, deleteEffect: DS4ItemSheet.prototype._onDeleteEffect, - deleteeffect: DS4ItemSheet.prototype._onDeleteEffect, changeTab: DS4ItemSheet.prototype._onChangeTab, editImage: DS4ItemSheet.prototype._onEditImage, }, diff --git a/src/handlebars/handlebars-helpers.ts b/src/handlebars/handlebars-helpers.ts index 015064a4..8f94b065 100644 --- a/src/handlebars/handlebars-helpers.ts +++ b/src/handlebars/handlebars-helpers.ts @@ -14,6 +14,11 @@ const helpers = { isEmpty: (input: Array | null | undefined): boolean => (input?.length ?? 0) === 0, + capitalize: (str: string): string => { + if (typeof str !== 'string') return ''; + return str.charAt(0).toUpperCase() + str.slice(1); + }, + toRomanNumerals, }; diff --git a/templates/sheets/shared/components/add-button.hbs b/templates/sheets/shared/components/add-button.hbs index 585d9659..da5a7e58 100644 --- a/templates/sheets/shared/components/add-button.hbs +++ b/templates/sheets/shared/components/add-button.hbs @@ -13,7 +13,7 @@ SPDX-License-Identifier: MIT }} {{#if @root/editable}}