From 83084252ccec18f582aa17877df286ca208dbee2 Mon Sep 17 00:00:00 2001 From: LemonNexus Date: Mon, 9 Feb 2026 21:21:32 +0000 Subject: [PATCH] fix: save and load new armor system fields properly - _get_current_config now includes new armor fields - to_dict properly serializes current_armor_decay as string - from_dict properly deserializes new armor fields - _set_config restores new armor fields when loading - Armor decay now flows from LoadoutManager to session --- ui/loadout_manager.py | 35 +++++++++++++++++++++++++++++++++++ ui/main_window.py | 29 ++++++++++++++++++++++++++--- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/ui/loadout_manager.py b/ui/loadout_manager.py index 346a9af..059deb5 100644 --- a/ui/loadout_manager.py +++ b/ui/loadout_manager.py @@ -441,6 +441,26 @@ class LoadoutConfig: else: data['equipped_armor'] = None + # Handle new armor system fields + if 'current_armor_protection' in data and data['current_armor_protection']: + data['current_armor_protection'] = ProtectionProfile.from_dict(data['current_armor_protection']) + else: + data['current_armor_protection'] = ProtectionProfile() + + if 'current_armor_pieces' in data and data['current_armor_pieces']: + from core.armor_system import ArmorPiece + data['current_armor_pieces'] = [ArmorPiece.from_dict(p) for p in data['current_armor_pieces']] + else: + data['current_armor_pieces'] = [] + + if 'current_armor_decay' in data: + try: + data['current_armor_decay'] = Decimal(data['current_armor_decay']) + except: + data['current_armor_decay'] = Decimal("0") + else: + data['current_armor_decay'] = Decimal("0") + # Handle legacy configs if 'heal_name' not in data: data['heal_name'] = '-- Custom --' @@ -2186,6 +2206,11 @@ class LoadoutManagerDialog(QDialog): shots_per_hour=3600, # Default, no longer in UI hits_per_hour=720, # Default, no longer in UI heals_per_hour=60, # Default, no longer in UI + # New armor system fields + current_armor_set_name=self.current_armor_set_name if hasattr(self, 'current_armor_set_name') else "None", + current_armor_pieces=self.current_armor_pieces if hasattr(self, 'current_armor_pieces') else [], + current_armor_protection=self.current_armor_protection if hasattr(self, 'current_armor_protection') else ProtectionProfile(), + current_armor_decay=self.current_armor_decay if hasattr(self, 'current_armor_decay') else Decimal("0"), ) def _set_config(self, config: LoadoutConfig): @@ -2232,6 +2257,16 @@ class LoadoutManagerDialog(QDialog): # Legacy or empty self._on_clear_armor() + # Restore new armor system fields + if hasattr(config, 'current_armor_set_name'): + self.current_armor_set_name = config.current_armor_set_name + if hasattr(config, 'current_armor_pieces'): + self.current_armor_pieces = config.current_armor_pieces + if hasattr(config, 'current_armor_protection'): + self.current_armor_protection = config.current_armor_protection + if hasattr(config, 'current_armor_decay'): + self.current_armor_decay = config.current_armor_decay + self._update_armor_summary() # Healing diff --git a/ui/main_window.py b/ui/main_window.py index dfd5831..e3e1a5f 100644 --- a/ui/main_window.py +++ b/ui/main_window.py @@ -949,18 +949,29 @@ class MainWindow(QMainWindow): loadout_info = getattr(self, '_session_loadout_info', None) loadout_name = loadout_info.get('name', 'Default') if loadout_info else "Default" + # Get cost data from session loadout + cost_per_shot = getattr(self, '_session_cost_per_shot', Decimal('0')) + cost_per_hit = getattr(self, '_session_cost_per_hit', Decimal('0')) + cost_per_heal = getattr(self, '_session_cost_per_heal', Decimal('0')) + self.hud.start_session( weapon=weapon_name, armor=armor_name, fap=healing_name, loadout=loadout_name, weapon_dpp=weapon_dpp, - weapon_cost_per_hour=weapon_cost_per_hour + weapon_cost_per_hour=weapon_cost_per_hour, + cost_per_shot=cost_per_shot, + cost_per_hit=cost_per_hit, + cost_per_heal=cost_per_heal ) - # Set up cost tracker if loadout selected - if loadout_info and loadout_info.get('id'): + # Set up cost tracker if loadout selected (database-based only) + if loadout_info and loadout_info.get('id') and loadout_info.get('source') == 'db': self._setup_session_cost_tracker(loadout_info) + else: + # For JSON-based loadouts, use manual cost tracking based on extracted values + self.log_info("CostTracker", "Using manual cost tracking for file-based loadout") self.log_info("HUD", f"HUD shown - Weapon: {weapon_name}, Armor: {armor_name}, Healing: {healing_name}, Loadout: {loadout_name}") @@ -1249,12 +1260,24 @@ class MainWindow(QMainWindow): self._session_weapon_name = loadout_data.get('weapon_name', 'Unknown') self._session_armor_name = loadout_data.get('armor_set_name', 'Unknown') self._session_healing_name = loadout_data.get('heal_name', 'Unknown') + + # Extract cost data for session tracking (even for JSON-based loadouts) + from decimal import Decimal + self._session_cost_per_shot = Decimal(str(loadout_data.get('weapon_decay_pec', 0))) / Decimal('100') + \ + Decimal(str(loadout_data.get('weapon_ammo_pec', 0))) * Decimal('0.0001') + self._session_cost_per_hit = Decimal(str(loadout_data.get('armor_decay_pec', 0))) / Decimal('100') + self._session_cost_per_heal = Decimal(str(loadout_data.get('heal_cost_pec', 0))) / Decimal('100') + + self.log_info("SessionCosts", f"Cost/Shot: {self._session_cost_per_shot:.4f}, Cost/Hit: {self._session_cost_per_hit:.4f}, Cost/Heal: {self._session_cost_per_heal:.4f}") else: self.log_info("Session", "Starting session without loadout") self._session_loadout_info = None self._session_weapon_name = None self._session_armor_name = None self._session_healing_name = None + self._session_cost_per_shot = None + self._session_cost_per_hit = None + self._session_cost_per_heal = None # Now start the session if self.current_project: