Rework toggle commands
This commit is contained in:
@@ -19,8 +19,6 @@ class FitChangeImplantLocationCommand(wx.Command):
|
||||
def Do(self):
|
||||
pyfalog.debug('Doing changing of implant source to {} for fit {}'.format(self.fitID, self.source))
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
if self.source == fit.implantSource:
|
||||
return False
|
||||
self.savedSource = fit.implantSource
|
||||
fit.implantSource = self.source
|
||||
eos.db.commit()
|
||||
|
||||
@@ -8,35 +8,32 @@ from service.fit import Fit
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class FitToggleProjectedModuleCommand(wx.Command):
|
||||
class FitChangeProjectedModuleStateCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position, click):
|
||||
wx.Command.__init__(self, True, "Toggle Projected Module")
|
||||
wx.Command.__init__(self, True, 'Change Projected Module State')
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.click = click
|
||||
self.oldState = None
|
||||
self.savedState = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Toggling projected module for fit ID: {}".format(self.fitID))
|
||||
pyfalog.debug('Doing change of projected module state at position {} to click {} on fit {}'.format(self.position, self.click, self.fitID))
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
mod = fit.projectedModules[self.position]
|
||||
self.oldState = mod.state
|
||||
|
||||
self.savedState = mod.state
|
||||
proposedState = mod.getProposedState(mod, self.click)
|
||||
if mod.state == proposedState:
|
||||
return False
|
||||
if not mod.canHaveState(proposedState, fit):
|
||||
return False
|
||||
|
||||
mod.state = proposedState
|
||||
eos.db.commit()
|
||||
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
pyfalog.debug("Toggling projected module for fit ID: {}".format(self.fitID))
|
||||
pyfalog.debug('Undoing change of projected module state at position {} to click {} on fit {}'.format(self.position, self.click, self.fitID))
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
mod = fit.projectedModules[self.position]
|
||||
mod.state = self.oldState
|
||||
mod.state = self.savedState
|
||||
return True
|
||||
@@ -17,8 +17,8 @@ class FitRebaseItemCommand(wx.Command):
|
||||
self.containerName = containerName
|
||||
self.position = position
|
||||
self.itemID = itemID
|
||||
self.savedItemID = None
|
||||
self.commit = commit
|
||||
self.savedItemID = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug('Doing rebase of item in {} at position {} to {}'.format(self.containerName, self.position, self.itemID))
|
||||
|
||||
@@ -22,7 +22,7 @@ class FitRemoveProjectedDroneCommand(wx.Command):
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
drone = next((pd for pd in fit.projectedDrones if pd.itemID == self.droneInfo.itemID), None)
|
||||
if drone is None:
|
||||
pyfalog.warning('Unable to find projected drone for removal')
|
||||
pyfalog.warning('Unable to find projected drone')
|
||||
return False
|
||||
self.savedDroneInfo = DroneInfo.fromDrone(drone)
|
||||
drone.amount = max(drone.amount - self.droneInfo.amount, 0)
|
||||
|
||||
@@ -8,7 +8,7 @@ from service.fit import Fit
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class FitRenameCommand(wx.Command):
|
||||
class FitFitRenameCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, name):
|
||||
wx.Command.__init__(self, True, 'Rename Fit')
|
||||
@@ -19,6 +19,8 @@ class FitRenameCommand(wx.Command):
|
||||
def Do(self):
|
||||
pyfalog.debug('Doing renaming of fit {} to {}'.format(self.fitID, self.name))
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
if fit.name == self.name:
|
||||
return False
|
||||
self.savedName = fit.name
|
||||
fit.name = self.name
|
||||
eos.db.commit()
|
||||
@@ -26,5 +28,5 @@ class FitRenameCommand(wx.Command):
|
||||
|
||||
def Undo(self):
|
||||
pyfalog.debug('Undoing renaming of fit {} to {}'.format(self.fitID, self.name))
|
||||
cmd = FitRenameCommand(fitID=self.fitID, name=self.savedName)
|
||||
cmd = FitFitRenameCommand(fitID=self.fitID, name=self.savedName)
|
||||
return cmd.Do()
|
||||
|
||||
@@ -2,6 +2,7 @@ import wx
|
||||
from logbook import Logger
|
||||
|
||||
import eos.db
|
||||
from eos.exception import HandledListActionError
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
@@ -26,12 +27,24 @@ class FitSwapModuleCommand(wx.Command):
|
||||
pyfalog.debug('Undoing swapping between {} and {} for fit {}'.format(self.position1, self.position2, self.fitID))
|
||||
return True
|
||||
|
||||
def __swap(self, fitID, src, dst):
|
||||
def __swap(self, fitID, srcPosition, dstPosition):
|
||||
fit = Fit.getInstance().getFit(fitID)
|
||||
srcMod = fit.modules[src]
|
||||
dstMod = fit.modules[dst]
|
||||
fit.modules.free(src)
|
||||
fit.modules.free(dst)
|
||||
fit.modules.replace(dst, srcMod)
|
||||
fit.modules.replace(src, dstMod)
|
||||
srcMod = fit.modules[srcPosition]
|
||||
dstMod = fit.modules[dstPosition]
|
||||
fit.modules.free(srcPosition)
|
||||
fit.modules.free(dstPosition)
|
||||
try:
|
||||
fit.modules.replace(dstPosition, srcMod)
|
||||
except HandledListActionError:
|
||||
fit.modules.replace(srcPosition, srcMod)
|
||||
fit.modules.replace(dstPosition, dstMod)
|
||||
return False
|
||||
try:
|
||||
fit.modules.replace(srcPosition, dstMod)
|
||||
except HandledListActionError:
|
||||
fit.modules.free(dstPosition)
|
||||
fit.modules.replace(srcPosition, srcMod)
|
||||
fit.modules.replace(dstPosition, dstMod)
|
||||
return False
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
@@ -1,29 +1,32 @@
|
||||
import wx
|
||||
import eos.db
|
||||
from logbook import Logger
|
||||
|
||||
import eos.db
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class FitToggleBoosterCommand(wx.Command):
|
||||
""""
|
||||
from sFit.toggleBooster
|
||||
"""
|
||||
def __init__(self, fitID, position):
|
||||
wx.Command.__init__(self, True, "Toggle Booster")
|
||||
class FitToggleBoosterStateCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position, forceState=None):
|
||||
wx.Command.__init__(self, True, 'Toggle Booster State')
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.forceState = forceState
|
||||
self.savedState = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Toggling booster for fit ID: {0}", self.fitID)
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
pyfalog.debug('Doing toggling of booster state at position {} for fit {}'.format(self.position, self.fitID))
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
booster = fit.boosters[self.position]
|
||||
booster.active = not booster.active
|
||||
|
||||
self.savedState = booster.active
|
||||
booster.active = not booster.active if self.forceState is None else self.forceState
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
cmd = FitToggleBoosterCommand(self.fitID, self.position)
|
||||
pyfalog.debug('Undoing toggling of booster state at position {} for fit {}'.format(self.position, self.fitID))
|
||||
cmd = FitToggleBoosterStateCommand(fitID=self.fitID, position=self.position, forceState=self.savedState)
|
||||
return cmd.Do()
|
||||
|
||||
@@ -8,29 +8,30 @@ from service.fit import Fit
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class FitToggleBoosterSideEffectCommand(wx.Command):
|
||||
class FitToggleBoosterSideEffectStateCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position, effectID):
|
||||
wx.Command.__init__(self, True, "Toggle Booster Side Effect")
|
||||
def __init__(self, fitID, position, effectID, forceState=None):
|
||||
wx.Command.__init__(self, True, 'Toggle Booster Side Effect State')
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.effectID = effectID
|
||||
self.forceState = forceState
|
||||
self.savedState = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Toggling booster side-effect for fit ID: {0}", self.fitID)
|
||||
pyfalog.debug('Doing toggling of booster side effect {} state at position {} for fit {}'.format(self.effectID, self.position, self.fitID))
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
booster = fit.boosters[self.position]
|
||||
for se in booster.sideEffects:
|
||||
if se.effectID == self.effectID:
|
||||
sideEffect = se
|
||||
break
|
||||
else:
|
||||
sideEffect = next((se for se in booster.sideEffects if se.effectID == self.effectID), None)
|
||||
if sideEffect is None:
|
||||
pyfalog.warning('Unable to find booster side effect')
|
||||
return False
|
||||
|
||||
sideEffect.active = not sideEffect.active
|
||||
self.savedState = sideEffect.active
|
||||
sideEffect.active = not sideEffect.active if self.forceState is None else self.forceState
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
cmd = FitToggleBoosterSideEffectCommand(self.fitID, self.position, self.effectID)
|
||||
pyfalog.debug('Undoing toggling of booster side effect {} state at position {} for fit {}'.format(self.effectID, self.position, self.fitID))
|
||||
cmd = FitToggleBoosterSideEffectStateCommand(fitID=self.fitID, position=self.position, effectID=self.effectID, forceState=self.savedState)
|
||||
return cmd.Do()
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
import wx
|
||||
import eos.db
|
||||
from logbook import Logger
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class FitToggleCommandCommand(wx.Command):
|
||||
""""
|
||||
from sFit.toggleCommandFit
|
||||
"""
|
||||
def __init__(self, fitID, commandFitId):
|
||||
wx.Command.__init__(self, True, "Toggle Command")
|
||||
self.fitID = fitID
|
||||
self.commandFitID = commandFitId
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Toggle command fit ({0}) for: {1}", self.commandFitID, self.fitID)
|
||||
commandFit = eos.db.getFit(self.commandFitID)
|
||||
|
||||
if not commandFit:
|
||||
pyfalog.debug(" -- Command fit not found, deleted?")
|
||||
return False
|
||||
|
||||
commandInfo = commandFit.getCommandInfo(self.fitID)
|
||||
|
||||
if not commandInfo:
|
||||
pyfalog.debug(" -- Command fit info not found, deleted?")
|
||||
return False
|
||||
|
||||
commandInfo.active = not commandInfo.active
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
cmd = FitToggleCommandCommand(self.fitID, self.commandFitID)
|
||||
return cmd.Do()
|
||||
39
gui/fitCommands/calc/fitToggleCommandFit.py
Normal file
39
gui/fitCommands/calc/fitToggleCommandFit.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import wx
|
||||
from logbook import Logger
|
||||
|
||||
import eos.db
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class FitToggleCommandFitStateCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, commandFitID, forceState=None):
|
||||
wx.Command.__init__(self, True, 'Toggle Command Fit State')
|
||||
self.fitID = fitID
|
||||
self.commandFitID = commandFitID
|
||||
self.forceState = forceState
|
||||
self.savedState = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug('Doing toggling of command fit {} state for fit {}'.format(self.commandFitID, self.fitID))
|
||||
commandFit = Fit.getInstance().getFit(self.commandFitID)
|
||||
# Command fit could have been deleted if we are redoing
|
||||
if commandFit is None:
|
||||
pyfalog.debug('Command fit is not available')
|
||||
return False
|
||||
commandInfo = commandFit.getCommandInfo(self.fitID)
|
||||
if commandInfo is None:
|
||||
pyfalog.warning('Fit command info is not available')
|
||||
return False
|
||||
self.savedState = commandInfo.active
|
||||
commandInfo.active = not commandInfo.active if self.forceState is None else self.forceState
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
pyfalog.debug('Undoing toggling of command fit {} state for fit {}'.format(self.commandFitID, self.fitID))
|
||||
cmd = FitToggleCommandFitStateCommand(fitID=self.fitID, commandFitID=self.commandFitID, forceState=self.savedState)
|
||||
return cmd.Do()
|
||||
@@ -1,30 +1,37 @@
|
||||
import wx
|
||||
import eos.db
|
||||
from logbook import Logger
|
||||
|
||||
import eos.db
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class FitToggleDroneCommand(wx.Command):
|
||||
""""
|
||||
from sFit.toggleDrone
|
||||
"""
|
||||
def __init__(self, fitID, position):
|
||||
wx.Command.__init__(self, True, "Toggle Drone")
|
||||
class FitToggleDroneStateCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position, forceAmountActive=None):
|
||||
wx.Command.__init__(self, True, 'Toggle Drone State')
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.forceAmountActive = forceAmountActive
|
||||
self.savedAmountActive = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Toggling drones for fit ID: {0}", self.fitID)
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
d = fit.drones[self.position]
|
||||
if d.amount == d.amountActive:
|
||||
d.amountActive = 0
|
||||
pyfalog.debug('Doing toggling of drone state at position {} for fit {}'.format(self.position, self.fitID))
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
drone = fit.drones[self.position]
|
||||
self.savedAmountActive = drone.amountActive
|
||||
if self.forceAmountActive is not None:
|
||||
drone.amountActive = self.forceAmountActive
|
||||
elif drone.amountActive > 0:
|
||||
drone.amountActive = 0
|
||||
else:
|
||||
d.amountActive = d.amount
|
||||
|
||||
drone.amountActive = drone.amount
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
cmd = FitToggleDroneCommand(self.fitID, self.position)
|
||||
pyfalog.debug('Undoing toggling of drone state at position {} for fit {}'.format(self.position, self.fitID))
|
||||
cmd = FitToggleDroneStateCommand(fitID=self.fitID, position=self.position, forceAmountActive=self.savedAmountActive)
|
||||
return cmd.Do()
|
||||
|
||||
@@ -1,27 +1,32 @@
|
||||
import wx
|
||||
import eos.db
|
||||
from logbook import Logger
|
||||
|
||||
import eos.db
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class FitToggleFighterCommand(wx.Command):
|
||||
""""
|
||||
from sFit.toggleFighter
|
||||
"""
|
||||
def __init__(self, fitID, position):
|
||||
wx.Command.__init__(self, True, "Toggle Fighter")
|
||||
class FitToggleFighterStateCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position, forceState=None):
|
||||
wx.Command.__init__(self, True, 'Toggle Fighter State')
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.forceState = forceState
|
||||
self.savedState = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Toggling fighters for fit ID: {0}", self.fitID)
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
f = fit.fighters[self.position]
|
||||
f.active = not f.active
|
||||
|
||||
pyfalog.debug('Doing toggling of fighter state at position {} for fit {}'.format(self.position, self.fitID))
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
fighter = fit.fighters[self.position]
|
||||
self.savedState = fighter.active
|
||||
fighter.active = not fighter.active if self.forceState is None else self.forceState
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
cmd = FitToggleFighterCommand(self.fitID, self.position)
|
||||
pyfalog.debug('Undoing toggling of fighter state at position {} for fit {}'.format(self.position, self.fitID))
|
||||
cmd = FitToggleFighterStateCommand(fitID=self.fitID, position=self.position, forceState=self.savedState)
|
||||
return cmd.Do()
|
||||
|
||||
@@ -8,34 +8,37 @@ from service.fit import Fit
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class FitToggleFighterAbilityCommand(wx.Command):
|
||||
class FitToggleFighterAbilityStateCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position, effectID, isProjected):
|
||||
wx.Command.__init__(self, True, "Toggle Fighter Ability")
|
||||
def __init__(self, fitID, position, effectID, projected, forceState=None):
|
||||
wx.Command.__init__(self, True, 'Toggle Fighter Ability State')
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.effectID = effectID
|
||||
self.isProjected = isProjected
|
||||
self.projected = projected
|
||||
self.forceState = forceState
|
||||
self.savedState = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Toggling fighter ability for fit ID: {0}", self.fitID)
|
||||
pyfalog.debug('Doing toggling of fighter ability {} state at position {} for fit {}'.format(self.effectID, self.position, self.fitID))
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
if self.isProjected:
|
||||
fighter = fit.projectedFighters[self.position]
|
||||
else:
|
||||
fighter = fit.fighters[self.position]
|
||||
|
||||
for fa in fighter.abilities:
|
||||
if fa.effectID == self.effectID:
|
||||
ability = fa
|
||||
break
|
||||
else:
|
||||
container = fit.projectedFighters if self.projected else fit.fighters
|
||||
fighter = container[self.position]
|
||||
ability = next((fa for fa in fighter.abilities if fa.effectID == self.effectID), None)
|
||||
if ability is None:
|
||||
pyfalog.warning('Unable to find fighter ability')
|
||||
return False
|
||||
|
||||
ability.active = not ability.active
|
||||
self.savedState = ability.active
|
||||
ability.active = not ability.active if self.forceState is None else self.forceState
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
cmd = FitToggleFighterAbilityCommand(self.fitID, self.position, self.effectID, self.isProjected)
|
||||
pyfalog.debug('Unoing toggling of fighter ability {} state at position {} for fit {}'.format(self.effectID, self.position, self.fitID))
|
||||
cmd = FitToggleFighterAbilityStateCommand(
|
||||
fitID=self.fitID,
|
||||
position=self.position,
|
||||
effectID=self.effectID,
|
||||
projected=self.projected,
|
||||
forceState=self.savedState)
|
||||
return cmd.Do()
|
||||
|
||||
@@ -2,29 +2,31 @@ import wx
|
||||
from logbook import Logger
|
||||
|
||||
import eos.db
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class FitToggleImplantCommand(wx.Command):
|
||||
""""
|
||||
from sFit.toggleImplant
|
||||
"""
|
||||
def __init__(self, fitID, position):
|
||||
wx.Command.__init__(self, True, "Toggle Implant")
|
||||
class FitToggleImplantStateCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position, forceState=None):
|
||||
wx.Command.__init__(self, True, 'Toggle Implant State')
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.forceState = forceState
|
||||
self.savedState = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Toggling implant for fit ID: {0}", self.fitID)
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
pyfalog.debug('Doing toggling of implant state at position {} for fit {}'.format(self.position, self.fitID))
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
implant = fit.implants[self.position]
|
||||
implant.active = not implant.active
|
||||
|
||||
self.savedState = implant.active
|
||||
implant.active = not implant.active if self.forceState is None else self.forceState
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
cmd = FitToggleImplantCommand(self.fitID, self.position)
|
||||
pyfalog.debug('Undoing toggling of implant state at position {} for fit {}'.format(self.position, self.fitID))
|
||||
cmd = FitToggleImplantStateCommand(fitID=self.fitID, position=self.position, forceState=self.savedState)
|
||||
return cmd.Do()
|
||||
|
||||
@@ -10,26 +10,37 @@ pyfalog = Logger(__name__)
|
||||
|
||||
class FitToggleProjectedDroneCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position):
|
||||
wx.Command.__init__(self, True, "Toggle Projected Drone")
|
||||
def __init__(self, fitID, itemID, forceAmountActive=None):
|
||||
wx.Command.__init__(self, True, 'Toggle Projected Drone State')
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.itemID = itemID
|
||||
self.forceAmountActive = forceAmountActive
|
||||
self.savedAmountActive = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Toggling projected drone for fit ID: {}".format(self.fitID))
|
||||
pyfalog.debug('Doing toggling of projected drone {} state for fit {}'.format(self.itemID, self.fitID))
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
drone = fit.projectedDrones[self.position]
|
||||
|
||||
if drone.amountActive == 0:
|
||||
drone = next((pd for pd in fit.projectedDrones if pd.itemID == self.itemID), None)
|
||||
if drone is None:
|
||||
pyfalog.warning('Unable to find projected drone')
|
||||
return False
|
||||
self.savedAmountActive = drone.amountActive
|
||||
if self.forceAmountActive is not None:
|
||||
if self.forceAmountActive > 0 and not drone.canBeApplied(fit):
|
||||
pyfalog.warning('Projected drone cannot be applied')
|
||||
return False
|
||||
drone.amountActive = self.forceAmountActive
|
||||
elif drone.amountActive > 0:
|
||||
drone.amountActive = 0
|
||||
else:
|
||||
if not drone.canBeApplied(fit):
|
||||
pyfalog.warning('Projected drone cannot be applied')
|
||||
return False
|
||||
drone.amountActive = drone.amount
|
||||
else:
|
||||
drone.amountActive = 0
|
||||
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
cmd = FitToggleProjectedDroneCommand(self.fitID, self.position)
|
||||
pyfalog.debug('Undoing toggling of projected drone {} state for fit {}'.format(self.itemID, self.fitID))
|
||||
cmd = FitToggleProjectedDroneCommand(fitID=self.fitID, itemID=self.itemID, forceAmountActive=self.savedAmountActive)
|
||||
return cmd.Do()
|
||||
|
||||
@@ -8,22 +8,25 @@ from service.fit import Fit
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class FitToggleProjectedFighterCommand(wx.Command):
|
||||
class FitToggleProjectedFighterStateCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position):
|
||||
wx.Command.__init__(self, True, "Toggle Projected Fighter")
|
||||
def __init__(self, fitID, position, forceState=None):
|
||||
wx.Command.__init__(self, True, 'Toggle Projected Fighter State')
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.forceState = forceState
|
||||
self.savedState = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Toggling projected fighter for fit ID: {}".format(self.fitID))
|
||||
pyfalog.debug('Doing toggling of projected fighter state at position {} for fit {}'.format(self.position, self.fitID))
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
fighter = fit.projectedFighters[self.position]
|
||||
fighter.active = not fighter.active
|
||||
|
||||
self.savedState = fighter.active
|
||||
fighter.active = not fighter.active if self.forceState is None else self.forceState
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
cmd = FitToggleProjectedFighterCommand(self.fitID, self.position)
|
||||
pyfalog.debug('Undoing toggling of projected fighter state at position {} for fit {}'.format(self.position, self.fitID))
|
||||
cmd = FitToggleProjectedFighterStateCommand(fitID=self.fitID, position=self.position, forceState=self.savedState)
|
||||
return cmd.Do()
|
||||
|
||||
@@ -10,22 +10,30 @@ pyfalog = Logger(__name__)
|
||||
|
||||
class FitToggleProjectedFitCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, projectingFitID):
|
||||
wx.Command.__init__(self, True, "Toggle Projected Fit")
|
||||
def __init__(self, fitID, projectedFitID, forceState=None):
|
||||
wx.Command.__init__(self, True, 'Toggle Projected Fit State')
|
||||
self.fitID = fitID
|
||||
self.projectingFitID = projectingFitID
|
||||
self.projectedFitID = projectedFitID
|
||||
self.forceState = forceState
|
||||
self.savedState = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Toggling projected fit {} for fit ID: {}".format(self.projectingFitID, self.fitID))
|
||||
projector = Fit.getInstance().getFit(self.projectingFitID)
|
||||
projectionInfo = projector.getProjectionInfo(self.fitID)
|
||||
if not projectionInfo:
|
||||
pyfalog.debug('Doing toggling of projected fit {} state for fit {}'.format(self.projectedFitID, self.fitID))
|
||||
projectedFit = Fit.getInstance().getFit(self.projectedFitID)
|
||||
# Projected fit could have been deleted if we are redoing
|
||||
if projectedFit is None:
|
||||
pyfalog.debug('Projected fit is not available')
|
||||
return False
|
||||
projectionInfo.active = not projectionInfo.active
|
||||
|
||||
projectionInfo = projectedFit.getProjectionInfo(self.fitID)
|
||||
if projectionInfo is None:
|
||||
pyfalog.warning('Fit projection info is not available')
|
||||
return False
|
||||
self.savedState = projectionInfo.active
|
||||
projectionInfo.active = not projectionInfo.active if self.forceState is None else self.forceState
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
cmd = FitToggleProjectedFitCommand(self.fitID, self.projectingFitID)
|
||||
pyfalog.debug('Undoing toggling of projected fit {} state for fit {}'.format(self.projectedFitID, self.fitID))
|
||||
cmd = FitToggleProjectedFitCommand(fitID=self.fitID, projectedFitID=self.projectedFitID, forceState=self.savedState)
|
||||
return cmd.Do()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import wx
|
||||
import gui.mainFrame
|
||||
from .calc.fitRename import FitRenameCommand
|
||||
from .calc.fitRename import FitFitRenameCommand
|
||||
from service.fit import Fit
|
||||
from logbook import Logger
|
||||
from gui.builtinShipBrowser.events import FitRenamed
|
||||
@@ -17,7 +17,7 @@ class GuiFitRenameCommand(wx.Command):
|
||||
self.internal_history = wx.CommandProcessor()
|
||||
|
||||
def Do(self):
|
||||
if self.internal_history.Submit(FitRenameCommand(self.fitID, self.newName)):
|
||||
if self.internal_history.Submit(FitFitRenameCommand(self.fitID, self.newName)):
|
||||
wx.PostEvent(self.mainFrame, FitRenamed(fitID=self.fitID))
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -3,7 +3,7 @@ from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from .calc.fitToggleBooster import FitToggleBoosterCommand
|
||||
from .calc.fitToggleBooster import FitToggleBoosterStateCommand
|
||||
|
||||
|
||||
class GuiToggleBoosterCommand(wx.Command):
|
||||
@@ -16,7 +16,7 @@ class GuiToggleBoosterCommand(wx.Command):
|
||||
self.position = position
|
||||
|
||||
def Do(self):
|
||||
if self.internal_history.Submit(FitToggleBoosterCommand(self.fitID, self.position)):
|
||||
if self.internal_history.Submit(FitToggleBoosterStateCommand(self.fitID, self.position)):
|
||||
self.sFit.recalc(self.fitID)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
|
||||
@@ -3,7 +3,7 @@ from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from .calc.fitToggleBoosterSideEffect import FitToggleBoosterSideEffectCommand
|
||||
from .calc.fitToggleBoosterSideEffect import FitToggleBoosterSideEffectStateCommand
|
||||
|
||||
|
||||
class GuiToggleBoosterSideEffectCommand(wx.Command):
|
||||
@@ -17,7 +17,7 @@ class GuiToggleBoosterSideEffectCommand(wx.Command):
|
||||
self.effectID = effectID
|
||||
|
||||
def Do(self):
|
||||
if self.internal_history.Submit(FitToggleBoosterSideEffectCommand(self.fitID, self.position, self.effectID)):
|
||||
if self.internal_history.Submit(FitToggleBoosterSideEffectStateCommand(self.fitID, self.position, self.effectID)):
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
|
||||
@@ -3,7 +3,7 @@ from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from .calc.fitToggleCommand import FitToggleCommandCommand
|
||||
from .calc.fitToggleCommandFit import FitToggleCommandFitStateCommand
|
||||
|
||||
|
||||
class GuiToggleCommandCommand(wx.Command):
|
||||
@@ -16,7 +16,7 @@ class GuiToggleCommandCommand(wx.Command):
|
||||
self.commandFitID = commandFitID
|
||||
|
||||
def Do(self):
|
||||
if self.internal_history.Submit(FitToggleCommandCommand(self.fitID, self.commandFitID)):
|
||||
if self.internal_history.Submit(FitToggleCommandFitStateCommand(self.fitID, self.commandFitID)):
|
||||
self.sFit.recalc(self.fitID)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
|
||||
@@ -3,7 +3,7 @@ from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from .calc.fitToggleDrone import FitToggleDroneCommand
|
||||
from .calc.fitToggleDrone import FitToggleDroneStateCommand
|
||||
|
||||
|
||||
class GuiToggleDroneCommand(wx.Command):
|
||||
@@ -16,7 +16,7 @@ class GuiToggleDroneCommand(wx.Command):
|
||||
self.position = position
|
||||
|
||||
def Do(self):
|
||||
if self.internal_history.Submit(FitToggleDroneCommand(self.fitID, self.position)):
|
||||
if self.internal_history.Submit(FitToggleDroneStateCommand(self.fitID, self.position)):
|
||||
self.sFit.recalc(self.fitID)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
|
||||
@@ -3,7 +3,7 @@ from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from .calc.fitToggleFighter import FitToggleFighterCommand
|
||||
from .calc.fitToggleFighter import FitToggleFighterStateCommand
|
||||
|
||||
|
||||
class GuiToggleFighterCommand(wx.Command):
|
||||
@@ -16,7 +16,7 @@ class GuiToggleFighterCommand(wx.Command):
|
||||
self.position = position
|
||||
|
||||
def Do(self):
|
||||
if self.internal_history.Submit(FitToggleFighterCommand(self.fitID, self.position)):
|
||||
if self.internal_history.Submit(FitToggleFighterStateCommand(self.fitID, self.position)):
|
||||
self.sFit.recalc(self.fitID)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
|
||||
@@ -3,7 +3,7 @@ from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from .calc.fitToggleFighterAbility import FitToggleFighterAbilityCommand
|
||||
from .calc.fitToggleFighterAbility import FitToggleFighterAbilityStateCommand
|
||||
|
||||
|
||||
class GuiToggleFighterAbilityCommand(wx.Command):
|
||||
@@ -18,7 +18,7 @@ class GuiToggleFighterAbilityCommand(wx.Command):
|
||||
self.isProjected = isProjected
|
||||
|
||||
def Do(self):
|
||||
if self.internal_history.Submit(FitToggleFighterAbilityCommand(self.fitID, self.position, self.effectID, self.isProjected)):
|
||||
if self.internal_history.Submit(FitToggleFighterAbilityStateCommand(self.fitID, self.position, self.effectID, self.isProjected)):
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
|
||||
@@ -3,7 +3,7 @@ from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from .calc.fitToggleImplant import FitToggleImplantCommand
|
||||
from .calc.fitToggleImplant import FitToggleImplantStateCommand
|
||||
|
||||
|
||||
class GuiToggleImplantCommand(wx.Command):
|
||||
@@ -16,7 +16,7 @@ class GuiToggleImplantCommand(wx.Command):
|
||||
self.position = position
|
||||
|
||||
def Do(self):
|
||||
if self.internal_history.Submit(FitToggleImplantCommand(self.fitID, self.position)):
|
||||
if self.internal_history.Submit(FitToggleImplantStateCommand(self.fitID, self.position)):
|
||||
self.sFit.recalc(self.fitID)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
|
||||
@@ -8,9 +8,9 @@ from eos.saveddata.module import Module as ModuleType
|
||||
from gui import globalEvents as GE
|
||||
from service.fit import Fit
|
||||
from .calc.fitToggleProjectedDrone import FitToggleProjectedDroneCommand
|
||||
from .calc.fitToggleProjectedFighter import FitToggleProjectedFighterCommand
|
||||
from .calc.fitToggleProjectedFighter import FitToggleProjectedFighterStateCommand
|
||||
from .calc.fitToggleProjectedFit import FitToggleProjectedFitCommand
|
||||
from .calc.fitToggleProjectedModule import FitToggleProjectedModuleCommand
|
||||
from .calc.fitChangeProjectedModuleState import FitChangeProjectedModuleStateCommand
|
||||
|
||||
|
||||
class GuiToggleProjectedCommand(wx.Command):
|
||||
@@ -26,15 +26,14 @@ class GuiToggleProjectedCommand(wx.Command):
|
||||
self.args = (self.fitID, thing.ID)
|
||||
elif isinstance(thing, ModuleType):
|
||||
position = fit.projectedModules.index(thing)
|
||||
self.commandType = FitToggleProjectedModuleCommand
|
||||
self.commandType = FitChangeProjectedModuleStateCommand
|
||||
self.args = (self.fitID, position, click)
|
||||
elif isinstance(thing, DroneType):
|
||||
position = fit.projectedDrones.index(thing)
|
||||
self.commandType = FitToggleProjectedDroneCommand
|
||||
self.args = (self.fitID, position)
|
||||
self.args = (self.fitID, thing.itemID)
|
||||
elif isinstance(thing, FighterType):
|
||||
position = fit.projectedFighters.index(thing)
|
||||
self.commandType = FitToggleProjectedFighterCommand
|
||||
self.commandType = FitToggleProjectedFighterStateCommand
|
||||
self.args = (self.fitID, position)
|
||||
else:
|
||||
self.commandType = None
|
||||
|
||||
Reference in New Issue
Block a user