work on getting abyssal modules imported via clipboard
This commit is contained in:
@@ -131,7 +131,7 @@ class EveFittings(wx.Frame):
|
|||||||
return
|
return
|
||||||
data = self.fitTree.fittingsTreeCtrl.GetItemData(selection)
|
data = self.fitTree.fittingsTreeCtrl.GetItemData(selection)
|
||||||
sPort = Port.getInstance()
|
sPort = Port.getInstance()
|
||||||
fits = sPort.importFitFromBuffer(data)
|
import_type, fits = sPort.importFitFromBuffer(data)
|
||||||
self.mainFrame._openAfterImport(fits)
|
self.mainFrame._openAfterImport(fits)
|
||||||
|
|
||||||
def deleteFitting(self, event):
|
def deleteFitting(self, event):
|
||||||
|
|||||||
@@ -32,4 +32,5 @@ from .guiChangeDroneQty import GuiChangeDroneQty
|
|||||||
from .guiChangeProjectedDroneQty import GuiChangeProjectedDroneQty
|
from .guiChangeProjectedDroneQty import GuiChangeProjectedDroneQty
|
||||||
from .guiToggleDrone import GuiToggleDroneCommand
|
from .guiToggleDrone import GuiToggleDroneCommand
|
||||||
from .guiFitRename import GuiFitRenameCommand
|
from .guiFitRename import GuiFitRenameCommand
|
||||||
from .guiChangeImplantLocation import GuiChangeImplantLocation
|
from .guiChangeImplantLocation import GuiChangeImplantLocation
|
||||||
|
from .guiImportAbyssalModule import GuiImportAbyssalModuleCommand
|
||||||
60
gui/fitCommands/calc/fitImportAbyssalModule.py
Normal file
60
gui/fitCommands/calc/fitImportAbyssalModule.py
Normal 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
|
||||||
35
gui/fitCommands/guiImportAbyssalModule.py
Normal file
35
gui/fitCommands/guiImportAbyssalModule.py
Normal 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
|
||||||
@@ -73,6 +73,7 @@ from service.fit import Fit
|
|||||||
from service.port import EfsPort, IPortUser, Port
|
from service.port import EfsPort, IPortUser, Port
|
||||||
from service.settings import HTMLExportSettings, SettingsProvider
|
from service.settings import HTMLExportSettings, SettingsProvider
|
||||||
from service.update import Update
|
from service.update import Update
|
||||||
|
import gui.fitCommands as cmd
|
||||||
|
|
||||||
disableOverrideEditor = False
|
disableOverrideEditor = False
|
||||||
|
|
||||||
@@ -728,12 +729,17 @@ class MainFrame(wx.Frame):
|
|||||||
|
|
||||||
def importFromClipboard(self, event):
|
def importFromClipboard(self, event):
|
||||||
clipboard = fromClipboard()
|
clipboard = fromClipboard()
|
||||||
|
activeFit = self.getActiveFit()
|
||||||
try:
|
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:
|
except:
|
||||||
pyfalog.error("Attempt to import failed:\n{0}", clipboard)
|
pyfalog.error("Attempt to import failed:\n{0}", clipboard)
|
||||||
else:
|
else:
|
||||||
self._openAfterImport(fits)
|
self._openAfterImport(data)
|
||||||
|
|
||||||
def exportToClipboard(self, event):
|
def exportToClipboard(self, event):
|
||||||
CopySelectDict = {CopySelectDialog.copyFormatEft: self.clipboardEft,
|
CopySelectDict = {CopySelectDialog.copyFormatEft: self.clipboardEft,
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ from service.port.esi import exportESI, importESI
|
|||||||
from service.port.multibuy import exportMultiBuy
|
from service.port.multibuy import exportMultiBuy
|
||||||
from service.port.shared import IPortUser, UserCancelException, processing_notify
|
from service.port.shared import IPortUser, UserCancelException, processing_notify
|
||||||
from service.port.xml import importXml, exportXml
|
from service.port.xml import importXml, exportXml
|
||||||
|
from service.port.muta import importMutant
|
||||||
|
|
||||||
|
|
||||||
pyfalog = Logger(__name__)
|
pyfalog = Logger(__name__)
|
||||||
@@ -188,18 +189,20 @@ class Port(object):
|
|||||||
# TODO: catch the exception?
|
# TODO: catch the exception?
|
||||||
# activeFit is reserved?, bufferStr is unicode? (assume only clipboard string?
|
# activeFit is reserved?, bufferStr is unicode? (assume only clipboard string?
|
||||||
sFit = svcFit.getInstance()
|
sFit = svcFit.getInstance()
|
||||||
_, fits = Port.importAuto(bufferStr, activeFit=activeFit)
|
import_type, fits = Port.importAuto(bufferStr, activeFit=activeFit)
|
||||||
for fit in fits:
|
|
||||||
fit.character = sFit.character
|
if import_type != 'Abyssal':
|
||||||
fit.damagePattern = sFit.pattern
|
for fit in fits:
|
||||||
fit.targetResists = sFit.targetResists
|
fit.character = sFit.character
|
||||||
if len(fit.implants) > 0:
|
fit.damagePattern = sFit.pattern
|
||||||
fit.implantLocation = ImplantLocation.FIT
|
fit.targetResists = sFit.targetResists
|
||||||
else:
|
if len(fit.implants) > 0:
|
||||||
useCharImplants = sFit.serviceFittingOptions["useCharacterImplantsByDefault"]
|
fit.implantLocation = ImplantLocation.FIT
|
||||||
fit.implantLocation = ImplantLocation.CHARACTER if useCharImplants else ImplantLocation.FIT
|
else:
|
||||||
db.save(fit)
|
useCharImplants = sFit.serviceFittingOptions["useCharacterImplantsByDefault"]
|
||||||
return fits
|
fit.implantLocation = ImplantLocation.CHARACTER if useCharImplants else ImplantLocation.FIT
|
||||||
|
db.save(fit)
|
||||||
|
return import_type, fits
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def importAuto(cls, string, path=None, activeFit=None, iportuser=None):
|
def importAuto(cls, string, path=None, activeFit=None, iportuser=None):
|
||||||
@@ -228,8 +231,11 @@ class Port(object):
|
|||||||
if re.match("\[.*,.*\]", firstLine):
|
if re.match("\[.*,.*\]", firstLine):
|
||||||
return "EFT", (cls.importEft(string),)
|
return "EFT", (cls.importEft(string),)
|
||||||
|
|
||||||
# Use DNA format for all other cases
|
try:
|
||||||
return "DNA", (cls.importDna(string),)
|
return "Abyssal", (importMutant(string.split("\n")),)
|
||||||
|
except:
|
||||||
|
# Use DNA format for all other cases
|
||||||
|
return "DNA", (cls.importDna(string),)
|
||||||
|
|
||||||
# EFT-related methods
|
# EFT-related methods
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
Reference in New Issue
Block a user