From 4ef03d96c8b7736ad6c743b25592c079edd309c6 Mon Sep 17 00:00:00 2001 From: LemonNexus Date: Mon, 9 Feb 2026 17:07:31 +0000 Subject: [PATCH] fix(api): improve NexusAttachment field parsing for weapon amplifiers - Updated from_api() to check multiple possible field names - Added fallback checks for Damage, Range, Decay, Efficiency fields - Type detection from both API Type field and item name - Improved display formatting in attachment selector --- core/nexus_full_api.py | 61 +++++++++++++++++++++++++++++++++++---- ui/attachment_selector.py | 25 +++++++++++++--- 2 files changed, 77 insertions(+), 9 deletions(-) diff --git a/core/nexus_full_api.py b/core/nexus_full_api.py index f955f3b..689f7f2 100644 --- a/core/nexus_full_api.py +++ b/core/nexus_full_api.py @@ -158,17 +158,68 @@ class NexusAttachment(NexusItem): def from_api(cls, data: Dict[str, Any]) -> "NexusAttachment": """Create from API response.""" props = data.get('Properties', {}) + + # Debug: Log available properties + logger.debug(f"Attachment {data.get('Name')} properties: {props.keys()}") + + # Try multiple possible field names for each stat + # Damage bonus might be in Damage, DamageBonus, or DamageIncrease + damage_bonus = Decimal("0") + for key in ['Damage', 'DamageBonus', 'DamageIncrease', 'dmg', 'damage']: + if key in props and props[key] is not None: + damage_bonus = safe_decimal(props[key]) + break + + # Range bonus + range_bonus = Decimal("0") + for key in ['Range', 'RangeBonus', 'RangeIncrease', 'range']: + if key in props and props[key] is not None: + range_bonus = safe_decimal(props[key]) + break + + # Decay - check in Economy dict or top-level + decay = Decimal("0") + if 'Economy' in props and isinstance(props['Economy'], dict): + decay = safe_decimal(props['Economy'].get('Decay')) + for key in ['Decay', 'decay', 'Cost']: + if key in props and props[key] is not None: + decay = safe_decimal(props[key]) + break + + # Efficiency + efficiency_bonus = Decimal("0") + if 'Economy' in props and isinstance(props['Economy'], dict): + efficiency_bonus = safe_decimal(props['Economy'].get('Efficiency')) + for key in ['Efficiency', 'efficiency', 'Eco', 'Eff']: + if key in props and props[key] is not None: + efficiency_bonus = safe_decimal(props[key]) + break + + # Determine attachment type from API type or name + api_type = props.get('Type', '').lower() + name = data.get('Name', '').lower() + + if 'amplifier' in api_type or 'amp' in name: + attachment_type = 'amplifier' + elif 'scope' in api_type or 'scope' in name: + attachment_type = 'scope' + elif 'sight' in api_type or 'sight' in name: + attachment_type = 'sight' + elif 'absorber' in api_type or 'absorber' in name: + attachment_type = 'absorber' + else: + attachment_type = api_type or 'unknown' return cls( id=data.get('Id', 0), name=data.get('Name', 'Unknown'), item_id=str(data.get('Id', 0)), category='attachment', - attachment_type=props.get('Type', ''), - damage_bonus=Decimal(str(props.get('DamageBonus', 0))), - range_bonus=Decimal(str(props.get('RangeBonus', 0))), - decay=Decimal(str(props.get('Decay', 0))), - efficiency_bonus=Decimal(str(props.get('Efficiency', 0))), + attachment_type=attachment_type, + damage_bonus=damage_bonus, + range_bonus=range_bonus, + decay=decay, + efficiency_bonus=efficiency_bonus, ) diff --git a/ui/attachment_selector.py b/ui/attachment_selector.py index 0d543ac..cabcf4e 100644 --- a/ui/attachment_selector.py +++ b/ui/attachment_selector.py @@ -232,14 +232,28 @@ class AttachmentSelectorDialog(QDialog): item = QTreeWidgetItem() item.setText(0, att.name) item.setText(1, att.attachment_type.title()) - item.setText(2, f"+{att.damage_bonus}") - item.setText(3, f"+{att.range_bonus}") - item.setText(4, f"{att.decay:.2f}") - item.setText(5, f"{att.efficiency_bonus:.1f}%") + + # Format damage with + sign if positive + dmg_text = f"+{att.damage_bonus}" if att.damage_bonus > 0 else str(att.damage_bonus) + item.setText(2, dmg_text) + + # Format range with + sign if positive + rng_text = f"+{att.range_bonus}" if att.range_bonus > 0 else str(att.range_bonus) + item.setText(3, rng_text) + + # Format decay (typically in PEC) + item.setText(4, f"{att.decay:.4f}") + + # Format efficiency as percentage + eff_text = f"{att.efficiency_bonus:.2f}%" if att.efficiency_bonus > 0 else "-" + item.setText(5, eff_text) # Color code by type if att.attachment_type == "amplifier": item.setForeground(0, QColor("#ff9800")) # Orange + # Highlight positive damage values + if att.damage_bonus > 0: + item.setForeground(2, QColor("#7FFF7F")) elif att.attachment_type == "scope": item.setForeground(0, QColor("#2196f3")) # Blue elif att.attachment_type == "sight": @@ -249,6 +263,9 @@ class AttachmentSelectorDialog(QDialog): item.setData(0, Qt.ItemDataRole.UserRole, att) tree.addTopLevelItem(item) + + item.setData(0, Qt.ItemDataRole.UserRole, att) + tree.addTopLevelItem(item) def _on_search_changed(self, tab: dict, text: str): """Handle search text change in a tab."""