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
This commit is contained in:
LemonNexus 2026-02-09 17:07:31 +00:00
parent 1be69b1879
commit 4ef03d96c8
2 changed files with 77 additions and 9 deletions

View File

@ -159,16 +159,67 @@ class NexusAttachment(NexusItem):
"""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,
)

View File

@ -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":
@ -250,6 +264,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."""
tree = tab["tree"]