Allow to undo operations even if removed module doesn't fit (e.g. removing excessive modules on t3c with removed subs)

This commit is contained in:
DarkPhoenix
2019-04-30 14:39:11 +03:00
parent 63a599ca85
commit 9249ef24b3
13 changed files with 38 additions and 20 deletions

View File

@@ -14,11 +14,12 @@ pyfalog = Logger(__name__)
class CalcAddLocalDroneCommand(wx.Command):
def __init__(self, fitID, droneInfo, forceNewStack=False, commit=True):
def __init__(self, fitID, droneInfo, forceNewStack=False, ignoreRestrictions=False, commit=True):
wx.Command.__init__(self, True, 'Add Local Drone')
self.fitID = fitID
self.droneInfo = droneInfo
self.forceNewStack = forceNewStack
self.ignoreRestrictions = ignoreRestrictions
self.commit = commit
self.savedDroneInfo = None
self.savedPosition = None
@@ -46,7 +47,7 @@ class CalcAddLocalDroneCommand(wx.Command):
drone = self.droneInfo.toDrone()
if drone is None:
return False
if not drone.fits(fit):
if not self.ignoreRestrictions and not drone.fits(fit):
pyfalog.warning('Drone does not fit')
return False
try:

View File

@@ -48,8 +48,6 @@ class CalcRemoveLocalDroneCommand(wx.Command):
drone = self.savedDroneInfo.toDrone()
if drone is None:
return False
if not drone.fits(fit):
return False
try:
fit.drones.insert(self.position, drone)
except HandledListActionError:

View File

@@ -11,11 +11,12 @@ pyfalog = Logger(__name__)
class CalcAddLocalFighterCommand(wx.Command):
def __init__(self, fitID, fighterInfo, position=None, commit=True):
def __init__(self, fitID, fighterInfo, position=None, ignoreRestrictions=False, commit=True):
wx.Command.__init__(self, True, 'Add Fighter')
self.fitID = fitID
self.fighterInfo = fighterInfo
self.position = position
self.ignoreRestrictions = ignoreRestrictions
self.commit = commit
def Do(self):
@@ -25,7 +26,7 @@ class CalcAddLocalFighterCommand(wx.Command):
return False
fit = Fit.getInstance().getFit(self.fitID)
if not fighter.fits(fit):
if not self.ignoreRestrictions and not fighter.fits(fit):
pyfalog.warning('Fighter does not fit')
return False

View File

@@ -35,5 +35,6 @@ class CalcRemoveLocalFighterCommand(wx.Command):
fitID=self.fitID,
fighterInfo=self.savedFighterInfo,
position=self.position,
ignoreRestrictions=True,
commit=self.commit)
return cmd.Do()

View File

@@ -12,11 +12,12 @@ pyfalog = Logger(__name__)
class CalcChangeModuleChargesCommand(wx.Command):
def __init__(self, fitID, projected, chargeMap, commit=True):
def __init__(self, fitID, projected, chargeMap, ignoreRestriction=False, commit=True):
wx.Command.__init__(self, True, 'Change Module Charges')
self.fitID = fitID
self.projected = projected
self.chargeMap = chargeMap
self.ignoreRestriction = ignoreRestriction
self.commit = commit
self.savedChargeMap = None
self.savedStateCheckChanges = None
@@ -40,7 +41,7 @@ class CalcChangeModuleChargesCommand(wx.Command):
chargeItem = sMkt.getItem(chargeItemID) if chargeItemID is not None else None
if chargeItem is not None and not chargeItem.isCharge:
continue
if not mod.isValidCharge(chargeItem):
if not self.ignoreRestriction and not mod.isValidCharge(chargeItem):
pyfalog.warning('Invalid charge {} for {}'.format(chargeItem, mod))
continue
pyfalog.debug('Setting charge {} for {} on fit {}'.format(chargeItem, mod, self.fitID))
@@ -61,6 +62,7 @@ class CalcChangeModuleChargesCommand(wx.Command):
fitID=self.fitID,
projected=self.projected,
chargeMap=self.savedChargeMap,
ignoreRestriction=True,
commit=self.commit)
if not cmd.Do():
return False

View File

@@ -60,12 +60,20 @@ class CalcRemoveLocalModulesCommand(wx.Command):
if len(self.savedSubInfos) > 0:
for position, modInfo in self.savedSubInfos.items():
cmd = CalcReplaceLocalModuleCommand(
fitID=self.fitID, position=position, newModInfo=modInfo, commit=False)
fitID=self.fitID,
position=position,
newModInfo=modInfo,
ignoreRestrictions=True,
commit=False)
results.append(cmd.Do())
sFit.recalc(fit)
for position, modInfo in self.savedModInfos.items():
cmd = CalcReplaceLocalModuleCommand(
fitID=self.fitID, position=position, newModInfo=modInfo, commit=False)
fitID=self.fitID,
position=position,
newModInfo=modInfo,
ignoreRestrictions=True,
commit=False)
results.append(cmd.Do())
if not any(results):
return False

