fix: fix to_dict to handle new armor system fields
- Properly serialize current_armor_protection (ProtectionProfile) - Properly serialize current_armor_pieces (list of ArmorPiece) - Convert Decimals to strings for JSON serialization
This commit is contained in:
parent
877ee96bcc
commit
0c843df4a7
|
|
@ -313,10 +313,33 @@ class LoadoutConfig:
|
|||
|
||||
def to_dict(self) -> dict:
|
||||
"""Convert to dictionary for JSON serialization."""
|
||||
data = {
|
||||
k: str(v) if isinstance(v, Decimal) else v
|
||||
for k, v in asdict(self).items()
|
||||
}
|
||||
from dataclasses import asdict
|
||||
|
||||
# Start with basic fields, excluding complex objects
|
||||
data = {}
|
||||
|
||||
# Handle simple fields
|
||||
for k, v in self.__dict__.items():
|
||||
if k in ('current_armor_protection', 'current_armor_pieces', 'equipped_armor',
|
||||
'weapon_amplifier', 'weapon_scope', 'weapon_absorber', 'weapon_enhancers',
|
||||
'armor_plates', 'enhancers'):
|
||||
continue # Handle these separately
|
||||
|
||||
if isinstance(v, Decimal):
|
||||
data[k] = str(v)
|
||||
elif isinstance(v, ProtectionProfile):
|
||||
data[k] = v.to_dict()
|
||||
else:
|
||||
data[k] = v
|
||||
|
||||
# Handle new armor system
|
||||
if hasattr(self, 'current_armor_protection') and self.current_armor_protection:
|
||||
data['current_armor_protection'] = self.current_armor_protection.to_dict()
|
||||
if hasattr(self, 'current_armor_pieces') and self.current_armor_pieces:
|
||||
data['current_armor_pieces'] = [p.to_dict() for p in self.current_armor_pieces]
|
||||
if hasattr(self, 'current_armor_decay') and self.current_armor_decay:
|
||||
data['current_armor_decay'] = str(self.current_armor_decay)
|
||||
|
||||
# Handle attachment configs
|
||||
if self.weapon_amplifier:
|
||||
data['weapon_amplifier'] = self.weapon_amplifier.to_dict()
|
||||
|
|
|
|||
Loading…
Reference in New Issue