Skip to content

Commit

Permalink
Add option to export implants/boosters via ESI
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkFenX committed Oct 30, 2023
1 parent bafaed1 commit a484698
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gui/copySelectDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def exportDna(self, options, callback):

def exportEsi(self, options, callback):
fit = getFit(self.mainFrame.getActiveFit())
Port.exportESI(fit, True, callback)
Port.exportESI(fit, False, False, False, callback)

def exportXml(self, options, callback):
fit = getFit(self.mainFrame.getActiveFit())
Expand Down
24 changes: 22 additions & 2 deletions gui/esiFittings.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class ExportToEve(AuxiliaryFrame):
def __init__(self, parent):
super().__init__(
parent, id=wx.ID_ANY, title=_t("Export fit to EVE"), pos=wx.DefaultPosition,
size=wx.Size(400, 140) if "wxGTK" in wx.PlatformInfo else wx.Size(350, 115), resizeable=True)
size=wx.Size(400, 175) if "wxGTK" in wx.PlatformInfo else wx.Size(350, 145), resizeable=True)

self.mainFrame = parent

Expand All @@ -305,6 +305,16 @@ def __init__(self, parent):
self.exportChargesCb.Bind(wx.EVT_CHECKBOX, self.OnChargeExportChange)
mainSizer.Add(self.exportChargesCb, 0, 0, 5)

self.exportImplantsCb = wx.CheckBox(self, wx.ID_ANY, _t('Export Implants'), wx.DefaultPosition, wx.DefaultSize, 0)
self.exportImplantsCb.SetValue(EsiSettings.getInstance().get('exportImplants'))
self.exportImplantsCb.Bind(wx.EVT_CHECKBOX, self.OnImplantsExportChange)
mainSizer.Add(self.exportImplantsCb, 0, 0, 5)

self.exportBoostersCb = wx.CheckBox(self, wx.ID_ANY, _t('Export Boosters'), wx.DefaultPosition, wx.DefaultSize, 0)
self.exportBoostersCb.SetValue(EsiSettings.getInstance().get('exportBoosters'))
self.exportBoostersCb.Bind(wx.EVT_CHECKBOX, self.OnBoostersExportChange)
mainSizer.Add(self.exportBoostersCb, 0, 0, 5)

self.exportBtn.Bind(wx.EVT_BUTTON, self.exportFitting)

self.statusbar = wx.StatusBar(self)
Expand All @@ -324,6 +334,14 @@ def OnChargeExportChange(self, event):
EsiSettings.getInstance().set('exportCharges', self.exportChargesCb.GetValue())
event.Skip()

def OnImplantsExportChange(self, event):
EsiSettings.getInstance().set('exportImplants', self.exportChargesCb.GetValue())
event.Skip()

def OnBoostersExportChange(self, event):
EsiSettings.getInstance().set('exportBoosters', self.exportChargesCb.GetValue())
event.Skip()

def updateCharList(self):
sEsi = Esi.getInstance()
chars = sEsi.getSsoCharacters()
Expand Down Expand Up @@ -360,8 +378,10 @@ def exportFitting(self, event):

sFit = Fit.getInstance()
exportCharges = self.exportChargesCb.GetValue()
exportImplants = self.exportImplantsCb.GetValue()
exportBoosters = self.exportBoostersCb.GetValue()
try:
data = sPort.exportESI(sFit.getFit(fitID), exportCharges)
data = sPort.exportESI(sFit.getFit(fitID), exportCharges, exportImplants, exportBoosters)
except ESIExportException as e:
msg = str(e)
if not msg:
Expand Down
18 changes: 17 additions & 1 deletion service/port/esi.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ESIExportException(Exception):
INV_FLAG_FIGHTER = 158


def exportESI(ofit, exportCharges, callback):
def exportESI(ofit, exportCharges, exportImplants, exportBoosters, callback):
# A few notes:
# max fit name length is 50 characters
# Most keys are created simply because they are required, but bogus data is okay
Expand Down Expand Up @@ -133,6 +133,22 @@ def exportESI(ofit, exportCharges, callback):
item['type_id'] = fighter.item.ID
fit['items'].append(item)

if exportImplants:
for implant in ofit.implants:
item = nested_dict()
item['flag'] = INV_FLAG_CARGOBAY
item['quantity'] = 1
item['type_id'] = implant.item.ID
fit['items'].append(item)

if exportBoosters:
for booster in ofit.boosters:
item = nested_dict()
item['flag'] = INV_FLAG_CARGOBAY
item['quantity'] = 1
item['type_id'] = booster.item.ID
fit['items'].append(item)

if len(fit['items']) == 0:
raise ESIExportException("Cannot export fitting: module list cannot be empty.")

Expand Down
4 changes: 2 additions & 2 deletions service/port/port.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ def importESI(string):
return importESI(string)

@staticmethod
def exportESI(fit, exportCharges, callback=None):
return exportESI(fit, exportCharges, callback=callback)
def exportESI(fit, exportCharges, exportImplants, exportBoosters, callback=None):
return exportESI(fit, exportCharges, exportImplants, exportBoosters, callback=callback)

# XML-related methods
@staticmethod
Expand Down
2 changes: 2 additions & 0 deletions service/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@ def __init__(self):
"timeout": 60,
"server": "Tranquility",
"exportCharges": True,
"exportImplants": True,
"exportBoosters": True,
"enforceJwtExpiration": True
}

Expand Down

0 comments on commit a484698

Please sign in to comment.