Save secondary state changes and restore them on undo

This commit is contained in:
DarkPhoenix
2019-04-16 14:48:25 +03:00
parent 30b12b04e8
commit fbf3cace10
21 changed files with 92 additions and 49 deletions

View File

@@ -3,7 +3,7 @@ from logbook import Logger
import eos.db import eos.db
from eos.exception import HandledListActionError from eos.exception import HandledListActionError
from gui.fitCommands.helpers import stateLimit from gui.fitCommands.helpers import restoreCheckedStates, stateLimit
from service.fit import Fit from service.fit import Fit
@@ -16,9 +16,10 @@ class CalcAddLocalModuleCommand(wx.Command):
wx.Command.__init__(self, True, 'Add Module') wx.Command.__init__(self, True, 'Add Module')
self.fitID = fitID self.fitID = fitID
self.newModInfo = newModInfo self.newModInfo = newModInfo
self.commit = commit
self.savedPosition = None self.savedPosition = None
self.subsystemCmd = None self.subsystemCmd = None
self.commit = commit self.savedStateCheckChanges = None
def Do(self): def Do(self):
pyfalog.debug('Doing addition of local module {} to fit {}'.format(self.newModInfo, self.fitID)) pyfalog.debug('Doing addition of local module {} to fit {}'.format(self.newModInfo, self.fitID))
@@ -50,8 +51,8 @@ class CalcAddLocalModuleCommand(wx.Command):
eos.db.commit() eos.db.commit()
return False return False
self.savedPosition = newMod.modPosition self.savedPosition = newMod.modPosition
sFit.recalc(self.fitID) sFit.recalc(fit)
sFit.checkStates(fit, newMod) self.savedStateCheckChanges = sFit.checkStates(fit, newMod)
if self.commit: if self.commit:
eos.db.commit() eos.db.commit()
return True return True
@@ -65,4 +66,7 @@ class CalcAddLocalModuleCommand(wx.Command):
if self.savedPosition is None: if self.savedPosition is None:
return False return False
cmd = CalcRemoveLocalModuleCommand(fitID=self.fitID, positions=[self.savedPosition], commit=self.commit) cmd = CalcRemoveLocalModuleCommand(fitID=self.fitID, positions=[self.savedPosition], commit=self.commit)
return cmd.Do() if not cmd.Do():
return False
restoreCheckedStates(Fit.getInstance().getFit(self.fitID), self.savedStateCheckChanges)
return True

View File

@@ -3,6 +3,7 @@ from logbook import Logger
import eos.db import eos.db
from eos.saveddata.module import Module from eos.saveddata.module import Module
from gui.fitCommands.helpers import restoreCheckedStates
from service.fit import Fit from service.fit import Fit
@@ -18,6 +19,7 @@ class CalcChangeLocalModuleStatesCommand(wx.Command):
self.positions = positions self.positions = positions
self.click = click self.click = click
self.savedStates = {} self.savedStates = {}
self.savedStateCheckChanges = None
def Do(self): def Do(self):
pyfalog.debug('Doing change of local module states at position {}/{} to click {} on fit {}'.format(self.mainPosition, self.positions, self.click, self.fitID)) pyfalog.debug('Doing change of local module states at position {}/{} to click {} on fit {}'.format(self.mainPosition, self.positions, self.click, self.fitID))
@@ -44,8 +46,8 @@ class CalcChangeLocalModuleStatesCommand(wx.Command):
mod.state = proposedState mod.state = proposedState
if not changed: if not changed:
return False return False
sFit.recalc(self.fitID) sFit.recalc(fit)
sFit.checkStates(fit, mainMod) self.savedStateCheckChanges = sFit.checkStates(fit, mainMod)
eos.db.commit() eos.db.commit()
return True return True
@@ -56,4 +58,6 @@ class CalcChangeLocalModuleStatesCommand(wx.Command):
mod = fit.modules[position] mod = fit.modules[position]
pyfalog.debug('Reverting {} to state {} for fit ID {}'.format(mod, state, self.fitID)) pyfalog.debug('Reverting {} to state {} for fit ID {}'.format(mod, state, self.fitID))
mod.state = state mod.state = state
restoreCheckedStates(fit, self.savedStateCheckChanges)
eos.db.commit()
return True return True

View File

