Created undo/redo command for module remove, along with reapplying some module-specific attributes (state, charge). Fixed a bug when trying to add a module that doesn't fit
This commit is contained in:
@@ -401,18 +401,10 @@ class FittingView(d.Display):
|
||||
|
||||
def removeModule(self, modules):
|
||||
"""Removes a list of modules from the fit"""
|
||||
sFit = Fit.getInstance()
|
||||
|
||||
if not isinstance(modules, list):
|
||||
modules = [modules]
|
||||
|
||||
positions = [mod.modPosition for mod in modules]
|
||||
result = sFit.removeModule(self.activeFitID, positions)
|
||||
|
||||
if result is not None:
|
||||
self.slotsChanged()
|
||||
ids = {mod.item.ID for mod in modules}
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.activeFitID, action="moddel", typeID=ids))
|
||||
self.mainFrame.command.Submit(cmd.FitModuleRemoveCommand(self.activeFitID, modules))
|
||||
|
||||
def addModule(self, x, y, srcIdx):
|
||||
"""Add a module from the market browser"""
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
from .moduleStateChange import FitModuleStateChangeCommand
|
||||
from.moduleAdd import FitModuleAddCommand
|
||||
from .moduleAdd import FitModuleAddCommand
|
||||
from .moduleRemove import FitModuleRemoveCommand
|
||||
@@ -7,8 +7,8 @@ from gui import globalEvents as GE
|
||||
|
||||
class FitModuleAddCommand(wx.Command):
|
||||
def __init__(self, fitID, itemID):
|
||||
# todo: instead of modules, needs to be positions. Dead objects are a thing
|
||||
wx.Command.__init__(self, True, "Module Add")
|
||||
# todo: evaluate mutaplasmid modules
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.sFit = Fit.getInstance()
|
||||
self.fitID = fitID
|
||||
@@ -16,6 +16,7 @@ class FitModuleAddCommand(wx.Command):
|
||||
self.new_position = None
|
||||
|
||||
def Do(self):
|
||||
# todo: figure how not to add this command to stack if module doesn't fit correctly.
|
||||
populate, self.new_position = self.sFit.appendModule(self.fitID, self.itemID)
|
||||
if populate is not None:
|
||||
# self.slotsChanged() # unsure how to handle this right now? Perhaps move this to the event itself?
|
||||
@@ -23,7 +24,8 @@ class FitModuleAddCommand(wx.Command):
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
# todo: self.slotsChanged()
|
||||
result = self.sFit.removeModule(self.fitID, [self.new_position])
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID, action="moddel", typeID=self.itemID))
|
||||
if (self.new_position):
|
||||
# todo: self.slotsChanged()
|
||||
result = self.sFit.removeModule(self.fitID, [self.new_position])
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID, action="moddel", typeID=self.itemID))
|
||||
return True
|
||||
|
||||
37
gui/fitCommands/moduleRemove.py
Normal file
37
gui/fitCommands/moduleRemove.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
ModuleInfoCache = namedtuple('ModuleInfoCache', ['modPosition', 'itemID', 'state', 'charge'])
|
||||
|
||||
class FitModuleRemoveCommand(wx.Command):
|
||||
def __init__(self, fitID, modules):
|
||||
# todo: evaluate mutaplasmid modules
|
||||
wx.Command.__init__(self, True, "Module Remove")
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.sFit = Fit.getInstance()
|
||||
self.fitID = fitID
|
||||
self.modCache = [ModuleInfoCache(mod.modPosition, mod.item.ID, mod.state, mod.charge) for mod in modules]
|
||||
|
||||
def Do(self):
|
||||
self.sFit.getFit(self.fitID)
|
||||
result = self.sFit.removeModule(self.fitID, [mod.modPosition for mod in self.modCache])
|
||||
|
||||
if result is not None:
|
||||
# self.slotsChanged() # todo: fix
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID, action="moddel", typeID=set([mod.itemID for mod in self.modCache])))
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
for mod in self.modCache:
|
||||
m = self.sFit.changeModule(self.fitID, mod.modPosition, mod.itemID, False)
|
||||
m.state = mod.state
|
||||
m.charge = mod.charge
|
||||
self.sFit.recalc(self.fitID)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID, action="modadd", typeID=set([mod.itemID for mod in self.modCache])))
|
||||
|
||||
return True
|
||||
@@ -568,7 +568,7 @@ class Fit(object):
|
||||
|
||||
return numSlots != len(fit.modules), m.modPosition
|
||||
else:
|
||||
return None
|
||||
return None, None
|
||||
|
||||
def removeModule(self, fitID, positions):
|
||||
"""Removes modules based on a number of positions."""
|
||||
@@ -627,7 +627,7 @@ class Fit(object):
|
||||
else:
|
||||
return None
|
||||
|
||||
def changeModule(self, fitID, position, newItemID):
|
||||
def changeModule(self, fitID, position, newItemID, recalc=True):
|
||||
fit = eos.db.getFit(fitID)
|
||||
|
||||
# We're trying to add a charge to a slot, which won't work. Instead, try to add the charge to the module in that slot.
|
||||
@@ -656,15 +656,16 @@ class Fit(object):
|
||||
if m.isValidState(State.ACTIVE):
|
||||
m.state = State.ACTIVE
|
||||
|
||||
# As some items may affect state-limiting attributes of the ship, calculate new attributes first
|
||||
self.recalc(fit)
|
||||
if (recalc):
|
||||
# As some items may affect state-limiting attributes of the ship, calculate new attributes first
|
||||
self.recalc(fit)
|
||||
# Then, check states of all modules and change where needed. This will recalc if needed
|
||||
self.checkStates(fit, m)
|
||||
|
||||
fit.fill()
|
||||
eos.db.commit()
|
||||
|
||||
return True
|
||||
return m
|
||||
else:
|
||||
return None
|
||||
|
||||
@@ -1073,7 +1074,7 @@ class Fit(object):
|
||||
def isAmmo(itemID):
|
||||
return eos.db.getItem(itemID).category.name == "Charge"
|
||||
|
||||
def setAmmo(self, fitID, ammoID, modules):
|
||||
def setAmmo(self, fitID, ammoID, modules, recalc=True):
|
||||
pyfalog.debug("Set ammo for fit ID: {0}", fitID)
|
||||
if fitID is None:
|
||||
return
|
||||
@@ -1085,7 +1086,8 @@ class Fit(object):
|
||||
if mod.isValidCharge(ammo):
|
||||
mod.charge = ammo
|
||||
|
||||
self.recalc(fit)
|
||||
if recalc:
|
||||
self.recalc(fit)
|
||||
|
||||
@staticmethod
|
||||
def getTargetResists(fitID):
|
||||
@@ -1259,6 +1261,8 @@ class Fit(object):
|
||||
self.recalc(fit)
|
||||
|
||||
def recalc(self, fit):
|
||||
if isinstance(fit, int):
|
||||
fit = self.getFit(fit)
|
||||
start_time = time()
|
||||
pyfalog.info("=" * 10 + "recalc: {0}" + "=" * 10, fit.name)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user