Do not remove items when quantity is 0 in fit commands, it will be done in gui commands instead
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -5,6 +5,7 @@ import eos.db
|
||||
from eos.saveddata.module import Module
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user