Fix implant set addition

This commit is contained in:
DarkPhoenix
2019-04-15 23:12:51 +03:00
parent c7ed6367f9
commit 46fa1eb0c6
13 changed files with 84 additions and 47 deletions

View File

@@ -138,9 +138,9 @@ class BoosterView(d.Display):
event.Skip()
return
if self.mainFrame.command.Submit(cmd.GuiAddBoosterCommand(fitID=fitID, itemID=event.itemID)):
self.mainFrame.additionsPane.select("Boosters")
self.mainFrame.command.Submit(cmd.GuiAddBoosterCommand(fitID=fitID, itemID=event.itemID))
# Select in any case - as we might've added booster which has been there already and command failed
self.mainFrame.additionsPane.select('Boosters')
event.Skip()
def removeItem(self, event):

View File

@@ -218,7 +218,7 @@ class DroneView(Display):
return
if self.mainFrame.command.Submit(cmd.GuiAddLocalDroneCommand(fitID=fitID, itemID=event.itemID, amount=1)):
self.mainFrame.additionsPane.select("Drones")
self.mainFrame.additionsPane.select('Drones')
event.Skip()

View File

@@ -264,7 +264,7 @@ class FighterDisplay(d.Display):
fitID = self.mainFrame.getActiveFit()
if self.mainFrame.command.Submit(cmd.GuiAddLocalFighterCommand(fitID, event.itemID)):
self.mainFrame.additionsPane.select("Fighters")
self.mainFrame.additionsPane.select('Fighters')
event.Skip()

View File

@@ -187,8 +187,9 @@ class ImplantDisplay(d.Display):
event.Skip()
return
if self.mainFrame.command.Submit(cmd.GuiAddImplantCommand(fitID, event.itemID)):
self.mainFrame.additionsPane.select("Implants")
self.mainFrame.command.Submit(cmd.GuiAddImplantCommand(fitID, event.itemID))
# Select in any case - as we might've added implant which has been there already and command failed
self.mainFrame.additionsPane.select('Implants')
event.Skip()

View File

@@ -1,6 +1,7 @@
# noinspection PyPackageRequirements
import wx
import gui.fitCommands as cmd
import gui.globalEvents as GE
import gui.mainFrame
from gui.contextMenu import ContextMenu
@@ -83,12 +84,9 @@ class ImplantSets(ContextMenu):
wx.PostEvent(self.selection, GE.CharChanged())
else:
sFit = Fit.getInstance()
fitID = self.mainFrame.getActiveFit()
for implant in set.implants:
sFit.addImplant(fitID, implant.item.ID, recalc=implant == set.implants[-1])
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID))
self.mainFrame.command.Submit(cmd.GuiAddImplantSetCommand(
fitID=self.mainFrame.getActiveFit(),
itemIDs=[i.itemID for i in set.implants]))
ImplantSets.register()

View File

@@ -66,9 +66,11 @@ class ItemRemove(ContextMenu):
self.mainFrame.command.Submit(cmd.GuiRemoveProjectedFighterCommand(
fitID=fitID, position=fit.projectedFighters.index(selection[0])))
elif srcContext == "projectedCharge":
self.mainFrame.command.Submit(cmd.GuiChangeProjectedModuleChargesCommand(fitID, [selection[0]], None))
self.mainFrame.command.Submit(cmd.GuiChangeProjectedModuleChargesCommand(
fitID=fitID, modules=[selection[0]], chargeItemID=None))
elif srcContext == "commandFit":
self.mainFrame.command.Submit(cmd.GuiRemoveCommandFitCommand(fitID, selection[0].ID))
self.mainFrame.command.Submit(cmd.GuiRemoveCommandFitCommand(
fitID=fitID, commandFitID=selection[0].ID))
ItemRemove.register()

View File

@@ -17,6 +17,7 @@ from .gui.implant.add import GuiAddImplantCommand
from .gui.implant.changeLocation import GuiChangeImplantLocationCommand
from .gui.implant.changeMeta import GuiChangeImplantMetaCommand
from .gui.implant.remove import GuiRemoveImplantCommand
from .gui.implant.setAdd import GuiAddImplantSetCommand
from .gui.implant.toggleState import GuiToggleImplantStateCommand
from .gui.itemsRebase import GuiRebaseItemsCommand
from .gui.localDrone.add import GuiAddLocalDroneCommand

View File

@@ -11,11 +11,12 @@ pyfalog = Logger(__name__)
class CalcAddImplantCommand(wx.Command):
def __init__(self, fitID, implantInfo, position=None):
def __init__(self, fitID, implantInfo, position=None, commit=True):
wx.Command.__init__(self, True, 'Add Implant')
self.fitID = fitID
self.newImplantInfo = implantInfo
self.newPosition = position
self.commit = commit
self.oldImplantInfo = None
self.oldPosition = None
@@ -50,7 +51,8 @@ class CalcAddImplantCommand(wx.Command):
cmd.Do()
return False
self.newPosition = fit.implants.index(newImplant)
eos.db.commit()
if self.commit:
eos.db.commit()
return True
def Undo(self):

View File

