Change how changing of projected drone amount is done via commands

This commit is contained in:
DarkPhoenix
2019-04-13 22:05:06 +03:00
parent c3bffcad34
commit 353b845102
7 changed files with 88 additions and 44 deletions

View File

@@ -56,7 +56,7 @@ class ChangeAmount(ContextMenu):
if srcContext == "droneItem":
self.mainFrame.command.Submit(cmd.GuiChangeDroneQty(fitID, fit.drones.index(thing), int(float(cleanInput))))
else:
self.mainFrame.command.Submit(cmd.GuiChangeProjectedDroneQty(fitID, fit.projectedDrones.index(thing), int(float(cleanInput))))
self.mainFrame.command.Submit(cmd.GuiChangeProjectedDroneQty(fitID, thing.itemID, int(float(cleanInput))))
elif isinstance(thing, es_Fit):
self.mainFrame.command.Submit(cmd.GuiChangeProjectedFitQty(fitID, thing.ID, int(float(cleanInput))))
return

View File

@@ -22,9 +22,15 @@ class FitChangeFighterAmount(wx.Command):
pyfalog.debug('Doing change of fighter amount to {} at position {} on fit {}'.format(self.amount, self.position, self.fitID))
fit = Fit.getInstance().getFit(self.fitID)
fighter = fit.fighters[self.position]
if self.amount == fighter.amount or self.amount == fighter.amountActive:
return False
self.savedAmount = fighter.amount
if self.amount > 0 or self.amount == -1:
fighter.amount = min(self.amount, fighter.fighterSquadronMaxSize)
if self.amount == -1:
fighter.amount = self.amount
eos.db.commit()
return True
elif self.amount > 0:
fighter.amount = max(min(self.amount, fighter.fighterSquadronMaxSize), 0)
eos.db.commit()
return True
else:

View File

@@ -1,25 +1,31 @@
import wx
import eos.db
from logbook import Logger
import eos.db
from service.fit import Fit
pyfalog = Logger(__name__)
class FitChangeImplantLocation(wx.Command):
def __init__(self, fitID, source):
wx.Command.__init__(self, True, "Drone add")
wx.Command.__init__(self, True, 'Change Implant Location')
self.fitID = fitID
self.source = source
self.old_source = None
self.savedSource = None
def Do(self):
pyfalog.debug("Toggling implant source for fit ID: {0}", self.fitID)
fit = eos.db.getFit(self.fitID)
self.old_source = fit.implantSource
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()
return True
def Undo(self):
cmd = FitChangeImplantLocation(self.fitID, self.old_source)
cmd = FitChangeImplantLocation(self.fitID, self.savedSource)
return cmd.Do()

View File

@@ -0,0 +1,59 @@
import math
import wx
from logbook import Logger
import eos.db
from gui.fitCommands.helpers import DroneInfo
from service.fit import Fit
pyfalog = Logger(__name__)
class FitChangeProjectedDroneAmount(wx.Command):
def __init__(self, fitID, itemID, amount):
wx.Command.__init__(self, True, 'Change Projected Drone Amount')
self.fitID = fitID
self.itemID = itemID
self.amount = amount
self.savedDroneInfo = None
self.removeCommand = None
def Do(self):
pyfalog.debug('Doing change of projected drone {} amount to {} on fit {}'.format(self.itemID, self.amount, self.fitID))
fit = Fit.getInstance().getFit(self.fitID)
drone = next((pd for pd in fit.projectedDrones if pd.itemID == self.itemID), None)
if drone is None:
pyfalog.warning('Cannot find projected drone')
return False
self.savedDroneInfo = DroneInfo.fromDrone(drone)
if self.amount > 0:
drone.amount = self.amount
if drone.amountActive > 0:
difference = self.amount - self.savedDroneInfo.amount
drone.amount = self.amount
drone.amountActive = max(min(drone.amountActive + difference, drone.amount), 0)
eos.db.commit()
return True
else:
from .fitRemoveProjectedDrone import FitRemoveProjectedDroneCommand
self.removeCommand = FitRemoveProjectedDroneCommand(fitID=self.fitID, droneInfo=DroneInfo(itemID=self.itemID, amount=math.inf, amountActive=math.inf))
return self.removeCommand.Do()
def Undo(self):
pyfalog.debug('Undoing change of projected drone {} amount to {} on fit {}'.format(self.itemID, self.amount, self.fitID))
if self.removeCommand is not None:
return self.removeCommand.Undo()
if self.savedDroneInfo is not None:
fit = Fit.getInstance().getFit(self.fitID)
drone = next((pd for pd in fit.projectedDrones if pd.itemID == self.savedDroneInfo.itemID), None)
if drone is None:
pyfalog.warning('Cannot find projected drone')
return False
drone.amount = self.savedDroneInfo.amount
drone.amountActive = self.savedDroneInfo.amountActive
eos.db.commit()
return True
return False

View File

@@ -1,27 +0,0 @@
import wx
import eos.db
from logbook import Logger
pyfalog = Logger(__name__)
class FitChangeProjectedDroneQty(wx.Command):
def __init__(self, fitID, position, amount=1):
wx.Command.__init__(self, True, "Drone add")
self.fitID = fitID
self.position = position
self.amount = amount # add x amount. If this goes over amount, removes stack
self.old_amount = None
def Do(self):
pyfalog.debug("Changing active fighters ({0}) for fit ({1}) to amount: {2}", self.position, self.fitID, self.amount)
fit = eos.db.getFit(self.fitID)
drone = fit.projectedDrones[self.position]
self.old_amount = drone.amount
drone.amount = self.amount
eos.db.commit()
return True
def Undo(self):
cmd = FitChangeProjectedDroneQty(self.fitID, self.position, self.old_amount)
return cmd.Do()

View File

@@ -25,13 +25,13 @@ class FitRemoveProjectedDroneCommand(wx.Command):
pyfalog.warning('Unable to find projected drone for removal')
return False
self.savedDroneInfo = DroneInfo.fromDrone(drone)
drone.amount -= self.droneInfo.amount
drone.amount = max(drone.amount - self.droneInfo.amount, 0)
# Remove stack if we have no items remaining
if drone.amount == 0:
fit.projectedDrones.remove(drone)
else:
if drone.amountActive > 0:
drone.amountActive -= self.droneInfo.amount
drone.amountActive = min(drone.amountActive, drone.amount)
eos.db.commit()
return True

View File

@@ -1,24 +1,24 @@
import wx
import gui.mainFrame
from gui import globalEvents as GE
from .calc.fitChangeProjectedDroneQty import FitChangeProjectedDroneQty
from .calc.fitChangeProjectedDroneAmount import FitChangeProjectedDroneAmount
from service.fit import Fit
from logbook import Logger
pyfalog = Logger(__name__)
class GuiChangeProjectedDroneQty(wx.Command):
def __init__(self, fitID, position, amount=1):
def __init__(self, fitID, itemID, amount=1):
wx.Command.__init__(self, True, "")
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
self.sFit = Fit.getInstance()
self.fitID = fitID
self.position = position
self.itemID = itemID
self.amount = amount
self.internal_history = wx.CommandProcessor()
def Do(self):
cmd = FitChangeProjectedDroneQty(self.fitID, self.position, self.amount)
cmd = FitChangeProjectedDroneAmount(self.fitID, self.itemID, self.amount)
if self.internal_history.Submit(cmd):
self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))