Change command-related commands a little
This commit is contained in:
@@ -37,5 +37,4 @@ class FitAddCargoCommand(wx.Command):
|
|||||||
pyfalog.debug('Undoing addition of cargo {} to fit {}'.format(self.cargoInfo, self.fitID))
|
pyfalog.debug('Undoing addition of cargo {} to fit {}'.format(self.cargoInfo, self.fitID))
|
||||||
from .fitRemoveCargo import FitRemoveCargoCommand
|
from .fitRemoveCargo import FitRemoveCargoCommand
|
||||||
cmd = FitRemoveCargoCommand(fitID=self.fitID, cargoInfo=self.cargoInfo)
|
cmd = FitRemoveCargoCommand(fitID=self.fitID, cargoInfo=self.cargoInfo)
|
||||||
cmd.Do()
|
return cmd.Do()
|
||||||
return True
|
|
||||||
|
|||||||
@@ -8,52 +8,52 @@ from service.fit import Fit
|
|||||||
pyfalog = Logger(__name__)
|
pyfalog = Logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class FitAddCommandCommand(wx.Command): # well that's an unfrtunate name
|
class FitAddCommandCommand(wx.Command):
|
||||||
""""
|
|
||||||
from sFit.addCommand
|
def __init__(self, fitID, commandFitID, state=None):
|
||||||
"""
|
|
||||||
def __init__(self, fitID, commandFitID, state):
|
|
||||||
wx.Command.__init__(self, True)
|
wx.Command.__init__(self, True)
|
||||||
self.fitID = fitID
|
self.fitID = fitID
|
||||||
self.commandFitID = commandFitID
|
self.commandFitID = commandFitID
|
||||||
self.state = state
|
self.state = state
|
||||||
|
|
||||||
def Do(self):
|
def Do(self):
|
||||||
pyfalog.debug("Projecting command fit ({0}) onto: {1}".format(self.fitID, self.commandFitID))
|
pyfalog.debug('Doing addition of command fit {} for fit {}'.format(self.commandFitID, self.fitID))
|
||||||
sFit = Fit.getInstance()
|
sFit = Fit.getInstance()
|
||||||
fit = sFit.getFit(self.fitID)
|
fit = sFit.getFit(self.fitID)
|
||||||
commandFit = sFit.getFit(self.commandFitID)
|
commandFit = sFit.getFit(self.commandFitID)
|
||||||
|
|
||||||
if not commandFit:
|
# Command fit could have been deleted if we were redoing
|
||||||
# if redoing when the command fit has been deleted, simply fail this command
|
if commandFit is None:
|
||||||
|
pyfalog.debug('Command fit is not available')
|
||||||
return False
|
return False
|
||||||
|
# Already commanding this ship
|
||||||
if commandFit in fit.commandFits:
|
if commandFit in fit.commandFits:
|
||||||
|
pyfalog.debug('Command fit had been applied already')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
fit.commandFitDict[commandFit.ID] = commandFit
|
fit.commandFitDict[commandFit.ID] = commandFit
|
||||||
|
|
||||||
# this bit is required -- see GH issue # 83
|
# this bit is required -- see GH issue # 83
|
||||||
eos.db.saveddata_session.flush()
|
eos.db.saveddata_session.flush()
|
||||||
eos.db.saveddata_session.refresh(commandFit)
|
eos.db.saveddata_session.refresh(commandFit)
|
||||||
|
|
||||||
if self.state is not None:
|
if self.state is not None:
|
||||||
commandInfo = commandFit.getCommandInfo(self.fitID)
|
fitCommandInfo = commandFit.getCommandInfo(self.fitID)
|
||||||
if not commandInfo:
|
if fitCommandInfo is None:
|
||||||
|
pyfalog.warning('Fit command info is not available')
|
||||||
|
self.Undo()
|
||||||
return False
|
return False
|
||||||
commandInfo.active = self.state
|
fitCommandInfo.active = self.state
|
||||||
|
|
||||||
eos.db.commit()
|
eos.db.commit()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def Undo(self):
|
def Undo(self):
|
||||||
command = eos.db.getFit(self.commandFitID)
|
pyfalog.debug('Undoing addition of command fit {} for fit {}'.format(self.commandFitID, self.fitID))
|
||||||
|
# Can't find the command fit, it must have been deleted. Just skip, as deleted fit
|
||||||
if not command:
|
# means that someone else just did exactly what we wanted to do
|
||||||
# can't find the command fit, it must have been deleted. Just skip this undo
|
commandFit = Fit.getInstance().getFit(self.commandFitID)
|
||||||
|
if commandFit is None:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
from .fitRemoveCommand import FitRemoveCommandCommand
|
from .fitRemoveCommand import FitRemoveCommandCommand
|
||||||
cmd = FitRemoveCommandCommand(self.fitID, self.commandFitID)
|
cmd = FitRemoveCommandCommand(fitID=self.fitID, commandFitID=self.commandFitID)
|
||||||
cmd.Do()
|
return cmd.Do()
|
||||||
return True
|
|
||||||
|
|||||||
@@ -8,43 +8,40 @@ from service.fit import Fit
|
|||||||
pyfalog = Logger(__name__)
|
pyfalog = Logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class FitRemoveCommandCommand(wx.Command): # well that's an unfortunate name
|
class FitRemoveCommandCommand(wx.Command):
|
||||||
""""
|
|
||||||
from sFit.removeCommand
|
|
||||||
"""
|
|
||||||
def __init__(self, fitID, commandFitID):
|
def __init__(self, fitID, commandFitID):
|
||||||
wx.Command.__init__(self, True)
|
wx.Command.__init__(self, True)
|
||||||
self.fitID = fitID
|
self.fitID = fitID
|
||||||
self.savedCommandFitID = commandFitID
|
self.commandFitID = commandFitID
|
||||||
self.savedState = None
|
self.savedState = None
|
||||||
|
|
||||||
def Do(self):
|
def Do(self):
|
||||||
pyfalog.debug("Removing command projection from fit ({0}) for: {1}".format(self.fitID, self.savedCommandFitID))
|
pyfalog.debug('Doing removal of command fit {} for fit {}'.format(self.commandFitID, self.fitID))
|
||||||
sFit = Fit.getInstance()
|
sFit = Fit.getInstance()
|
||||||
fit = sFit.getFit(self.fitID)
|
fit = sFit.getFit(self.fitID)
|
||||||
commandFit = sFit.getFit(self.savedCommandFitID)
|
commandFit = sFit.getFit(self.commandFitID)
|
||||||
if not commandFit:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
# Can be removed by the time we're redoing it
|
||||||
|
if commandFit is None:
|
||||||
|
pyfalog.debug('Command fit is not available')
|
||||||
|
return False
|
||||||
commandInfo = commandFit.getCommandInfo(self.fitID)
|
commandInfo = commandFit.getCommandInfo(self.fitID)
|
||||||
if not commandInfo:
|
if commandInfo is None:
|
||||||
|
pyfalog.warning('Fit command info is not available')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.savedState = commandInfo.active
|
self.savedState = commandInfo.active
|
||||||
|
|
||||||
del fit.commandFitDict[commandFit.ID]
|
del fit.commandFitDict[commandFit.ID]
|
||||||
|
|
||||||
eos.db.commit()
|
eos.db.commit()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def Undo(self):
|
def Undo(self):
|
||||||
command = eos.db.getFit(self.savedCommandFitID)
|
pyfalog.debug('Undoing removal of command fit {} for fit {}'.format(self.commandFitID, self.fitID))
|
||||||
|
# Can't find the command fit, it must have been deleted. Fail as there's no way to restore it
|
||||||
if not command:
|
commandFit = Fit.getInstance().getFit(self.commandFitID)
|
||||||
# can't find the command fit, it must have been deleted. Just skip this undo
|
if commandFit is None:
|
||||||
return True
|
return False
|
||||||
|
|
||||||
from .fitAddCommand import FitAddCommandCommand
|
from .fitAddCommand import FitAddCommandCommand
|
||||||
cmd = FitAddCommandCommand(self.fitID, self.savedCommandFitID, self.savedState)
|
cmd = FitAddCommandCommand(fitID=self.fitID, commandFitID=self.commandFitID, state=self.savedState)
|
||||||
cmd.Do()
|
return cmd.Do()
|
||||||
return True
|
|
||||||
|
|||||||
@@ -144,8 +144,6 @@ class CargoInfo:
|
|||||||
return makeReprStr(self, ['itemID', 'amount'])
|
return makeReprStr(self, ['itemID', 'amount'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def stateLimit(itemIdentity):
|
def stateLimit(itemIdentity):
|
||||||
item = Market.getInstance().getItem(itemIdentity)
|
item = Market.getInstance().getItem(itemIdentity)
|
||||||
if {'moduleBonusAssaultDamageControl', 'moduleBonusIndustrialInvulnerability'}.intersection(item.effects):
|
if {'moduleBonusAssaultDamageControl', 'moduleBonusIndustrialInvulnerability'}.intersection(item.effects):
|
||||||
|
|||||||
Reference in New Issue
Block a user