@@ -10,20 +10,24 @@ pyfalog = Logger(__name__)
class CalcChangeImplantLocationCommand(wx.Command):
def __init__(self, fitID, source):
def __init__(self, fitID, source, commit=True):
wx.Command.__init__(self, True, 'Change Implant Location')
self.fitID = fitID
self.source = source
self.commit = commit
self.savedSource = None
def Do(self):
pyfalog.debug('Doing changing of implant source to {} for fit {}'.format(self.fitID, self.source))
fit = Fit.getInstance().getFit(self.fitID)
self.savedSource = fit.implantSource
if self.source == self.savedSource:
return False
fit.implantSource = self.source
eos.db.commit()
if self.commit:
eos.db.commit()
return True
def Undo(self):
cmd = CalcChangeImplantLocationCommand(fitID=self.fitID, source=self.savedSource)
cmd = CalcChangeImplantLocationCommand(fitID=self.fitID, source=self.savedSource, commit=self.commit)
return cmd.Do()

View File

@@ -11,10 +11,11 @@ pyfalog = Logger(__name__)
class CalcRemoveImplantCommand(wx.Command):
def __init__(self, fitID, position):
def __init__(self, fitID, position, commit=True):
wx.Command.__init__(self, True, 'Remove Implant')
self.fitID = fitID
self.position = position
self.commit = commit
self.savedImplantInfo = None
def Do(self):
@@ -23,11 +24,12 @@ class CalcRemoveImplantCommand(wx.Command):
implant = fit.implants[self.position]
self.savedImplantInfo = ImplantInfo.fromImplant(implant)
fit.implants.remove(implant)
eos.db.commit()
if self.commit:
eos.db.commit()
return True
def Undo(self):
pyfalog.debug('Undoing removal of implant {} on fit {}'.format(self.savedImplantInfo, self.fitID))
from .add import CalcAddImplantCommand
cmd = CalcAddImplantCommand(fitID=self.fitID, implantInfo=self.savedImplantInfo, position=self.position)
cmd = CalcAddImplantCommand(fitID=self.fitID, implantInfo=self.savedImplantInfo, position=self.position, commit=self.commit)
return cmd.Do()

View File

@@ -1,5 +1,6 @@
import wx
import eos.db
import gui.mainFrame
from eos.const import ImplantLocation
from gui import globalEvents as GE
@@ -18,15 +19,25 @@ class GuiAddImplantCommand(wx.Command):
self.itemID = itemID
def Do(self):
cmdLocation = CalcChangeImplantLocationCommand(fitID=self.fitID, source=ImplantLocation.FIT)
cmdAdd = CalcAddImplantCommand(fitID=self.fitID, implantInfo=ImplantInfo(itemID=self.itemID))
success = self.internalHistory.submitBatch(cmdLocation, cmdAdd)
Fit.getInstance().recalc(self.fitID)
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
if fit.implantSource != ImplantLocation.FIT:
cmd = CalcChangeImplantLocationCommand(fitID=self.fitID, source=ImplantLocation.FIT, commit=False)
successSource = self.internalHistory.submit(cmd)
else:
successSource = False
cmd = CalcAddImplantCommand(fitID=self.fitID, implantInfo=ImplantInfo(itemID=self.itemID), commit=False)
successImplant = self.internalHistory.submit(cmd)
eos.db.commit()
sFit.recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success
# Acceptable behavior when we already have passed implant and just switch source, or
# when we have source and add implant, but not if we do not change anything
return successSource or successImplant
def Undo(self):
success = self.internalHistory.undoAll()
eos.db.commit()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success

View File

@@ -0,0 +1,35 @@
import wx
import eos.db
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.implant.add import CalcAddImplantCommand
from gui.fitCommands.helpers import ImplantInfo, InternalCommandHistory
from service.fit import Fit
class GuiAddImplantSetCommand(wx.Command):
def __init__(self, fitID, itemIDs):
wx.Command.__init__(self, True, 'Add Implant Set')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.itemIDs = itemIDs
def Do(self):
results = []
for itemID in self.itemIDs:
cmd = CalcAddImplantCommand(fitID=self.fitID, implantInfo=ImplantInfo(itemID=itemID), commit=False)
results.append(self.internalHistory.submit(cmd))
eos.db.commit()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
# Some might fail, as we already might have these implants
return any(results)
def Undo(self):
success = self.internalHistory.undoAll()
eos.db.commit()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success

View File

@@ -200,25 +200,6 @@ class FitDeprecated(object):
else:
return False
@deprecated
def addImplant(self, fitID, itemID, recalc=True):
pyfalog.debug("Adding implant to fit ({0}) for item ID: {1}", fitID, itemID)
if fitID is None:
return False
fit = eos.db.getFit(fitID)
item = eos.db.getItem(itemID, eager="attributes")
try:
implant = es_Implant(item)
except ValueError:
pyfalog.warning("Invalid item: {0}", itemID)
return False
fit.implants.append(implant)
if recalc:
self.recalc(fit)
return True
@deprecated
def removeImplant(self, fitID, position, recalc=True):
pyfalog.debug("Removing implant from position ({0}) for fit ID: {1}", position, fitID)