move some files around and create a context manager for fit recalclation

This commit is contained in:
blitzmann
2018-07-28 00:06:44 -04:00
parent dd430bc9bb
commit 984978a80d
25 changed files with 143 additions and 40 deletions

View File

@@ -436,10 +436,14 @@ class FittingView(d.Display):
fit = sFit.getFit(self.activeFitID)
typeID = fit.cargo[srcIdx].item.ID
sFit.moveCargoToModule(self.mainFrame.getActiveFit(), module.modPosition, srcIdx,
mstate.CmdDown() and module.isEmpty)
self.mainFrame.command.Submit(cmd.GuiCargoToModuleCommand(
self.mainFrame.getActiveFit(),
module.modPosition,
srcIdx,
mstate.CmdDown() and module.isEmpty))
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.mainFrame.getActiveFit(), action="modadd", typeID=typeID))
# wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.mainFrame.getActiveFit(), action="modadd", typeID=typeID))
def swapItems(self, x, y, srcIdx):
"""Swap two modules in fitting window"""

View File

@@ -1,11 +1,9 @@
from .moduleStateChange import GuiModuleStateChangeCommand
from .moduleAdd import GuiModuleAddCommand
from .moduleRemove import GuiModuleRemoveCommand
from .moduleAddCharge import GuiModuleAddChargeCommand
from .moduleSwapOrClone import GuiModuleSwapOrCloneCommand
from .guiToggleModuleState import GuiModuleStateChangeCommand
from .guiAddModule import GuiModuleAddCommand
from .guiRemoveModule import GuiModuleRemoveCommand
from .guiAddCharge import GuiModuleAddChargeCommand
from .guiSwapCloneModule import GuiModuleSwapOrCloneCommand
from .guiRemoveCargo import GuiRemoveCargoCommand
from .guiAddCargo import GuiAddCargoCommand
from .fitAddCargo import FitAddCargoCommand
from .fitRemoveCargo import FitRemoveCargoCommand
from .guiRemoveImplant import GuiRemoveImplantCommand
from .guiAddImplant import GuiAddImplantCommand
from .guiAddImplant import GuiAddImplantCommand

View File

View File

@@ -1,10 +1,6 @@
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__)
@@ -47,7 +43,7 @@ class FitRemoveCargoCommand(wx.Command):
return True
def Undo(self):
from .fitAddCargo import FitAddCargoCommand # Avoid circular import
from gui.fitCommands.calc.fitAddCargo import FitAddCargoCommand # Avoid circular import
cmd = FitAddCargoCommand(self.fitID, self.itemID, self.old_amount, True)
cmd.Do()
return True

View File

@@ -1,10 +1,6 @@
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__)
@@ -32,7 +28,7 @@ class FitRemoveImplantCommand(wx.Command):
return True
def Undo(self):
from .fitAddImplant import FitAddImplantCommand # Avoid circular import
from gui.fitCommands.calc.fitAddImplant import FitAddImplantCommand # Avoid circular import
cmd = FitAddImplantCommand(self.fitID, self.old_implant)
cmd.Do()
return True

View File

@@ -1,10 +1,6 @@
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
from gui.fitCommands.helpers import ModuleInfoCache
import eos.db
from logbook import Logger
pyfalog = Logger(__name__)
@@ -48,7 +44,7 @@ class FitRemoveModuleCommand(wx.Command):
return True
def Undo(self):
from .fitAddModule import FitAddModuleCommand # avoids circular import
from gui.fitCommands.calc.fitAddModule import FitAddModuleCommand # avoids circular import
for mod in self.modCache:
cmd = FitAddModuleCommand(self.fitID, mod.itemID)
cmd.Do()

View File

@@ -3,7 +3,7 @@ from service.fit import Fit
import gui.mainFrame
from gui import globalEvents as GE
from .helpers import ModuleInfoCache
from gui.fitCommands.helpers import ModuleInfoCache
from eos.saveddata.module import Module, State
import eos.db
from logbook import Logger

View File