View File

@@ -12,13 +12,14 @@ pyfalog = Logger(__name__)
class CalcReplaceLocalModuleCommand(wx.Command):
def __init__(self, fitID, position, newModInfo, unloadInvalidCharges=False, commit=True):
def __init__(self, fitID, position, newModInfo, unloadInvalidCharges=False, ignoreRestrictions=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.ignoreRestrictions = ignoreRestrictions
self.commit = commit
self.savedStateCheckChanges = None
self.unloadedCharge = None
@@ -40,11 +41,11 @@ class CalcReplaceLocalModuleCommand(wx.Command):
return False
# Dummy it out in case the next bit fails
fit.modules.free(self.position)
if not newMod.fits(fit):
if not self.ignoreRestrictions and not newMod.fits(fit):
pyfalog.warning('Module does not fit')
self.Undo()
return False
if not newMod.isValidCharge(newMod.charge):
if not not self.ignoreRestrictions and not newMod.isValidCharge(newMod.charge):
if self.unloadInvalidCharges:
newMod.charge = None
self.unloadedCharge = True
@@ -86,10 +87,6 @@ class CalcReplaceLocalModuleCommand(wx.Command):
if oldMod is None:
return False
fit.modules.free(self.position)
if not oldMod.fits(fit):
pyfalog.warning('Module does not fit')
self.Do()
return False
try:
fit.modules.replace(self.position, oldMod)
except HandledListActionError:

View File

@@ -13,11 +13,12 @@ pyfalog = Logger(__name__)
class CalcAddProjectedModuleCommand(wx.Command):
def __init__(self, fitID, modInfo, position=None, commit=True):
def __init__(self, fitID, modInfo, position=None, ignoreRestrictions=False, commit=True):
wx.Command.__init__(self, True)
self.fitID = fitID
self.newModInfo = modInfo
self.newPosition = position
self.ignoreRestrictions = ignoreRestrictions
self.commit = commit
self.oldModInfo = None
self.oldPosition = None
@@ -33,7 +34,7 @@ class CalcAddProjectedModuleCommand(wx.Command):
fit = sFit.getFit(self.fitID)
if not newMod.canHaveState(newMod.state, projectedOnto=fit):
newMod.state = FittingModuleState.OFFLINE
if not newMod.isValidCharge(newMod.charge):
if not self.ignoreRestrictions and not newMod.isValidCharge(newMod.charge):
newMod.charge = None
self.oldPosition, self.oldModInfo = fit.projectedModules.makeRoom(newMod)
@@ -69,6 +70,7 @@ class CalcAddProjectedModuleCommand(wx.Command):
fitID=self.fitID,
modInfo=self.oldModInfo,
position=self.oldPosition,
ignoreRestrictions=True,
commit=False)
if not cmd.Do():
return False

View File

@@ -43,6 +43,7 @@ class CalcRemoveProjectedModuleCommand(wx.Command):
fitID=self.fitID,
modInfo=self.savedModInfo,
position=self.position,
ignoreRestrictions=True,
commit=False)
if not cmd.Do():
return False

View File

@@ -39,6 +39,7 @@ class GuiChangeLocalDroneMetasCommand(wx.Command):
fitID=self.fitID,
droneInfo=info,
forceNewStack=True,
ignoreRestrictions=True,
commit=False)
results.append(self.internalHistory.submitBatch(cmdRemove, cmdAdd))
success = any(results)

View File

@@ -37,6 +37,7 @@ class GuiSplitLocalDroneStackCommand(wx.Command):
fitID=self.fitID,
droneInfo=info,
forceNewStack=True,
ignoreRestrictions=True,
commit=False))
success = self.internalHistory.submitBatch(*commands)
eos.db.commit()

View File

@@ -35,6 +35,7 @@ class GuiChangeLocalFighterMetasCommand(wx.Command):
cmdAdd = CalcAddLocalFighterCommand(
fitID=self.fitID,
fighterInfo=info,
ignoreRestrictions=True,
commit=False)
results.append(self.internalHistory.submitBatch(cmdRemove, cmdAdd))
success = any(results)

View File

@@ -21,7 +21,11 @@ class GuiReplaceLocalModuleCommand(wx.Command):
def Do(self):
results = []
for position in self.positions:
cmd = CalcReplaceLocalModuleCommand(fitID=self.fitID, position=position, newModInfo=ModuleInfo(itemID=self.itemID), commit=False)
cmd = CalcReplaceLocalModuleCommand(
fitID=self.fitID,
position=position,
newModInfo=ModuleInfo(itemID=self.itemID),
commit=False)
results.append(self.internalHistory.submit(cmd))
success = any(results)
eos.db.commit()