More tweaks to existing commands
This commit is contained in:
@@ -26,9 +26,6 @@ class FitChangeStatesCommand(wx.Command):
|
||||
self.old_states[mod.modPosition] = mod.state
|
||||
|
||||
def Do(self):
|
||||
# todo: determine if we've changed state (recalc). If not, store that so we don't attempt to recalc on undo
|
||||
# self.sFit.toggleModulesState(self.fitID, self.baseMod, self.modules, self.click)
|
||||
|
||||
pyfalog.debug("Toggle module state for fit ID: {0}", self.fitID)
|
||||
changed = False
|
||||
proposedState = Module.getProposedState(self.baseMod, self.click)
|
||||
@@ -43,6 +40,7 @@ class FitChangeStatesCommand(wx.Command):
|
||||
if p != mod.state:
|
||||
changed = True
|
||||
|
||||
# if we haven't change the state (eg, overheat -> overheat), simply fail the command
|
||||
if changed:
|
||||
self.changed = changed
|
||||
eos.db.commit()
|
||||
|
||||
@@ -10,7 +10,7 @@ from logbook import Logger
|
||||
pyfalog = Logger(__name__)
|
||||
import copy
|
||||
|
||||
class FitCloneModduleCommand(wx.Command):
|
||||
class FitCloneModuleCommand(wx.Command):
|
||||
"""
|
||||
Clone a module from src to dst
|
||||
This will overwrite dst! Checking for empty module must be
|
||||
@@ -25,7 +25,6 @@ class FitCloneModduleCommand(wx.Command):
|
||||
self.dst = dst
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Cloning modules from source ({0}) to destination ({1}) for fit ID: {1}", self.src, self.dst, self.fitID)
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
# Gather modules
|
||||
srcMod = fit.modules[self.src]
|
||||
@@ -34,6 +33,7 @@ class FitCloneModduleCommand(wx.Command):
|
||||
new = copy.deepcopy(srcMod)
|
||||
new.owner = fit
|
||||
if new.fits(fit):
|
||||
pyfalog.debug("Cloning {} from source {} to destination {} for fit ID {}", srcMod, self.src, self.dst, self.fitID)
|
||||
# insert copy if module meets hardpoint restrictions
|
||||
fit.modules.remove(dstMod)
|
||||
fit.modules.insert(self.dst, new)
|
||||
|
||||
@@ -23,7 +23,7 @@ class GuiModuleAddChargeCommand(wx.Command):
|
||||
return False
|
||||
|
||||
def Undo(self):
|
||||
for x in self.internal_history.Commands:
|
||||
for _ in self.internal_history.Commands:
|
||||
self.internal_history.Undo()
|
||||
self.sFit.recalc(self.fitID)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
|
||||
@@ -4,11 +4,14 @@ from service.fit import Fit
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from gui.fitCommands.calc.fitSwapModule import FitSwapModuleCommand
|
||||
from .calc.fitCloneModule import FitCloneModduleCommand
|
||||
from .calc.fitCloneModule import FitCloneModuleCommand
|
||||
from logbook import Logger
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class GuiModuleSwapOrCloneCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, srcPosition, dstPosition, clone=False):
|
||||
# todo: instead of modules, needs to be positions. Dead objects are a thing
|
||||
wx.Command.__init__(self, True, "Module State Change")
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.sFit = Fit.getInstance()
|
||||
@@ -19,17 +22,24 @@ class GuiModuleSwapOrCloneCommand(wx.Command):
|
||||
self.internal_history = wx.CommandProcessor()
|
||||
|
||||
def Do(self):
|
||||
result = None
|
||||
if self.clone:
|
||||
result = self.internal_history.Submit(FitCloneModduleCommand(self.fitID, self.srcPosition, self.dstPosition))
|
||||
else:
|
||||
result = self.internal_history.Submit(FitSwapModuleCommand(self.fitID, self.srcPosition, self.dstPosition))
|
||||
pyfalog.debug("{} Do()".format(self))
|
||||
|
||||
if result:
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return result
|
||||
if self.clone:
|
||||
pyfalog.debug("Trying to clone module")
|
||||
if self.internal_history.Submit(FitCloneModuleCommand(self.fitID, self.srcPosition, self.dstPosition)):
|
||||
self.sFit.recalc(self.fitID) # clone needs a recalc
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
else:
|
||||
pyfalog.debug("Trying to Swap module")
|
||||
if self.internal_history.Submit(FitSwapModuleCommand(self.fitID, self.srcPosition, self.dstPosition)):
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def Undo(self):
|
||||
pyfalog.debug("{} Undo()".format(self))
|
||||
for _ in self.internal_history.Commands:
|
||||
self.internal_history.Undo()
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
|
||||
@@ -5,6 +5,7 @@ import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from .calc.fitChangeState import FitChangeStatesCommand
|
||||
|
||||
|
||||
class GuiModuleStateChangeCommand(wx.Command):
|
||||
def __init__(self, fitID, baseMod, modules, click):
|
||||
# todo: instead of modules, needs to be positions. Dead objects are a thing
|
||||
@@ -16,16 +17,19 @@ class GuiModuleStateChangeCommand(wx.Command):
|
||||
self.modules = modules
|
||||
self.click = click
|
||||
self.internal_history = wx.CommandProcessor()
|
||||
self.cmd = FitChangeStatesCommand(self.fitID, self.baseMod, self.modules, self.click)
|
||||
|
||||
def Do(self):
|
||||
# todo: determine if we've changed state (recalc). If not, store that so we don't attempt to recalc on undo
|
||||
self.internal_history.Submit(FitChangeStatesCommand(self.fitID, self.baseMod, self.modules, self.click))
|
||||
if self.internal_history.Submit(self.cmd):
|
||||
self.sFit.recalc(self.fitID)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
return False
|
||||
|
||||
def Undo(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))
|
||||
return True
|
||||
|
||||
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