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

Class CalcAddLocalFighterCommand

gui/fitCommands/calc/fighter/localAdd.py:10–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8
9
10class CalcAddLocalFighterCommand(wx.Command):
11
12 def __init__(self, fitID, fighterInfo, position=None, ignoreRestrictions=False):
13 wx.Command.__init__(self, True, 'Add Fighter')
14 self.fitID = fitID
15 self.fighterInfo = fighterInfo
16 self.position = position
17 self.ignoreRestrictions = ignoreRestrictions
18
19 def Do(self):
20 pyfalog.debug('Doing addition of fighter {} to fit {}'.format(self.fighterInfo, self.fitID))
21 fighter = self.fighterInfo.toFighter()
22 if fighter is None:
23 return False
24
25 fit = Fit.getInstance().getFit(self.fitID)
26 if not self.ignoreRestrictions and not fighter.fits(fit):
27 pyfalog.warning('Fighter does not fit')
28 return False
29
30 # If we were not asked to set specific state, figure it out based on available tubes
31 if self.fighterInfo.state is None:
32 typeUsed = fit.getSlotsUsed(fighter.slot)
33 typeTotal = fit.getNumSlots(fighter.slot)
34
35 if fit.fighterTubesUsed >= fit.fighterTubesTotal or typeUsed >= typeTotal:
36 fighter.active = False
37 else:
38 fighter.active = True
39
40 if self.position is None:
41 fit.fighters.append(fighter)
42 if fighter not in fit.fighters:
43 pyfalog.warning('Failed to append to list')
44 return False
45 self.position = fit.fighters.index(fighter)
46 else:
47 fit.fighters.insert(self.position, fighter)
48 if fighter not in fit.fighters:
49 pyfalog.warning('Failed to insert to list')
50 return False
51 return True
52
53 def Undo(self):
54 pyfalog.debug('Undoing addition of fighter {} to fit {}'.format(self.fighterInfo, self.fitID))
55 from .localRemove import CalcRemoveLocalFighterCommand
56 cmd = CalcRemoveLocalFighterCommand(fitID=self.fitID, position=self.position)
57 cmd.Do()
58 return True

Callers 4

DoMethod · 0.90
DoMethod · 0.90
DoMethod · 0.90
UndoMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected