Store mutation results on window close for undo/redo purposes
This commit is contained in:
@@ -240,7 +240,9 @@ class ItemMutatorList(wx.ScrolledWindow):
|
|||||||
# Submit mutation changes
|
# Submit mutation changes
|
||||||
sFit = Fit.getInstance()
|
sFit = Fit.getInstance()
|
||||||
fit = sFit.getFit(self.carryingFitID)
|
fit = sFit.getFit(self.carryingFitID)
|
||||||
if self.stuff in fit.modules:
|
isCurrentMod = self.stuff in fit.modules
|
||||||
|
isCurrentDrone = self.stuff in fit.drones
|
||||||
|
if isCurrentMod or isCurrentDrone:
|
||||||
if self.isModified:
|
if self.isModified:
|
||||||
currentMutation = {}
|
currentMutation = {}
|
||||||
for slider, m in self.event_mapping.items():
|
for slider, m in self.event_mapping.items():
|
||||||
@@ -254,11 +256,18 @@ class ItemMutatorList(wx.ScrolledWindow):
|
|||||||
else:
|
else:
|
||||||
currentMutation = self.initialMutations
|
currentMutation = self.initialMutations
|
||||||
mainFrame = gui.mainFrame.MainFrame.getInstance()
|
mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||||
mainFrame.getCommandForFit(self.carryingFitID).Submit(cmd.GuiChangeLocalModuleMutationCommand(
|
if isCurrentMod:
|
||||||
fitID=self.carryingFitID,
|
mainFrame.getCommandForFit(self.carryingFitID).Submit(cmd.GuiChangeLocalModuleMutationCommand(
|
||||||
position=fit.modules.index(self.stuff),
|
fitID=self.carryingFitID,
|
||||||
mutation=currentMutation,
|
position=fit.modules.index(self.stuff),
|
||||||
oldMutation=self.initialMutations))
|
mutation=currentMutation,
|
||||||
|
oldMutation=self.initialMutations))
|
||||||
|
elif isCurrentDrone:
|
||||||
|
mainFrame.getCommandForFit(self.carryingFitID).Submit(cmd.GuiChangeLocalDroneMutationCommand(
|
||||||
|
fitID=self.carryingFitID,
|
||||||
|
position=fit.drones.index(self.stuff),
|
||||||
|
mutation=currentMutation,
|
||||||
|
oldMutation=self.initialMutations))
|
||||||
for slider in self.event_mapping:
|
for slider in self.event_mapping:
|
||||||
slider.OnWindowClose()
|
slider.OnWindowClose()
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ from .gui.itemsRebase import GuiRebaseItemsCommand
|
|||||||
from .gui.localDrone.add import GuiAddLocalDroneCommand
|
from .gui.localDrone.add import GuiAddLocalDroneCommand
|
||||||
from .gui.localDrone.changeAmount import GuiChangeLocalDroneAmountCommand
|
from .gui.localDrone.changeAmount import GuiChangeLocalDroneAmountCommand
|
||||||
from .gui.localDrone.changeMetas import GuiChangeLocalDroneMetasCommand
|
from .gui.localDrone.changeMetas import GuiChangeLocalDroneMetasCommand
|
||||||
|
from .gui.localDrone.changeMutation import GuiChangeLocalDroneMutationCommand
|
||||||
from .gui.localDrone.clone import GuiCloneLocalDroneCommand
|
from .gui.localDrone.clone import GuiCloneLocalDroneCommand
|
||||||
from .gui.localDrone.imprt import GuiImportLocalDronesCommand
|
from .gui.localDrone.imprt import GuiImportLocalDronesCommand
|
||||||
from .gui.localDrone.mutatedConvert import GuiConvertMutatedLocalDroneCommand
|
from .gui.localDrone.mutatedConvert import GuiConvertMutatedLocalDroneCommand
|
||||||
|
|||||||
51
gui/fitCommands/calc/drone/localChangeMutation.py
Normal file
51
gui/fitCommands/calc/drone/localChangeMutation.py
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import wx
|
||||||
|
from logbook import Logger
|
||||||
|
|
||||||
|
from service.fit import Fit
|
||||||
|
|
||||||
|
|
||||||
|
pyfalog = Logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class CalcChangeLocalDroneMutationCommand(wx.Command):
|
||||||
|
|
||||||
|
def __init__(self, fitID, position, mutation, oldMutation=None):
|
||||||
|
wx.Command.__init__(self, True, 'Change Local Drone Mutation')
|
||||||
|
self.fitID = fitID
|
||||||
|
self.position = position
|
||||||
|
self.mutation = mutation
|
||||||
|
self.savedMutation = oldMutation
|
||||||
|
|
||||||
|
def Do(self):
|
||||||
|
pyfalog.debug('Doing changing of local drone mutation at position {} to {} for fit ID {}'.format(
|
||||||
|
self.position, self.mutation, self.fitID))
|
||||||
|
sFit = Fit.getInstance()
|
||||||
|
fit = sFit.getFit(self.fitID)
|
||||||
|
drone = fit.drones[self.position]
|
||||||
|
if not drone.isMutated:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if self.savedMutation is None:
|
||||||
|
self.savedMutation = {}
|
||||||
|
for mutator in drone.mutators.values():
|
||||||
|
self.savedMutation[mutator.attrID] = mutator.value
|
||||||
|
|
||||||
|
if self.mutation == self.savedMutation:
|
||||||
|
return False
|
||||||
|
|
||||||
|
for mutator in drone.mutators.values():
|
||||||
|
if mutator.attrID not in self.mutation:
|
||||||
|
continue
|
||||||
|
if mutator.value != self.mutation[mutator.attrID]:
|
||||||
|
mutator.value = self.mutation[mutator.attrID]
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
def Undo(self):
|
||||||
|
pyfalog.debug('Undoing changing of local drone mutation at position {} to {} for fit ID {}'.format(
|
||||||
|
self.position, self.mutation, self.fitID))
|
||||||
|
cmd = CalcChangeLocalDroneMutationCommand(
|
||||||
|
fitID=self.fitID,
|
||||||
|
position=self.position,
|
||||||
|
mutation=self.savedMutation)
|
||||||
|
return cmd.Do()
|
||||||
44
gui/fitCommands/gui/localDrone/changeMutation.py
Normal file
44
gui/fitCommands/gui/localDrone/changeMutation.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import wx
|
||||||
|
|
||||||
|
import eos.db
|
||||||
|
import gui.mainFrame
|
||||||
|
from gui import globalEvents as GE
|
||||||
|
from gui.fitCommands.calc.drone.localChangeMutation import CalcChangeLocalDroneMutationCommand
|
||||||
|
from gui.fitCommands.helpers import InternalCommandHistory
|
||||||
|
from service.fit import Fit
|
||||||
|
|
||||||
|
|
||||||
|
class GuiChangeLocalDroneMutationCommand(wx.Command):
|
||||||
|
|
||||||
|
def __init__(self, fitID, position, mutation, oldMutation=None):
|
||||||
|
wx.Command.__init__(self, True, 'Change Local Drone Mutation')
|
||||||
|
self.internalHistory = InternalCommandHistory()
|
||||||
|
self.fitID = fitID
|
||||||
|
self.position = position
|
||||||
|
self.mutation = mutation
|
||||||
|
self.oldMutation = oldMutation
|
||||||
|
|
||||||
|
def Do(self):
|
||||||
|
cmd = CalcChangeLocalDroneMutationCommand(
|
||||||
|
fitID=self.fitID,
|
||||||
|
position=self.position,
|
||||||
|
mutation=self.mutation,
|
||||||
|
oldMutation=self.oldMutation)
|
||||||
|
success = self.internalHistory.submit(cmd)
|
||||||
|
eos.db.flush()
|
||||||
|
sFit = Fit.getInstance()
|
||||||
|
sFit.recalc(self.fitID)
|
||||||
|
sFit.fill(self.fitID)
|
||||||
|
eos.db.commit()
|
||||||
|
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitIDs=(self.fitID,)))
|
||||||
|
return success
|
||||||
|
|
||||||
|
def Undo(self):
|
||||||
|
success = self.internalHistory.undoAll()
|
||||||
|
eos.db.flush()
|
||||||
|
sFit = Fit.getInstance()
|
||||||
|
sFit.recalc(self.fitID)
|
||||||
|
sFit.fill(self.fitID)
|
||||||
|
eos.db.commit()
|
||||||
|
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitIDs=(self.fitID,)))
|
||||||
|
return success
|
||||||
Reference in New Issue
Block a user