@@ -5,6 +5,7 @@ from logbook import Logger
import eos.db import eos.db
from eos.exception import HandledListActionError from eos.exception import HandledListActionError
from gui.fitCommands.helpers import restoreCheckedStates
from service.fit import Fit from service.fit import Fit
@@ -18,6 +19,7 @@ class CalcCloneLocalModuleCommand(wx.Command):
self.fitID = fitID self.fitID = fitID
self.srcPosition = srcPosition self.srcPosition = srcPosition
self.dstPosition = dstPosition self.dstPosition = dstPosition
self.savedStateCheckChanges = None
def Do(self): def Do(self):
pyfalog.debug('Doing cloning of local module from position {} to position {} for fit ID {}'.format(self.srcPosition, self.dstPosition, self.fitID)) pyfalog.debug('Doing cloning of local module from position {} to position {} for fit ID {}'.format(self.srcPosition, self.dstPosition, self.fitID))
@@ -36,8 +38,8 @@ class CalcCloneLocalModuleCommand(wx.Command):
pyfalog.warning('Failed to replace module') pyfalog.warning('Failed to replace module')
eos.db.commit() eos.db.commit()
return False return False
sFit.recalc(self.fitID) sFit.recalc(fit)
sFit.checkStates(fit, copyMod) self.savedStateCheckChanges = sFit.checkStates(fit, copyMod)
eos.db.commit() eos.db.commit()
return True return True
@@ -45,4 +47,7 @@ class CalcCloneLocalModuleCommand(wx.Command):
pyfalog.debug('Undoing cloning of local module from position {} to position {} for fit ID {}'.format(self.srcPosition, self.dstPosition, self.fitID)) pyfalog.debug('Undoing cloning of local module from position {} to position {} for fit ID {}'.format(self.srcPosition, self.dstPosition, self.fitID))
from .localRemove import CalcRemoveLocalModuleCommand from .localRemove import CalcRemoveLocalModuleCommand
cmd = CalcRemoveLocalModuleCommand(fitID=self.fitID, positions=[self.dstPosition]) cmd = CalcRemoveLocalModuleCommand(fitID=self.fitID, positions=[self.dstPosition])
return cmd.Do() if not cmd.Do():
return False
restoreCheckedStates(Fit.getInstance().getFit(self.fitID), self.savedStateCheckChanges)
return True

View File

@@ -2,7 +2,7 @@ import wx
from logbook import Logger from logbook import Logger
import eos.db import eos.db
from gui.fitCommands.helpers import ModuleInfo from gui.fitCommands.helpers import ModuleInfo, restoreCheckedStates
from service.fit import Fit from service.fit import Fit
@@ -17,6 +17,7 @@ class CalcRemoveLocalModuleCommand(wx.Command):
self.positions = positions self.positions = positions
self.savedModInfos = {} self.savedModInfos = {}
self.commit = commit self.commit = commit
self.savedStateCheckChanges = None
def Do(self): def Do(self):
pyfalog.debug('Doing removal of local modules from positions {} on fit {}'.format(self.positions, self.fitID)) pyfalog.debug('Doing removal of local modules from positions {} on fit {}'.format(self.positions, self.fitID))
@@ -29,7 +30,8 @@ class CalcRemoveLocalModuleCommand(wx.Command):
self.savedModInfos[position] = ModuleInfo.fromModule(mod) self.savedModInfos[position] = ModuleInfo.fromModule(mod)
fit.modules.free(position) fit.modules.free(position)
sFit.checkStates(fit, None) sFit.recalc(fit)
self.savedStateCheckChanges = sFit.checkStates(fit, None)
if self.commit: if self.commit:
eos.db.commit() eos.db.commit()
# If no modules were removed, report that command was not completed # If no modules were removed, report that command was not completed
@@ -42,6 +44,9 @@ class CalcRemoveLocalModuleCommand(wx.Command):
for position, modInfo in self.savedModInfos.items(): for position, modInfo in self.savedModInfos.items():
cmd = CalcReplaceLocalModuleCommand(fitID=self.fitID, position=position, newModInfo=modInfo, commit=False) cmd = CalcReplaceLocalModuleCommand(fitID=self.fitID, position=position, newModInfo=modInfo, commit=False)
results.append(cmd.Do()) results.append(cmd.Do())
if not any(results):
return False
restoreCheckedStates(Fit.getInstance().getFit(self.fitID), self.savedStateCheckChanges)
if self.commit: if self.commit:
eos.db.commit() eos.db.commit()
return any(results) return True

