Overhaul module-related commands

This commit is contained in:
DarkPhoenix
2019-04-12 04:02:28 +03:00
parent 5579929f83
commit ad03f907fa
18 changed files with 307 additions and 373 deletions

View File

@@ -1,16 +1,21 @@
import wx
import eos.db
from logbook import Logger
import gui.mainFrame
from service.market import Market
from service.fit import Fit
from gui import globalEvents as GE
from gui.fitCommands.helpers import ModuleInfo
from .calc.fitAddModule import FitAddModuleCommand
from .calc.fitReplaceModule import FitReplaceModuleCommand
from .calc.fitSetCharge import FitSetChargeCommand
from service.fit import Fit
from logbook import Logger
pyfalog = Logger(__name__)
class GuiModuleAddCommand(wx.Command):
def __init__(self, fitID, itemID, position=None):
"""
Handles adding an item, usually a module, to the Fitting Window.
@@ -20,57 +25,51 @@ class GuiModuleAddCommand(wx.Command):
set the charge on the underlying module (requires position)
:param position: Optional. The position in fit.modules that we are attempting to set the item to
"""
wx.Command.__init__(self, True, "Module Add: {}".format(itemID))
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
self.sFit = Fit.getInstance()
wx.Command.__init__(self, True, 'Module Add')
self.fitID = fitID
self.itemID = itemID
self.internal_history = wx.CommandProcessor()
self.position = position
self.old_mod = None
self.internalHistory = wx.CommandProcessor()
def Do(self):
pyfalog.debug("{} Do()".format(self))
success = False
item = eos.db.getItem(self.itemID)
item = Market.getInstance().getItem(self.itemID)
# Charge
if item.isCharge and self.position is not None:
pyfalog.debug("Trying to add a charge")
success = self.internal_history.Submit(FitSetChargeCommand(self.fitID, [self.position], self.itemID))
success = self.internalHistory.Submit(FitSetChargeCommand(self.fitID, [self.position], self.itemID))
if not success:
pyfalog.debug(" Failed")
return False # if it's a charge item and this failed, nothing more we can try.
# if we have a position set, try to apply the module to that position
# Module to position
elif self.position is not None:
pyfalog.debug("Trying to add a module to a specific position")
success = self.internal_history.Submit(FitReplaceModuleCommand(
success = self.internalHistory.Submit(FitReplaceModuleCommand(
fitID=self.fitID,
position=self.position,
newItemID=self.itemID,
newBaseItemID=None,
newMutaplasmidID=None,
newMutations=None,
newState=None,
newChargeID=None))
newModInfo=ModuleInfo(itemID=self.itemID)))
if not success:
pyfalog.debug(" Failed")
# something went wrong with trying to fit the module into specific location, attempt to append it
self.position = None
# if we're not trying to set module to a position, simply append
# Module without position
if self.position is None:
pyfalog.debug("Trying to append a module")
success = self.internal_history.Submit(FitAddModuleCommand(self.fitID, self.itemID))
success = self.internalHistory.Submit(FitAddModuleCommand(
fitID=self.fitID,
newModInfo=ModuleInfo(itemID=self.itemID)))
if success:
self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID, action="modadd", typeID=self.itemID))
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID, action="modadd", typeID=self.itemID))
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", typeID=self.itemID))
for _ in self.internalHistory.Commands:
self.internalHistory.Undo()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID, action="moddel", typeID=self.itemID))
return True