Allow removal of batches of fighters
This commit is contained in:
@@ -29,7 +29,7 @@ from .gui.localFighter.abilityToggleState import GuiToggleLocalFighterAbilitySta
|
||||
from .gui.localFighter.add import GuiAddLocalFighterCommand
|
||||
from .gui.localFighter.changeAmount import GuiChangeLocalFighterAmountCommand
|
||||
from .gui.localFighter.changeMeta import GuiChangeLocalFighterMetaCommand
|
||||
from .gui.localFighter.remove import GuiRemoveLocalFighterCommand
|
||||
from .gui.localFighter.remove import GuiRemoveLocalFightersCommand
|
||||
from .gui.localFighter.toggleState import GuiToggleLocalFighterStateCommand
|
||||
from .gui.localModule.add import GuiAddLocalModuleCommand
|
||||
from .gui.localModule.changeCharges import GuiChangeLocalModuleChargesCommand
|
||||
|
||||
@@ -11,11 +11,12 @@ pyfalog = Logger(__name__)
|
||||
|
||||
class CalcAddLocalFighterCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, fighterInfo, position=None):
|
||||
def __init__(self, fitID, fighterInfo, position=None, commit=True):
|
||||
wx.Command.__init__(self, True, 'Add Fighter')
|
||||
self.fitID = fitID
|
||||
self.fighterInfo = fighterInfo
|
||||
self.position = position
|
||||
self.commit = commit
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug('Doing addition of fighter {} to fit {}'.format(self.fighterInfo, self.fitID))
|
||||
@@ -43,7 +44,8 @@ class CalcAddLocalFighterCommand(wx.Command):
|
||||
fit.fighters.append(fighter)
|
||||
except HandledListActionError:
|
||||
pyfalog.warning('Failed to append to list')
|
||||
eos.db.commit()
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return False
|
||||
self.position = fit.fighters.index(fighter)
|
||||
else:
|
||||
@@ -51,14 +53,16 @@ class CalcAddLocalFighterCommand(wx.Command):
|
||||
fit.fighters.insert(self.position, fighter)
|
||||
except HandledListActionError:
|
||||
pyfalog.warning('Failed to insert to list')
|
||||
eos.db.commit()
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return False
|
||||
eos.db.commit()
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
pyfalog.debug('Undoing addition of fighter {} to fit {}'.format(self.fighterInfo, self.fitID))
|
||||
from .localRemove import CalcRemoveLocalFighterCommand
|
||||
cmd = CalcRemoveLocalFighterCommand(fitID=self.fitID, position=self.position)
|
||||
cmd = CalcRemoveLocalFighterCommand(fitID=self.fitID, position=self.position, commit=self.commit)
|
||||
cmd.Do()
|
||||
return True
|
||||
|
||||
@@ -11,10 +11,11 @@ pyfalog = Logger(__name__)
|
||||
|
||||
class CalcRemoveLocalFighterCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position):
|
||||
def __init__(self, fitID, position, commit=True):
|
||||
wx.Command.__init__(self, True, 'Remove Fighter')
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.commit = commit
|
||||
self.savedFighterInfo = None
|
||||
|
||||
def Do(self):
|
||||
@@ -23,11 +24,16 @@ class CalcRemoveLocalFighterCommand(wx.Command):
|
||||
fighter = fit.fighters[self.position]
|
||||
self.savedFighterInfo = FighterInfo.fromFighter(fighter)
|
||||
fit.fighters.remove(fighter)
|
||||
eos.db.commit()
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
pyfalog.debug('Undoing removal of fighter at position {} from fit {}'.format(self.position, self.fitID))
|
||||
from .localAdd import CalcAddLocalFighterCommand
|
||||
cmd = CalcAddLocalFighterCommand(fitID=self.fitID, fighterInfo=self.savedFighterInfo, position=self.position)
|
||||
cmd = CalcAddLocalFighterCommand(
|
||||
fitID=self.fitID,
|
||||
fighterInfo=self.savedFighterInfo,
|
||||
position=self.position,
|
||||
commit=self.commit)
|
||||
return cmd.Do()
|
||||
|
||||
@@ -19,7 +19,7 @@ class GuiRemoveLocalDronesCommand(wx.Command):
|
||||
|
||||
def Do(self):
|
||||
results = []
|
||||
for position in self.positions:
|
||||
for position in sorted(self.positions, reverse=True):
|
||||
cmd = CalcRemoveLocalDroneCommand(
|
||||
fitID=self.fitID,
|
||||
position=position,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import wx
|
||||
|
||||
import eos.db
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from gui.fitCommands.calc.fighter.localRemove import CalcRemoveLocalFighterCommand
|
||||
@@ -7,23 +8,28 @@ from gui.fitCommands.helpers import InternalCommandHistory
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
class GuiRemoveLocalFighterCommand(wx.Command):
|
||||
class GuiRemoveLocalFightersCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position):
|
||||
wx.Command.__init__(self, True, 'Remove Local Fighter')
|
||||
def __init__(self, fitID, positions):
|
||||
wx.Command.__init__(self, True, 'Remove Local Fighters')
|
||||
self.internalHistory = InternalCommandHistory()
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.positions = positions
|
||||
|
||||
def Do(self):
|
||||
cmd = CalcRemoveLocalFighterCommand(fitID=self.fitID, position=self.position)
|
||||
success = self.internalHistory.submit(cmd)
|
||||
results = []
|
||||
for position in sorted(self.positions, reverse=True):
|
||||
cmd = CalcRemoveLocalFighterCommand(fitID=self.fitID, position=position, commit=False)
|
||||
results.append(self.internalHistory.submit(cmd))
|
||||
success = any(results)
|
||||
eos.db.commit()
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return success
|
||||
|
||||
def Undo(self):
|
||||
success = self.internalHistory.undoAll()
|
||||
eos.db.commit()
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return success
|
||||
|
||||
@@ -377,3 +377,31 @@ def getSimilarModPositions(mods, mainMod):
|
||||
positions.append(position)
|
||||
continue
|
||||
return positions
|
||||
|
||||
|
||||
def getSimilarFighters(fighters, mainFighter):
|
||||
sMkt = Market.getInstance()
|
||||
mainGroupID = getattr(sMkt.getGroupByItem(mainFighter.item), 'ID', None)
|
||||
mainAbilityIDs = set(a.effectID for a in mainFighter.abilities)
|
||||
similarFighters = []
|
||||
for fighter in fighters:
|
||||
# Always include selected fighter itself
|
||||
if fighter is mainFighter:
|
||||
similarFighters.append(fighter)
|
||||
continue
|
||||
if fighter.itemID is None:
|
||||
continue
|
||||
# Fighters which have the same item ID
|
||||
if fighter.itemID == mainFighter.itemID:
|
||||
similarFighters.append(fighter)
|
||||
continue
|
||||
# And fighters from the same group and with the same abilities too
|
||||
fighterGroupID = getattr(sMkt.getGroupByItem(fighter.item), 'ID', None)
|
||||
fighterAbilityIDs = set(a.effectID for a in fighter.abilities)
|
||||
if (
|
||||
fighterGroupID is not None and fighterGroupID == mainGroupID and
|
||||
len(fighterAbilityIDs) > 0 and fighterAbilityIDs == mainAbilityIDs
|
||||
):
|
||||
similarFighters.append(fighter)
|
||||
continue
|
||||
return similarFighters
|
||||
|
||||
Reference in New Issue
Block a user