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:
parent
1be69b1879
commit
4ef03d96c8
|
|
@ -159,16 +159,67 @@ class NexusAttachment(NexusItem):
|
||||||
"""Create from API response."""
|
"""Create from API response."""
|
||||||
props = data.get('Properties', {})
|
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(
|
return cls(
|
||||||
id=data.get('Id', 0),
|
id=data.get('Id', 0),
|
||||||
name=data.get('Name', 'Unknown'),
|
name=data.get('Name', 'Unknown'),
|
||||||
item_id=str(data.get('Id', 0)),
|
item_id=str(data.get('Id', 0)),
|
||||||
category='attachment',
|
category='attachment',
|
||||||
attachment_type=props.get('Type', ''),
|
attachment_type=attachment_type,
|
||||||
damage_bonus=Decimal(str(props.get('DamageBonus', 0))),
|
damage_bonus=damage_bonus,
|
||||||
range_bonus=Decimal(str(props.get('RangeBonus', 0))),
|
range_bonus=range_bonus,
|
||||||
decay=Decimal(str(props.get('Decay', 0))),
|
decay=decay,
|
||||||
efficiency_bonus=Decimal(str(props.get('Efficiency', 0))),
|
efficiency_bonus=efficiency_bonus,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -232,14 +232,28 @@ class AttachmentSelectorDialog(QDialog):
|
||||||
item = QTreeWidgetItem()
|
item = QTreeWidgetItem()
|
||||||
item.setText(0, att.name)
|
item.setText(0, att.name)
|
||||||
item.setText(1, att.attachment_type.title())
|
item.setText(1, att.attachment_type.title())
|
||||||
item.setText(2, f"+{att.damage_bonus}")
|
|
||||||
item.setText(3, f"+{att.range_bonus}")
|
# Format damage with + sign if positive
|
||||||
item.setText(4, f"{att.decay:.2f}")
|
dmg_text = f"+{att.damage_bonus}" if att.damage_bonus > 0 else str(att.damage_bonus)
|
||||||
item.setText(5, f"{att.efficiency_bonus:.1f}%")
|
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
|
# Color code by type
|
||||||
if att.attachment_type == "amplifier":
|
if att.attachment_type == "amplifier":
|
||||||
item.setForeground(0, QColor("#ff9800")) # Orange
|
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":
|
elif att.attachment_type == "scope":
|
||||||
item.setForeground(0, QColor("#2196f3")) # Blue
|
item.setForeground(0, QColor("#2196f3")) # Blue
|
||||||
elif att.attachment_type == "sight":
|
elif att.attachment_type == "sight":
|
||||||
|
|
@ -250,6 +264,9 @@ class AttachmentSelectorDialog(QDialog):
|
||||||
item.setData(0, Qt.ItemDataRole.UserRole, att)
|
item.setData(0, Qt.ItemDataRole.UserRole, att)
|
||||||
tree.addTopLevelItem(item)
|
tree.addTopLevelItem(item)
|
||||||
|
|
||||||
|
item.setData(0, Qt.ItemDataRole.UserRole, att)
|
||||||
|
tree.addTopLevelItem(item)
|
||||||
|
|
||||||
def _on_search_changed(self, tab: dict, text: str):
|
def _on_search_changed(self, tab: dict, text: str):
|
||||||
"""Handle search text change in a tab."""
|
"""Handle search text change in a tab."""
|
||||||
tree = tab["tree"]
|
tree = tab["tree"]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue