Add commands for booster and command fits
This commit is contained in:
@@ -138,7 +138,7 @@ es_Fit._Fit__projectedFits = association_proxy(
|
||||
creator=lambda sourceID, source_fit: ProjectedFit(sourceID, source_fit)
|
||||
)
|
||||
|
||||
es_Fit._Fit__commandFits = association_proxy(
|
||||
es_Fit.commandFitDict = association_proxy(
|
||||
"boostedOf", # look at the boostedOf association...
|
||||
"booster_fit", # .. and return the booster fit
|
||||
creator=lambda boosterID, booster_fit: CommandFit(boosterID, booster_fit)
|
||||
|
||||
@@ -262,7 +262,7 @@ class Fit(object):
|
||||
|
||||
@property
|
||||
def commandFits(self):
|
||||
return [fit for fit in list(self.__commandFits.values()) if not fit.isInvalid]
|
||||
return [fit for fit in list(self.commandFitDict.values()) if not fit.isInvalid]
|
||||
|
||||
def getProjectionInfo(self, fitID):
|
||||
return self.projectedOnto.get(fitID, None)
|
||||
@@ -1605,7 +1605,7 @@ class Fit(object):
|
||||
eos.db.saveddata_session.refresh(fit)
|
||||
|
||||
for fit in self.commandFits:
|
||||
copy_ship.__commandFits[fit.ID] = fit
|
||||
copy_ship.commandFitDict[fit.ID] = fit
|
||||
forceUpdateSavedata(fit)
|
||||
copyCommandInfo = fit.getCommandInfo(copy_ship.ID)
|
||||
originalCommandInfo = fit.getCommandInfo(self.ID)
|
||||
|
||||
@@ -26,7 +26,7 @@ from gui.builtinViewColumns.state import State
|
||||
from gui.contextMenu import ContextMenu
|
||||
from gui.utils.staticHelpers import DragDropHelper
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.fitCommands as cmd
|
||||
|
||||
class BoosterViewDrop(wx.DropTarget):
|
||||
def __init__(self, dropFn, *args, **kwargs):
|
||||
@@ -134,9 +134,7 @@ class BoosterView(d.Display):
|
||||
event.Skip()
|
||||
return
|
||||
|
||||
trigger = sFit.addBooster(fitID, event.itemID)
|
||||
if trigger:
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID))
|
||||
if self.mainFrame.command.Submit(cmd.GuiAddBoosterCommand(fitID, event.itemID)):
|
||||
self.mainFrame.additionsPane.select("Boosters")
|
||||
|
||||
event.Skip()
|
||||
@@ -150,9 +148,7 @@ class BoosterView(d.Display):
|
||||
|
||||
def removeBooster(self, booster):
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
sFit = Fit.getInstance()
|
||||
sFit.removeBooster(fitID, self.origional.index(booster))
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID))
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveImplantCommand(fitID, self.origional.index(booster)))
|
||||
|
||||
def click(self, event):
|
||||
event.Skip()
|
||||
|
||||
@@ -30,7 +30,7 @@ from gui.builtinViewColumns.state import State
|
||||
from gui.contextMenu import ContextMenu
|
||||
from gui.utils.staticHelpers import DragDropHelper
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.fitCommands as cmd
|
||||
|
||||
class DummyItem(object):
|
||||
def __init__(self, txt):
|
||||
@@ -111,10 +111,11 @@ class CommandView(d.Display):
|
||||
if type == "fit":
|
||||
activeFit = self.mainFrame.getActiveFit()
|
||||
if activeFit:
|
||||
sFit = Fit.getInstance()
|
||||
draggedFit = sFit.getFit(fitID)
|
||||
sFit.addCommandFit(activeFit, draggedFit)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=activeFit))
|
||||
# sFit = Fit.getInstance()
|
||||
# draggedFit = sFit.getFit(fitID)
|
||||
# sFit.addCommandFit(activeFit, draggedFit)
|
||||
# wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=activeFit))
|
||||
self.mainFrame.command.Submit(cmd.GuiAddCommandCommand(activeFit, fitID))
|
||||
|
||||
def startDrag(self, event):
|
||||
row = event.GetIndex()
|
||||
|
||||
@@ -48,7 +48,8 @@ class ItemRemove(ContextMenu):
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveImplantCommand(fitID, fit.implants.index(selection[0])))
|
||||
return # the command takes care of the PostEvent
|
||||
elif srcContext == "boosterItem":
|
||||
sFit.removeBooster(fitID, fit.boosters.index(selection[0]))
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveBoosterCommand(fitID, fit.boosters.index(selection[0])))
|
||||
return # the command takes care of the PostEvent
|
||||
elif srcContext == "cargoItem":
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveCargoCommand(fitID, selection[0].itemID))
|
||||
return # the command takes care of the PostEvent
|
||||
|
||||
@@ -140,6 +140,7 @@ class MetaSwap(ContextMenu):
|
||||
if isinstance(selected_item, Module):
|
||||
pos = fit.modules.index(selected_item)
|
||||
sFit.changeModule(fitID, pos, item.ID)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID))
|
||||
|
||||
elif isinstance(selected_item, Drone):
|
||||
drone_count = None
|
||||
@@ -152,6 +153,7 @@ class MetaSwap(ContextMenu):
|
||||
|
||||
if drone_count:
|
||||
sFit.addDrone(fitID, item.ID, drone_count, True)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID))
|
||||
|
||||
elif isinstance(selected_item, Fighter):
|
||||
fighter_count = None
|
||||
@@ -172,12 +174,13 @@ class MetaSwap(ContextMenu):
|
||||
break
|
||||
|
||||
sFit.addFighter(fitID, item.ID, True)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID))
|
||||
|
||||
elif isinstance(selected_item, Booster):
|
||||
for idx, booster_stack in enumerate(fit.boosters):
|
||||
if booster_stack is selected_item:
|
||||
sFit.removeBooster(fitID, idx, False)
|
||||
sFit.addBooster(fitID, item.ID, True)
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveBoosterCommand(fitID, idx))
|
||||
self.mainFrame.command.Submit(cmd.GuiAddBoosterCommand(fitID, item.ID))
|
||||
break
|
||||
|
||||
elif isinstance(selected_item, Implant):
|
||||
@@ -185,7 +188,7 @@ class MetaSwap(ContextMenu):
|
||||
if implant_stack is selected_item:
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveImplantCommand(fitID, idx))
|
||||
self.mainFrame.command.Submit(cmd.GuiAddImplantCommand(fitID, item.ID))
|
||||
return
|
||||
break
|
||||
|
||||
elif isinstance(selected_item, Cargo):
|
||||
for idx, cargo_stack in enumerate(fit.cargo):
|
||||
@@ -194,9 +197,8 @@ class MetaSwap(ContextMenu):
|
||||
# utilize the two fitting commands that we need to remove then add?
|
||||
sFit.removeCargo(fitID, idx)
|
||||
self.mainFrame.command.Submit(cmd.GuiAddCargoCommand(fitID, item.ID, cargo_stack.amount, True))
|
||||
return # don't need the post event
|
||||
break
|
||||
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID))
|
||||
|
||||
|
||||
MetaSwap.register()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -365,6 +365,7 @@ class Fit(object):
|
||||
self.recalc(fit)
|
||||
return True
|
||||
|
||||
@deprecated
|
||||
def addBooster(self, fitID, itemID, recalc=True):
|
||||
pyfalog.debug("Adding booster ({0}) to fit ID: {1}", itemID, fitID)
|
||||
if fitID is None:
|
||||
@@ -383,6 +384,7 @@ class Fit(object):
|
||||
self.recalc(fit)
|
||||
return True
|
||||
|
||||
@deprecated
|
||||
def removeBooster(self, fitID, position, recalc=True):
|
||||
pyfalog.debug("Removing booster from position ({0}) for fit ID: {1}", position, fitID)
|
||||
if fitID is None:
|
||||
@@ -451,6 +453,7 @@ class Fit(object):
|
||||
self.recalc(fit)
|
||||
return True
|
||||
|
||||
@deprecated
|
||||
def addCommandFit(self, fitID, thing):
|
||||
pyfalog.debug("Projecting command fit ({0}) onto: {1}", fitID, thing)
|
||||
if fitID is None:
|
||||
@@ -461,7 +464,7 @@ class Fit(object):
|
||||
if thing in fit.commandFits:
|
||||
return
|
||||
|
||||
fit.__commandFits[thing.ID] = thing
|
||||
fit.commandFitDict[thing.ID] = thing
|
||||
|
||||
# this bit is required -- see GH issue # 83
|
||||
eos.db.saveddata_session.flush()
|
||||
@@ -539,10 +542,11 @@ class Fit(object):
|
||||
eos.db.commit()
|
||||
self.recalc(fit)
|
||||
|
||||
@deprecated
|
||||
def removeCommand(self, fitID, thing):
|
||||
pyfalog.debug("Removing command projection from fit ({0}) for: {1}", fitID, thing)
|
||||
fit = eos.db.getFit(fitID)
|
||||
del fit.__commandFits[thing.ID]
|
||||
del fit.commandFitDict[thing.ID]
|
||||
|
||||
eos.db.commit()
|
||||
self.recalc(fit)
|
||||
|
||||
Reference in New Issue
Block a user