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

Method Do

gui/fitCommands/calc/fighter/localAdd.py:19–51  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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))

Callers 1

UndoMethod · 0.95

Calls 8

toFighterMethod · 0.80
getFitMethod · 0.80
getSlotsUsedMethod · 0.80
getNumSlotsMethod · 0.80
getInstanceMethod · 0.45
fitsMethod · 0.45
appendMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected