MCPcopy Index your code
hub / github.com/pyfa-org/Pyfa / CalcAddProjectedDroneCommand

Class CalcAddProjectedDroneCommand

gui/fitCommands/calc/drone/projectedAdd.py:12–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10
11
12class CalcAddProjectedDroneCommand(wx.Command):
13
14 def __init__(self, fitID, droneInfo):
15 wx.Command.__init__(self, True, 'Add Projected Drone')
16 self.fitID = fitID
17 self.droneInfo = droneInfo
18 self.savedDroneInfo = None
19
20 def Do(self):
21 pyfalog.debug('Doing addition of projected drone {} to fit {}'.format(self.droneInfo, self.fitID))
22 fit = Fit.getInstance().getFit(self.fitID)
23 drone = next((pd for pd in fit.projectedDrones if pd.itemID == self.droneInfo.itemID), None)
24 # Changing existing stack
25 if drone is not None:
26 self.savedDroneInfo = DroneInfo.fromDrone(drone)
27 # Ignore drone info's active amount parameter if we're adding to existing stack,
28 # and decide based on stack's state
29 drone.amount += self.droneInfo.amount
30 if drone.amountActive > 0:
31 drone.amountActive += self.droneInfo.amount
32 return True
33 # Making new stack
34 drone = self.droneInfo.toDrone()
35 if drone is None:
36 return False
37 if not drone.item.isType('projected'):
38 pyfalog.debug('Drone is not projectable')
39 return False
40 fit.projectedDrones.append(drone)
41 if drone not in fit.projectedDrones:
42 pyfalog.warning('Failed to append to list')
43 return False
44 return True
45
46 def Undo(self):
47 pyfalog.debug('Undoing addition of projected drone {} to fit {}'.format(self.droneInfo, self.fitID))
48 # Changing existing stack
49 if self.savedDroneInfo is not None:
50 fit = Fit.getInstance().getFit(self.fitID)
51 drone = next((pd for pd in fit.projectedDrones if pd.itemID == self.savedDroneInfo.itemID), None)
52 if drone is None:
53 pyfalog.warning('Unable to find projected drone for modification')
54 return False
55 drone.amount = self.savedDroneInfo.amount
56 drone.amountActive = self.savedDroneInfo.amountActive
57 return True
58 # Removing previously added stack
59 from .projectedRemove import CalcRemoveProjectedDroneCommand
60 cmd = CalcRemoveProjectedDroneCommand(
61 fitID=self.fitID,
62 itemID=self.droneInfo.itemID,
63 amount=math.inf)
64 return cmd.Do()

Callers 3

DoMethod · 0.90
DoMethod · 0.90
UndoMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected