work on getting abyssal modules imported via clipboard

This commit is contained in:
Ryan Holmes
2018-11-20 00:49:04 -05:00
parent 0294684bb8
commit 58daf2a543
6 changed files with 126 additions and 18 deletions

View File

@@ -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):

View File

@@ -32,4 +32,5 @@ from .guiChangeDroneQty import GuiChangeDroneQty
from .guiChangeProjectedDroneQty import GuiChangeProjectedDroneQty
from .guiToggleDrone import GuiToggleDroneCommand
from .guiFitRename import GuiFitRenameCommand
from .guiChangeImplantLocation import GuiChangeImplantLocation
from .guiChangeImplantLocation import GuiChangeImplantLocation
from .guiImportAbyssalModule import GuiImportAbyssalModuleCommand

View File

@@ -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

View File

@@ -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

View File

@@ -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,