Migrate over the ammo setting stuff to fit/gui commands
This commit is contained in:
44
gui/fitCommands/fitSetCharge.py
Normal file
44
gui/fitCommands/fitSetCharge.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from eos.saveddata.module import Module
|
||||
from logbook import Logger
|
||||
pyfalog = Logger(__name__)
|
||||
import eos.db
|
||||
|
||||
class FitSetChargeCommand(wx.Command):
|
||||
def __init__(self, fitID, modules, chargeID=None):
|
||||
# todo: determine if this command really should be used with a group of modules, or a simple per module basis
|
||||
wx.Command.__init__(self, True, "Module Charge Add")
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.sFit = Fit.getInstance()
|
||||
self.fitID = fitID
|
||||
self.chargeID = chargeID
|
||||
self.modules = modules
|
||||
self.positions = {mod.modPosition: mod.chargeID for mod in modules}
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Set ammo for fit ID: {0}", self.fitID)
|
||||
if self.fitID is None:
|
||||
return False
|
||||
return self.__setAmmo(self.modules, self.chargeID)
|
||||
|
||||
def Undo(self):
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
for position, chargeID in self.positions.items():
|
||||
self.__setAmmo([fit.modules[position]], chargeID)
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def __setAmmo(modules, chargeID):
|
||||
ammo = eos.db.getItem(chargeID) if chargeID else None
|
||||
result = False
|
||||
|
||||
for mod in modules:
|
||||
if mod.isValidCharge(ammo):
|
||||
result = True
|
||||
mod.charge = ammo
|
||||
eos.db.commit()
|
||||
return result
|
||||
@@ -3,28 +3,27 @@ from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
|
||||
from .fitSetCharge import FitSetChargeCommand
|
||||
|
||||
class GuiModuleAddChargeCommand(wx.Command):
|
||||
def __init__(self, fitID, itemID, modules):
|
||||
wx.Command.__init__(self, True, "Module Charge Add")
|
||||
# todo: evaluate mutaplasmid modules
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.sFit = Fit.getInstance()
|
||||
self.internal_history = wx.CommandProcessor()
|
||||
self.fitID = fitID
|
||||
self.itemID = itemID
|
||||
self.positions = {mod.modPosition: mod.chargeID for mod in modules}
|
||||
# can set his up no to not have to set variables on our object
|
||||
self.cmd = FitSetChargeCommand(fitID, modules, itemID)
|
||||
|
||||
def Do(self):
|
||||
fit = self.sFit.getFit(self.fitID)
|
||||
self.sFit.setAmmo(self.fitID, self.itemID, [fit.modules[i] for i in self.positions.keys()])
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
if self.internal_history.Submit(self.cmd):
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
return False
|
||||
|
||||
def Undo(self):
|
||||
fit = self.sFit.getFit(self.fitID)
|
||||
for position, chargeID in self.positions.items():
|
||||
self.sFit.setAmmo(self.fitID, chargeID, [fit.modules[position]], False)
|
||||
self.sFit.recalc(self.fitID)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
for x in self.internal_history.Commands:
|
||||
self.internal_history.Undo()
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
|
||||
|
||||
@@ -1077,6 +1077,7 @@ class Fit(object):
|
||||
def isAmmo(itemID):
|
||||
return eos.db.getItem(itemID).category.name == "Charge"
|
||||
|
||||
@deprecated
|
||||
def setAmmo(self, fitID, ammoID, modules, recalc=True):
|
||||
pyfalog.debug("Set ammo for fit ID: {0}", fitID)
|
||||
if fitID is None:
|
||||
|
||||
Reference in New Issue
Block a user