| 9 | |
| 10 | |
| 11 | class CalcRemoveProjectedDroneCommand(wx.Command): |
| 12 | |
| 13 | def __init__(self, fitID, itemID, amount): |
| 14 | wx.Command.__init__(self, True, 'Remove Projected Drone') |
| 15 | self.fitID = fitID |
| 16 | self.itemID = itemID |
| 17 | self.amountToRemove = amount |
| 18 | self.savedDroneInfo = None |
| 19 | |
| 20 | def Do(self): |
| 21 | pyfalog.debug('Doing removal of {} projected drones {} from fit {}'.format(self.amountToRemove, self.itemID, self.fitID)) |
| 22 | fit = Fit.getInstance().getFit(self.fitID) |
| 23 | drone = next((pd for pd in fit.projectedDrones if pd.itemID == self.itemID), None) |
| 24 | if drone is None: |
| 25 | pyfalog.warning('Unable to find projected drone') |
| 26 | return False |
| 27 | self.savedDroneInfo = DroneInfo.fromDrone(drone) |
| 28 | drone.amount = max(drone.amount - self.amountToRemove, 0) |
| 29 | # Remove stack if we have no items remaining |
| 30 | if drone.amount == 0: |
| 31 | fit.projectedDrones.remove(drone) |
| 32 | else: |
| 33 | if drone.amountActive > 0: |
| 34 | drone.amountActive = min(drone.amountActive, drone.amount) |
| 35 | return True |
| 36 | |
| 37 | def Undo(self): |
| 38 | pyfalog.debug('Undoing removal of {} projected drones {} from fit {}'.format(self.amountToRemove, self.itemID, self.fitID)) |
| 39 | fit = Fit.getInstance().getFit(self.fitID) |
| 40 | # Change stack if we still have it |
| 41 | drone = next((pd for pd in fit.projectedDrones if pd.itemID == self.savedDroneInfo.itemID), None) |
| 42 | if drone is not None: |
| 43 | drone.amount = self.savedDroneInfo.amount |
| 44 | drone.amountActive = self.savedDroneInfo.amountActive |
| 45 | return True |
| 46 | # Make new stack |
| 47 | from .projectedAdd import CalcAddProjectedDroneCommand |
| 48 | cmd = CalcAddProjectedDroneCommand(fitID=self.fitID, droneInfo=self.savedDroneInfo) |
| 49 | return cmd.Do() |