fix: add missing _session_costs initialization and verbose debug logging
- Initialize _session_costs and _session_display in __init__ (was causing crashes) - Add [EVENT], [HUD], [DEBUG], [ERROR] prefix logging to all event handlers - Add traceback logging for better debugging - Add debug logging to all HUD update methods - Log session_active state in HUD methods
This commit is contained in:
parent
b8bd462d09
commit
818d0f98f3
|
|
@ -839,6 +839,7 @@ class HUDOverlay(QWidget):
|
|||
|
||||
def update_loot(self, value_ped: Decimal, is_shrapnel: bool = False):
|
||||
"""Update loot value - tracks per-kill totals for highest loot."""
|
||||
logger.debug(f"[HUD] update_loot called: value={value_ped}, is_shrapnel={is_shrapnel}, session_active={self.session_active}")
|
||||
if self.session_active:
|
||||
now = datetime.now()
|
||||
|
||||
|
|
@ -868,6 +869,7 @@ class HUDOverlay(QWidget):
|
|||
|
||||
self._stats.recalculate()
|
||||
self._refresh_display()
|
||||
logger.debug(f"[HUD] update_loot complete: shrapnel={self._stats.shrapnel_total}, other={self._stats.loot_other}")
|
||||
|
||||
def update_shrapnel(self, amount: Decimal):
|
||||
"""Update shrapnel amount (convenience method)."""
|
||||
|
|
@ -875,6 +877,7 @@ class HUDOverlay(QWidget):
|
|||
|
||||
def update_weapon_cost(self, cost_ped: Decimal):
|
||||
"""Update weapon cost."""
|
||||
logger.debug(f"[HUD] update_weapon_cost called: cost={cost_ped}, session_active={self.session_active}")
|
||||
if self.session_active:
|
||||
self._stats.weapon_cost_total += cost_ped
|
||||
self._stats.cost_total += cost_ped
|
||||
|
|
@ -883,6 +886,7 @@ class HUDOverlay(QWidget):
|
|||
|
||||
def update_armor_cost(self, cost_ped: Decimal):
|
||||
"""Update armor cost."""
|
||||
logger.debug(f"[HUD] update_armor_cost called: cost={cost_ped}, session_active={self.session_active}")
|
||||
if self.session_active:
|
||||
self._stats.armor_cost_total += cost_ped
|
||||
self._stats.cost_total += cost_ped
|
||||
|
|
@ -891,6 +895,7 @@ class HUDOverlay(QWidget):
|
|||
|
||||
def update_healing_cost(self, cost_ped: Decimal):
|
||||
"""Update healing cost."""
|
||||
logger.debug(f"[HUD] update_healing_cost called: cost={cost_ped}, session_active={self.session_active}")
|
||||
if self.session_active:
|
||||
self._stats.healing_cost_total += cost_ped
|
||||
self._stats.cost_total += cost_ped
|
||||
|
|
@ -899,6 +904,7 @@ class HUDOverlay(QWidget):
|
|||
|
||||
def update_kills(self, count: int = 1):
|
||||
"""Update kill count."""
|
||||
logger.debug(f"[HUD] update_kills called: count={count}, session_active={self.session_active}")
|
||||
if self.session_active:
|
||||
self._stats.kills += count
|
||||
self._refresh_display()
|
||||
|
|
|
|||
|
|
@ -280,6 +280,18 @@ class MainWindow(QMainWindow):
|
|||
self._selected_medical_tool_stats: Optional[dict] = None
|
||||
self._selected_loadout: Optional[Any] = None
|
||||
|
||||
# Session cost tracking (initialized empty, populated by loadout selection)
|
||||
self._session_costs: dict = {
|
||||
'cost_per_shot': Decimal('0'),
|
||||
'cost_per_hit': Decimal('0'),
|
||||
'cost_per_heal': Decimal('0'),
|
||||
}
|
||||
self._session_display: dict = {
|
||||
'weapon_name': 'None',
|
||||
'armor_name': 'None',
|
||||
'healing_name': 'None',
|
||||
}
|
||||
|
||||
# Setup UI
|
||||
self.setup_ui()
|
||||
self.apply_dark_theme()
|
||||
|
|
@ -1004,6 +1016,7 @@ class MainWindow(QMainWindow):
|
|||
Calculates healing cost based on FAP decay and updates HUD.
|
||||
"""
|
||||
heal_amount = event.data.get('heal_amount', Decimal('0'))
|
||||
logger.debug(f"[EVENT] on_heal: heal_amount={heal_amount}")
|
||||
|
||||
# Calculate heal cost based on selected medical tool decay
|
||||
# Get decay per heal from loadout or use default
|
||||
|
|
@ -1021,16 +1034,23 @@ class MainWindow(QMainWindow):
|
|||
|
||||
# Update HUD with heal event
|
||||
try:
|
||||
logger.debug(f"[DEBUG] _session_costs={self._session_costs}")
|
||||
# Track healing cost
|
||||
if self._session_costs:
|
||||
cost_per_heal = self._session_costs.get('cost_per_heal', Decimal('0'))
|
||||
logger.debug(f"[DEBUG] cost_per_heal={cost_per_heal}")
|
||||
if cost_per_heal > 0:
|
||||
logger.debug(f"[HUD] update_healing_cost({cost_per_heal})")
|
||||
self.hud.update_healing_cost(cost_per_heal)
|
||||
|
||||
# Track heal amount (as event dict for new HUD)
|
||||
logger.debug(f"[HUD] on_heal_event({{'heal_amount': {heal_amount}}})")
|
||||
self.hud.on_heal_event({'heal_amount': heal_amount})
|
||||
logger.debug(f"[HUD] Heal update successful")
|
||||
except Exception as e:
|
||||
logger.error(f"Error updating HUD heal: {e}")
|
||||
logger.error(f"[ERROR] Error updating HUD heal: {e}")
|
||||
import traceback
|
||||
logger.error(traceback.format_exc())
|
||||
|
||||
# Log to UI
|
||||
self.log_info("Heal", f"Healed {heal_amount} HP (Cost: {decay_cost:.4f} PED)")
|
||||
|
|
@ -1043,19 +1063,27 @@ class MainWindow(QMainWindow):
|
|||
value_ped = event.data.get('value_ped', Decimal('0.0'))
|
||||
quantity = event.data.get('quantity', 1)
|
||||
|
||||
logger.debug(f"[EVENT] on_loot: item={item_name}, value={value_ped}, qty={quantity}")
|
||||
|
||||
# Skip Universal Ammo
|
||||
if item_name == 'Universal Ammo':
|
||||
logger.debug("[EVENT] on_loot: skipped Universal Ammo")
|
||||
return
|
||||
|
||||
try:
|
||||
# Update kill count (each loot event = 1 kill)
|
||||
logger.debug(f"[HUD] update_kills(1)")
|
||||
self.hud.update_kills(1)
|
||||
|
||||
# Update loot value
|
||||
is_shrapnel = 'shrapnel' in item_name.lower()
|
||||
logger.debug(f"[HUD] update_loot({value_ped}, is_shrapnel={is_shrapnel})")
|
||||
self.hud.update_loot(value_ped, is_shrapnel=is_shrapnel)
|
||||
logger.debug(f"[HUD] Loot update successful")
|
||||
except Exception as e:
|
||||
logger.error(f"Error updating HUD loot: {e}")
|
||||
logger.error(f"[ERROR] Error updating HUD loot: {e}")
|
||||
import traceback
|
||||
logger.error(traceback.format_exc())
|
||||
|
||||
# Queue database write for main thread (SQLite thread safety)
|
||||
if self._current_db_session_id:
|
||||
|
|
@ -1114,17 +1142,24 @@ class MainWindow(QMainWindow):
|
|||
from decimal import Decimal
|
||||
try:
|
||||
damage = event.data.get('damage', 0)
|
||||
logger.debug(f"[EVENT] on_damage_dealt: damage={damage}")
|
||||
if damage:
|
||||
# Track damage amount
|
||||
logger.debug(f"[HUD] on_damage_dealt({damage})")
|
||||
self.hud.on_damage_dealt(Decimal(str(damage)))
|
||||
|
||||
# Track weapon cost per shot
|
||||
logger.debug(f"[DEBUG] _session_costs={self._session_costs}")
|
||||
if self._session_costs:
|
||||
cost_per_shot = self._session_costs.get('cost_per_shot', Decimal('0'))
|
||||
logger.debug(f"[DEBUG] cost_per_shot={cost_per_shot}")
|
||||
if cost_per_shot > 0:
|
||||
logger.debug(f"[HUD] update_weapon_cost({cost_per_shot})")
|
||||
self.hud.update_weapon_cost(cost_per_shot)
|
||||
except Exception as e:
|
||||
logger.error(f"Error in on_damage_dealt: {e}")
|
||||
logger.error(f"[ERROR] Error in on_damage_dealt: {e}")
|
||||
import traceback
|
||||
logger.error(traceback.format_exc())
|
||||
|
||||
def on_critical_hit(event):
|
||||
"""Handle critical hit - same as damage dealt."""
|
||||
|
|
@ -1138,17 +1173,24 @@ class MainWindow(QMainWindow):
|
|||
from decimal import Decimal
|
||||
try:
|
||||
damage = event.data.get('damage', 0)
|
||||
logger.debug(f"[EVENT] on_damage_taken: damage={damage}")
|
||||
if damage:
|
||||
# Track damage amount
|
||||
logger.debug(f"[HUD] on_damage_taken({damage})")
|
||||
self.hud.on_damage_taken(Decimal(str(damage)))
|
||||
|
||||
# Track armor cost per hit
|
||||
logger.debug(f"[DEBUG] _session_costs={self._session_costs}")
|
||||
if self._session_costs:
|
||||
cost_per_hit = self._session_costs.get('cost_per_hit', Decimal('0'))
|
||||
logger.debug(f"[DEBUG] cost_per_hit={cost_per_hit}")
|
||||
if cost_per_hit > 0:
|
||||
logger.debug(f"[HUD] update_armor_cost({cost_per_hit})")
|
||||
self.hud.update_armor_cost(cost_per_hit)
|
||||
except Exception as e:
|
||||
logger.error(f"Error in on_damage_taken: {e}")
|
||||
logger.error(f"[ERROR] Error in on_damage_taken: {e}")
|
||||
import traceback
|
||||
logger.error(traceback.format_exc())
|
||||
|
||||
def on_evade(event):
|
||||
"""Handle evade."""
|
||||
|
|
|
|||
Loading…
Reference in New Issue