From fbf3cace10fd81a9393bb2902bf160267cbf4aec Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Tue, 16 Apr 2019 14:48:25 +0300 Subject: [PATCH] Save secondary state changes and restore them on undo --- gui/fitCommands/calc/module/localAdd.py | 14 ++++++++----- .../calc/module/localChangeStates.py | 8 +++++-- gui/fitCommands/calc/module/localClone.py | 11 +++++++--- gui/fitCommands/calc/module/localRemove.py | 11 +++++++--- gui/fitCommands/calc/module/localReplace.py | 21 ++++++++++++------- gui/fitCommands/gui/booster/changeMeta.py | 5 +++-- gui/fitCommands/gui/implant/add.py | 2 +- gui/fitCommands/gui/implant/changeMeta.py | 5 +++-- gui/fitCommands/gui/itemsRebase.py | 2 +- gui/fitCommands/gui/localDrone/changeMeta.py | 5 +++-- .../gui/localFighter/changeMeta.py | 5 +++-- .../gui/localModule/changeMetas.py | 2 +- gui/fitCommands/gui/localModule/clone.py | 5 +++-- .../gui/localModule/mutatedConvert.py | 2 +- .../gui/localModule/mutatedRevert.py | 2 +- .../localModuleCargo/cargoToLocalModule.py | 2 +- .../gui/projectedDrone/changeMeta.py | 2 +- .../gui/projectedFighter/changeMeta.py | 5 +++-- .../gui/projectedModule/changeMeta.py | 2 +- gui/fitCommands/helpers.py | 12 +++++++++++ service/fit.py | 18 +++++++++------- 21 files changed, 92 insertions(+), 49 deletions(-) diff --git a/gui/fitCommands/calc/module/localAdd.py b/gui/fitCommands/calc/module/localAdd.py index a69101952..64b9337ce 100644 --- a/gui/fitCommands/calc/module/localAdd.py +++ b/gui/fitCommands/calc/module/localAdd.py @@ -3,7 +3,7 @@ from logbook import Logger import eos.db from eos.exception import HandledListActionError -from gui.fitCommands.helpers import stateLimit +from gui.fitCommands.helpers import restoreCheckedStates, stateLimit from service.fit import Fit @@ -16,9 +16,10 @@ class CalcAddLocalModuleCommand(wx.Command): wx.Command.__init__(self, True, 'Add Module') self.fitID = fitID self.newModInfo = newModInfo + self.commit = commit self.savedPosition = None self.subsystemCmd = None - self.commit = commit + self.savedStateCheckChanges = None def Do(self): pyfalog.debug('Doing addition of local module {} to fit {}'.format(self.newModInfo, self.fitID)) @@ -50,8 +51,8 @@ class CalcAddLocalModuleCommand(wx.Command): eos.db.commit() return False self.savedPosition = newMod.modPosition - sFit.recalc(self.fitID) - sFit.checkStates(fit, newMod) + sFit.recalc(fit) + self.savedStateCheckChanges = sFit.checkStates(fit, newMod) if self.commit: eos.db.commit() return True @@ -65,4 +66,7 @@ class CalcAddLocalModuleCommand(wx.Command): if self.savedPosition is None: return False cmd = CalcRemoveLocalModuleCommand(fitID=self.fitID, positions=[self.savedPosition], commit=self.commit) - return cmd.Do() + if not cmd.Do(): + return False + restoreCheckedStates(Fit.getInstance().getFit(self.fitID), self.savedStateCheckChanges) + return True diff --git a/gui/fitCommands/calc/module/localChangeStates.py b/gui/fitCommands/calc/module/localChangeStates.py index 70596e37c..2cf643f42 100644 --- a/gui/fitCommands/calc/module/localChangeStates.py +++ b/gui/fitCommands/calc/module/localChangeStates.py @@ -3,6 +3,7 @@ from logbook import Logger import eos.db from eos.saveddata.module import Module +from gui.fitCommands.helpers import restoreCheckedStates from service.fit import Fit @@ -18,6 +19,7 @@ class CalcChangeLocalModuleStatesCommand(wx.Command): self.positions = positions self.click = click self.savedStates = {} + self.savedStateCheckChanges = None def Do(self): pyfalog.debug('Doing change of local module states at position {}/{} to click {} on fit {}'.format(self.mainPosition, self.positions, self.click, self.fitID)) @@ -44,8 +46,8 @@ class CalcChangeLocalModuleStatesCommand(wx.Command): mod.state = proposedState if not changed: return False - sFit.recalc(self.fitID) - sFit.checkStates(fit, mainMod) + sFit.recalc(fit) + self.savedStateCheckChanges = sFit.checkStates(fit, mainMod) eos.db.commit() return True @@ -56,4 +58,6 @@ class CalcChangeLocalModuleStatesCommand(wx.Command): mod = fit.modules[position] pyfalog.debug('Reverting {} to state {} for fit ID {}'.format(mod, state, self.fitID)) mod.state = state + restoreCheckedStates(fit, self.savedStateCheckChanges) + eos.db.commit() return True diff --git a/gui/fitCommands/calc/module/localClone.py b/gui/fitCommands/calc/module/localClone.py index 0410571d4..66326ea8f 100644 --- a/gui/fitCommands/calc/module/localClone.py +++ b/gui/fitCommands/calc/module/localClone.py @@ -5,6 +5,7 @@ from logbook import Logger import eos.db from eos.exception import HandledListActionError +from gui.fitCommands.helpers import restoreCheckedStates from service.fit import Fit @@ -18,6 +19,7 @@ class CalcCloneLocalModuleCommand(wx.Command): self.fitID = fitID self.srcPosition = srcPosition self.dstPosition = dstPosition + self.savedStateCheckChanges = None def Do(self): pyfalog.debug('Doing cloning of local module from position {} to position {} for fit ID {}'.format(self.srcPosition, self.dstPosition, self.fitID)) @@ -36,8 +38,8 @@ class CalcCloneLocalModuleCommand(wx.Command): pyfalog.warning('Failed to replace module') eos.db.commit() return False - sFit.recalc(self.fitID) - sFit.checkStates(fit, copyMod) + sFit.recalc(fit) + self.savedStateCheckChanges = sFit.checkStates(fit, copyMod) eos.db.commit() return True @@ -45,4 +47,7 @@ class CalcCloneLocalModuleCommand(wx.Command): pyfalog.debug('Undoing cloning of local module from position {} to position {} for fit ID {}'.format(self.srcPosition, self.dstPosition, self.fitID)) from .localRemove import CalcRemoveLocalModuleCommand cmd = CalcRemoveLocalModuleCommand(fitID=self.fitID, positions=[self.dstPosition]) - return cmd.Do() + if not cmd.Do(): + return False + restoreCheckedStates(Fit.getInstance().getFit(self.fitID), self.savedStateCheckChanges) + return True diff --git a/gui/fitCommands/calc/module/localRemove.py b/gui/fitCommands/calc/module/localRemove.py index 45cbec868..43439bda8 100644 --- a/gui/fitCommands/calc/module/localRemove.py +++ b/gui/fitCommands/calc/module/localRemove.py @@ -2,7 +2,7 @@ import wx from logbook import Logger import eos.db -from gui.fitCommands.helpers import ModuleInfo +from gui.fitCommands.helpers import ModuleInfo, restoreCheckedStates from service.fit import Fit @@ -17,6 +17,7 @@ class CalcRemoveLocalModuleCommand(wx.Command): self.positions = positions self.savedModInfos = {} self.commit = commit + self.savedStateCheckChanges = None def Do(self): pyfalog.debug('Doing removal of local modules from positions {} on fit {}'.format(self.positions, self.fitID)) @@ -29,7 +30,8 @@ class CalcRemoveLocalModuleCommand(wx.Command): self.savedModInfos[position] = ModuleInfo.fromModule(mod) fit.modules.free(position) - sFit.checkStates(fit, None) + sFit.recalc(fit) + self.savedStateCheckChanges = sFit.checkStates(fit, None) if self.commit: eos.db.commit() # If no modules were removed, report that command was not completed @@ -42,6 +44,9 @@ class CalcRemoveLocalModuleCommand(wx.Command): for position, modInfo in self.savedModInfos.items(): cmd = CalcReplaceLocalModuleCommand(fitID=self.fitID, position=position, newModInfo=modInfo, commit=False) results.append(cmd.Do()) + if not any(results): + return False + restoreCheckedStates(Fit.getInstance().getFit(self.fitID), self.savedStateCheckChanges) if self.commit: eos.db.commit() - return any(results) + return True diff --git a/gui/fitCommands/calc/module/localReplace.py b/gui/fitCommands/calc/module/localReplace.py index 59dc29c8d..bf9e1717f 100644 --- a/gui/fitCommands/calc/module/localReplace.py +++ b/gui/fitCommands/calc/module/localReplace.py @@ -3,7 +3,7 @@ from logbook import Logger import eos.db from eos.exception import HandledListActionError -from gui.fitCommands.helpers import ModuleInfo, stateLimit +from gui.fitCommands.helpers import ModuleInfo, restoreCheckedStates, stateLimit from service.fit import Fit @@ -20,6 +20,7 @@ class CalcReplaceLocalModuleCommand(wx.Command): self.oldModInfo = None self.unloadInvalidCharges = unloadInvalidCharges self.commit = commit + self.savedStateCheckChanges = None self.unloadedCharge = None def Do(self): @@ -56,22 +57,26 @@ class CalcReplaceLocalModuleCommand(wx.Command): pyfalog.warning('Failed to replace in list') self.Undo() return False - sFit.recalc(self.fitID) - sFit.checkStates(fit, newMod) + sFit.recalc(fit) + self.savedStateCheckChanges = sFit.checkStates(fit, newMod) if self.commit: eos.db.commit() return True def Undo(self): pyfalog.debug('Undoing replacement of local module at position {} to {} on fit {}'.format(self.newModInfo, self.position, self.fitID)) + sFit = Fit.getInstance() + fit = sFit.getFit(self.fitID) # Remove if there was no module if self.oldModInfo is None: from .localRemove import CalcRemoveLocalModuleCommand cmd = CalcRemoveLocalModuleCommand(fitID=self.fitID, positions=[self.position], commit=self.commit) - return cmd.Do() + if not cmd.Do(): + return False + sFit.recalc(fit) + restoreCheckedStates(fit, self.savedStateCheckChanges) + return True # Replace if there was - sFit = Fit.getInstance() - fit = sFit.getFit(self.fitID) oldMod = self.oldModInfo.toModule() if oldMod is None: return False @@ -87,8 +92,8 @@ class CalcReplaceLocalModuleCommand(wx.Command): pyfalog.warning('Failed to replace in list') self.Do() return False - sFit.recalc(self.fitID) - sFit.checkStates(fit, oldMod) + sFit.recalc(fit) + restoreCheckedStates(fit, self.savedStateCheckChanges) if self.commit: eos.db.commit() return True diff --git a/gui/fitCommands/gui/booster/changeMeta.py b/gui/fitCommands/gui/booster/changeMeta.py index 1b268ff5e..0f48cdb6d 100644 --- a/gui/fitCommands/gui/booster/changeMeta.py +++ b/gui/fitCommands/gui/booster/changeMeta.py @@ -18,14 +18,15 @@ class GuiChangeBoosterMetaCommand(wx.Command): def Do(self): sFit = Fit.getInstance() - booster = sFit.getFit(self.fitID).boosters[self.position] + fit = sFit.getFit(self.fitID) + booster = fit.boosters[self.position] if booster.itemID == self.newItemID: return False info = BoosterInfo.fromBooster(booster) info.itemID = self.newItemID cmd = CalcAddBoosterCommand(fitID=self.fitID, boosterInfo=info) success = self.internalHistory.submit(cmd) - sFit.recalc(self.fitID) + sFit.recalc(fit) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) return success diff --git a/gui/fitCommands/gui/implant/add.py b/gui/fitCommands/gui/implant/add.py index be2ec725c..2dbf5b712 100644 --- a/gui/fitCommands/gui/implant/add.py +++ b/gui/fitCommands/gui/implant/add.py @@ -29,7 +29,7 @@ class GuiAddImplantCommand(wx.Command): cmd = CalcAddImplantCommand(fitID=self.fitID, implantInfo=ImplantInfo(itemID=self.itemID), commit=False) successImplant = self.internalHistory.submit(cmd) eos.db.commit() - sFit.recalc(self.fitID) + sFit.recalc(fit) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) # 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 diff --git a/gui/fitCommands/gui/implant/changeMeta.py b/gui/fitCommands/gui/implant/changeMeta.py index 7b9bf2ff8..2987ae694 100644 --- a/gui/fitCommands/gui/implant/changeMeta.py +++ b/gui/fitCommands/gui/implant/changeMeta.py @@ -18,14 +18,15 @@ class GuiChangeImplantMetaCommand(wx.Command): def Do(self): sFit = Fit.getInstance() - implant = sFit.getFit(self.fitID).implants[self.position] + fit = sFit.getFit(self.fitID) + implant = fit.implants[self.position] if implant.itemID == self.newItemID: return False info = ImplantInfo.fromImplant(implant) info.itemID = self.newItemID cmd = CalcAddImplantCommand(fitID=self.fitID, implantInfo=info) success = self.internalHistory.submit(cmd) - sFit.recalc(self.fitID) + sFit.recalc(fit) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) return success diff --git a/gui/fitCommands/gui/itemsRebase.py b/gui/fitCommands/gui/itemsRebase.py index c7a6daed9..437c2c151 100644 --- a/gui/fitCommands/gui/itemsRebase.py +++ b/gui/fitCommands/gui/itemsRebase.py @@ -57,7 +57,7 @@ class GuiRebaseItemsCommand(wx.Command): cmdAdd = CalcAddCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.rebaseMap[cargo.itemID], amount=amount)) self.internalHistory.submitBatch(cmdRemove, cmdAdd) eos.db.commit() - sFit.recalc(self.fitID) + sFit.recalc(fit) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) return len(self.internalHistory) > 0 diff --git a/gui/fitCommands/gui/localDrone/changeMeta.py b/gui/fitCommands/gui/localDrone/changeMeta.py index cf3e61467..41c88a1dc 100644 --- a/gui/fitCommands/gui/localDrone/changeMeta.py +++ b/gui/fitCommands/gui/localDrone/changeMeta.py @@ -21,7 +21,8 @@ class GuiChangeLocalDroneMetaCommand(wx.Command): def Do(self): sFit = Fit.getInstance() - drone = sFit.getFit(self.fitID).drones[self.position] + fit = sFit.getFit(self.fitID) + drone = fit.drones[self.position] if drone.itemID == self.newItemID: return False info = DroneInfo.fromDrone(drone) @@ -29,7 +30,7 @@ class GuiChangeLocalDroneMetaCommand(wx.Command): cmdRemove = CalcRemoveLocalDroneCommand(fitID=self.fitID, position=self.position, amount=math.inf) cmdAdd = CalcAddLocalDroneCommand(fitID=self.fitID, droneInfo=info, forceNewStack=True) success = self.internalHistory.submitBatch(cmdRemove, cmdAdd) - sFit.recalc(self.fitID) + sFit.recalc(fit) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) return success diff --git a/gui/fitCommands/gui/localFighter/changeMeta.py b/gui/fitCommands/gui/localFighter/changeMeta.py index b0e654c1d..05ad0ca41 100644 --- a/gui/fitCommands/gui/localFighter/changeMeta.py +++ b/gui/fitCommands/gui/localFighter/changeMeta.py @@ -19,7 +19,8 @@ class GuiChangeLocalFighterMetaCommand(wx.Command): def Do(self): sFit = Fit.getInstance() - fighter = sFit.getFit(self.fitID).fighters[self.position] + fit = sFit.getFit(self.fitID) + fighter = fit.fighters[self.position] if fighter.itemID == self.newItemID: return False info = FighterInfo.fromFighter(fighter) @@ -27,7 +28,7 @@ class GuiChangeLocalFighterMetaCommand(wx.Command): cmdRemove = CalcRemoveLocalFighterCommand(fitID=self.fitID, position=self.position) cmdAdd = CalcAddLocalFighterCommand(fitID=self.fitID, fighterInfo=info) success = self.internalHistory.submitBatch(cmdRemove, cmdAdd) - sFit.recalc(self.fitID) + sFit.recalc(fit) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) return success diff --git a/gui/fitCommands/gui/localModule/changeMetas.py b/gui/fitCommands/gui/localModule/changeMetas.py index 42808a5e8..1a2d2d01b 100644 --- a/gui/fitCommands/gui/localModule/changeMetas.py +++ b/gui/fitCommands/gui/localModule/changeMetas.py @@ -33,7 +33,7 @@ class GuiChangeLocalModuleMetasCommand(wx.Command): return False success = self.internalHistory.submitBatch(*commands) eos.db.commit() - sFit.recalc(self.fitID) + sFit.recalc(fit) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) return success diff --git a/gui/fitCommands/gui/localModule/clone.py b/gui/fitCommands/gui/localModule/clone.py index 019bbcea1..95c5e8b69 100644 --- a/gui/fitCommands/gui/localModule/clone.py +++ b/gui/fitCommands/gui/localModule/clone.py @@ -23,8 +23,9 @@ class GuiCloneLocalModuleCommand(wx.Command): sFit = Fit.getInstance() cmd = CalcCloneLocalModuleCommand(fitID=self.fitID, srcPosition=self.srcPosition, dstPosition=self.dstPosition) success = self.internalHistory.submit(cmd) - sFit.recalc(self.fitID) - self.savedItemID = sFit.getFit(self.fitID).modules[self.srcPosition].itemID + fit = sFit.getFit(self.fitID) + sFit.recalc(fit) + self.savedItemID = fit.modules[self.srcPosition].itemID if success and self.savedItemID is not None: event = GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.savedItemID) else: diff --git a/gui/fitCommands/gui/localModule/mutatedConvert.py b/gui/fitCommands/gui/localModule/mutatedConvert.py index 7e35df777..d8db12430 100644 --- a/gui/fitCommands/gui/localModule/mutatedConvert.py +++ b/gui/fitCommands/gui/localModule/mutatedConvert.py @@ -38,7 +38,7 @@ class GuiConvertMutatedLocalModuleCommand(wx.Command): spoolType=mod.spoolType, spoolAmount=mod.spoolAmount)) success = self.internalHistory.submit(cmd) - sFit.recalc(self.fitID) + sFit.recalc(fit) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) return success diff --git a/gui/fitCommands/gui/localModule/mutatedRevert.py b/gui/fitCommands/gui/localModule/mutatedRevert.py index d82782cee..658d680b9 100644 --- a/gui/fitCommands/gui/localModule/mutatedRevert.py +++ b/gui/fitCommands/gui/localModule/mutatedRevert.py @@ -33,7 +33,7 @@ class GuiRevertMutatedLocalModuleCommand(wx.Command): spoolType=mod.spoolType, spoolAmount=mod.spoolAmount)) success = self.internalHistory.submit(cmd) - sFit.recalc(self.fitID) + sFit.recalc(fit) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) return success diff --git a/gui/fitCommands/gui/localModuleCargo/cargoToLocalModule.py b/gui/fitCommands/gui/localModuleCargo/cargoToLocalModule.py index b75a503e0..dee4d5bf2 100644 --- a/gui/fitCommands/gui/localModuleCargo/cargoToLocalModule.py +++ b/gui/fitCommands/gui/localModuleCargo/cargoToLocalModule.py @@ -138,7 +138,7 @@ class GuiCargoToLocalModuleCommand(wx.Command): else: return False eos.db.commit() - sFit.recalc(self.fitID) + sFit.recalc(fit) events = [] if self.removedModItemID is not None: events.append(GE.FitChanged(fitID=self.fitID, action='moddel', typeID=self.removedModItemID)) diff --git a/gui/fitCommands/gui/projectedDrone/changeMeta.py b/gui/fitCommands/gui/projectedDrone/changeMeta.py index 93332dcc5..e595343a2 100644 --- a/gui/fitCommands/gui/projectedDrone/changeMeta.py +++ b/gui/fitCommands/gui/projectedDrone/changeMeta.py @@ -32,7 +32,7 @@ class GuiChangeProjectedDroneMetaCommand(wx.Command): cmdRemove = CalcRemoveProjectedDroneCommand(fitID=self.fitID, itemID=self.itemID, amount=math.inf) cmdAdd = CalcAddProjectedDroneCommand(fitID=self.fitID, droneInfo=info) success = self.internalHistory.submitBatch(cmdRemove, cmdAdd) - sFit.recalc(self.fitID) + sFit.recalc(fit) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) return success diff --git a/gui/fitCommands/gui/projectedFighter/changeMeta.py b/gui/fitCommands/gui/projectedFighter/changeMeta.py index 02a74c4a7..31669efb6 100644 --- a/gui/fitCommands/gui/projectedFighter/changeMeta.py +++ b/gui/fitCommands/gui/projectedFighter/changeMeta.py @@ -19,7 +19,8 @@ class GuiChangeProjectedFighterMetaCommand(wx.Command): def Do(self): sFit = Fit.getInstance() - fighter = sFit.getFit(self.fitID).projectedFighters[self.position] + fit = sFit.getFit(self.fitID) + fighter = fit.projectedFighters[self.position] if fighter.itemID == self.newItemID: return False info = FighterInfo.fromFighter(fighter) @@ -27,7 +28,7 @@ class GuiChangeProjectedFighterMetaCommand(wx.Command): cmdRemove = CalcRemoveProjectedFighterCommand(fitID=self.fitID, position=self.position) cmdAdd = CalcAddProjectedFighterCommand(fitID=self.fitID, fighterInfo=info) success = self.internalHistory.submitBatch(cmdRemove, cmdAdd) - sFit.recalc(self.fitID) + sFit.recalc(fit) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) return success diff --git a/gui/fitCommands/gui/projectedModule/changeMeta.py b/gui/fitCommands/gui/projectedModule/changeMeta.py index 5259f6a2d..8ec84bfe8 100644 --- a/gui/fitCommands/gui/projectedModule/changeMeta.py +++ b/gui/fitCommands/gui/projectedModule/changeMeta.py @@ -28,7 +28,7 @@ class GuiChangeProjectedModuleMetaCommand(wx.Command): cmdRemove = CalcRemoveProjectedModuleCommand(fitID=self.fitID, position=self.position) cmdAdd = CalcAddProjectedModuleCommand(fitID=self.fitID, modInfo=info) success = self.internalHistory.submitBatch(cmdRemove, cmdAdd) - sFit.recalc(self.fitID) + sFit.recalc(fit) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) return success diff --git a/gui/fitCommands/helpers.py b/gui/fitCommands/helpers.py index 94174fb5b..5918f16de 100644 --- a/gui/fitCommands/helpers.py +++ b/gui/fitCommands/helpers.py @@ -320,3 +320,15 @@ def stateLimit(itemIdentity): if {'moduleBonusAssaultDamageControl', 'moduleBonusIndustrialInvulnerability'}.intersection(item.effects): return FittingModuleState.ONLINE return FittingModuleState.ACTIVE + + +def restoreCheckedStates(fit, stateInfo): + if stateInfo is None: + return + changedMods, changedProjMods, changedProjDrones = stateInfo + for pos, state in changedMods.items(): + fit.modules[pos].state = state + for pos, state in changedProjMods.items(): + fit.projectedModules[pos].state = state + for pos, amountActive in changedProjDrones.items(): + fit.projectedDrones[pos].amountActive = amountActive diff --git a/service/fit.py b/service/fit.py index 567a40041..9860346d9 100644 --- a/service/fit.py +++ b/service/fit.py @@ -461,26 +461,28 @@ class Fit(FitDeprecated): def checkStates(self, fit, base): pyfalog.debug("Check states for fit ID: {0}", fit) - changed = False - for mod in fit.modules: + changedMods = {} + changedProjMods = {} + changedProjDrones = {} + for pos, mod in enumerate(fit.modules): if mod != base: # fix for #529, where a module may be in incorrect state after CCP changes mechanics of module if not mod.canHaveState(mod.state) or not mod.isValidState(mod.state): + changedMods[pos] = mod.state mod.state = FittingModuleState.ONLINE - changed = True - for mod in fit.projectedModules: + for pos, mod in enumerate(fit.projectedModules): # fix for #529, where a module may be in incorrect state after CCP changes mechanics of module if not mod.canHaveState(mod.state, fit) or not mod.isValidState(mod.state): + changedProjMods[pos] = mod.state mod.state = FittingModuleState.OFFLINE - changed = True - for drone in fit.projectedDrones: + for pos, drone in enumerate(fit.projectedDrones): if drone.amountActive > 0 and not drone.canBeApplied(fit): + changedProjDrones[pos] = drone.amountActive drone.amountActive = 0 - changed = True - return changed + return changedMods, changedProjMods, changedProjDrones @classmethod def fitObjectIter(cls, fit):