From 58daf2a54348ea4152e03ce455a487fb2bef8556 Mon Sep 17 00:00:00 2001 From: Ryan Holmes Date: Tue, 20 Nov 2018 00:49:04 -0500 Subject: [PATCH] work on getting abyssal modules imported via clipboard --- gui/esiFittings.py | 2 +- gui/fitCommands/__init__.py | 3 +- .../calc/fitImportAbyssalModule.py | 60 +++++++++++++++++++ gui/fitCommands/guiImportAbyssalModule.py | 35 +++++++++++ gui/mainFrame.py | 10 +++- service/port/port.py | 34 ++++++----- 6 files changed, 126 insertions(+), 18 deletions(-) create mode 100644 gui/fitCommands/calc/fitImportAbyssalModule.py create mode 100644 gui/fitCommands/guiImportAbyssalModule.py diff --git a/gui/esiFittings.py b/gui/esiFittings.py index 20fc2ed74..9d14ad8fe 100644 --- a/gui/esiFittings.py +++ b/gui/esiFittings.py @@ -131,7 +131,7 @@ class EveFittings(wx.Frame): return data = self.fitTree.fittingsTreeCtrl.GetItemData(selection) sPort = Port.getInstance() - fits = sPort.importFitFromBuffer(data) + import_type, fits = sPort.importFitFromBuffer(data) self.mainFrame._openAfterImport(fits) def deleteFitting(self, event): diff --git a/gui/fitCommands/__init__.py b/gui/fitCommands/__init__.py index 145201559..e78cb4922 100644 --- a/gui/fitCommands/__init__.py +++ b/gui/fitCommands/__init__.py @@ -32,4 +32,5 @@ from .guiChangeDroneQty import GuiChangeDroneQty from .guiChangeProjectedDroneQty import GuiChangeProjectedDroneQty from .guiToggleDrone import GuiToggleDroneCommand from .guiFitRename import GuiFitRenameCommand -from .guiChangeImplantLocation import GuiChangeImplantLocation \ No newline at end of file +from .guiChangeImplantLocation import GuiChangeImplantLocation +from .guiImportAbyssalModule import GuiImportAbyssalModuleCommand \ No newline at end of file diff --git a/gui/fitCommands/calc/fitImportAbyssalModule.py b/gui/fitCommands/calc/fitImportAbyssalModule.py new file mode 100644 index 000000000..3bcecdb9e --- /dev/null +++ b/gui/fitCommands/calc/fitImportAbyssalModule.py @@ -0,0 +1,60 @@ +import wx +from eos.saveddata.module import Module, State +import eos.db +from logbook import Logger +from service.fit import Fit +pyfalog = Logger(__name__) + + +class FitImportAbyssalCommand(wx.Command): + """" + Fitting command that takes in a complete Abyssal module and adds it to a fit + """ + def __init__(self, fitID, module): + wx.Command.__init__(self, True) + self.fitID = fitID + self.module = module + self.new_position = None + self.change = None + self.replace_cmd = None + + def Do(self): + sFit = Fit.getInstance() + fitID = self.fitID + fit = eos.db.getFit(fitID) + + # this is essentially the same as the FitAddModule command. possibly look into centralizing this functionality somewhere? + if self.module.fits(fit): + pyfalog.debug("Adding {} as module for fit {}", self.module, fit) + self.module.owner = fit + numSlots = len(fit.modules) + fit.modules.append(self.module) + if self.module.isValidState(State.ACTIVE): + self.module.state = State.ACTIVE + + # todo: fix these + # As some items may affect state-limiting attributes of the ship, calculate new attributes first + # self.recalc(fit) + # Then, check states of all modules and change where needed. This will recalc if needed + sFit.checkStates(fit, self.module) + + # fit.fill() + eos.db.commit() + + self.change = numSlots != len(fit.modules) + self.new_position = self.module.modPosition + else: + return False + + return True + + def Undo(self): + # We added a subsystem module, which actually ran the replace command. Run the undo for that guy instead + if self.replace_cmd: + return self.replace_cmd.Undo() + + from .fitRemoveModule import FitRemoveModuleCommand # Avoid circular import + if self.new_position is not None: + cmd = FitRemoveModuleCommand(self.fitID, [self.new_position]) + cmd.Do() + return True diff --git a/gui/fitCommands/guiImportAbyssalModule.py b/gui/fitCommands/guiImportAbyssalModule.py new file mode 100644 index 000000000..81dbb81b4 --- /dev/null +++ b/gui/fitCommands/guiImportAbyssalModule.py @@ -0,0 +1,35 @@ +import wx +import eos.db +import gui.mainFrame +from gui import globalEvents as GE +from .calc.fitImportAbyssalModule import FitImportAbyssalCommand +from service.fit import Fit +from logbook import Logger +pyfalog = Logger(__name__) + + +class GuiImportAbyssalModuleCommand(wx.Command): + def __init__(self, fitID, module): + wx.Command.__init__(self, True, "Abyssal Module Import: {}".format(module)) + self.mainFrame = gui.mainFrame.MainFrame.getInstance() + self.sFit = Fit.getInstance() + self.fitID = fitID + self.module = module + self.internal_history = wx.CommandProcessor() + + def Do(self): + pyfalog.debug("{} Do()".format(self)) + + if self.internal_history.Submit(FitImportAbyssalCommand(self.fitID, self.module)): + self.sFit.recalc(self.fitID) + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID, action="modadd")) + return True + return False + + def Undo(self): + pyfalog.debug("{} Undo()".format(self)) + for _ in self.internal_history.Commands: + self.internal_history.Undo() + self.sFit.recalc(self.fitID) + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID, action="moddel")) + return True diff --git a/gui/mainFrame.py b/gui/mainFrame.py index 2a3665f74..8eed38635 100644 --- a/gui/mainFrame.py +++ b/gui/mainFrame.py @@ -73,6 +73,7 @@ from service.fit import Fit from service.port import EfsPort, IPortUser, Port from service.settings import HTMLExportSettings, SettingsProvider from service.update import Update +import gui.fitCommands as cmd disableOverrideEditor = False @@ -728,12 +729,17 @@ class MainFrame(wx.Frame): def importFromClipboard(self, event): clipboard = fromClipboard() + activeFit = self.getActiveFit() try: - fits = Port().importFitFromBuffer(clipboard, self.getActiveFit()) + import_type, data = Port().importFitFromBuffer(clipboard, activeFit) + if import_type == "Abyssal": + # we've imported an Abyssal module, need to fire off the command to add it to the fit + self.command.Submit(cmd.GuiImportAbyssalModuleCommand(activeFit, data[0])) + return # no need to do anything else except: pyfalog.error("Attempt to import failed:\n{0}", clipboard) else: - self._openAfterImport(fits) + self._openAfterImport(data) def exportToClipboard(self, event): CopySelectDict = {CopySelectDialog.copyFormatEft: self.clipboardEft, diff --git a/service/port/port.py b/service/port/port.py index 560af14ea..2fc7a13d7 100644 --- a/service/port/port.py +++ b/service/port/port.py @@ -37,6 +37,7 @@ from service.port.esi import exportESI, importESI from service.port.multibuy import exportMultiBuy from service.port.shared import IPortUser, UserCancelException, processing_notify from service.port.xml import importXml, exportXml +from service.port.muta import importMutant pyfalog = Logger(__name__) @@ -188,18 +189,20 @@ class Port(object): # TODO: catch the exception? # activeFit is reserved?, bufferStr is unicode? (assume only clipboard string? sFit = svcFit.getInstance() - _, fits = Port.importAuto(bufferStr, activeFit=activeFit) - for fit in fits: - fit.character = sFit.character - fit.damagePattern = sFit.pattern - fit.targetResists = sFit.targetResists - if len(fit.implants) > 0: - fit.implantLocation = ImplantLocation.FIT - else: - useCharImplants = sFit.serviceFittingOptions["useCharacterImplantsByDefault"] - fit.implantLocation = ImplantLocation.CHARACTER if useCharImplants else ImplantLocation.FIT - db.save(fit) - return fits + import_type, fits = Port.importAuto(bufferStr, activeFit=activeFit) + + if import_type != 'Abyssal': + for fit in fits: + fit.character = sFit.character + fit.damagePattern = sFit.pattern + fit.targetResists = sFit.targetResists + if len(fit.implants) > 0: + fit.implantLocation = ImplantLocation.FIT + else: + useCharImplants = sFit.serviceFittingOptions["useCharacterImplantsByDefault"] + fit.implantLocation = ImplantLocation.CHARACTER if useCharImplants else ImplantLocation.FIT + db.save(fit) + return import_type, fits @classmethod def importAuto(cls, string, path=None, activeFit=None, iportuser=None): @@ -228,8 +231,11 @@ class Port(object): if re.match("\[.*,.*\]", firstLine): return "EFT", (cls.importEft(string),) - # Use DNA format for all other cases - return "DNA", (cls.importDna(string),) + try: + return "Abyssal", (importMutant(string.split("\n")),) + except: + # Use DNA format for all other cases + return "DNA", (cls.importDna(string),) # EFT-related methods @staticmethod