View File

@@ -3,7 +3,7 @@ from logbook import Logger
import eos.db import eos.db
from eos.exception import HandledListActionError from eos.exception import HandledListActionError
from gui.fitCommands.helpers import ModuleInfo, stateLimit from gui.fitCommands.helpers import ModuleInfo, restoreCheckedStates, stateLimit
from service.fit import Fit from service.fit import Fit
@@ -20,6 +20,7 @@ class CalcReplaceLocalModuleCommand(wx.Command):
self.oldModInfo = None self.oldModInfo = None
self.unloadInvalidCharges = unloadInvalidCharges self.unloadInvalidCharges = unloadInvalidCharges
self.commit = commit self.commit = commit
self.savedStateCheckChanges = None
self.unloadedCharge = None self.unloadedCharge = None
def Do(self): def Do(self):
@@ -56,22 +57,26 @@ class CalcReplaceLocalModuleCommand(wx.Command):
pyfalog.warning('Failed to replace in list') pyfalog.warning('Failed to replace in list')
self.Undo() self.Undo()
return False return False
sFit.recalc(self.fitID) sFit.recalc(fit)
sFit.checkStates(fit, newMod) self.savedStateCheckChanges = sFit.checkStates(fit, newMod)
if self.commit: if self.commit:
eos.db.commit() eos.db.commit()
return True return True
def Undo(self): def Undo(self):
pyfalog.debug('Undoing replacement of local module at position {} to {} on fit {}'.format(self.newModInfo, self.position, self.fitID)) pyfalog.debug('Undoing replacement of local module at position {} to {} on fit {}'.format(self.newModInfo, self.position, self.fitID))
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
# Remove if there was no module # Remove if there was no module
if self.oldModInfo is None: if self.oldModInfo is None:
from .localRemove import CalcRemoveLocalModuleCommand from .localRemove import CalcRemoveLocalModuleCommand
cmd = CalcRemoveLocalModuleCommand(fitID=self.fitID, positions=[self.position], commit=self.commit) cmd = CalcRemoveLocalModuleCommand(fitID=self.fitID, positions=[self.position], commit=self.commit)
return cmd.Do() if not cmd.Do():
return False
sFit.recalc(fit)
restoreCheckedStates(fit, self.savedStateCheckChanges)
return True
# Replace if there was # Replace if there was
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
oldMod = self.oldModInfo.toModule() oldMod = self.oldModInfo.toModule()
if oldMod is None: if oldMod is None:
return False return False
@@ -87,8 +92,8 @@ class CalcReplaceLocalModuleCommand(wx.Command):
pyfalog.warning('Failed to replace in list') pyfalog.warning('Failed to replace in list')
self.Do() self.Do()
return False return False
sFit.recalc(self.fitID) sFit.recalc(fit)
sFit.checkStates(fit, oldMod) restoreCheckedStates(fit, self.savedStateCheckChanges)
if self.commit: if self.commit:
eos.db.commit() eos.db.commit()
return True return True

View File

@@ -18,14 +18,15 @@ class GuiChangeBoosterMetaCommand(wx.Command):
def Do(self): def Do(self):
sFit = Fit.getInstance() sFit = Fit.getInstance()
booster = sFit.getFit(self.fitID).boosters[self.position] fit = sFit.getFit(self.fitID)
booster = fit.boosters[self.position]
if booster.itemID == self.newItemID: if booster.itemID == self.newItemID:
return False return False
info = BoosterInfo.fromBooster(booster) info = BoosterInfo.fromBooster(booster)
info.itemID = self.newItemID info.itemID = self.newItemID
cmd = CalcAddBoosterCommand(fitID=self.fitID, boosterInfo=info) cmd = CalcAddBoosterCommand(fitID=self.fitID, boosterInfo=info)
success = self.internalHistory.submit(cmd) success = self.internalHistory.submit(cmd)
sFit.recalc(self.fitID) sFit.recalc(fit)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success return success

View File

@@ -29,7 +29,7 @@ class GuiAddImplantCommand(wx.Command):
cmd = CalcAddImplantCommand(fitID=self.fitID, implantInfo=ImplantInfo(itemID=self.itemID), commit=False) cmd = CalcAddImplantCommand(fitID=self.fitID, implantInfo=ImplantInfo(itemID=self.itemID), commit=False)
successImplant = self.internalHistory.submit(cmd) successImplant = self.internalHistory.submit(cmd)
eos.db.commit() eos.db.commit()
sFit.recalc(self.fitID) sFit.recalc(fit)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
# Acceptable behavior when we already have passed implant and just switch source, or # Acceptable behavior when we already have passed implant and just switch source, or
# when we have source and add implant, but not if we do not change anything # when we have source and add implant, but not if we do not change anything

