Add commands for booster and command fits
This commit is contained in:
@@ -7,3 +7,7 @@ from .guiRemoveCargo import GuiRemoveCargoCommand
|
||||
from .guiAddCargo import GuiAddCargoCommand
|
||||
from .guiRemoveImplant import GuiRemoveImplantCommand
|
||||
from .guiAddImplant import GuiAddImplantCommand
|
||||
from .guiAddBooster import GuiAddBoosterCommand
|
||||
from .guiRemoveBooster import GuiRemoveBoosterCommand
|
||||
from .guiAddCommand import GuiAddCommandCommand
|
||||
from .guiRemoveCommand import GuiRemoveCommandCommand
|
||||
42
gui/fitCommands/calc/fitAddBooster.py
Normal file
42
gui/fitCommands/calc/fitAddBooster.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
#from .helpers import ModuleInfoCache
|
||||
from eos.saveddata.module import Module, State
|
||||
import eos.db
|
||||
from logbook import Logger
|
||||
pyfalog = Logger(__name__)
|
||||
from eos.saveddata.booster import Booster
|
||||
|
||||
class FitAddBoosterCommand(wx.Command):
|
||||
""""
|
||||
from sFit.addBooster
|
||||
"""
|
||||
def __init__(self, fitID, itemID):
|
||||
wx.Command.__init__(self, True)
|
||||
self.fitID = fitID
|
||||
self.itemID = itemID
|
||||
self.new_index = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Adding booster ({0}) to fit ID: {1}", self.itemID, self.fitID)
|
||||
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
item = eos.db.getItem(self.itemID, eager="attributes")
|
||||
try:
|
||||
booster = Booster(item)
|
||||
except ValueError:
|
||||
pyfalog.warning("Invalid item: {0}", self.itemID)
|
||||
return False
|
||||
|
||||
fit.boosters.append(booster)
|
||||
self.new_index = fit.boosters.index(booster)
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
from .fitRemoveBooster import FitRemoveBoosterCommand # Avoid circular import
|
||||
cmd = FitRemoveBoosterCommand(self.fitID, self.new_index)
|
||||
cmd.Do()
|
||||
return True
|
||||
53
gui/fitCommands/calc/fitAddCommand.py
Normal file
53
gui/fitCommands/calc/fitAddCommand.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
#from .helpers import ModuleInfoCache
|
||||
from eos.saveddata.module import Module, State
|
||||
import eos.db
|
||||
from logbook import Logger
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class FitAddCommandCommand(wx.Command): # well that's an unfrtunate name
|
||||
""""
|
||||
from sFit.addCommand
|
||||
"""
|
||||
def __init__(self, fitID, commandFitID):
|
||||
wx.Command.__init__(self, True)
|
||||
self.fitID = fitID
|
||||
self.commandFitID = commandFitID
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Projecting command fit ({0}) onto: {1}", self.fitID, self.commandFitID)
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
command = eos.db.getFit(self.commandFitID)
|
||||
|
||||
if not command:
|
||||
# if redoing when the command fit has been deleted, simply fail this command
|
||||
return False
|
||||
|
||||
if command in fit.commandFits:
|
||||
return
|
||||
|
||||
fit.commandFitDict[command.ID] = command
|
||||
|
||||
# this bit is required -- see GH issue # 83
|
||||
eos.db.saveddata_session.flush()
|
||||
eos.db.saveddata_session.refresh(command)
|
||||
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
command = eos.db.getFit(self.commandFitID)
|
||||
|
||||
if not command:
|
||||
# can't find the command fit, it must have been deleted. Just skip this undo
|
||||
return True
|
||||
|
||||
from .fitRemoveCommand import FitRemoveCommandCommand
|
||||
cmd = FitRemoveCommandCommand(self.fitID, self.commandFitID)
|
||||
cmd.Do()
|
||||
return True
|
||||
32
gui/fitCommands/calc/fitRemoveBooster.py
Normal file
32
gui/fitCommands/calc/fitRemoveBooster.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import wx
|
||||
|
||||
#from .helpers import ModuleInfoCache
|
||||
import eos.db
|
||||
from logbook import Logger
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class FitRemoveBoosterCommand(wx.Command):
|
||||
""""
|
||||
from sFit.removeBooster
|
||||
"""
|
||||
def __init__(self, fitID, position):
|
||||
wx.Command.__init__(self, True, "Implant remove")
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.old = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Removing booster from position ({0}) for fit ID: {1}", self.position, self.fitID)
|
||||
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
booster = fit.boosters[self.position]
|
||||
self.old = booster.itemID
|
||||
fit.boosters.remove(booster)
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
from .fitAddBooster import FitAddBoosterCommand # Avoid circular import
|
||||
cmd = FitAddBoosterCommand(self.fitID, self.old)
|
||||
cmd.Do()
|
||||
return True
|
||||
43
gui/fitCommands/calc/fitRemoveCommand.py
Normal file
43
gui/fitCommands/calc/fitRemoveCommand.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
#from .helpers import ModuleInfoCache
|
||||
from eos.saveddata.module import Module, State
|
||||
import eos.db
|
||||
from logbook import Logger
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class FitRemoveCommandCommand(wx.Command): # well that's an unfrtunate name
|
||||
""""
|
||||
from sFit.removeCommand
|
||||
"""
|
||||
def __init__(self, fitID, commandFitID):
|
||||
wx.Command.__init__(self, True)
|
||||
self.fitID = fitID
|
||||
self.commandFitID = commandFitID
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Removing command projection from fit ({0}) for: {1}", self.fitID, self.commandFitID)
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
command = eos.db.getFit(self.commandFitID)
|
||||
if not command:
|
||||
return False
|
||||
del fit.commandFitDict[command.ID]
|
||||
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
command = eos.db.getFit(self.commandFitID)
|
||||
|
||||
if not command:
|
||||
# can't find the command fit, it must have been deleted. Just skip this undo
|
||||
return True
|
||||
|
||||
from .fitAddCommand import FitAddCommandCommand
|
||||
cmd = FitAddCommandCommand(self.fitID, self.commandFitID)
|
||||
cmd.Do()
|
||||
return True
|
||||
29
gui/fitCommands/guiAddBooster.py
Normal file
29
gui/fitCommands/guiAddBooster.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from .calc.fitAddBooster import FitAddBoosterCommand
|
||||
|
||||
class GuiAddBoosterCommand(wx.Command):
|
||||
def __init__(self, fitID, itemID):
|
||||
wx.Command.__init__(self, True, "Booster Add")
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.sFit = Fit.getInstance()
|
||||
self.internal_history = wx.CommandProcessor()
|
||||
self.fitID = fitID
|
||||
# can set his up no to not have to set variables on our object
|
||||
self.cmd = FitAddBoosterCommand(fitID, itemID)
|
||||
|
||||
def Do(self):
|
||||
if self.internal_history.Submit(self.cmd):
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
return False
|
||||
|
||||
def Undo(self):
|
||||
for x in self.internal_history.Commands:
|
||||
self.internal_history.Undo()
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
|
||||
29
gui/fitCommands/guiAddCommand.py
Normal file
29
gui/fitCommands/guiAddCommand.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from .calc.fitAddCommand import FitAddCommandCommand
|
||||
|
||||
class GuiAddCommandCommand(wx.Command):
|
||||
def __init__(self, fitID, commandFitID):
|
||||
wx.Command.__init__(self, True, "")
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.sFit = Fit.getInstance()
|
||||
self.internal_history = wx.CommandProcessor()
|
||||
self.fitID = fitID
|
||||
# can set his up no to not have to set variables on our object
|
||||
self.cmd = FitAddCommandCommand(fitID, commandFitID)
|
||||
|
||||
def Do(self):
|
||||
if self.internal_history.Submit(self.cmd):
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
return False
|
||||
|
||||
def Undo(self):
|
||||
for x in self.internal_history.Commands:
|
||||
self.internal_history.Undo()
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import wx
|
||||
|
||||
import gui.mainFrame
|
||||
from service.fit import Fit
|
||||
from gui import globalEvents as GE
|
||||
from .calc.fitAddModule import FitAddModuleCommand
|
||||
from .calc.fitReplaceModule import FitReplaceModuleCommand
|
||||
|
||||
29
gui/fitCommands/guiRemoveBooster.py
Normal file
29
gui/fitCommands/guiRemoveBooster.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from .calc.fitRemoveBooster import FitRemoveBoosterCommand
|
||||
|
||||
class GuiRemoveBoosterCommand(wx.Command):
|
||||
def __init__(self, fitID, position):
|
||||
wx.Command.__init__(self, True, "")
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.sFit = Fit.getInstance()
|
||||
self.internal_history = wx.CommandProcessor()
|
||||
self.fitID = fitID
|
||||
# can set his up no to not have to set variables on our object
|
||||
self.cmd = FitRemoveBoosterCommand(fitID, position)
|
||||
|
||||
def Do(self):
|
||||
if self.internal_history.Submit(self.cmd):
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
return False
|
||||
|
||||
def Undo(self):
|
||||
for x in self.internal_history.Commands:
|
||||
self.internal_history.Undo()
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
|
||||
29
gui/fitCommands/guiRemoveCommand.py
Normal file
29
gui/fitCommands/guiRemoveCommand.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from .calc.fitRemoveCommand import FitRemoveCommandCommand
|
||||
|
||||
class GuiRemoveCommandCommand(wx.Command):
|
||||
def __init__(self, fitID, commandFitID):
|
||||
wx.Command.__init__(self, True, "")
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.sFit = Fit.getInstance()
|
||||
self.internal_history = wx.CommandProcessor()
|
||||
self.fitID = fitID
|
||||
# can set his up no to not have to set variables on our object
|
||||
self.cmd = FitRemoveCommandCommand(fitID, commandFitID)
|
||||
|
||||
def Do(self):
|
||||
if self.internal_history.Submit(self.cmd):
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
return False
|
||||
|
||||
def Undo(self):
|
||||
for x in self.internal_history.Commands:
|
||||
self.internal_history.Undo()
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user