Add meta swap support to projected items

This commit is contained in:
DarkPhoenix
2019-04-15 20:03:00 +03:00
parent 8b0f5f871c
commit 9523c6f349
12 changed files with 177 additions and 37 deletions

View File

@@ -19,12 +19,15 @@ class MetaSwap(ContextMenu):
return False
if self.mainFrame.getActiveFit() is None or srcContext not in (
"fittingModule",
"droneItem",
"fighterItem",
"boosterItem",
"implantItem",
"cargoItem",
'fittingModule',
'droneItem',
'fighterItem',
'boosterItem',
'implantItem',
'cargoItem',
'projectedModule',
'projectedDrone',
'projectedFighter'
):
return False
@@ -48,7 +51,7 @@ class MetaSwap(ContextMenu):
return True
def getText(self, itmContext, selection):
return "Variations"
return 'Variations'
def getSubMenu(self, context, selection, rootMenu, i, pitem):
self.moduleLookup = {}
@@ -56,9 +59,9 @@ class MetaSwap(ContextMenu):
fit = sFit.getFit(self.mainFrame.getActiveFit())
def get_metalevel(x):
if "metaLevel" not in x.attributes:
if 'metaLevel' not in x.attributes:
return 0
return x.attributes["metaLevel"].value
return x.attributes['metaLevel'].value
def get_metagroup(x):
return x.metaGroup.ID if x.metaGroup is not None else 0
@@ -78,7 +81,7 @@ class MetaSwap(ContextMenu):
# If on Windows we need to bind out events into the root menu, on other
# platforms they need to go to our sub menu
if "wxMSW" in wx.PlatformInfo:
if 'wxMSW' in wx.PlatformInfo:
bindmenu = rootMenu
else:
bindmenu = m
@@ -86,10 +89,10 @@ class MetaSwap(ContextMenu):
# Sort items by metalevel, and group within that metalevel
items = list(self.variations)
if "implantItem" in context:
if 'implantItem' in context:
# sort implants based on name
items.sort(key=lambda x: x.name)
elif "boosterItem" in context:
elif 'boosterItem' in context:
# boosters don't have meta or anything concrete that we can rank by. Go by chance to inflict side effect
items.sort(key=get_boosterrank)
else:
@@ -100,14 +103,14 @@ class MetaSwap(ContextMenu):
group = None
for item in items:
# Apparently no metaGroup for the Tech I variant:
if "subSystem" in item.effects:
if 'subSystem' in item.effects:
thisgroup = item.marketGroup.marketGroupName
elif item.metaGroup is None:
thisgroup = "Tech I"
thisgroup = 'Tech I'
else:
thisgroup = item.metaGroup.name
if thisgroup != group and context not in ("implantItem", "boosterItem"):
if thisgroup != group and context not in ('implantItem', 'boosterItem'):
group = thisgroup
id = ContextMenu.nextID()
m.Append(id, '%s' % group)
@@ -133,15 +136,15 @@ class MetaSwap(ContextMenu):
fit = Fit.getInstance().getFit(fitID)
if context == 'fittingModule':
positions = [mod.modPosition for mod in self.selection]
self.mainFrame.command.Submit(cmd.GuiChangeModuleMetaCommand(
self.mainFrame.command.Submit(cmd.GuiChangeLocalModuleMetasCommand(
fitID=fitID, positions=positions, newItemID=item.ID))
elif context == 'droneItem':
position = fit.drones.index(self.selection[0])
self.mainFrame.command.Submit(cmd.GuiChangeDroneMetaCommand(
self.mainFrame.command.Submit(cmd.GuiChangeLocalDroneMetaCommand(
fitID=fitID, position=position, newItemID=item.ID))
elif context == 'fighterItem':
position = fit.fighters.index(self.selection[0])
self.mainFrame.command.Submit(cmd.GuiChangeFighterMetaCommand(
self.mainFrame.command.Submit(cmd.GuiChangeLocalFighterMetaCommand(
fitID=fitID, position=position, newItemID=item.ID))
elif context == 'implantItem':
position = fit.implants.index(self.selection[0])
@@ -154,6 +157,17 @@ class MetaSwap(ContextMenu):
elif context == 'cargoItem':
self.mainFrame.command.Submit(cmd.GuiChangeCargoMetaCommand(
fitID=fitID, itemID=self.selection[0].itemID, newItemID=item.ID))
elif context == 'projectedModule':
position = fit.projectedModules.index(self.selection[0])
self.mainFrame.command.Submit(cmd.GuiChangeProjectedModuleMetaCommand(
fitID=fitID, position=position, newItemID=item.ID))
elif context == 'projectedDrone':
self.mainFrame.command.Submit(cmd.GuiChangeProjectedDroneMetaCommand(
fitID=fitID, itemID=self.selection[0].itemID, newItemID=item.ID))
elif context == 'projectedFighter':
position = fit.projectedFighters.index(self.selection[0])
self.mainFrame.command.Submit(cmd.GuiChangeProjectedFighterMetaCommand(
fitID=fitID, position=position, newItemID=item.ID))
MetaSwap.register()

View File

@@ -12,7 +12,6 @@ from .gui.commandFit.remove import GuiRemoveCommandFitCommand
from .gui.commandFit.toggleState import GuiToggleCommandFitStateCommand
from .gui.fitRename import GuiRenameFitCommand
from .gui.guiCargoToModule import GuiCargoToModuleCommand
from .gui.localModule.changeMeta import GuiChangeModuleMetaCommand
from .gui.guiModuleToCargo import GuiModuleToCargoCommand
from .gui.guiSwapCloneModule import GuiModuleSwapOrCloneCommand
from .gui.implant.add import GuiAddImplantCommand
@@ -23,17 +22,18 @@ from .gui.implant.toggleState import GuiToggleImplantStateCommand
from .gui.itemsRebase import GuiRebaseItemsCommand
from .gui.localDrone.add import GuiAddLocalDroneCommand
from .gui.localDrone.changeAmount import GuiChangeLocalDroneAmountCommand
from .gui.localDrone.changeMeta import GuiChangeDroneMetaCommand
from .gui.localDrone.changeMeta import GuiChangeLocalDroneMetaCommand
from .gui.localDrone.remove import GuiRemoveLocalDroneCommand
from .gui.localDrone.toggleState import GuiToggleLocalDroneStateCommand
from .gui.localFighter.abilityToggleState import GuiToggleLocalFighterAbilityStateCommand
from .gui.localFighter.add import GuiAddLocalFighterCommand
from .gui.localFighter.changeAmount import GuiChangeLocalFighterAmountCommand
from .gui.localFighter.changeMeta import GuiChangeFighterMetaCommand
from .gui.localFighter.changeMeta import GuiChangeLocalFighterMetaCommand
from .gui.localFighter.remove import GuiRemoveLocalFighterCommand
from .gui.localFighter.toggleState import GuiToggleLocalFighterStateCommand
from .gui.localModule.add import GuiAddLocalModuleCommand
from .gui.localModule.changeCharges import GuiChangeLocalModuleChargesCommand
from .gui.localModule.changeMetas import GuiChangeLocalModuleMetasCommand
from .gui.localModule.changeSpool import GuiChangeLocalModuleSpoolCommand
from .gui.localModule.changeStates import GuiChangeLocalModuleStatesCommand
from .gui.localModule.fill import GuiFillWithLocalModulesCommand
@@ -43,11 +43,13 @@ from .gui.localModule.mutatedRevert import GuiRevertMutatedLocalModuleCommand
from .gui.localModule.remove import GuiRemoveLocalModuleCommand
from .gui.projectedDrone.add import GuiAddProjectedDroneCommand
from .gui.projectedDrone.changeAmount import GuiChangeProjectedDroneAmountCommand
from .gui.projectedDrone.changeMeta import GuiChangeProjectedDroneMetaCommand
from .gui.projectedDrone.remove import GuiRemoveProjectedDroneCommand
from .gui.projectedDrone.toggleState import GuiToggleProjectedDroneStateCommand
from .gui.projectedFighter.abilityToggleState import GuiToggleProjectedFighterAbilityStateCommand
from .gui.projectedFighter.add import GuiAddProjectedFighterCommand
from .gui.projectedFighter.changeAmount import GuiChangeProjectedFighterAmountCommand
from .gui.projectedFighter.changeMeta import GuiChangeProjectedFighterMetaCommand
from .gui.projectedFighter.remove import GuiRemoveProjectedFighterCommand
from .gui.projectedFighter.toggleState import GuiToggleProjectedFighterStateCommand
from .gui.projectedFit.add import GuiAddProjectedFitCommand
@@ -56,6 +58,7 @@ from .gui.projectedFit.remove import GuiRemoveProjectedFitCommand
from .gui.projectedFit.toggleState import GuiToggleProjectedFitStateCommand
from .gui.projectedModule.add import GuiAddProjectedModuleCommand
from .gui.projectedModule.changeCharges import GuiChangeProjectedModuleChargesCommand
from .gui.projectedModule.changeMeta import GuiChangeProjectedModuleMetaCommand
from .gui.projectedModule.changeSpool import GuiChangeProjectedModuleSpoolCommand
from .gui.projectedModule.changeState import GuiChangeProjectedModuleStateCommand
from .gui.projectedModule.remove import GuiRemoveProjectedModuleCommand

View File

@@ -1,3 +1,5 @@
import math
import wx
from logbook import Logger
@@ -60,7 +62,7 @@ class CalcAddProjectedDroneCommand(wx.Command):
drone.amount = self.savedDroneInfo.amount
drone.amountActive = self.savedDroneInfo.amountActive
return True
# Removing new stack
# Removing previously added stack
from .projectedRemove import CalcRemoveProjectedDroneCommand
cmd = CalcRemoveProjectedDroneCommand(fitID=self.fitID, droneInfo=self.droneInfo)
cmd = CalcRemoveProjectedDroneCommand(fitID=self.fitID, itemID=self.droneInfo.itemID, amount=math.inf)
return cmd.Do()

View File

@@ -11,21 +11,22 @@ pyfalog = Logger(__name__)
class CalcRemoveProjectedDroneCommand(wx.Command):
def __init__(self, fitID, droneInfo):
def __init__(self, fitID, itemID, amount):
wx.Command.__init__(self, True, 'Remove Projected Drone')
self.fitID = fitID
self.droneInfo = droneInfo
self.itemID = itemID
self.amountToRemove = amount
self.savedDroneInfo = None
def Do(self):
pyfalog.debug('Doing removal of projected drone {} from fit {}'.format(self.droneInfo, self.fitID))
pyfalog.debug('Doing removal of {} projected drones {} from fit {}'.format(self.amountToRemove, self.itemID, self.fitID))
fit = Fit.getInstance().getFit(self.fitID)
drone = next((pd for pd in fit.projectedDrones if pd.itemID == self.droneInfo.itemID), None)
drone = next((pd for pd in fit.projectedDrones if pd.itemID == self.itemID), None)
if drone is None:
pyfalog.warning('Unable to find projected drone')
return False
self.savedDroneInfo = DroneInfo.fromDrone(drone)
drone.amount = max(drone.amount - self.droneInfo.amount, 0)
drone.amount = max(drone.amount - self.amountToRemove, 0)
# Remove stack if we have no items remaining
if drone.amount == 0:
fit.projectedDrones.remove(drone)
@@ -36,7 +37,7 @@ class CalcRemoveProjectedDroneCommand(wx.Command):
return True
def Undo(self):
pyfalog.debug('Undoing removal of projected drone {} from fit {}'.format(self.droneInfo, self.fitID))
pyfalog.debug('Undoing removal of {} projected drones {} from fit {}'.format(self.amountToRemove, self.itemID, self.fitID))
fit = Fit.getInstance().getFit(self.fitID)
# Change stack if we still have it
drone = next((pd for pd in fit.projectedDrones if pd.itemID == self.savedDroneInfo.itemID), None)

View File

@@ -10,10 +10,10 @@ from gui.fitCommands.helpers import DroneInfo, InternalCommandHistory
from service.fit import Fit
class GuiChangeDroneMetaCommand(wx.Command):
class GuiChangeLocalDroneMetaCommand(wx.Command):
def __init__(self, fitID, position, newItemID):
wx.Command.__init__(self, True, 'Change Drone Meta')
wx.Command.__init__(self, True, 'Change Local Drone Meta')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.position = position

View File

@@ -8,10 +8,10 @@ from gui.fitCommands.helpers import FighterInfo, InternalCommandHistory
from service.fit import Fit
class GuiChangeFighterMetaCommand(wx.Command):
class GuiChangeLocalFighterMetaCommand(wx.Command):
def __init__(self, fitID, position, newItemID):
wx.Command.__init__(self, True, 'Change Fighter Meta')
wx.Command.__init__(self, True, 'Change Local Fighter Meta')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.position = position

View File

@@ -8,10 +8,10 @@ from gui.fitCommands.helpers import InternalCommandHistory, ModuleInfo
from service.fit import Fit
class GuiChangeModuleMetaCommand(wx.Command):
class GuiChangeLocalModuleMetasCommand(wx.Command):
def __init__(self, fitID, positions, newItemID):
wx.Command.__init__(self, True, 'Change Module Meta')
wx.Command.__init__(self, True, 'Change Local Module Metas')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.positions = positions

View File

@@ -23,7 +23,7 @@ class GuiChangeProjectedDroneAmountCommand(wx.Command):
if self.amount > 0:
cmd = CalcChangeProjectedDroneAmountCommand(fitID=self.fitID, itemID=self.itemID, amount=self.amount)
else:
cmd = CalcRemoveProjectedDroneCommand(fitID=self.fitID, droneInfo=DroneInfo(itemID=self.itemID, amount=math.inf, amountActive=math.inf))
cmd = CalcRemoveProjectedDroneCommand(fitID=self.fitID, itemID=self.itemID, amount=math.inf)
success = self.internalHistory.submit(cmd)
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))

View File

@@ -0,0 +1,43 @@
import math
import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.drone.projectedAdd import CalcAddProjectedDroneCommand
from gui.fitCommands.calc.drone.projectedRemove import CalcRemoveProjectedDroneCommand
from gui.fitCommands.helpers import DroneInfo, InternalCommandHistory
from service.fit import Fit
class GuiChangeProjectedDroneMetaCommand(wx.Command):
def __init__(self, fitID, itemID, newItemID):
wx.Command.__init__(self, True, 'Change Projected Drone Meta')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.itemID = itemID
self.newItemID = newItemID
def Do(self):
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
drone = next((pd for pd in fit.projectedDrones if pd.itemID == self.itemID), None)
if drone is None:
return False
if drone.itemID == self.newItemID:
return False
info = DroneInfo.fromDrone(drone)
info.itemID = self.newItemID
cmdRemove = CalcRemoveProjectedDroneCommand(fitID=self.fitID, itemID=self.itemID, amount=math.inf)
cmdAdd = CalcAddProjectedDroneCommand(fitID=self.fitID, droneInfo=info)
success = self.internalHistory.submitBatch(cmdRemove, cmdAdd)
sFit.recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success
def Undo(self):
success = self.internalHistory.undoAll()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success

View File

@@ -17,7 +17,7 @@ class GuiRemoveProjectedDroneCommand(wx.Command):
self.amount = amount
def Do(self):
cmd = CalcRemoveProjectedDroneCommand(fitID=self.fitID, droneInfo=DroneInfo(itemID=self.itemID, amount=self.amount, amountActive=self.amount))
cmd = CalcRemoveProjectedDroneCommand(fitID=self.fitID, itemID=self.itemID, amount=self.amount)
success = self.internalHistory.submit(cmd)
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))

View File

@@ -0,0 +1,38 @@
import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.fighter.projectedAdd import CalcAddProjectedFighterCommand
from gui.fitCommands.calc.fighter.projectedRemove import CalcRemoveProjectedFighterCommand
from gui.fitCommands.helpers import FighterInfo, InternalCommandHistory
from service.fit import Fit
class GuiChangeProjectedFighterMetaCommand(wx.Command):
def __init__(self, fitID, position, newItemID):
wx.Command.__init__(self, True, 'Change Projected Fighter Meta')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.position = position
self.newItemID = newItemID
def Do(self):
sFit = Fit.getInstance()
fighter = sFit.getFit(self.fitID).projectedFighters[self.position]
if fighter.itemID == self.newItemID:
return False
info = FighterInfo.fromFighter(fighter)
info.itemID = self.newItemID
cmdRemove = CalcRemoveProjectedFighterCommand(fitID=self.fitID, position=self.position)
cmdAdd = CalcAddProjectedFighterCommand(fitID=self.fitID, fighterInfo=info)
success = self.internalHistory.submitBatch(cmdRemove, cmdAdd)
sFit.recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success
def Undo(self):
success = self.internalHistory.undoAll()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success

View File

@@ -0,0 +1,39 @@
import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.module.projectedAdd import CalcAddProjectedModuleCommand
from gui.fitCommands.calc.module.projectedRemove import CalcRemoveProjectedModuleCommand
from gui.fitCommands.helpers import InternalCommandHistory, ModuleInfo
from service.fit import Fit
class GuiChangeProjectedModuleMetaCommand(wx.Command):
def __init__(self, fitID, position, newItemID):
wx.Command.__init__(self, True, 'Change Projected Module Meta')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.position = position
self.newItemID = newItemID
def Do(self):
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
module = fit.projectedModules[self.position]
if module.itemID == self.newItemID:
return
info = ModuleInfo.fromModule(module)
info.itemID = self.newItemID
cmdRemove = CalcRemoveProjectedModuleCommand(fitID=self.fitID, position=self.position)
cmdAdd = CalcAddProjectedModuleCommand(fitID=self.fitID, modInfo=info)
success = self.internalHistory.submitBatch(cmdRemove, cmdAdd)
sFit.recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success
def Undo(self):
success = self.internalHistory.undoAll()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success