View File

@@ -18,14 +18,15 @@ class GuiChangeImplantMetaCommand(wx.Command):
def Do(self): def Do(self):
sFit = Fit.getInstance() sFit = Fit.getInstance()
implant = sFit.getFit(self.fitID).implants[self.position] fit = sFit.getFit(self.fitID)
implant = fit.implants[self.position]
if implant.itemID == self.newItemID: if implant.itemID == self.newItemID:
return False return False
info = ImplantInfo.fromImplant(implant) info = ImplantInfo.fromImplant(implant)
info.itemID = self.newItemID info.itemID = self.newItemID
cmd = CalcAddImplantCommand(fitID=self.fitID, implantInfo=info) cmd = CalcAddImplantCommand(fitID=self.fitID, implantInfo=info)
success = self.internalHistory.submit(cmd) success = self.internalHistory.submit(cmd)
sFit.recalc(self.fitID) sFit.recalc(fit)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success return success

View File

@@ -57,7 +57,7 @@ class GuiRebaseItemsCommand(wx.Command):
cmdAdd = CalcAddCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.rebaseMap[cargo.itemID], amount=amount)) cmdAdd = CalcAddCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.rebaseMap[cargo.itemID], amount=amount))
self.internalHistory.submitBatch(cmdRemove, cmdAdd) self.internalHistory.submitBatch(cmdRemove, cmdAdd)
eos.db.commit() eos.db.commit()
sFit.recalc(self.fitID) sFit.recalc(fit)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return len(self.internalHistory) > 0 return len(self.internalHistory) > 0

View File

@@ -21,7 +21,8 @@ class GuiChangeLocalDroneMetaCommand(wx.Command):
def Do(self): def Do(self):
sFit = Fit.getInstance() sFit = Fit.getInstance()
drone = sFit.getFit(self.fitID).drones[self.position] fit = sFit.getFit(self.fitID)
drone = fit.drones[self.position]
if drone.itemID == self.newItemID: if drone.itemID == self.newItemID:
return False return False
info = DroneInfo.fromDrone(drone) info = DroneInfo.fromDrone(drone)
@@ -29,7 +30,7 @@ class GuiChangeLocalDroneMetaCommand(wx.Command):
cmdRemove = CalcRemoveLocalDroneCommand(fitID=self.fitID, position=self.position, amount=math.inf) cmdRemove = CalcRemoveLocalDroneCommand(fitID=self.fitID, position=self.position, amount=math.inf)
cmdAdd = CalcAddLocalDroneCommand(fitID=self.fitID, droneInfo=info, forceNewStack=True) cmdAdd = CalcAddLocalDroneCommand(fitID=self.fitID, droneInfo=info, forceNewStack=True)
success = self.internalHistory.submitBatch(cmdRemove, cmdAdd) success = self.internalHistory.submitBatch(cmdRemove, cmdAdd)
sFit.recalc(self.fitID) sFit.recalc(fit)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success return success

View File

@@ -19,7 +19,8 @@ class GuiChangeLocalFighterMetaCommand(wx.Command):
def Do(self): def Do(self):
sFit = Fit.getInstance() sFit = Fit.getInstance()
fighter = sFit.getFit(self.fitID).fighters[self.position] fit = sFit.getFit(self.fitID)
fighter = fit.fighters[self.position]
if fighter.itemID == self.newItemID: if fighter.itemID == self.newItemID:
return False return False
info = FighterInfo.fromFighter(fighter) info = FighterInfo.fromFighter(fighter)
@@ -27,7 +28,7 @@ class GuiChangeLocalFighterMetaCommand(wx.Command):
cmdRemove = CalcRemoveLocalFighterCommand(fitID=self.fitID, position=self.position) cmdRemove = CalcRemoveLocalFighterCommand(fitID=self.fitID, position=self.position)
cmdAdd = CalcAddLocalFighterCommand(fitID=self.fitID, fighterInfo=info) cmdAdd = CalcAddLocalFighterCommand(fitID=self.fitID, fighterInfo=info)
success = self.internalHistory.submitBatch(cmdRemove, cmdAdd) success = self.internalHistory.submitBatch(cmdRemove, cmdAdd)
sFit.recalc(self.fitID) sFit.recalc(fit)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success return success

