feat(dashboard): integrate User Attributes widget with trackerConfig.rpgAttributes

Integrates the User Attributes Widget with upstream's new RPG attributes
customization system, enabling full attribute customization (add/remove/rename)
with bi-directional sync between widget and Tracker Editor.

Changes to userAttributesWidget.js:

1. render() method (lines 44-106):
   - Read from trackerConfig.userStats.rpgAttributes (not hardcoded)
   - Filter to enabled attributes only
   - Use custom attr.name for labels (e.g., "STRENGTH" vs "STR")
   - Support widget-level visibleAttrs filtering
   - Support legacy visibleStats config for backward compat
   - Fallback to default 6 attributes if no config

2. getConfig() method (lines 112-143):
   - Dynamically generate options from enabled attributes
   - Changed visibleStats → visibleAttrs (with legacy support)
   - Set default to null (show all enabled attributes)
   - Add hint: "To add/remove/rename attributes globally, use Tracker Settings"

3. getOptimalSize() method (lines 179-199):
   - Calculate height based on enabled attribute count (not hardcoded 6)
   - Respect widget-level visibleAttrs override if specified
   - Support legacy visibleStats parameter

4. Widget description updated:
   - Header docs: Added customization features, bi-directional sync
   - Registry description: "Customizable RPG attributes" instead of "Classic RPG stats"

Changes to dashboardManager.js:

1. shouldWidgetBeRemoved() (lines 1976-1984):
   - Add 'userAttributes' removal rule
   - Remove if showRPGAttributes === false
   - Remove if all attributes disabled

2. detectConfigChanges() (lines 1743-1752):
   - Detect when RPG Attributes section re-enabled
   - Detect when attributes re-enabled
   - Auto-add widget when conditions met

Integration Benefits:
 Custom attribute names (e.g., "STRENGTH", "AGILITY", "LUCK")
 Add custom attributes (e.g., "LCK", "PER", "APP")
 Remove unwanted default attributes
 Widget auto-updates when tracker config changes
 Widget auto-removed when section/attrs disabled
 Widget auto-added when section/attrs re-enabled
 Widget-level filtering (show subset of enabled attrs)
 Backward compatible with existing dashboards

Testing Required:
- Widget renders with default attributes
- Widget respects custom attribute names
- Widget supports custom attributes (e.g., adding "LCK")
- Widget removed when section disabled
- Widget re-added when section re-enabled
- +/- buttons work with custom attributes
- AI prompts use custom attribute names

Follows pattern from: userStatsWidget.js (lines 51-78)
Related: commit a02be34 (upstream merge)
This commit is contained in:
Lucas 'Paperboy' Rose-Winters
2025-11-04 10:00:07 +11:00
parent a02be34827
commit 724281b6bb
2 changed files with 96 additions and 28 deletions
+20
View File
@@ -1740,6 +1740,17 @@ export class DashboardManager {
console.log('[DashboardManager] Detected re-enabled userStats widget');
}
// Check userAttributes widget (enabled when RPG Attributes section is enabled AND at least one attribute is enabled)
const oldAttrsDisabled = oldConfig.userStats?.showRPGAttributes === false ||
(oldConfig.userStats?.rpgAttributes?.filter(a => a.enabled).length || 0) === 0;
const newAttrsEnabled = newConfig.userStats?.showRPGAttributes !== false &&
(newConfig.userStats?.rpgAttributes?.filter(a => a.enabled).length || 0) > 0;
if (oldAttrsDisabled && newAttrsEnabled) {
widgetsToAdd.push('userAttributes');
console.log('[DashboardManager] Detected re-enabled userAttributes widget');
}
// Check presentCharacters widget
const wasThoughtsDisabled = oldConfig.presentCharacters?.thoughts?.enabled === false;
const isThoughtsEnabled = newConfig.presentCharacters?.thoughts?.enabled !== false;
@@ -1973,6 +1984,15 @@ export class DashboardManager {
const customStats = config.userStats?.customStats || [];
return customStats.filter(s => s.enabled).length === 0;
},
'userAttributes': () => {
// Remove if RPG Attributes section is disabled
if (config.userStats?.showRPGAttributes === false) {
return true;
}
// Remove if all attributes are disabled
const rpgAttrs = config.userStats?.rpgAttributes || [];
return rpgAttrs.filter(attr => attr.enabled).length === 0;
},
'presentCharacters': () => config.presentCharacters?.thoughts?.enabled === false
};