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
This commit is contained in:
@@ -96,6 +96,7 @@ import {
|
|||||||
|
|
||||||
// Feature modules
|
// Feature modules
|
||||||
import { setupPlotButtons } from './src/systems/features/plotProgression.js';
|
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
|
// Old state variable declarations removed - now imported from core modules
|
||||||
// (extensionSettings, lastGeneratedData, committedTrackerData, etc. are now in src/core/state.js)
|
// (extensionSettings, lastGeneratedData, committedTrackerData, etc. are now in src/core/state.js)
|
||||||
@@ -357,37 +358,6 @@ async function initUI() {
|
|||||||
setupContentEditableScrolling();
|
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.
|
* Sends a plot progression request and appends the result to the last message.
|
||||||
|
|||||||
@@ -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]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user