From 3473f2ac44bc3abeb3d47bbca2d32280edf174ad Mon Sep 17 00:00:00 2001 From: Lucas 'Paperboy' Rose-Winters Date: Fri, 17 Oct 2025 13:45:36 +1100 Subject: [PATCH] refactor(features): extract classic stats controls to standalone module Extract setupClassicStatsButtons into src/systems/features/classicStats.js. This module handles the delegated event listeners for classic RPG stat +/- buttons (STR, DEX, CON, INT, WIS, CHA). - Create classicStats.js with event delegation for stat buttons - Update index.js to import and use the new module - Maintain backward compatibility with existing functionality --- index.js | 32 +-------------------- src/systems/features/classicStats.js | 42 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 31 deletions(-) create mode 100644 src/systems/features/classicStats.js diff --git a/index.js b/index.js index 3b8146e..20eb581 100644 --- a/index.js +++ b/index.js @@ -96,6 +96,7 @@ import { // Feature modules import { setupPlotButtons } from './src/systems/features/plotProgression.js'; +import { setupClassicStatsButtons } from './src/systems/features/classicStats.js'; // Old state variable declarations removed - now imported from core modules // (extensionSettings, lastGeneratedData, committedTrackerData, etc. are now in src/core/state.js) @@ -357,37 +358,6 @@ async function initUI() { setupContentEditableScrolling(); } -/** - * Sets up event listeners for classic stat +/- buttons using delegation. - * Uses delegated events to persist across re-renders of the stats section. - */ -function setupClassicStatsButtons() { - if (!$userStatsContainer) return; - - // Delegated event listener for increase buttons - $userStatsContainer.on('click', '.rpg-stat-increase', function() { - const stat = $(this).data('stat'); - if (extensionSettings.classicStats[stat] < 100) { - extensionSettings.classicStats[stat]++; - saveSettings(); - saveChatData(); - // Update only the specific stat value, not the entire stats panel - $(this).closest('.rpg-classic-stat').find('.rpg-classic-stat-value').text(extensionSettings.classicStats[stat]); - } - }); - - // Delegated event listener for decrease buttons - $userStatsContainer.on('click', '.rpg-stat-decrease', function() { - const stat = $(this).data('stat'); - if (extensionSettings.classicStats[stat] > 1) { - extensionSettings.classicStats[stat]--; - saveSettings(); - saveChatData(); - // Update only the specific stat value, not the entire stats panel - $(this).closest('.rpg-classic-stat').find('.rpg-classic-stat-value').text(extensionSettings.classicStats[stat]); - } - }); -} /** * Sends a plot progression request and appends the result to the last message. diff --git a/src/systems/features/classicStats.js b/src/systems/features/classicStats.js new file mode 100644 index 0000000..281f1c4 --- /dev/null +++ b/src/systems/features/classicStats.js @@ -0,0 +1,42 @@ +/** + * Classic Stats Module + * Handles classic RPG stat buttons (STR, DEX, CON, INT, WIS, CHA) +/- controls + */ + +import { + extensionSettings, + $userStatsContainer +} from '../../core/state.js'; +import { saveSettings, saveChatData } from '../../core/persistence.js'; + +/** + * Sets up event listeners for classic stat +/- buttons using delegation. + * Uses delegated events to persist across re-renders of the stats section. + */ +export function setupClassicStatsButtons() { + if (!$userStatsContainer) return; + + // Delegated event listener for increase buttons + $userStatsContainer.on('click', '.rpg-stat-increase', function() { + const stat = $(this).data('stat'); + if (extensionSettings.classicStats[stat] < 100) { + extensionSettings.classicStats[stat]++; + saveSettings(); + saveChatData(); + // Update only the specific stat value, not the entire stats panel + $(this).closest('.rpg-classic-stat').find('.rpg-classic-stat-value').text(extensionSettings.classicStats[stat]); + } + }); + + // Delegated event listener for decrease buttons + $userStatsContainer.on('click', '.rpg-stat-decrease', function() { + const stat = $(this).data('stat'); + if (extensionSettings.classicStats[stat] > 1) { + extensionSettings.classicStats[stat]--; + saveSettings(); + saveChatData(); + // Update only the specific stat value, not the entire stats panel + $(this).closest('.rpg-classic-stat').find('.rpg-classic-stat-value').text(extensionSettings.classicStats[stat]); + } + }); +}