diff --git a/eos/effectHandlerHelpers.py b/eos/effectHandlerHelpers.py index 8732f67aa..d3d25b81c 100644 --- a/eos/effectHandlerHelpers.py +++ b/eos/effectHandlerHelpers.py @@ -213,45 +213,46 @@ class HandledDroneCargoList(HandledList): class HandledImplantList(HandledList): - def append(self, thing): - if thing.isInvalid: - HandledList.append(self, thing) - self.remove(thing) + def append(self, implant): + if implant.isInvalid: + HandledList.append(self, implant) + self.remove(implant) return - self.makeRoom(thing) - HandledList.append(self, thing) + self.makeRoom(implant) + HandledList.append(self, implant) - def makeRoom(self, thing): + def makeRoom(self, implant): # if needed, remove booster that was occupying slot - oldObj = next((m for m in self if m.slot == thing.slot), None) + oldObj = next((m for m in self if m.slot == implant.slot), None) if oldObj: - pyfalog.info("Slot {0} occupied with {1}, replacing with {2}", thing.slot, oldObj.item.name, - thing.item.name) + pyfalog.info("Slot {0} occupied with {1}, replacing with {2}", implant.slot, oldObj.item.name, + implant.item.name) itemID = oldObj.itemID + state = oldObj.active oldObj.itemID = 0 # hack to remove from DB. See GH issue #324 self.remove(oldObj) - return itemID - return None + return itemID, state + return None, None class HandledBoosterList(HandledList): - def append(self, thing): - if thing.isInvalid: - HandledList.append(self, thing) - self.remove(thing) + def append(self, booster): + if booster.isInvalid: + HandledList.append(self, booster) + self.remove(booster) return - self.makeRoom(thing) - HandledList.append(self, thing) + self.makeRoom(booster) + HandledList.append(self, booster) - def makeRoom(self, thing): + def makeRoom(self, booster): # if needed, remove booster that was occupying slot - oldObj = next((m for m in self if m.slot == thing.slot), None) + oldObj = next((m for m in self if m.slot == booster.slot), None) if oldObj: - pyfalog.info("Slot {0} occupied with {1}, replacing with {2}", thing.slot, oldObj.item.name, - thing.item.name) + pyfalog.info("Slot {0} occupied with {1}, replacing with {2}", booster.slot, oldObj.item.name, + booster.item.name) itemID = oldObj.itemID state = oldObj.active sideEffects = {se.effectID: se.active for se in oldObj.sideEffects} diff --git a/gui/fitCommands/calc/fitAddImplant.py b/gui/fitCommands/calc/fitAddImplant.py index 4e3fd372c..f2838efeb 100644 --- a/gui/fitCommands/calc/fitAddImplant.py +++ b/gui/fitCommands/calc/fitAddImplant.py @@ -9,40 +9,44 @@ class FitAddImplantCommand(wx.Command): """" from sFit.addImplant """ - def __init__(self, fitID, itemID): - wx.Command.__init__(self, True, "Cargo add") + def __init__(self, fitID, itemID, state): + wx.Command.__init__(self, True, "Add Implant") self.fitID = fitID - self.itemID = itemID - self.old_item = None + self.newItemID = itemID + self.newState = state + self.newIndex = None + self.oldItemID = None + self.oldState = None def Do(self): - pyfalog.debug("Adding implant to fit ({0}) for item ID: {1}", self.fitID, self.itemID) + pyfalog.debug("Adding implant to fit ({0}) for item ID: {1}", self.fitID, self.newItemID) fit = eos.db.getFit(self.fitID) - item = eos.db.getItem(self.itemID, eager="attributes") + item = eos.db.getItem(self.newItemID, eager="attributes") - if next((x for x in fit.implants if x.itemID == self.itemID), None): + if next((x for x in fit.implants if x.itemID == self.newItemID), None): return False # already have item in list of implants try: implant = Implant(item) except ValueError: - pyfalog.warning("Invalid item: {0}", self.itemID) + pyfalog.warning("Invalid item: {0}", self.newItemID) return False - - self.old_item = fit.implants.makeRoom(implant) + implant.active = self.newState + + self.oldItemID, self.oldState = fit.implants.makeRoom(implant) fit.implants.append(implant) - self.new_index = fit.implants.index(implant) + self.newIndex = fit.implants.index(implant) return True def Undo(self): - if self.old_item: + if self.oldItemID: # If we had an item in the slot previously, add it back. - cmd = FitAddImplantCommand(self.fitID, self.old_item) + cmd = FitAddImplantCommand(self.fitID, self.oldItemID, self.oldState) cmd.Do() return True from .fitRemoveImplant import FitRemoveImplantCommand # Avoid circular import - cmd = FitRemoveImplantCommand(self.fitID, self.new_index) + cmd = FitRemoveImplantCommand(self.fitID, self.newIndex) cmd.Do() return True diff --git a/gui/fitCommands/calc/fitRemoveImplant.py b/gui/fitCommands/calc/fitRemoveImplant.py index d0f8101cd..0a52bb49f 100644 --- a/gui/fitCommands/calc/fitRemoveImplant.py +++ b/gui/fitCommands/calc/fitRemoveImplant.py @@ -14,19 +14,21 @@ class FitRemoveImplantCommand(wx.Command): wx.Command.__init__(self, True, "Implant remove") self.fitID = fitID self.position = position - self.old_implant = None + self.savedItemID = None + self.savedState = None def Do(self): pyfalog.debug("Removing implant from position ({0}) for fit ID: {1}", self.position, self.fitID) fit = eos.db.getFit(self.fitID) implant = fit.implants[self.position] - self.old_implant = implant.itemID + self.savedItemID = implant.itemID + self.savedState = implant.active fit.implants.remove(implant) return True def Undo(self): from gui.fitCommands.calc.fitAddImplant import FitAddImplantCommand # Avoid circular import - cmd = FitAddImplantCommand(self.fitID, self.old_implant) + cmd = FitAddImplantCommand(self.fitID, self.savedItemID, self.savedState) cmd.Do() return True diff --git a/gui/fitCommands/guiAddImplant.py b/gui/fitCommands/guiAddImplant.py index 52b284071..a9850f82d 100644 --- a/gui/fitCommands/guiAddImplant.py +++ b/gui/fitCommands/guiAddImplant.py @@ -18,7 +18,7 @@ class GuiAddImplantCommand(wx.Command): self.itemID = itemID def Do(self): - if self.internal_history.Submit(FitAddImplantCommand(self.fitID, self.itemID)) and self.internal_history.Submit(FitChangeImplantLocation(self.fitID, ImplantLocation.FIT)): + if self.internal_history.Submit(FitAddImplantCommand(self.fitID, self.itemID, True)) and self.internal_history.Submit(FitChangeImplantLocation(self.fitID, ImplantLocation.FIT)): self.sFit.recalc(self.fitID) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) return True diff --git a/gui/fitCommands/guiMetaSwap.py b/gui/fitCommands/guiMetaSwap.py index 2e6837249..b29b37df1 100644 --- a/gui/fitCommands/guiMetaSwap.py +++ b/gui/fitCommands/guiMetaSwap.py @@ -33,7 +33,8 @@ class GuiMetaSwapCommand(wx.Command): elif context == 'implantItem': for x in selection: idx = fit.implants.index(x) - self.data.append(((FitRemoveImplantCommand, fitID, idx), (FitAddImplantCommand, fitID, itemID))) + state = x.active + self.data.append(((FitRemoveImplantCommand, fitID, idx), (FitAddImplantCommand, fitID, itemID, state))) elif context == 'boosterItem': for x in selection: idx = fit.boosters.index(x)