Fixes #20: After change errors (JSON parse + equipment tab) #21

Merged
Pakobbix merged 3 commits from issue-20-fix-json-parse-equipment into main 2026-07-12 16:22:01 +00:00
4 changed files with 29 additions and 5 deletions
+3
View File
@@ -349,6 +349,9 @@ jQuery(async () => {
initThoughtBasedExpressions(); initThoughtBasedExpressions();
updateFabWidgets(); updateFabWidgets();
updateStripWidgets(); updateStripWidgets();
// Ensure section visibility matches settings (equipment is hidden by CSS, needs explicit .show())
updateSectionVisibility();
renderEquipment();
} catch (error) { } catch (error) {
console.error('[RPG Companion] Chat data load failed, using defaults:', error); console.error('[RPG Companion] Chat data load failed, using defaults:', error);
} }
+19
View File
@@ -146,10 +146,29 @@ function generateEquipmentHTML() {
* Gets data from state/settings and updates DOM directly. * Gets data from state/settings and updates DOM directly.
*/ */
export function renderEquipment() { export function renderEquipment() {
// Ensure showEquipment defaults to true if undefined
if (extensionSettings.showEquipment === undefined) {
extensionSettings.showEquipment = true;
}
if (!$equipmentContainer || !extensionSettings.showEquipment) { if (!$equipmentContainer || !extensionSettings.showEquipment) {
return; 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(); const html = generateEquipmentHTML();
updateIfChanged($equipmentContainer, html, 'rpg-equipment'); updateIfChanged($equipmentContainer, html, 'rpg-equipment');
+3 -2
View File
@@ -6,6 +6,7 @@
import { i18n } from '../../core/i18n.js'; import { i18n } from '../../core/i18n.js';
import { extensionSettings, lastGeneratedData, committedTrackerData } from '../../core/state.js'; import { extensionSettings, lastGeneratedData, committedTrackerData } from '../../core/state.js';
import { hexToRgba } from './theme.js'; import { hexToRgba } from './theme.js';
import { repairJSON } from '../../utils/jsonRepair.js';
/** /**
* Helper to parse time string and calculate clock hand angles * Helper to parse time string and calculate clock hand angles
@@ -50,7 +51,7 @@ export function updateStripWidgets() {
let infoData = null; let infoData = null;
if (infoBox) { if (infoBox) {
try { try {
infoData = typeof infoBox === 'string' ? JSON.parse(infoBox) : infoBox; infoData = typeof infoBox === 'string' ? repairJSON(infoBox) : infoBox;
} catch (e) { } catch (e) {
console.warn('[RPG Strip Widgets] Failed to parse infoBox:', e); console.warn('[RPG Strip Widgets] Failed to parse infoBox:', e);
} }
@@ -124,7 +125,7 @@ export function updateStripWidgets() {
const userStatsData = lastGeneratedData?.userStats || committedTrackerData?.userStats; const userStatsData = lastGeneratedData?.userStats || committedTrackerData?.userStats;
if (userStatsData) { if (userStatsData) {
try { try {
const parsedStats = typeof userStatsData === 'string' ? JSON.parse(userStatsData) : userStatsData; const parsedStats = typeof userStatsData === 'string' ? repairJSON(userStatsData) : userStatsData;
if (parsedStats?.stats) { if (parsedStats?.stats) {
allStats = parsedStats.stats; allStats = parsedStats.stats;
} }
+4 -3
View File
@@ -9,6 +9,7 @@ import { closeMobilePanelWithAnimation, updateCollapseToggleIcon } from './layou
import { setupDesktopTabs, removeDesktopTabs } from './desktop.js'; import { setupDesktopTabs, removeDesktopTabs } from './desktop.js';
import { i18n } from '../../core/i18n.js'; import { i18n } from '../../core/i18n.js';
import { hexToRgba } from './theme.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. * Updates the text labels of the mobile navigation tabs based on the current language.
@@ -1322,7 +1323,7 @@ export function updateFabWidgets() {
let infoData = null; let infoData = null;
if (infoBox) { if (infoBox) {
try { try {
infoData = typeof infoBox === 'string' ? JSON.parse(infoBox) : infoBox; infoData = typeof infoBox === 'string' ? repairJSON(infoBox) : infoBox;
} catch (e) { } catch (e) {
console.warn('[RPG FAB Widgets] Failed to parse infoBox:', e); console.warn('[RPG FAB Widgets] Failed to parse infoBox:', e);
} }
@@ -1332,7 +1333,7 @@ export function updateFabWidgets() {
let statsData = null; let statsData = null;
if (userStats) { if (userStats) {
try { try {
statsData = typeof userStats === 'string' ? JSON.parse(userStats) : userStats; statsData = typeof userStats === 'string' ? repairJSON(userStats) : userStats;
} catch (e) { } catch (e) {
console.warn('[RPG FAB Widgets] Failed to parse userStats:', e); console.warn('[RPG FAB Widgets] Failed to parse userStats:', e);
} }
@@ -1444,7 +1445,7 @@ export function updateFabWidgets() {
let allStats = []; let allStats = [];
try { try {
const userStatsJson = extensionSettings.userStats; const userStatsJson = extensionSettings.userStats;
const parsedUserStats = typeof userStatsJson === 'string' ? JSON.parse(userStatsJson) : userStatsJson; const parsedUserStats = typeof userStatsJson === 'string' ? repairJSON(userStatsJson) : userStatsJson;
if (parsedUserStats?.stats) { if (parsedUserStats?.stats) {
allStats = parsedUserStats.stats; allStats = parsedUserStats.stats;
} }