From 6d9e60648e230921bbce53e4a243485bda604ace Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Sat, 13 Apr 2019 23:11:28 +0300 Subject: [PATCH] Do not remove items when quantity is 0 in fit commands, it will be done in gui commands instead --- gui/fitCommands/calc/fitChangeCargoAmount.py | 14 +++---------- gui/fitCommands/calc/fitChangeDroneAmount.py | 20 ++++++------------- .../calc/fitChangeFighterAmount.py | 9 +-------- gui/fitCommands/calc/fitChangeModuleStates.py | 1 + .../calc/fitChangeProjectedDroneAmount.py | 20 ++++++------------- 5 files changed, 17 insertions(+), 47 deletions(-) diff --git a/gui/fitCommands/calc/fitChangeCargoAmount.py b/gui/fitCommands/calc/fitChangeCargoAmount.py index 998951c97..d8b9fac90 100644 --- a/gui/fitCommands/calc/fitChangeCargoAmount.py +++ b/gui/fitCommands/calc/fitChangeCargoAmount.py @@ -16,7 +16,6 @@ class FitChangeCargoAmount(wx.Command): self.fitID = fitID self.cargoInfo = cargoInfo self.savedCargoInfo = None - self.removeCommand = None def Do(self): pyfalog.debug('Doing change of cargo {} for fit {}'.format(self.cargoInfo, self.fitID)) @@ -28,18 +27,11 @@ class FitChangeCargoAmount(wx.Command): self.savedCargoInfo = CargoInfo.fromCargo(cargo) if self.cargoInfo.amount == self.savedCargoInfo.amount: return False - if self.cargoInfo.amount > 0: - cargo.amount = self.cargoInfo.amount - eos.db.commit() - return True - else: - from .fitRemoveCargo import FitRemoveCargoCommand - self.removeCommand = FitRemoveCargoCommand(fitID=self.fitID, cargoInfo=self.savedCargoInfo) - return self.removeCommand.Do() + cargo.amount = self.cargoInfo.amount + eos.db.commit() + return True def Undo(self): pyfalog.debug('Undoing change of cargo {} for fit {}'.format(self.cargoInfo, self.fitID)) - if self.removeCommand is not None: - return self.removeCommand.Undo() cmd = FitChangeCargoAmount(self.fitID, self.savedCargoInfo) return cmd.Do() diff --git a/gui/fitCommands/calc/fitChangeDroneAmount.py b/gui/fitCommands/calc/fitChangeDroneAmount.py index 492a4559c..7ff533f23 100644 --- a/gui/fitCommands/calc/fitChangeDroneAmount.py +++ b/gui/fitCommands/calc/fitChangeDroneAmount.py @@ -19,7 +19,6 @@ class FitChangeDroneAmount(wx.Command): self.position = position self.amount = amount self.savedDroneInfo = None - self.removeCommand = None def Do(self): pyfalog.debug('Doing change of drone amount to {} at position {} on fit {}'.format(self.amount, self.position, self.fitID)) @@ -28,23 +27,16 @@ class FitChangeDroneAmount(wx.Command): self.savedDroneInfo = DroneInfo.fromDrone(drone) if self.amount == self.savedDroneInfo.amount: return False - if self.amount > 0: + drone.amount = self.amount + if drone.amountActive > 0: + difference = self.amount - self.savedDroneInfo.amount drone.amount = self.amount - if drone.amountActive > 0: - difference = self.amount - self.savedDroneInfo.amount - drone.amount = self.amount - drone.amountActive = max(min(drone.amountActive + difference, drone.amount), 0) - eos.db.commit() - return True - else: - from .fitRemoveDrone import FitRemoveDroneCommand - self.removeCommand = FitRemoveDroneCommand(fitID=self.fitID, position=self.position, amount=math.inf) - return self.removeCommand.Do() + drone.amountActive = max(min(drone.amountActive + difference, drone.amount), 0) + eos.db.commit() + return True def Undo(self): pyfalog.debug('Undoing change of drone quantity to {} at position {} on fit {}'.format(self.amount, self.position, self.fitID)) - if self.removeCommand is not None: - return self.removeCommand.Undo() if self.savedDroneInfo is not None: fit = Fit.getInstance().getFit(self.fitID) drone = fit.drones[self.position] diff --git a/gui/fitCommands/calc/fitChangeFighterAmount.py b/gui/fitCommands/calc/fitChangeFighterAmount.py index 02d72bc8b..d1fe43e95 100644 --- a/gui/fitCommands/calc/fitChangeFighterAmount.py +++ b/gui/fitCommands/calc/fitChangeFighterAmount.py @@ -16,7 +16,6 @@ class FitChangeFighterAmount(wx.Command): self.position = position self.amount = amount self.savedAmount = None - self.removeCommand = None def Do(self): pyfalog.debug('Doing change of fighter amount to {} at position {} on fit {}'.format(self.amount, self.position, self.fitID)) @@ -29,18 +28,12 @@ class FitChangeFighterAmount(wx.Command): fighter.amount = self.amount eos.db.commit() return True - elif self.amount > 0: + else: fighter.amount = max(min(self.amount, fighter.fighterSquadronMaxSize), 0) eos.db.commit() return True - else: - from .fitRemoveFighter import FitRemoveFighterCommand - self.removeCommand = FitRemoveFighterCommand(fitID=self.fitID, position=self.position) - return self.removeCommand.Do() def Undo(self): pyfalog.debug('Undoing change of fighter amount to {} at position {} on fit {}'.format(self.amount, self.position, self.fitID)) - if self.removeCommand is not None: - return self.removeCommand.Undo() cmd = FitChangeFighterAmount(self.fitID, self.position, self.savedAmount) return cmd.Do() diff --git a/gui/fitCommands/calc/fitChangeModuleStates.py b/gui/fitCommands/calc/fitChangeModuleStates.py index 6d92ae6c2..791311e46 100644 --- a/gui/fitCommands/calc/fitChangeModuleStates.py +++ b/gui/fitCommands/calc/fitChangeModuleStates.py @@ -5,6 +5,7 @@ import eos.db from eos.saveddata.module import Module from service.fit import Fit + pyfalog = Logger(__name__) diff --git a/gui/fitCommands/calc/fitChangeProjectedDroneAmount.py b/gui/fitCommands/calc/fitChangeProjectedDroneAmount.py index 5e082aa45..5503be915 100644 --- a/gui/fitCommands/calc/fitChangeProjectedDroneAmount.py +++ b/gui/fitCommands/calc/fitChangeProjectedDroneAmount.py @@ -19,7 +19,6 @@ class FitChangeProjectedDroneAmount(wx.Command): self.itemID = itemID self.amount = amount self.savedDroneInfo = None - self.removeCommand = None def Do(self): pyfalog.debug('Doing change of projected drone {} amount to {} on fit {}'.format(self.itemID, self.amount, self.fitID)) @@ -29,23 +28,16 @@ class FitChangeProjectedDroneAmount(wx.Command): pyfalog.warning('Cannot find projected drone') return False self.savedDroneInfo = DroneInfo.fromDrone(drone) - if self.amount > 0: + drone.amount = self.amount + if drone.amountActive > 0: + difference = self.amount - self.savedDroneInfo.amount drone.amount = self.amount - if drone.amountActive > 0: - difference = self.amount - self.savedDroneInfo.amount - drone.amount = self.amount - drone.amountActive = max(min(drone.amountActive + difference, drone.amount), 0) - eos.db.commit() - return True - else: - from .fitRemoveProjectedDrone import FitRemoveProjectedDroneCommand - self.removeCommand = FitRemoveProjectedDroneCommand(fitID=self.fitID, droneInfo=DroneInfo(itemID=self.itemID, amount=math.inf, amountActive=math.inf)) - return self.removeCommand.Do() + drone.amountActive = max(min(drone.amountActive + difference, drone.amount), 0) + eos.db.commit() + return True def Undo(self): pyfalog.debug('Undoing change of projected drone {} amount to {} on fit {}'.format(self.itemID, self.amount, self.fitID)) - if self.removeCommand is not None: - return self.removeCommand.Undo() if self.savedDroneInfo is not None: fit = Fit.getInstance().getFit(self.fitID) drone = next((pd for pd in fit.projectedDrones if pd.itemID == self.savedDroneInfo.itemID), None)