From 4c0f88cdfa8cfb88867ce43588a3d65c6c146b5e Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Mon, 15 Apr 2019 18:05:18 +0300 Subject: [PATCH] Rework meta swap command --- gui/builtinContextMenus/metaSwap.py | 28 +++++--- gui/fitCommands/__init__.py | 9 ++- gui/fitCommands/calc/module/localAdd.py | 11 +-- gui/fitCommands/calc/module/localRemove.py | 15 ++-- gui/fitCommands/calc/module/localReplace.py | 17 ++++- gui/fitCommands/gui/booster/add.py | 9 ++- .../booster/{metaSwap.py => changeMeta.py} | 28 ++++---- gui/fitCommands/gui/booster/remove.py | 9 ++- .../gui/booster/sideEffectToggleState.py | 9 ++- gui/fitCommands/gui/booster/toggleState.py | 9 ++- gui/fitCommands/gui/cargo/add.py | 7 +- gui/fitCommands/gui/cargo/changeAmount.py | 10 +-- gui/fitCommands/gui/cargo/changeMeta.py | 41 +++++++++++ gui/fitCommands/gui/cargo/remove.py | 9 ++- gui/fitCommands/gui/commandFit/add.py | 9 ++- gui/fitCommands/gui/commandFit/remove.py | 9 ++- gui/fitCommands/gui/commandFit/toggleState.py | 9 ++- gui/fitCommands/gui/fitRename.py | 7 +- gui/fitCommands/gui/guiMetaSwap.py | 68 ------------------- gui/fitCommands/gui/implant/add.py | 11 ++- gui/fitCommands/gui/implant/changeLocation.py | 9 ++- .../implant/{metaSwap.py => changeMeta.py} | 23 ++++--- gui/fitCommands/gui/implant/remove.py | 9 ++- gui/fitCommands/gui/implant/toggleState.py | 9 ++- gui/fitCommands/gui/itemsRebase.py | 38 +++++++---- gui/fitCommands/gui/localDrone/add.py | 9 ++- .../gui/localDrone/changeAmount.py | 13 ++-- gui/fitCommands/gui/localDrone/changeMeta.py | 40 +++++++++++ gui/fitCommands/gui/localDrone/remove.py | 9 ++- gui/fitCommands/gui/localDrone/toggleState.py | 9 ++- .../gui/localFighter/abilityToggleState.py | 9 ++- gui/fitCommands/gui/localFighter/add.py | 9 ++- .../gui/localFighter/changeAmount.py | 13 ++-- .../gui/localFighter/changeMeta.py | 38 +++++++++++ gui/fitCommands/gui/localFighter/remove.py | 9 ++- .../gui/localFighter/toggleState.py | 9 ++- gui/fitCommands/gui/localModule/add.py | 9 ++- .../gui/localModule/changeCharges.py | 9 ++- gui/fitCommands/gui/localModule/changeMeta.py | 45 ++++++++++++ .../gui/localModule/changeSpool.py | 9 ++- .../gui/localModule/changeStates.py | 9 ++- gui/fitCommands/gui/localModule/fill.py | 16 +++-- .../gui/localModule/mutatedConvert.py | 9 ++- .../gui/localModule/mutatedImport.py | 13 ++-- .../gui/localModule/mutatedRevert.py | 9 ++- gui/fitCommands/gui/localModule/remove.py | 13 ++-- gui/fitCommands/gui/projectedDrone/add.py | 9 ++- .../gui/projectedDrone/changeAmount.py | 13 ++-- gui/fitCommands/gui/projectedDrone/remove.py | 9 ++- .../gui/projectedDrone/toggleState.py | 9 ++- .../projectedFighter/abilityToggleState.py | 9 ++- gui/fitCommands/gui/projectedFighter/add.py | 9 ++- .../gui/projectedFighter/changeAmount.py | 13 ++-- .../gui/projectedFighter/remove.py | 9 ++- .../gui/projectedFighter/toggleState.py | 9 ++- gui/fitCommands/gui/projectedFit/add.py | 9 ++- .../gui/projectedFit/changeAmount.py | 13 ++-- gui/fitCommands/gui/projectedFit/remove.py | 9 ++- .../gui/projectedFit/toggleState.py | 9 ++- gui/fitCommands/gui/projectedModule/add.py | 9 ++- .../gui/projectedModule/changeCharges.py | 9 ++- .../gui/projectedModule/changeSpool.py | 9 ++- .../gui/projectedModule/changeState.py | 9 ++- gui/fitCommands/gui/projectedModule/remove.py | 9 ++- gui/fitCommands/gui/shipModeChange.py | 9 ++- gui/fitCommands/helpers.py | 24 +++++-- 66 files changed, 502 insertions(+), 425 deletions(-) rename gui/fitCommands/gui/booster/{metaSwap.py => changeMeta.py} (50%) create mode 100644 gui/fitCommands/gui/cargo/changeMeta.py delete mode 100644 gui/fitCommands/gui/guiMetaSwap.py rename gui/fitCommands/gui/implant/{metaSwap.py => changeMeta.py} (59%) create mode 100644 gui/fitCommands/gui/localDrone/changeMeta.py create mode 100644 gui/fitCommands/gui/localFighter/changeMeta.py create mode 100644 gui/fitCommands/gui/localModule/changeMeta.py diff --git a/gui/builtinContextMenus/metaSwap.py b/gui/builtinContextMenus/metaSwap.py index ba489b866..f1e98f4cb 100644 --- a/gui/builtinContextMenus/metaSwap.py +++ b/gui/builtinContextMenus/metaSwap.py @@ -131,17 +131,29 @@ class MetaSwap(ContextMenu): fitID = self.mainFrame.getActiveFit() fit = Fit.getInstance().getFit(fitID) - if context == 'implantItem': + if context == 'fittingModule': + positions = [mod.modPosition for mod in self.selection] + self.mainFrame.command.Submit(cmd.GuiChangeModuleMetaCommand( + fitID=fitID, positions=positions, newItemID=item.ID)) + elif context == 'droneItem': + position = fit.drones.index(self.selection[0]) + self.mainFrame.command.Submit(cmd.GuiChangeDroneMetaCommand( + fitID=fitID, position=position, newItemID=item.ID)) + elif context == 'fighterItem': + position = fit.fighters.index(self.selection[0]) + self.mainFrame.command.Submit(cmd.GuiChangeFighterMetaCommand( + fitID=fitID, position=position, newItemID=item.ID)) + elif context == 'implantItem': position = fit.implants.index(self.selection[0]) - self.mainFrame.command.Submit(cmd.GuiSwapImplantMetaCommand( - fitID=fitID, position=position, itemID=item.ID)) + self.mainFrame.command.Submit(cmd.GuiChangeImplantMetaCommand( + fitID=fitID, position=position, newItemID=item.ID)) elif context == 'boosterItem': position = fit.boosters.index(self.selection[0]) - self.mainFrame.command.Submit(cmd.GuiSwapBoosterMetaCommand( - fitID=fitID, position=position, itemID=item.ID)) - else: - self.mainFrame.command.Submit(cmd.GuiMetaSwapCommand(fitID, context, item.ID, self.selection)) - + self.mainFrame.command.Submit(cmd.GuiChangeBoosterMetaCommand( + fitID=fitID, position=position, newItemID=item.ID)) + elif context == 'cargoItem': + self.mainFrame.command.Submit(cmd.GuiChangeCargoMetaCommand( + fitID=fitID, itemID=self.selection[0].itemID, newItemID=item.ID)) MetaSwap.register() diff --git a/gui/fitCommands/__init__.py b/gui/fitCommands/__init__.py index 7cbeef8bc..8a100cc25 100644 --- a/gui/fitCommands/__init__.py +++ b/gui/fitCommands/__init__.py @@ -1,32 +1,35 @@ from .gui.booster.add import GuiAddBoosterCommand -from .gui.booster.metaSwap import GuiSwapBoosterMetaCommand +from .gui.booster.changeMeta import GuiChangeBoosterMetaCommand from .gui.booster.remove import GuiRemoveBoosterCommand from .gui.booster.sideEffectToggleState import GuiToggleBoosterSideEffectStateCommand from .gui.booster.toggleState import GuiToggleBoosterStateCommand from .gui.cargo.add import GuiAddCargoCommand from .gui.cargo.changeAmount import GuiChangeCargoAmountCommand +from .gui.cargo.changeMeta import GuiChangeCargoMetaCommand from .gui.cargo.remove import GuiRemoveCargoCommand from .gui.commandFit.add import GuiAddCommandFitCommand from .gui.commandFit.remove import GuiRemoveCommandFitCommand from .gui.commandFit.toggleState import GuiToggleCommandFitStateCommand from .gui.fitRename import GuiRenameFitCommand from .gui.guiCargoToModule import GuiCargoToModuleCommand -from .gui.guiMetaSwap import GuiMetaSwapCommand +from .gui.localModule.changeMeta import GuiChangeModuleMetaCommand from .gui.guiModuleToCargo import GuiModuleToCargoCommand from .gui.guiSwapCloneModule import GuiModuleSwapOrCloneCommand from .gui.implant.add import GuiAddImplantCommand from .gui.implant.changeLocation import GuiChangeImplantLocationCommand -from .gui.implant.metaSwap import GuiSwapImplantMetaCommand +from .gui.implant.changeMeta import GuiChangeImplantMetaCommand from .gui.implant.remove import GuiRemoveImplantCommand 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.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.remove import GuiRemoveLocalFighterCommand from .gui.localFighter.toggleState import GuiToggleLocalFighterStateCommand from .gui.localModule.add import GuiAddLocalModuleCommand diff --git a/gui/fitCommands/calc/module/localAdd.py b/gui/fitCommands/calc/module/localAdd.py index 2d515e93d..50f5a0981 100644 --- a/gui/fitCommands/calc/module/localAdd.py +++ b/gui/fitCommands/calc/module/localAdd.py @@ -12,12 +12,13 @@ pyfalog = Logger(__name__) class CalcAddLocalModuleCommand(wx.Command): - def __init__(self, fitID, newModInfo): + def __init__(self, fitID, newModInfo, commit=True): wx.Command.__init__(self, True, 'Add Module') self.fitID = fitID self.newModInfo = newModInfo self.savedPosition = None self.subsystemCmd = None + self.commit = commit def Do(self): pyfalog.debug('Doing addition of local module {} to fit {}'.format(self.newModInfo, self.fitID)) @@ -45,10 +46,12 @@ class CalcAddLocalModuleCommand(wx.Command): fit.modules.append(newMod) except HandledListActionError: pyfalog.warning('Failed to append to list') - eos.db.commit() + if self.commit: + eos.db.commit() return False sFit.checkStates(fit, newMod) - eos.db.commit() + if self.commit: + eos.db.commit() self.savedPosition = newMod.modPosition return True @@ -60,5 +63,5 @@ class CalcAddLocalModuleCommand(wx.Command): from .localRemove import CalcRemoveLocalModuleCommand if self.savedPosition is None: return False - cmd = CalcRemoveLocalModuleCommand(fitID=self.fitID, positions=[self.savedPosition]) + cmd = CalcRemoveLocalModuleCommand(fitID=self.fitID, positions=[self.savedPosition], commit=self.commit) return cmd.Do() diff --git a/gui/fitCommands/calc/module/localRemove.py b/gui/fitCommands/calc/module/localRemove.py index 3d3a140a4..14b9df1c5 100644 --- a/gui/fitCommands/calc/module/localRemove.py +++ b/gui/fitCommands/calc/module/localRemove.py @@ -11,11 +11,12 @@ pyfalog = Logger(__name__) class CalcRemoveLocalModuleCommand(wx.Command): - def __init__(self, fitID, positions): + def __init__(self, fitID, positions, commit=True): wx.Command.__init__(self, True, 'Remove Module') self.fitID = fitID self.positions = positions self.savedModInfos = {} + self.commit = commit def Do(self): pyfalog.debug('Doing removal of local modules from positions {} on fit {}'.format(self.positions, self.fitID)) @@ -27,18 +28,18 @@ class CalcRemoveLocalModuleCommand(wx.Command): self.savedModInfos[position] = ModuleInfo.fromModule(mod) fit.modules.free(position) - # If no modules were removed, report that command was not completed - if not len(self.savedModInfos) > 0: + if self.commit: eos.db.commit() - return False - eos.db.commit() - return True + # If no modules were removed, report that command was not completed + return len(self.savedModInfos) > 0 def Undo(self): pyfalog.debug('Undoing removal of local modules {} on fit {}'.format(self.savedModInfos, self.fitID)) results = [] from .localReplace import CalcReplaceLocalModuleCommand for position, modInfo in self.savedModInfos.items(): - cmd = CalcReplaceLocalModuleCommand(fitID=self.fitID, position=position, newModInfo=modInfo) + cmd = CalcReplaceLocalModuleCommand(fitID=self.fitID, position=position, newModInfo=modInfo, commit=False) results.append(cmd.Do()) + if self.commit: + eos.db.commit() return any(results) diff --git a/gui/fitCommands/calc/module/localReplace.py b/gui/fitCommands/calc/module/localReplace.py index b4efffc1b..4fcc7d43f 100644 --- a/gui/fitCommands/calc/module/localReplace.py +++ b/gui/fitCommands/calc/module/localReplace.py @@ -12,12 +12,14 @@ pyfalog = Logger(__name__) class CalcReplaceLocalModuleCommand(wx.Command): - def __init__(self, fitID, position, newModInfo): + def __init__(self, fitID, position, newModInfo, unloadInvalidCharges=False, commit=True): wx.Command.__init__(self, True, 'Replace Module') self.fitID = fitID self.position = position self.newModInfo = newModInfo self.oldModInfo = None + self.unloadInvalidCharges = unloadInvalidCharges + self.commit = commit def Do(self): pyfalog.debug('Doing replacement of local module at position {} to {} on fit {}'.format(self.newModInfo, self.position, self.fitID)) @@ -37,6 +39,13 @@ class CalcReplaceLocalModuleCommand(wx.Command): pyfalog.warning('Module does not fit') self.Undo() return False + if not newMod.isValidCharge(newMod.charge): + if self.unloadInvalidCharges: + newMod.charge = None + else: + pyfalog.warning('Invalid charge') + self.Undo() + return False newMod.owner = fit try: fit.modules.replace(self.position, newMod) @@ -45,7 +54,8 @@ class CalcReplaceLocalModuleCommand(wx.Command): self.Undo() return False sFit.checkStates(fit, newMod) - eos.db.commit() + if self.commit: + eos.db.commit() return True def Undo(self): @@ -74,5 +84,6 @@ class CalcReplaceLocalModuleCommand(wx.Command): self.Do() return False sFit.checkStates(fit, oldMod) - eos.db.commit() + if self.commit: + eos.db.commit() return True diff --git a/gui/fitCommands/gui/booster/add.py b/gui/fitCommands/gui/booster/add.py index 69203fd50..b3b34434b 100644 --- a/gui/fitCommands/gui/booster/add.py +++ b/gui/fitCommands/gui/booster/add.py @@ -17,11 +17,10 @@ class GuiAddBoosterCommand(wx.Command): def Do(self): cmd = CalcAddBoosterCommand(fitID=self.fitID, boosterInfo=BoosterInfo(itemID=self.itemID)) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/booster/metaSwap.py b/gui/fitCommands/gui/booster/changeMeta.py similarity index 50% rename from gui/fitCommands/gui/booster/metaSwap.py rename to gui/fitCommands/gui/booster/changeMeta.py index 0829ab445..1b268ff5e 100644 --- a/gui/fitCommands/gui/booster/metaSwap.py +++ b/gui/fitCommands/gui/booster/changeMeta.py @@ -7,31 +7,27 @@ from gui.fitCommands.helpers import BoosterInfo, InternalCommandHistory from service.fit import Fit -class GuiSwapBoosterMetaCommand(wx.Command): +class GuiChangeBoosterMetaCommand(wx.Command): - def __init__(self, fitID, position, itemID): - wx.Command.__init__(self, True, 'Swap Booster Meta') + def __init__(self, fitID, position, newItemID): + wx.Command.__init__(self, True, 'Change Booster Meta') self.internalHistory = InternalCommandHistory() self.fitID = fitID self.position = position - self.itemID = itemID + self.newItemID = newItemID def Do(self): sFit = Fit.getInstance() booster = sFit.getFit(self.fitID).boosters[self.position] - if booster.itemID == self.itemID: + if booster.itemID == self.newItemID: return False - cmd = CalcAddBoosterCommand( - fitID=self.fitID, - boosterInfo=BoosterInfo( - itemID=self.itemID, - state=booster.active, - sideEffects={se.effectID: se.active for se in booster.sideEffects})) - if self.internalHistory.submit(cmd): - sFit.recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + info = BoosterInfo.fromBooster(booster) + info.itemID = self.newItemID + cmd = CalcAddBoosterCommand(fitID=self.fitID, boosterInfo=info) + success = self.internalHistory.submit(cmd) + sFit.recalc(self.fitID) + wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) + return success def Undo(self): success = self.internalHistory.undoAll() diff --git a/gui/fitCommands/gui/booster/remove.py b/gui/fitCommands/gui/booster/remove.py index d2d704bf1..5d0b28e21 100644 --- a/gui/fitCommands/gui/booster/remove.py +++ b/gui/fitCommands/gui/booster/remove.py @@ -16,11 +16,10 @@ class GuiRemoveBoosterCommand(wx.Command): def Do(self): cmd = CalcRemoveBoosterCommand(fitID=self.fitID, position=self.position) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/booster/sideEffectToggleState.py b/gui/fitCommands/gui/booster/sideEffectToggleState.py index 7331313e6..d09e788c6 100644 --- a/gui/fitCommands/gui/booster/sideEffectToggleState.py +++ b/gui/fitCommands/gui/booster/sideEffectToggleState.py @@ -18,11 +18,10 @@ class GuiToggleBoosterSideEffectStateCommand(wx.Command): def Do(self): cmd = CalcToggleBoosterSideEffectStateCommand(fitID=self.fitID, position=self.position, effectID=self.effectID) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/booster/toggleState.py b/gui/fitCommands/gui/booster/toggleState.py index 5b080f403..99fe35420 100644 --- a/gui/fitCommands/gui/booster/toggleState.py +++ b/gui/fitCommands/gui/booster/toggleState.py @@ -16,11 +16,10 @@ class GuiToggleBoosterStateCommand(wx.Command): def Do(self): cmd = CalcToggleBoosterStateCommand(fitID=self.fitID, position=self.position) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/cargo/add.py b/gui/fitCommands/gui/cargo/add.py index 70a043e0e..0ac391391 100644 --- a/gui/fitCommands/gui/cargo/add.py +++ b/gui/fitCommands/gui/cargo/add.py @@ -17,10 +17,9 @@ class GuiAddCargoCommand(wx.Command): def Do(self): cmd = CalcAddCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.itemID, amount=self.amount)) - if self.internalHistory.submit(cmd): - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) + return success def Undo(self): success = self.internalHistory.undoAll() diff --git a/gui/fitCommands/gui/cargo/changeAmount.py b/gui/fitCommands/gui/cargo/changeAmount.py index 4b7fac530..b93fbb2f5 100644 --- a/gui/fitCommands/gui/cargo/changeAmount.py +++ b/gui/fitCommands/gui/cargo/changeAmount.py @@ -21,15 +21,11 @@ class GuiChangeCargoAmountCommand(wx.Command): def Do(self): if self.amount > 0: cmd = CalcChangeCargoAmountCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.itemID, amount=self.amount)) - if self.internalHistory.submit(cmd): - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True else: cmd = CalcRemoveCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.itemID, amount=math.inf)) - if self.internalHistory.submit(cmd): - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) + return success def Undo(self): success = self.internalHistory.undoAll() diff --git a/gui/fitCommands/gui/cargo/changeMeta.py b/gui/fitCommands/gui/cargo/changeMeta.py new file mode 100644 index 000000000..5cb1ef461 --- /dev/null +++ b/gui/fitCommands/gui/cargo/changeMeta.py @@ -0,0 +1,41 @@ +import math + +import wx + +import gui.mainFrame +from gui import globalEvents as GE +from gui.fitCommands.calc.cargo.add import CalcAddCargoCommand +from gui.fitCommands.calc.cargo.remove import CalcRemoveCargoCommand +from gui.fitCommands.helpers import CargoInfo, InternalCommandHistory +from service.fit import Fit + + +class GuiChangeCargoMetaCommand(wx.Command): + + def __init__(self, fitID, itemID, newItemID): + wx.Command.__init__(self, True, 'Change Cargo Meta') + self.internalHistory = InternalCommandHistory() + self.fitID = fitID + self.itemID = itemID + self.newItemID = newItemID + + def Do(self): + sFit = Fit.getInstance() + fit = sFit.getFit(self.fitID) + cargo = next((c for c in fit.cargo if c.itemID == self.itemID), None) + if cargo is None: + return False + if cargo.itemID == self.newItemID: + return False + amount = cargo.amount + cmdRemove = CalcRemoveCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.itemID, amount=math.inf)) + cmdAdd = CalcAddCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.newItemID, amount=amount)) + success = self.internalHistory.submitBatch(cmdRemove, cmdAdd) + 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 diff --git a/gui/fitCommands/gui/cargo/remove.py b/gui/fitCommands/gui/cargo/remove.py index 77bcb2cdb..8db09bcb9 100644 --- a/gui/fitCommands/gui/cargo/remove.py +++ b/gui/fitCommands/gui/cargo/remove.py @@ -17,11 +17,10 @@ class GuiRemoveCargoCommand(wx.Command): self.itemID = itemID def Do(self): - cmd = CalcRemoveCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.itemID, amount=math.inf)) - if self.internalHistory.submit(cmd): - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + cmd =CalcRemoveCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.itemID, amount=math.inf)) + success = self.internalHistory.submit(cmd) + wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) + return success def Undo(self): success = self.internalHistory.undoAll() diff --git a/gui/fitCommands/gui/commandFit/add.py b/gui/fitCommands/gui/commandFit/add.py index 549da6bc1..031041cc9 100644 --- a/gui/fitCommands/gui/commandFit/add.py +++ b/gui/fitCommands/gui/commandFit/add.py @@ -17,11 +17,10 @@ class GuiAddCommandFitCommand(wx.Command): def Do(self): cmd = CalcAddCommandCommand(fitID=self.fitID, commandFitID=self.commandFitID) - if self.internalHistory.submit(cmd): - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - Fit.getInstance().recalc(self.fitID) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/commandFit/remove.py b/gui/fitCommands/gui/commandFit/remove.py index f519eb03d..d2a3394d8 100644 --- a/gui/fitCommands/gui/commandFit/remove.py +++ b/gui/fitCommands/gui/commandFit/remove.py @@ -17,11 +17,10 @@ class GuiRemoveCommandFitCommand(wx.Command): def Do(self): cmd = CalcRemoveCommandCommand(fitID=self.fitID, commandFitID=self.commandFitID) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/commandFit/toggleState.py b/gui/fitCommands/gui/commandFit/toggleState.py index 1ca34fd81..59a7f1365 100644 --- a/gui/fitCommands/gui/commandFit/toggleState.py +++ b/gui/fitCommands/gui/commandFit/toggleState.py @@ -17,11 +17,10 @@ class GuiToggleCommandFitStateCommand(wx.Command): def Do(self): cmd = CalcToggleCommandFitStateCommand(fitID=self.fitID, commandFitID=self.commandFitID) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/fitRename.py b/gui/fitCommands/gui/fitRename.py index f4bb2863a..b8b118ad4 100644 --- a/gui/fitCommands/gui/fitRename.py +++ b/gui/fitCommands/gui/fitRename.py @@ -16,10 +16,9 @@ class GuiRenameFitCommand(wx.Command): def Do(self): cmd = CalcFitRenameCommand(fitID=self.fitID, name=self.name) - if self.internalHistory.submit(cmd): - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), FitRenamed(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), FitRenamed(fitID=self.fitID)) + return success def Undo(self): success = self.internalHistory.undoAll() diff --git a/gui/fitCommands/gui/guiMetaSwap.py b/gui/fitCommands/gui/guiMetaSwap.py deleted file mode 100644 index 472742408..000000000 --- a/gui/fitCommands/gui/guiMetaSwap.py +++ /dev/null @@ -1,68 +0,0 @@ -import wx -from service.fit import Fit - -import gui.mainFrame -from gui import globalEvents as GE -from gui.fitCommands.helpers import ModuleInfo, FighterInfo, BoosterInfo -from gui.fitCommands.calc.implant.remove import CalcRemoveImplantCommand -from gui.fitCommands.calc.implant.add import CalcAddImplantCommand -from gui.fitCommands.calc.booster.add import CalcAddBoosterCommand -from gui.fitCommands.calc.cargo.remove import CalcRemoveCargoCommand -from gui.fitCommands.calc.cargo.add import CalcAddCargoCommand -from gui.fitCommands.calc.module.localReplace import CalcReplaceLocalModuleCommand -from gui.fitCommands.calc.fighter.localAdd import CalcAddLocalFighterCommand -from gui.fitCommands.calc.fighter.localRemove import CalcRemoveLocalFighterCommand -from gui.fitCommands.calc.itemRebase import CalcRebaseItemCommand - - -class GuiMetaSwapCommand(wx.Command): - def __init__(self, fitID, context, itemID, selection: list): - wx.Command.__init__(self, True, "Meta Swap") - self.internalHistory = wx.CommandProcessor() - self.fitID = fitID - self.itemID = itemID - self.context = context - self.data = [] - fit = Fit.getInstance().getFit(fitID) - - if context == 'fittingModule': - for x in selection: - position = fit.modules.index(x) - self.data.append(((CalcReplaceLocalModuleCommand, fitID, position, ModuleInfo( - itemID=itemID, chargeID=x.chargeID, state=x.state, spoolType=x.spoolType, spoolAmount=x.spoolAmount)),)) - elif context == 'implantItem': - for x in selection: - idx = fit.implants.index(x) - state = x.active - self.data.append(((CalcRemoveImplantCommand, fitID, idx), (CalcAddImplantCommand, fitID, itemID, state))) - elif context == 'boosterItem': - for x in selection: - self.data.append(((CalcAddBoosterCommand, fitID, BoosterInfo( - itemID=itemID, state=x.active, sideEffects={se.effectID: se.active for se in x.sideEffects})),)) - elif context == 'cargoItem': - for x in selection: - self.data.append(((CalcRemoveCargoCommand, fitID, x.itemID, 1, True), (CalcAddCargoCommand, fitID, itemID, x.amount))) - elif context == 'fighterItem': - for x in selection: - fighterInfo = FighterInfo.fromFighter(x) - fighterInfo.itemID = itemID - self.data.append(((CalcRemoveLocalFighterCommand, fitID, fit.fighters.index(x)), (CalcAddLocalFighterCommand, fitID, fighterInfo))) - elif context == 'droneItem': - for x in selection: - self.data.append(((CalcRebaseItemCommand, fitID, 'drones', fit.drones.index(x), itemID),), ) - - def Do(self): - for cmds in self.data: - for cmd in cmds: - self.internalHistory.Submit(cmd[0](*cmd[1:])) - - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - - def Undo(self): - for _ in self.internalHistory.Commands: - self.internalHistory.Undo() - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True diff --git a/gui/fitCommands/gui/implant/add.py b/gui/fitCommands/gui/implant/add.py index 2560a4320..9a6308755 100644 --- a/gui/fitCommands/gui/implant/add.py +++ b/gui/fitCommands/gui/implant/add.py @@ -18,13 +18,12 @@ class GuiAddImplantCommand(wx.Command): self.itemID = itemID def Do(self): - cmdImplant = CalcAddImplantCommand(fitID=self.fitID, implantInfo=ImplantInfo(itemID=self.itemID)) cmdLocation = CalcChangeImplantLocationCommand(fitID=self.fitID, source=ImplantLocation.FIT) - if self.internalHistory.submit(cmdImplant) and self.internalHistory.submit(cmdLocation): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + cmdAdd = CalcAddImplantCommand(fitID=self.fitID, implantInfo=ImplantInfo(itemID=self.itemID)) + success = self.internalHistory.submitBatch(cmdLocation, cmdAdd) + 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() diff --git a/gui/fitCommands/gui/implant/changeLocation.py b/gui/fitCommands/gui/implant/changeLocation.py index a5b3ec7b3..e966f7f9d 100644 --- a/gui/fitCommands/gui/implant/changeLocation.py +++ b/gui/fitCommands/gui/implant/changeLocation.py @@ -17,11 +17,10 @@ class GuiChangeImplantLocationCommand(wx.Command): def Do(self): cmd = CalcChangeImplantLocationCommand(fitID=self.fitID, source=self.source) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/implant/metaSwap.py b/gui/fitCommands/gui/implant/changeMeta.py similarity index 59% rename from gui/fitCommands/gui/implant/metaSwap.py rename to gui/fitCommands/gui/implant/changeMeta.py index 5f984c58d..7b9bf2ff8 100644 --- a/gui/fitCommands/gui/implant/metaSwap.py +++ b/gui/fitCommands/gui/implant/changeMeta.py @@ -7,26 +7,27 @@ from gui.fitCommands.helpers import ImplantInfo, InternalCommandHistory from service.fit import Fit -class GuiSwapImplantMetaCommand(wx.Command): +class GuiChangeImplantMetaCommand(wx.Command): - def __init__(self, fitID, position, itemID): - wx.Command.__init__(self, True, 'Swap Implant Meta') + def __init__(self, fitID, position, newItemID): + wx.Command.__init__(self, True, 'Change Implant Meta') self.internalHistory = InternalCommandHistory() self.fitID = fitID self.position = position - self.itemID = itemID + self.newItemID = newItemID def Do(self): sFit = Fit.getInstance() implant = sFit.getFit(self.fitID).implants[self.position] - if implant.itemID == self.itemID: + if implant.itemID == self.newItemID: return False - cmd = CalcAddImplantCommand(fitID=self.fitID, implantInfo=ImplantInfo(itemID=self.itemID, state=implant.active)) - if self.internalHistory.submit(cmd): - sFit.recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + info = ImplantInfo.fromImplant(implant) + info.itemID = self.newItemID + cmd = CalcAddImplantCommand(fitID=self.fitID, implantInfo=info) + success = self.internalHistory.submit(cmd) + sFit.recalc(self.fitID) + wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) + return success def Undo(self): success = self.internalHistory.undoAll() diff --git a/gui/fitCommands/gui/implant/remove.py b/gui/fitCommands/gui/implant/remove.py index a06e88915..55f1293d9 100644 --- a/gui/fitCommands/gui/implant/remove.py +++ b/gui/fitCommands/gui/implant/remove.py @@ -17,11 +17,10 @@ class GuiRemoveImplantCommand(wx.Command): def Do(self): cmd = CalcRemoveImplantCommand(fitID=self.fitID, position=self.position) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/implant/toggleState.py b/gui/fitCommands/gui/implant/toggleState.py index b51586d75..bcecacbe9 100644 --- a/gui/fitCommands/gui/implant/toggleState.py +++ b/gui/fitCommands/gui/implant/toggleState.py @@ -17,11 +17,10 @@ class GuiToggleImplantStateCommand(wx.Command): def Do(self): cmd = CalcToggleImplantStateCommand(fitID=self.fitID, position=self.position) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/itemsRebase.py b/gui/fitCommands/gui/itemsRebase.py index 70d960a83..c7a6daed9 100644 --- a/gui/fitCommands/gui/itemsRebase.py +++ b/gui/fitCommands/gui/itemsRebase.py @@ -24,28 +24,42 @@ class GuiRebaseItemsCommand(wx.Command): fit = sFit.getFit(self.fitID) for mod in fit.modules: if mod.itemID in self.rebaseMap: - self.internalHistory.submit(CalcRebaseItemCommand(fitID=self.fitID, containerName='modules', position=mod.modPosition, itemID=self.rebaseMap[mod.itemID], commit=False)) + cmd = CalcRebaseItemCommand( + fitID=self.fitID, + containerName='modules', + position=mod.modPosition, + itemID=self.rebaseMap[mod.itemID], + commit=False) + self.internalHistory.submit(cmd) if mod.chargeID in self.rebaseMap: - self.internalHistory.submit(CalcChangeModuleChargesCommand(fitID=self.fitID, projected=False, chargeMap={mod.modPosition: self.rebaseMap[mod.chargeID]})) + cmd = CalcChangeModuleChargesCommand( + fitID=self.fitID, + projected=False, + chargeMap={mod.modPosition: self.rebaseMap[mod.chargeID]}) + self.internalHistory.submit(cmd) for containerName in ('drones', 'fighters', 'implants', 'boosters'): container = getattr(fit, containerName) for obj in container: if obj.itemID in self.rebaseMap: - self.internalHistory.submit(CalcRebaseItemCommand(fitID=self.fitID, containerName=containerName, position=container.index(obj), itemID=self.rebaseMap[obj.itemID], commit=False)) + cmd = CalcRebaseItemCommand( + fitID=self.fitID, + containerName=containerName, + position=container.index(obj), + itemID=self.rebaseMap[obj.itemID], + commit=False) + self.internalHistory.submit(cmd) # Need to process cargo separately as we want to merge items when needed, # e.g. FN iron and CN iron into single stack of CN iron for cargo in fit.cargo: if cargo.itemID in self.rebaseMap: amount = cargo.amount - self.internalHistory.submit(CalcRemoveCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=cargo.itemID, amount=amount))) - self.internalHistory.submit(CalcAddCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.rebaseMap[cargo.itemID], amount=amount))) - if self.internalHistory: - eos.db.commit() - sFit.recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - else: - return False + cmdRemove = CalcRemoveCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=cargo.itemID, amount=amount)) + cmdAdd = CalcAddCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.rebaseMap[cargo.itemID], amount=amount)) + self.internalHistory.submitBatch(cmdRemove, cmdAdd) + eos.db.commit() + sFit.recalc(self.fitID) + wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) + return len(self.internalHistory) > 0 def Undo(self): success = self.internalHistory.undoAll() diff --git a/gui/fitCommands/gui/localDrone/add.py b/gui/fitCommands/gui/localDrone/add.py index e5f9367a8..74f775e5c 100644 --- a/gui/fitCommands/gui/localDrone/add.py +++ b/gui/fitCommands/gui/localDrone/add.py @@ -18,11 +18,10 @@ class GuiAddLocalDroneCommand(wx.Command): def Do(self): cmd = CalcAddLocalDroneCommand(fitID=self.fitID, droneInfo=DroneInfo(itemID=self.itemID, amount=self.amount, amountActive=0)) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/localDrone/changeAmount.py b/gui/fitCommands/gui/localDrone/changeAmount.py index cf25ae073..8b6e349de 100644 --- a/gui/fitCommands/gui/localDrone/changeAmount.py +++ b/gui/fitCommands/gui/localDrone/changeAmount.py @@ -22,17 +22,12 @@ class GuiChangeLocalDroneAmountCommand(wx.Command): def Do(self): if self.amount > 0: cmd = CalcChangeLocalDroneAmountCommand(fitID=self.fitID, position=self.position, amount=self.amount) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True else: cmd = CalcRemoveLocalDroneCommand(fitID=self.fitID, position=self.position, amount=math.inf) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/localDrone/changeMeta.py b/gui/fitCommands/gui/localDrone/changeMeta.py new file mode 100644 index 000000000..6f9ac21df --- /dev/null +++ b/gui/fitCommands/gui/localDrone/changeMeta.py @@ -0,0 +1,40 @@ +import math + +import wx + +import gui.mainFrame +from gui import globalEvents as GE +from gui.fitCommands.calc.drone.localAdd import CalcAddLocalDroneCommand +from gui.fitCommands.calc.drone.localRemove import CalcRemoveLocalDroneCommand +from gui.fitCommands.helpers import DroneInfo, InternalCommandHistory +from service.fit import Fit + + +class GuiChangeDroneMetaCommand(wx.Command): + + def __init__(self, fitID, position, newItemID): + wx.Command.__init__(self, True, 'Change Drone Meta') + self.internalHistory = InternalCommandHistory() + self.fitID = fitID + self.position = position + self.newItemID = newItemID + + def Do(self): + sFit = Fit.getInstance() + drone = sFit.getFit(self.fitID).drones[self.position] + if drone.itemID == self.newItemID: + return False + info = DroneInfo.fromDrone(drone) + info.itemID = self.newItemID + cmdRemove = CalcRemoveLocalDroneCommand(fitID=self.fitID, position=self.position, amount=math.inf) + cmdAdd = CalcAddLocalDroneCommand(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 diff --git a/gui/fitCommands/gui/localDrone/remove.py b/gui/fitCommands/gui/localDrone/remove.py index 2077ca04b..72a99b21d 100644 --- a/gui/fitCommands/gui/localDrone/remove.py +++ b/gui/fitCommands/gui/localDrone/remove.py @@ -18,11 +18,10 @@ class GuiRemoveLocalDroneCommand(wx.Command): def Do(self): cmd = CalcRemoveLocalDroneCommand(fitID=self.fitID, position=self.position, amount=self.amount) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/localDrone/toggleState.py b/gui/fitCommands/gui/localDrone/toggleState.py index f9adb50c3..003032c00 100644 --- a/gui/fitCommands/gui/localDrone/toggleState.py +++ b/gui/fitCommands/gui/localDrone/toggleState.py @@ -17,11 +17,10 @@ class GuiToggleLocalDroneStateCommand(wx.Command): def Do(self): cmd = CalcToggleLocalDroneStateCommand(fitID=self.fitID, position=self.position) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/localFighter/abilityToggleState.py b/gui/fitCommands/gui/localFighter/abilityToggleState.py index 128565f1c..4ba75260a 100644 --- a/gui/fitCommands/gui/localFighter/abilityToggleState.py +++ b/gui/fitCommands/gui/localFighter/abilityToggleState.py @@ -18,11 +18,10 @@ class GuiToggleLocalFighterAbilityStateCommand(wx.Command): def Do(self): cmd = CalcToggleFighterAbilityStateCommand(fitID=self.fitID, projected=False, position=self.position, effectID=self.effectID) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/localFighter/add.py b/gui/fitCommands/gui/localFighter/add.py index 20458d362..a0664cf54 100644 --- a/gui/fitCommands/gui/localFighter/add.py +++ b/gui/fitCommands/gui/localFighter/add.py @@ -17,11 +17,10 @@ class GuiAddLocalFighterCommand(wx.Command): def Do(self): cmd = CalcAddLocalFighterCommand(fitID=self.fitID, fighterInfo=FighterInfo(itemID=self.itemID)) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/localFighter/changeAmount.py b/gui/fitCommands/gui/localFighter/changeAmount.py index 6e463c469..39fb60fd3 100644 --- a/gui/fitCommands/gui/localFighter/changeAmount.py +++ b/gui/fitCommands/gui/localFighter/changeAmount.py @@ -20,17 +20,12 @@ class GuiChangeLocalFighterAmountCommand(wx.Command): def Do(self): if self.amount > 0: cmd = CalcChangeFighterAmountCommand(fitID=self.fitID, projected=False, position=self.position, amount=self.amount) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True else: cmd = CalcRemoveLocalFighterCommand(fitID=self.fitID, position=self.position) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/localFighter/changeMeta.py b/gui/fitCommands/gui/localFighter/changeMeta.py new file mode 100644 index 000000000..1d3dc17e6 --- /dev/null +++ b/gui/fitCommands/gui/localFighter/changeMeta.py @@ -0,0 +1,38 @@ +import wx + +import gui.mainFrame +from gui import globalEvents as GE +from gui.fitCommands.calc.fighter.localAdd import CalcAddLocalFighterCommand +from gui.fitCommands.calc.fighter.localRemove import CalcRemoveLocalFighterCommand +from gui.fitCommands.helpers import FighterInfo, InternalCommandHistory +from service.fit import Fit + + +class GuiChangeFighterMetaCommand(wx.Command): + + def __init__(self, fitID, position, newItemID): + wx.Command.__init__(self, True, 'Change 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).fighters[self.position] + if fighter.itemID == self.newItemID: + return False + info = FighterInfo.fromFighter(fighter) + info.itemID = self.newItemID + cmdRemove = CalcRemoveLocalFighterCommand(fitID=self.fitID, position=self.position) + cmdAdd = CalcAddLocalFighterCommand(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 diff --git a/gui/fitCommands/gui/localFighter/remove.py b/gui/fitCommands/gui/localFighter/remove.py index 3a3d130a4..f383ebb87 100644 --- a/gui/fitCommands/gui/localFighter/remove.py +++ b/gui/fitCommands/gui/localFighter/remove.py @@ -17,11 +17,10 @@ class GuiRemoveLocalFighterCommand(wx.Command): def Do(self): cmd = CalcRemoveLocalFighterCommand(fitID=self.fitID, position=self.position) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit() + 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() diff --git a/gui/fitCommands/gui/localFighter/toggleState.py b/gui/fitCommands/gui/localFighter/toggleState.py index d97b2d61b..71bca07a1 100644 --- a/gui/fitCommands/gui/localFighter/toggleState.py +++ b/gui/fitCommands/gui/localFighter/toggleState.py @@ -17,11 +17,10 @@ class GuiToggleLocalFighterStateCommand(wx.Command): def Do(self): cmd = CalcToggleFighterStateCommand(fitID=self.fitID, projected=False, position=self.position) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/localModule/add.py b/gui/fitCommands/gui/localModule/add.py index 5a5339b80..f6a183cad 100644 --- a/gui/fitCommands/gui/localModule/add.py +++ b/gui/fitCommands/gui/localModule/add.py @@ -28,24 +28,23 @@ class GuiAddLocalModuleCommand(wx.Command): cmd = CalcChangeModuleChargesCommand(fitID=self.fitID, projected=False, chargeMap={position: self.itemID}) success = self.internalHistory.submit(cmd) if not success: + Fit.getInstance().recalc(self.fitID) + wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.itemID)) return False # Module to position elif position is not None: cmd = CalcReplaceLocalModuleCommand(fitID=self.fitID, position=position, newModInfo=ModuleInfo(itemID=self.itemID)) success = self.internalHistory.submit(cmd) - # Something went wrong with trying to fit the module into specific location, - # keep going to append it instead + # Something went wrong with trying to fit the module into specific location, keep going to append it instead if not success: position = None # Module without position if position is None: cmd = CalcAddLocalModuleCommand(fitID=self.fitID, newModInfo=ModuleInfo(itemID=self.itemID)) success = self.internalHistory.submit(cmd) - if not success: - return False Fit.getInstance().recalc(self.fitID) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.itemID)) - return True + return success def Undo(self): success = self.internalHistory.undoAll() diff --git a/gui/fitCommands/gui/localModule/changeCharges.py b/gui/fitCommands/gui/localModule/changeCharges.py index eefc31628..d856e5c1a 100644 --- a/gui/fitCommands/gui/localModule/changeCharges.py +++ b/gui/fitCommands/gui/localModule/changeCharges.py @@ -18,11 +18,10 @@ class GuiChangeLocalModuleChargesCommand(wx.Command): def Do(self): cmd = CalcChangeModuleChargesCommand(fitID=self.fitID, projected=False, chargeMap={p: self.chargeItemID for p in self.positions}) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/localModule/changeMeta.py b/gui/fitCommands/gui/localModule/changeMeta.py new file mode 100644 index 000000000..8d1d11094 --- /dev/null +++ b/gui/fitCommands/gui/localModule/changeMeta.py @@ -0,0 +1,45 @@ +import wx + +import eos.db +import gui.mainFrame +from gui import globalEvents as GE +from gui.fitCommands.calc.module.localReplace import CalcReplaceLocalModuleCommand +from gui.fitCommands.helpers import InternalCommandHistory, ModuleInfo +from service.fit import Fit + + +class GuiChangeModuleMetaCommand(wx.Command): + + def __init__(self, fitID, positions, newItemID): + wx.Command.__init__(self, True, 'Change Module Meta') + self.internalHistory = InternalCommandHistory() + self.fitID = fitID + self.positions = positions + self.newItemID = newItemID + + def Do(self): + sFit = Fit.getInstance() + fit = sFit.getFit(self.fitID) + commands = [] + for position in self.positions: + module = fit.modules[position] + if module.itemID == self.newItemID: + continue + info = ModuleInfo.fromModule(module) + info.itemID = self.newItemID + cmd = CalcReplaceLocalModuleCommand(fitID=self.fitID, position=position, newModInfo=info, unloadInvalidCharges=True, commit=False) + commands.append(cmd) + if not commands: + return False + success = self.internalHistory.submitBatch(*commands) + eos.db.commit() + sFit.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 diff --git a/gui/fitCommands/gui/localModule/changeSpool.py b/gui/fitCommands/gui/localModule/changeSpool.py index ff9017a20..e75efa7bf 100644 --- a/gui/fitCommands/gui/localModule/changeSpool.py +++ b/gui/fitCommands/gui/localModule/changeSpool.py @@ -24,11 +24,10 @@ class GuiChangeLocalModuleSpoolCommand(wx.Command): position=self.position, spoolType=self.spoolType, spoolAmount=self.spoolAmount) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/localModule/changeStates.py b/gui/fitCommands/gui/localModule/changeStates.py index cf466144d..17acf267c 100644 --- a/gui/fitCommands/gui/localModule/changeStates.py +++ b/gui/fitCommands/gui/localModule/changeStates.py @@ -23,11 +23,10 @@ class GuiChangeLocalModuleStatesCommand(wx.Command): mainPosition=self.mainPosition, positions=self.positions, click=self.click) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/localModule/fill.py b/gui/fitCommands/gui/localModule/fill.py index 189ce13bd..f87610df0 100644 --- a/gui/fitCommands/gui/localModule/fill.py +++ b/gui/fitCommands/gui/localModule/fill.py @@ -1,5 +1,6 @@ import wx +import eos.db import gui.mainFrame from gui import globalEvents as GE from gui.fitCommands.calc.module.localAdd import CalcAddLocalModuleCommand @@ -17,16 +18,19 @@ class GuiFillWithLocalModulesCommand(wx.Command): def Do(self): added_modules = 0 - while self.internalHistory.submit(CalcAddLocalModuleCommand(fitID=self.fitID, newModInfo=ModuleInfo(itemID=self.itemID))): + while True: + cmd = CalcAddLocalModuleCommand(fitID=self.fitID, newModInfo=ModuleInfo(itemID=self.itemID), commit=False) + if not self.internalHistory.submit(cmd): + break added_modules += 1 - if added_modules > 0: - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.itemID)) - return True - return False + eos.db.commit() + Fit.getInstance().recalc(self.fitID) + wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.itemID)) + return added_modules > 0 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, action='moddel', typeID=self.itemID)) return success diff --git a/gui/fitCommands/gui/localModule/mutatedConvert.py b/gui/fitCommands/gui/localModule/mutatedConvert.py index f648423af..7e35df777 100644 --- a/gui/fitCommands/gui/localModule/mutatedConvert.py +++ b/gui/fitCommands/gui/localModule/mutatedConvert.py @@ -37,11 +37,10 @@ class GuiConvertMutatedLocalModuleCommand(wx.Command): state=mod.state, spoolType=mod.spoolType, spoolAmount=mod.spoolAmount)) - if self.internalHistory.submit(cmd): - sFit.recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + sFit.recalc(self.fitID) + wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) + return success def Undo(self): success = self.internalHistory.undoAll() diff --git a/gui/fitCommands/gui/localModule/mutatedImport.py b/gui/fitCommands/gui/localModule/mutatedImport.py index 4e8b1daac..ef67e263e 100644 --- a/gui/fitCommands/gui/localModule/mutatedImport.py +++ b/gui/fitCommands/gui/localModule/mutatedImport.py @@ -21,13 +21,12 @@ class GuiImportLocalMutatedModuleCommand(wx.Command): def Do(self): cmd = CalcAddLocalModuleCommand(fitID=self.fitID, newModInfo=self.newModInfo) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent( - gui.mainFrame.MainFrame.getInstance(), - GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.newModInfo.itemID)) - return True - return False + success = self.internalHistory.submit(cmd) + Fit.getInstance().recalc(self.fitID) + wx.PostEvent( + gui.mainFrame.MainFrame.getInstance(), + GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.newModInfo.itemID)) + return success def Undo(self): success = self.internalHistory.undoAll() diff --git a/gui/fitCommands/gui/localModule/mutatedRevert.py b/gui/fitCommands/gui/localModule/mutatedRevert.py index d91d8b555..d82782cee 100644 --- a/gui/fitCommands/gui/localModule/mutatedRevert.py +++ b/gui/fitCommands/gui/localModule/mutatedRevert.py @@ -32,11 +32,10 @@ class GuiRevertMutatedLocalModuleCommand(wx.Command): state=mod.state, spoolType=mod.spoolType, spoolAmount=mod.spoolAmount)) - if self.internalHistory.submit(cmd): - sFit.recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + sFit.recalc(self.fitID) + wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) + return success def Undo(self): success = self.internalHistory.undoAll() diff --git a/gui/fitCommands/gui/localModule/remove.py b/gui/fitCommands/gui/localModule/remove.py index 4852782a0..e945ab557 100644 --- a/gui/fitCommands/gui/localModule/remove.py +++ b/gui/fitCommands/gui/localModule/remove.py @@ -17,13 +17,12 @@ class GuiRemoveLocalModuleCommand(wx.Command): def Do(self): cmd = CalcRemoveLocalModuleCommand(fitID=self.fitID, positions=[pos for pos in self.modCache]) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent( - gui.mainFrame.MainFrame.getInstance(), - GE.FitChanged(fitID=self.fitID, action='moddel', typeID=set([mod.itemID for mod in self.modCache.values()]))) - return True - return False + success = self.internalHistory.submit(cmd) + Fit.getInstance().recalc(self.fitID) + wx.PostEvent( + gui.mainFrame.MainFrame.getInstance(), + GE.FitChanged(fitID=self.fitID, action='moddel', typeID=set([mod.itemID for mod in self.modCache.values()]))) + return success def Undo(self): success = self.internalHistory.undoAll() diff --git a/gui/fitCommands/gui/projectedDrone/add.py b/gui/fitCommands/gui/projectedDrone/add.py index eb43f6b25..c3c776969 100644 --- a/gui/fitCommands/gui/projectedDrone/add.py +++ b/gui/fitCommands/gui/projectedDrone/add.py @@ -17,11 +17,10 @@ class GuiAddProjectedDroneCommand(wx.Command): def Do(self): cmd = CalcAddProjectedDroneCommand(fitID=self.fitID, droneInfo=DroneInfo(itemID=self.itemID, amount=1, amountActive=1)) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/projectedDrone/changeAmount.py b/gui/fitCommands/gui/projectedDrone/changeAmount.py index 2df9fcaba..a17a81b7c 100644 --- a/gui/fitCommands/gui/projectedDrone/changeAmount.py +++ b/gui/fitCommands/gui/projectedDrone/changeAmount.py @@ -22,17 +22,12 @@ class GuiChangeProjectedDroneAmountCommand(wx.Command): def Do(self): if self.amount > 0: cmd = CalcChangeProjectedDroneAmountCommand(fitID=self.fitID, itemID=self.itemID, amount=self.amount) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True else: cmd = CalcRemoveProjectedDroneCommand(fitID=self.fitID, droneInfo=DroneInfo(itemID=self.itemID, amount=math.inf, amountActive=math.inf)) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/projectedDrone/remove.py b/gui/fitCommands/gui/projectedDrone/remove.py index eaccf9b3c..6f33334b8 100644 --- a/gui/fitCommands/gui/projectedDrone/remove.py +++ b/gui/fitCommands/gui/projectedDrone/remove.py @@ -18,11 +18,10 @@ class GuiRemoveProjectedDroneCommand(wx.Command): def Do(self): cmd = CalcRemoveProjectedDroneCommand(fitID=self.fitID, droneInfo=DroneInfo(itemID=self.itemID, amount=self.amount, amountActive=self.amount)) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/projectedDrone/toggleState.py b/gui/fitCommands/gui/projectedDrone/toggleState.py index 8c592be42..e6e315ffe 100644 --- a/gui/fitCommands/gui/projectedDrone/toggleState.py +++ b/gui/fitCommands/gui/projectedDrone/toggleState.py @@ -17,11 +17,10 @@ class GuiToggleProjectedDroneStateCommand(wx.Command): def Do(self): cmd = CalcToggleProjectedDroneStateCommand(fitID=self.fitID, itemID=self.itemID) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/projectedFighter/abilityToggleState.py b/gui/fitCommands/gui/projectedFighter/abilityToggleState.py index 4d2773a25..ca7807db0 100644 --- a/gui/fitCommands/gui/projectedFighter/abilityToggleState.py +++ b/gui/fitCommands/gui/projectedFighter/abilityToggleState.py @@ -18,11 +18,10 @@ class GuiToggleProjectedFighterAbilityStateCommand(wx.Command): def Do(self): cmd = CalcToggleFighterAbilityStateCommand(fitID=self.fitID, projected=True, position=self.position, effectID=self.effectID) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/projectedFighter/add.py b/gui/fitCommands/gui/projectedFighter/add.py index 4296f601b..ba75398fc 100644 --- a/gui/fitCommands/gui/projectedFighter/add.py +++ b/gui/fitCommands/gui/projectedFighter/add.py @@ -17,11 +17,10 @@ class GuiAddProjectedFighterCommand(wx.Command): def Do(self): cmd = CalcAddProjectedFighterCommand(fitID=self.fitID, fighterInfo=FighterInfo(itemID=self.itemID)) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/projectedFighter/changeAmount.py b/gui/fitCommands/gui/projectedFighter/changeAmount.py index bceab03a3..3835adc57 100644 --- a/gui/fitCommands/gui/projectedFighter/changeAmount.py +++ b/gui/fitCommands/gui/projectedFighter/changeAmount.py @@ -20,17 +20,12 @@ class GuiChangeProjectedFighterAmountCommand(wx.Command): def Do(self): if self.amount > 0: cmd = CalcChangeFighterAmountCommand(fitID=self.fitID, projected=True, position=self.position, amount=self.amount) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True else: cmd = CalcRemoveProjectedFighterCommand(fitID=self.fitID, position=self.position) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/projectedFighter/remove.py b/gui/fitCommands/gui/projectedFighter/remove.py index cb15b986d..bc543321a 100644 --- a/gui/fitCommands/gui/projectedFighter/remove.py +++ b/gui/fitCommands/gui/projectedFighter/remove.py @@ -17,11 +17,10 @@ class GuiRemoveProjectedFighterCommand(wx.Command): def Do(self): cmd = CalcRemoveProjectedFighterCommand(fitID=self.fitID, position=self.position) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/projectedFighter/toggleState.py b/gui/fitCommands/gui/projectedFighter/toggleState.py index 051af3f11..63c646fda 100644 --- a/gui/fitCommands/gui/projectedFighter/toggleState.py +++ b/gui/fitCommands/gui/projectedFighter/toggleState.py @@ -17,11 +17,10 @@ class GuiToggleProjectedFighterStateCommand(wx.Command): def Do(self): cmd = CalcToggleFighterStateCommand(fitID=self.fitID, projected=True, position=self.position) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/projectedFit/add.py b/gui/fitCommands/gui/projectedFit/add.py index 9a67bdac1..c36e712f4 100644 --- a/gui/fitCommands/gui/projectedFit/add.py +++ b/gui/fitCommands/gui/projectedFit/add.py @@ -17,11 +17,10 @@ class GuiAddProjectedFitCommand(wx.Command): def Do(self): cmd = CalcAddProjectedFitCommand(fitID=self.fitID, projectedFitID=self.projectedFitID) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/projectedFit/changeAmount.py b/gui/fitCommands/gui/projectedFit/changeAmount.py index 65ac93a43..e046d3970 100644 --- a/gui/fitCommands/gui/projectedFit/changeAmount.py +++ b/gui/fitCommands/gui/projectedFit/changeAmount.py @@ -20,17 +20,12 @@ class GuiChangeProjectedFitAmountCommand(wx.Command): def Do(self): if self.amount > 0: cmd = CalcChangeProjectedFitAmountCommand(fitID=self.fitID, projectedFitID=self.projectedFitID, amount=self.amount) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True else: cmd = CalcRemoveProjectedFitCommand(fitID=self.fitID, projectedFitID=self.projectedFitID) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/projectedFit/remove.py b/gui/fitCommands/gui/projectedFit/remove.py index e1264962b..2f611dd65 100644 --- a/gui/fitCommands/gui/projectedFit/remove.py +++ b/gui/fitCommands/gui/projectedFit/remove.py @@ -17,11 +17,10 @@ class GuiRemoveProjectedFitCommand(wx.Command): def Do(self): cmd = CalcRemoveProjectedFitCommand(fitID=self.fitID, projectedFitID=self.projectedFitID) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/projectedFit/toggleState.py b/gui/fitCommands/gui/projectedFit/toggleState.py index 234af1eea..a285ae575 100644 --- a/gui/fitCommands/gui/projectedFit/toggleState.py +++ b/gui/fitCommands/gui/projectedFit/toggleState.py @@ -17,11 +17,10 @@ class GuiToggleProjectedFitStateCommand(wx.Command): def Do(self): cmd = CalcToggleProjectedFitCommand(fitID=self.fitID, projectedFitID=self.projectedFitID) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/projectedModule/add.py b/gui/fitCommands/gui/projectedModule/add.py index 23444b197..58319d44c 100644 --- a/gui/fitCommands/gui/projectedModule/add.py +++ b/gui/fitCommands/gui/projectedModule/add.py @@ -17,11 +17,10 @@ class GuiAddProjectedModuleCommand(wx.Command): def Do(self): cmd = CalcAddProjectedModuleCommand(fitID=self.fitID, modInfo=ModuleInfo(itemID=self.itemID)) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/projectedModule/changeCharges.py b/gui/fitCommands/gui/projectedModule/changeCharges.py index 3dbc35856..88983c8d9 100644 --- a/gui/fitCommands/gui/projectedModule/changeCharges.py +++ b/gui/fitCommands/gui/projectedModule/changeCharges.py @@ -18,11 +18,10 @@ class GuiChangeProjectedModuleChargesCommand(wx.Command): def Do(self): cmd = CalcChangeModuleChargesCommand(fitID=self.fitID, projected=True, chargeMap={p: self.chargeItemID for p in self.positions}) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/projectedModule/changeSpool.py b/gui/fitCommands/gui/projectedModule/changeSpool.py index 2d4317124..819232ce9 100644 --- a/gui/fitCommands/gui/projectedModule/changeSpool.py +++ b/gui/fitCommands/gui/projectedModule/changeSpool.py @@ -24,11 +24,10 @@ class GuiChangeProjectedModuleSpoolCommand(wx.Command): position=self.position, spoolType=self.spoolType, spoolAmount=self.spoolAmount) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/projectedModule/changeState.py b/gui/fitCommands/gui/projectedModule/changeState.py index 70e78cbcb..b8bf4ede3 100644 --- a/gui/fitCommands/gui/projectedModule/changeState.py +++ b/gui/fitCommands/gui/projectedModule/changeState.py @@ -18,11 +18,10 @@ class GuiChangeProjectedModuleStateCommand(wx.Command): def Do(self): cmd = CalcChangeProjectedModuleStateCommand(fitID=self.fitID, position=self.position, click=self.click) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/projectedModule/remove.py b/gui/fitCommands/gui/projectedModule/remove.py index c3f18eb69..3e9abeca6 100644 --- a/gui/fitCommands/gui/projectedModule/remove.py +++ b/gui/fitCommands/gui/projectedModule/remove.py @@ -17,11 +17,10 @@ class GuiRemoveProjectedModuleCommand(wx.Command): def Do(self): cmd = CalcRemoveProjectedModuleCommand(fitID=self.fitID, position=self.position) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/gui/shipModeChange.py b/gui/fitCommands/gui/shipModeChange.py index da16d6c81..3e5624e64 100644 --- a/gui/fitCommands/gui/shipModeChange.py +++ b/gui/fitCommands/gui/shipModeChange.py @@ -17,11 +17,10 @@ class GuiChangeShipModeCommand(wx.Command): def Do(self): cmd = CalcChangeShipModeCommand(fitID=self.fitID, itemID=self.itemID) - if self.internalHistory.submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False + success = self.internalHistory.submit(cmd) + 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() diff --git a/gui/fitCommands/helpers.py b/gui/fitCommands/helpers.py index e580d794a..55e397f6e 100644 --- a/gui/fitCommands/helpers.py +++ b/gui/fitCommands/helpers.py @@ -21,19 +21,29 @@ class InternalCommandHistory: def __init__(self): self.__buffer = wx.CommandProcessor() - def submit(self, *args, **kwargs): - return self.__buffer.Submit(*args, **kwargs) + def submit(self, command): + return self.__buffer.Submit(command) + + def submitBatch(self, *commands): + for command in commands: + if not self.__buffer.Submit(command): + # Undo what we already submitted + for commandToUndo in reversed(self.__buffer.Commands): + if commandToUndo in commands: + self.__buffer.Undo() + return False + return True def undoAll(self): undoneCommands = [] # Undo commands one by one, starting from the last - for cmdToUndo in reversed(self.__buffer.Commands): - if cmdToUndo.Undo(): - undoneCommands.append(cmdToUndo) + for commandToUndo in reversed(self.__buffer.Commands): + if commandToUndo.Undo(): + undoneCommands.append(commandToUndo) # If undoing fails, redo already undone commands, starting from the last undone else: - for cmdToRedo in reversed(undoneCommands): - if not cmdToRedo.Do(): + for commandToRedo in reversed(undoneCommands): + if not commandToRedo.Do(): break self.__buffer.ClearCommands() return False