From 40c70bfbe11cf2178a3f6b110f4fd7a0ecfc4469 Mon Sep 17 00:00:00 2001 From: JesseRWeigel Date: Mon, 16 Mar 2026 13:25:49 -0400 Subject: [PATCH] fix: equipment crash on old saves and music lifecycle - Guard p.equipment access with fallback to empty object, fixing "Cannot read properties of undefined (reading 'weapon')" crash when loading saves from before equipment system was added - Play combat music when entering a gate - Resume ambient music when dismissing combat results - Start ambient music 2s after game loads Co-Authored-By: Claude Opus 4.6 (1M context) --- client/src/components/game/HuntersPath.tsx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/client/src/components/game/HuntersPath.tsx b/client/src/components/game/HuntersPath.tsx index 4472b64..4aa4af2 100644 --- a/client/src/components/game/HuntersPath.tsx +++ b/client/src/components/game/HuntersPath.tsx @@ -998,6 +998,12 @@ export default function HuntersPath() { return () => clearTimeout(timer); }, []); // Only run once on mount + // Start ambient music on mount + useEffect(() => { + const timer = setTimeout(() => playMusic("ambient_music"), 2000); + return () => clearTimeout(timer); + }, []); // eslint-disable-line react-hooks/exhaustive-deps + // Periodic save for ancillary data (daily quests, statistics, prestige) useEffect(() => { const autoSaveInterval = setInterval(() => { @@ -2105,6 +2111,7 @@ export default function HuntersPath() { const initLog = dialogueLine ? [dialogueLine] : []; setCombatLog(initLog); setCombatResult(null); + playMusic("combat_music"); combatDamageDealtRef.current = 0; combatDamageTakenRef.current = 0; @@ -2465,6 +2472,7 @@ export default function HuntersPath() { setCombatResult(null); setRunning(null); // Clear the combat state setCombatLog([]); // Clear the combat log + playMusic("ambient_music"); // Resume ambient music after combat } function triggerVisualEffect(effect: keyof typeof visualEffects) { @@ -3116,12 +3124,11 @@ export default function HuntersPath() { } // Create new equipment object with explicit copying + const eq = p.equipment || {}; const newEquipment = { - weapon: p.equipment.weapon ? { ...p.equipment.weapon } : undefined, - armor: p.equipment.armor ? { ...p.equipment.armor } : undefined, - accessory: p.equipment.accessory - ? { ...p.equipment.accessory } - : undefined, + weapon: eq.weapon ? { ...eq.weapon } : undefined, + armor: eq.armor ? { ...eq.armor } : undefined, + accessory: eq.accessory ? { ...eq.accessory } : undefined, }; // Set the new item