View File

@@ -33,7 +33,7 @@ class GuiChangeLocalModuleMetasCommand(wx.Command):
return False return False
success = self.internalHistory.submitBatch(*commands) success = self.internalHistory.submitBatch(*commands)
eos.db.commit() eos.db.commit()
sFit.recalc(self.fitID) sFit.recalc(fit)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success return success

View File

@@ -23,8 +23,9 @@ class GuiCloneLocalModuleCommand(wx.Command):
sFit = Fit.getInstance() sFit = Fit.getInstance()
cmd = CalcCloneLocalModuleCommand(fitID=self.fitID, srcPosition=self.srcPosition, dstPosition=self.dstPosition) cmd = CalcCloneLocalModuleCommand(fitID=self.fitID, srcPosition=self.srcPosition, dstPosition=self.dstPosition)
success = self.internalHistory.submit(cmd) success = self.internalHistory.submit(cmd)
sFit.recalc(self.fitID) fit = sFit.getFit(self.fitID)
self.savedItemID = sFit.getFit(self.fitID).modules[self.srcPosition].itemID sFit.recalc(fit)
self.savedItemID = fit.modules[self.srcPosition].itemID
if success and self.savedItemID is not None: if success and self.savedItemID is not None:
event = GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.savedItemID) event = GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.savedItemID)
else: else:

View File

@@ -38,7 +38,7 @@ class GuiConvertMutatedLocalModuleCommand(wx.Command):
spoolType=mod.spoolType, spoolType=mod.spoolType,
spoolAmount=mod.spoolAmount)) spoolAmount=mod.spoolAmount))
success = self.internalHistory.submit(cmd) success = self.internalHistory.submit(cmd)
sFit.recalc(self.fitID) sFit.recalc(fit)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success return success

View File

@@ -33,7 +33,7 @@ class GuiRevertMutatedLocalModuleCommand(wx.Command):
spoolType=mod.spoolType, spoolType=mod.spoolType,
spoolAmount=mod.spoolAmount)) spoolAmount=mod.spoolAmount))
success = self.internalHistory.submit(cmd) success = self.internalHistory.submit(cmd)
sFit.recalc(self.fitID) sFit.recalc(fit)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success return success

View File

@@ -138,7 +138,7 @@ class GuiCargoToLocalModuleCommand(wx.Command):
else: else:
return False return False
eos.db.commit() eos.db.commit()
sFit.recalc(self.fitID) sFit.recalc(fit)
events = [] events = []
if self.removedModItemID is not None: if self.removedModItemID is not None:
events.append(GE.FitChanged(fitID=self.fitID, action='moddel', typeID=self.removedModItemID)) events.append(GE.FitChanged(fitID=self.fitID, action='moddel', typeID=self.removedModItemID))

View File

@@ -32,7 +32,7 @@ class GuiChangeProjectedDroneMetaCommand(wx.Command):
cmdRemove = CalcRemoveProjectedDroneCommand(fitID=self.fitID, itemID=self.itemID, amount=math.inf) cmdRemove = CalcRemoveProjectedDroneCommand(fitID=self.fitID, itemID=self.itemID, amount=math.inf)
cmdAdd = CalcAddProjectedDroneCommand(fitID=self.fitID, droneInfo=info) cmdAdd = CalcAddProjectedDroneCommand(fitID=self.fitID, droneInfo=info)
success = self.internalHistory.submitBatch(cmdRemove, cmdAdd) success = self.internalHistory.submitBatch(cmdRemove, cmdAdd)
sFit.recalc(self.fitID) sFit.recalc(fit)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success return success

View File