@@ -0,0 +1,100 @@
import wx
from service.fit import Fit
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.fitSetCharge import FitSetChargeCommand
from logbook import Logger
pyfalog = Logger(__name__)
class GuiCargoToModuleCommand(wx.Command):
"""
Moves cargo to fitting window. Can either do a copy, move, or swap with current module
If we try to copy/move into a spot with a non-empty module, we swap instead.
To avoid redundancy in converting Cargo item, this function does the
sanity checks as opposed to the GUI View. This is different than how the
normal .swapModules() does things, which is mostly a blind swap.
"""
def __init__(self, fitID, moduleIdx, cargoIdx, copy=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()
self.fitID = fitID
self.moduleIdx = moduleIdx
self.cargoIdx = cargoIdx
self.copy = copy
self.internal_history = wx.CommandProcessor()
def Do(self):
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
module = fit.modules[self.moduleIdx]
cargo = fit.cargo[self.cargoIdx]
result = None
# We're trying to move a charge from cargo to a slot. Use SetCharge command (don't respect move vs copy)
if sFit.isAmmo(cargo.item.ID):
result = self.internal_history.Submit(FitSetChargeCommand(self.fitID, [module], cargo.item.ID))
# else:
#
# pyfalog.debug("Moving cargo item to module for fit ID: {0}", self.fitID)
#
# # Gather modules and convert Cargo item to Module, silently return if not a module
# try:
# cargoP = es_Module(cargo.item)
# cargoP.owner = fit
# if cargoP.isValidState(State.ACTIVE):
# cargoP.state = State.ACTIVE
# except:
# pyfalog.warning("Invalid item: {0}", cargo.item)
# return
#
# if cargoP.slot != module.slot: # can't swap modules to different racks
# return
#
# # remove module that we are trying to move cargo to
# fit.modules.remove(module)
#
# if not cargoP.fits(fit): # if cargo doesn't fit, rollback and return
# fit.modules.insert(moduleIdx, module)
# return
#
# fit.modules.insert(moduleIdx, cargoP)
#
# if not copyMod: # remove existing cargo if not cloning
# if cargo.amount == 1:
# fit.cargo.remove(cargo)
# else:
# cargo.amount -= 1
#
# if not module.isEmpty: # if module is placeholder, we don't want to convert/add it
# moduleItem = module.item if not module.item.isAbyssal else module.baseItem
# for x in fit.cargo.find(moduleItem):
# x.amount += 1
# break
# else:
# moduleP = es_Cargo(moduleItem)
# moduleP.amount = 1
# fit.cargo.insert(cargoIdx, moduleP)
#
# eos.db.commit()
# self.recalc(fit)
# #
# #
# #
# # 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))
if result:
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return result
def Undo(self):
for _ in self.internal_history.Commands:
self.internal_history.Undo()
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True

View File

@@ -3,7 +3,7 @@ from service.fit import Fit
import gui.mainFrame
from gui import globalEvents as GE
from .fitAddCargo import FitAddCargoCommand
from .calc.fitAddCargo import FitAddCargoCommand
class GuiAddCargoCommand(wx.Command):
def __init__(self, fitID, itemID, amount=1, replace=False):

View File

@@ -3,7 +3,7 @@ from service.fit import Fit
import gui.mainFrame
from gui import globalEvents as GE
from .fitSetCharge import FitSetChargeCommand
from .calc.fitSetCharge import FitSetChargeCommand
class GuiModuleAddChargeCommand(wx.Command):
def __init__(self, fitID, itemID, modules):

View File

@@ -3,7 +3,7 @@ from service.fit import Fit
import gui.mainFrame
from gui import globalEvents as GE
from .fitAddImplant import FitAddImplantCommand
from .calc.fitAddImplant import FitAddImplantCommand
class GuiAddImplantCommand(wx.Command):
def __init__(self, fitID, itemID):

View File

@@ -3,9 +3,8 @@ from service.fit import Fit
import gui.mainFrame
from gui import globalEvents as GE
from .helpers import ModuleInfoCache
from .fitAddModule import FitAddModuleCommand
from .fitReplaceModule import FitReplaceModuleCommand
from .calc.fitAddModule import FitAddModuleCommand
from .calc.fitReplaceModule import FitReplaceModuleCommand
class GuiModuleAddCommand(wx.Command):
def __init__(self, fitID, itemID, position=None):

View File

@@ -3,7 +3,7 @@ from service.fit import Fit
import gui.mainFrame
from gui import globalEvents as GE
from .fitRemoveCargo import FitRemoveCargoCommand
from .calc.fitRemoveCargo import FitRemoveCargoCommand
class GuiRemoveCargoCommand(wx.Command):
def __init__(self, fitID, itemID):

View File

@@ -3,7 +3,7 @@ from service.fit import Fit
import gui.mainFrame
from gui import globalEvents as GE
from .fitRemoveImplant import FitRemoveImplantCommand
from .calc.fitRemoveImplant import FitRemoveImplantCommand
class GuiRemoveImplantCommand(wx.Command):
def __init__(self, fitID, position):

View File

@@ -5,7 +5,7 @@ import gui.mainFrame
from gui import globalEvents as GE
from .helpers import ModuleInfoCache
from .fitRemoveModule import FitRemoveModuleCommand
from .calc.fitRemoveModule import FitRemoveModuleCommand
class GuiModuleRemoveCommand(wx.Command):

View File

@@ -3,8 +3,8 @@ from service.fit import Fit
import gui.mainFrame
from gui import globalEvents as GE
from .fitSwapModule import FitSwapModuleCommand
from .fitCloneModule import FitCloneModduleCommand
from gui.fitCommands.calc.fitSwapModule import FitSwapModuleCommand
from .calc.fitCloneModule import FitCloneModduleCommand
class GuiModuleSwapOrCloneCommand(wx.Command):
def __init__(self, fitID, srcPosition, dstPosition, clone=False):

View File

@@ -3,7 +3,7 @@ from service.fit import Fit
import gui.mainFrame
from gui import globalEvents as GE
from .fitChangeState import FitChangeStatesCommand
from .calc.fitChangeState import FitChangeStatesCommand
class GuiModuleStateChangeCommand(wx.Command):
def __init__(self, fitID, baseMod, modules, click):