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
This commit is contained in:
parent
0c843df4a7
commit
83084252cc
|
|
@ -441,6 +441,26 @@ class LoadoutConfig:
|
||||||
else:
|
else:
|
||||||
data['equipped_armor'] = None
|
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
|
# Handle legacy configs
|
||||||
if 'heal_name' not in data:
|
if 'heal_name' not in data:
|
||||||
data['heal_name'] = '-- Custom --'
|
data['heal_name'] = '-- Custom --'
|
||||||
|
|
@ -2186,6 +2206,11 @@ class LoadoutManagerDialog(QDialog):
|
||||||
shots_per_hour=3600, # Default, no longer in UI
|
shots_per_hour=3600, # Default, no longer in UI
|
||||||
hits_per_hour=720, # Default, no longer in UI
|
hits_per_hour=720, # Default, no longer in UI
|
||||||
heals_per_hour=60, # 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):
|
def _set_config(self, config: LoadoutConfig):
|
||||||
|
|
@ -2232,6 +2257,16 @@ class LoadoutManagerDialog(QDialog):
|
||||||
# Legacy or empty
|
# Legacy or empty
|
||||||
self._on_clear_armor()
|
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()
|
self._update_armor_summary()
|
||||||
|
|
||||||
# Healing
|
# Healing
|
||||||
|
|
|
||||||
|
|
@ -949,18 +949,29 @@ class MainWindow(QMainWindow):
|
||||||
loadout_info = getattr(self, '_session_loadout_info', None)
|
loadout_info = getattr(self, '_session_loadout_info', None)
|
||||||
loadout_name = loadout_info.get('name', 'Default') if loadout_info else "Default"
|
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(
|
self.hud.start_session(
|
||||||
weapon=weapon_name,
|
weapon=weapon_name,
|
||||||
armor=armor_name,
|
armor=armor_name,
|
||||||
fap=healing_name,
|
fap=healing_name,
|
||||||
loadout=loadout_name,
|
loadout=loadout_name,
|
||||||
weapon_dpp=weapon_dpp,
|
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
|
# Set up cost tracker if loadout selected (database-based only)
|
||||||
if loadout_info and loadout_info.get('id'):
|
if loadout_info and loadout_info.get('id') and loadout_info.get('source') == 'db':
|
||||||
self._setup_session_cost_tracker(loadout_info)
|
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}")
|
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_weapon_name = loadout_data.get('weapon_name', 'Unknown')
|
||||||
self._session_armor_name = loadout_data.get('armor_set_name', 'Unknown')
|
self._session_armor_name = loadout_data.get('armor_set_name', 'Unknown')
|
||||||
self._session_healing_name = loadout_data.get('heal_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:
|
else:
|
||||||
self.log_info("Session", "Starting session without loadout")
|
self.log_info("Session", "Starting session without loadout")
|
||||||
self._session_loadout_info = None
|
self._session_loadout_info = None
|
||||||
self._session_weapon_name = None
|
self._session_weapon_name = None
|
||||||
self._session_armor_name = None
|
self._session_armor_name = None
|
||||||
self._session_healing_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
|
# Now start the session
|
||||||
if self.current_project:
|
if self.current_project:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue