From 4bd29a207a813e50fa557e1067f433d0eed738ae Mon Sep 17 00:00:00 2001 From: ARIA Date: Sun, 12 Jul 2026 17:33:08 +0200 Subject: [PATCH 1/3] Fixes #20: Fix JSON parse errors and empty equipment tab - Replace JSON.parse() with repairJSON() in desktop.js and mobile.js to handle malformed JSON from infoBox/userStats data - Add defensive initialization in renderEquipment(): ensure showEquipment defaults to true and equipment data structure exists - Add explicit renderEquipment() call during initialization --- index.js | 2 ++ src/systems/rendering/equipment.js | 19 +++++++++++++++++++ src/systems/ui/desktop.js | 5 +++-- src/systems/ui/mobile.js | 7 ++++--- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 1db8294..c298000 100644 --- a/index.js +++ b/index.js @@ -349,6 +349,8 @@ jQuery(async () => { initThoughtBasedExpressions(); updateFabWidgets(); updateStripWidgets(); + // Explicit initial render of equipment to ensure it's visible + renderEquipment(); } catch (error) { console.error('[RPG Companion] Chat data load failed, using defaults:', error); } diff --git a/src/systems/rendering/equipment.js b/src/systems/rendering/equipment.js index 4bd0c6c..efb934c 100644 --- a/src/systems/rendering/equipment.js +++ b/src/systems/rendering/equipment.js @@ -146,10 +146,29 @@ function generateEquipmentHTML() { * Gets data from state/settings and updates DOM directly. */ export function renderEquipment() { + // Ensure showEquipment defaults to true if undefined + if (extensionSettings.showEquipment === undefined) { + extensionSettings.showEquipment = true; + } + if (!$equipmentContainer || !extensionSettings.showEquipment) { return; } + // Ensure equipment data structure exists (defensive initialization) + if (!extensionSettings.userStats?.equipment) { + extensionSettings.userStats = extensionSettings.userStats || {}; + extensionSettings.userStats.equipment = { + items: [], + slots: { + helmet: null, ring1: null, ring2: null, ring3: null, ring4: null, + ring5: null, ring6: null, ring7: null, ring8: null, ring9: null, ring10: null, + necklace: null, bodyArmor: null, pants: null, shoes: null, gloves: null, + accessory1: null, accessory2: null, accessory3: null + } + }; + } + const html = generateEquipmentHTML(); updateIfChanged($equipmentContainer, html, 'rpg-equipment'); diff --git a/src/systems/ui/desktop.js b/src/systems/ui/desktop.js index edfa5f0..582cf48 100644 --- a/src/systems/ui/desktop.js +++ b/src/systems/ui/desktop.js @@ -6,6 +6,7 @@ import { i18n } from '../../core/i18n.js'; import { extensionSettings, lastGeneratedData, committedTrackerData } from '../../core/state.js'; import { hexToRgba } from './theme.js'; +import { repairJSON } from '../../utils/jsonRepair.js'; /** * Helper to parse time string and calculate clock hand angles @@ -50,7 +51,7 @@ export function updateStripWidgets() { let infoData = null; if (infoBox) { try { - infoData = typeof infoBox === 'string' ? JSON.parse(infoBox) : infoBox; + infoData = typeof infoBox === 'string' ? repairJSON(infoBox) : infoBox; } catch (e) { console.warn('[RPG Strip Widgets] Failed to parse infoBox:', e); } @@ -124,7 +125,7 @@ export function updateStripWidgets() { const userStatsData = lastGeneratedData?.userStats || committedTrackerData?.userStats; if (userStatsData) { try { - const parsedStats = typeof userStatsData === 'string' ? JSON.parse(userStatsData) : userStatsData; + const parsedStats = typeof userStatsData === 'string' ? repairJSON(userStatsData) : userStatsData; if (parsedStats?.stats) { allStats = parsedStats.stats; } diff --git a/src/systems/ui/mobile.js b/src/systems/ui/mobile.js index cf47c5e..60188c6 100644 --- a/src/systems/ui/mobile.js +++ b/src/systems/ui/mobile.js @@ -9,6 +9,7 @@ import { closeMobilePanelWithAnimation, updateCollapseToggleIcon } from './layou import { setupDesktopTabs, removeDesktopTabs } from './desktop.js'; import { i18n } from '../../core/i18n.js'; import { hexToRgba } from './theme.js'; +import { repairJSON } from '../../utils/jsonRepair.js'; /** * Updates the text labels of the mobile navigation tabs based on the current language. @@ -1322,7 +1323,7 @@ export function updateFabWidgets() { let infoData = null; if (infoBox) { try { - infoData = typeof infoBox === 'string' ? JSON.parse(infoBox) : infoBox; + infoData = typeof infoBox === 'string' ? repairJSON(infoBox) : infoBox; } catch (e) { console.warn('[RPG FAB Widgets] Failed to parse infoBox:', e); } @@ -1332,7 +1333,7 @@ export function updateFabWidgets() { let statsData = null; if (userStats) { try { - statsData = typeof userStats === 'string' ? JSON.parse(userStats) : userStats; + statsData = typeof userStats === 'string' ? repairJSON(userStats) : userStats; } catch (e) { console.warn('[RPG FAB Widgets] Failed to parse userStats:', e); } @@ -1444,7 +1445,7 @@ export function updateFabWidgets() { let allStats = []; try { const userStatsJson = extensionSettings.userStats; - const parsedUserStats = typeof userStatsJson === 'string' ? JSON.parse(userStatsJson) : userStatsJson; + const parsedUserStats = typeof userStatsJson === 'string' ? repairJSON(userStatsJson) : userStatsJson; if (parsedUserStats?.stats) { allStats = parsedUserStats.stats; } -- 2.54.0 From 59b125fd2aa7f58f663a406d77ed9eba597297be Mon Sep 17 00:00:00 2001 From: ARIA Date: Sun, 12 Jul 2026 17:56:35 +0200 Subject: [PATCH 2/3] Fixes #20: Call updateSectionVisibility() during init to show equipment tab The equipment section has display:none in CSS and updateSectionVisibility() is the only function that calls .show() on it. It was never called during initialization, only when settings toggles changed. Added the call to the main init flow so the equipment tab becomes visible on page load. --- index.js | 3 ++- src/systems/ui/desktop.js | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index c298000..b6eade4 100644 --- a/index.js +++ b/index.js @@ -349,7 +349,8 @@ jQuery(async () => { initThoughtBasedExpressions(); updateFabWidgets(); updateStripWidgets(); - // Explicit initial render of equipment to ensure it's visible + // Ensure section visibility matches settings (equipment is hidden by CSS, needs explicit .show()) + updateSectionVisibility(); renderEquipment(); } catch (error) { console.error('[RPG Companion] Chat data load failed, using defaults:', error); diff --git a/src/systems/ui/desktop.js b/src/systems/ui/desktop.js index 582cf48..2a847b0 100644 --- a/src/systems/ui/desktop.js +++ b/src/systems/ui/desktop.js @@ -7,6 +7,7 @@ import { i18n } from '../../core/i18n.js'; import { extensionSettings, lastGeneratedData, committedTrackerData } from '../../core/state.js'; import { hexToRgba } from './theme.js'; import { repairJSON } from '../../utils/jsonRepair.js'; +import { invalidateCache } from './renderUtils.js'; /** * Helper to parse time string and calculate clock hand angles -- 2.54.0 From 28ef82aae722836d17e29197473b8b428ecf33f3 Mon Sep 17 00:00:00 2001 From: ARIA Date: Sun, 12 Jul 2026 18:14:59 +0200 Subject: [PATCH 3/3] Fix: remove broken import in desktop.js that caused 404 and extension load failure --- src/systems/ui/desktop.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/systems/ui/desktop.js b/src/systems/ui/desktop.js index 2a847b0..582cf48 100644 --- a/src/systems/ui/desktop.js +++ b/src/systems/ui/desktop.js @@ -7,7 +7,6 @@ import { i18n } from '../../core/i18n.js'; import { extensionSettings, lastGeneratedData, committedTrackerData } from '../../core/state.js'; import { hexToRgba } from './theme.js'; import { repairJSON } from '../../utils/jsonRepair.js'; -import { invalidateCache } from './renderUtils.js'; /** * Helper to parse time string and calculate clock hand angles -- 2.54.0