Rework meta swap command

This commit is contained in:
DarkPhoenix
2019-04-15 18:05:18 +03:00
parent 0fedb17586
commit 4c0f88cdfa
66 changed files with 502 additions and 425 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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