@@ -19,7 +19,8 @@ class GuiChangeProjectedFighterMetaCommand(wx.Command):
def Do(self): def Do(self):
sFit = Fit.getInstance() sFit = Fit.getInstance()
fighter = sFit.getFit(self.fitID).projectedFighters[self.position] fit = sFit.getFit(self.fitID)
fighter = fit.projectedFighters[self.position]
if fighter.itemID == self.newItemID: if fighter.itemID == self.newItemID:
return False return False
info = FighterInfo.fromFighter(fighter) info = FighterInfo.fromFighter(fighter)
@@ -27,7 +28,7 @@ class GuiChangeProjectedFighterMetaCommand(wx.Command):
cmdRemove = CalcRemoveProjectedFighterCommand(fitID=self.fitID, position=self.position) cmdRemove = CalcRemoveProjectedFighterCommand(fitID=self.fitID, position=self.position)
cmdAdd = CalcAddProjectedFighterCommand(fitID=self.fitID, fighterInfo=info) cmdAdd = CalcAddProjectedFighterCommand(fitID=self.fitID, fighterInfo=info)
success = self.internalHistory.submitBatch(cmdRemove, cmdAdd) success = self.internalHistory.submitBatch(cmdRemove, cmdAdd)
sFit.recalc(self.fitID) sFit.recalc(fit)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success return success

View File

@@ -28,7 +28,7 @@ class GuiChangeProjectedModuleMetaCommand(wx.Command):
cmdRemove = CalcRemoveProjectedModuleCommand(fitID=self.fitID, position=self.position) cmdRemove = CalcRemoveProjectedModuleCommand(fitID=self.fitID, position=self.position)
cmdAdd = CalcAddProjectedModuleCommand(fitID=self.fitID, modInfo=info) cmdAdd = CalcAddProjectedModuleCommand(fitID=self.fitID, modInfo=info)
success = self.internalHistory.submitBatch(cmdRemove, cmdAdd) success = self.internalHistory.submitBatch(cmdRemove, cmdAdd)
sFit.recalc(self.fitID) sFit.recalc(fit)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success return success

View File

@@ -320,3 +320,15 @@ def stateLimit(itemIdentity):
if {'moduleBonusAssaultDamageControl', 'moduleBonusIndustrialInvulnerability'}.intersection(item.effects): if {'moduleBonusAssaultDamageControl', 'moduleBonusIndustrialInvulnerability'}.intersection(item.effects):
return FittingModuleState.ONLINE return FittingModuleState.ONLINE
return FittingModuleState.ACTIVE return FittingModuleState.ACTIVE
def restoreCheckedStates(fit, stateInfo):
if stateInfo is None:
return
changedMods, changedProjMods, changedProjDrones = stateInfo
for pos, state in changedMods.items():
fit.modules[pos].state = state
for pos, state in changedProjMods.items():
fit.projectedModules[pos].state = state
for pos, amountActive in changedProjDrones.items():
fit.projectedDrones[pos].amountActive = amountActive

View File

@@ -461,26 +461,28 @@ class Fit(FitDeprecated):
def checkStates(self, fit, base): def checkStates(self, fit, base):
pyfalog.debug("Check states for fit ID: {0}", fit) pyfalog.debug("Check states for fit ID: {0}", fit)
changed = False changedMods = {}
for mod in fit.modules: changedProjMods = {}
changedProjDrones = {}
for pos, mod in enumerate(fit.modules):
if mod != base: if mod != base:
# fix for #529, where a module may be in incorrect state after CCP changes mechanics of module # fix for #529, where a module may be in incorrect state after CCP changes mechanics of module
if not mod.canHaveState(mod.state) or not mod.isValidState(mod.state): if not mod.canHaveState(mod.state) or not mod.isValidState(mod.state):
changedMods[pos] = mod.state
mod.state = FittingModuleState.ONLINE mod.state = FittingModuleState.ONLINE
changed = True
for mod in fit.projectedModules: for pos, mod in enumerate(fit.projectedModules):
# fix for #529, where a module may be in incorrect state after CCP changes mechanics of module # fix for #529, where a module may be in incorrect state after CCP changes mechanics of module
if not mod.canHaveState(mod.state, fit) or not mod.isValidState(mod.state): if not mod.canHaveState(mod.state, fit) or not mod.isValidState(mod.state):
changedProjMods[pos] = mod.state
mod.state = FittingModuleState.OFFLINE mod.state = FittingModuleState.OFFLINE
changed = True
for drone in fit.projectedDrones: for pos, drone in enumerate(fit.projectedDrones):
if drone.amountActive > 0 and not drone.canBeApplied(fit): if drone.amountActive > 0 and not drone.canBeApplied(fit):
changedProjDrones[pos] = drone.amountActive
drone.amountActive = 0 drone.amountActive = 0
changed = True
return changed return changedMods, changedProjMods, changedProjDrones
@classmethod @classmethod
def fitObjectIter(cls, fit): def fitObjectIter(cls, fit):