From 7bb44f64730359351f1a022a2a92f8a88413ac4e Mon Sep 17 00:00:00 2001 From: blitzmann Date: Sun, 14 Oct 2018 23:26:43 -0400 Subject: [PATCH] Support changing variation for drones #1773 --- eos/saveddata/drone.py | 4 ++ .../calc/fitChangeDroneVariation.py | 39 +++++++++++++++++++ gui/fitCommands/guiMetaSwap.py | 5 ++- 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 gui/fitCommands/calc/fitChangeDroneVariation.py diff --git a/eos/saveddata/drone.py b/eos/saveddata/drone.py index da4c512f2..4cddbea42 100644 --- a/eos/saveddata/drone.py +++ b/eos/saveddata/drone.py @@ -124,6 +124,10 @@ class Drone(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut): def dps(self): return self.damageStats() + def changeType(self, typeID): + self.itemID = typeID + self.init() + def damageStats(self, targetResists=None): if self.__dps is None: self.__volley = 0 diff --git a/gui/fitCommands/calc/fitChangeDroneVariation.py b/gui/fitCommands/calc/fitChangeDroneVariation.py new file mode 100644 index 000000000..7f277895a --- /dev/null +++ b/gui/fitCommands/calc/fitChangeDroneVariation.py @@ -0,0 +1,39 @@ +import wx +from logbook import Logger + +import eos.db +pyfalog = Logger(__name__) + + +class FitChangeDroneVariationCommand(wx.Command): + """" + Fitting command that changes an existing drone into another variation. + """ + def __init__(self, fitID, position, itemID): + wx.Command.__init__(self, True, "Change Module") + + self.fitID = fitID + self.itemID = itemID + self.position = position + self.old_drone = None + + def Do(self): + return self.change_drone(self.fitID, self.position, self.itemID) + + def Undo(self): + self.change_drone(self.fitID, self.position, self.old_drone) + return True + + def change_drone(self, fitID, position, itemID): + fit = eos.db.getFit(self.fitID) + drone = fit.drones[self.position] + + if itemID == drone.itemID: + return False + + self.old_drone = drone.itemID + + drone.changeType(itemID) + eos.db.commit() + # todo: ensure that, whatever type we send in, is actually a variation of the original drone. If not, return False + return True diff --git a/gui/fitCommands/guiMetaSwap.py b/gui/fitCommands/guiMetaSwap.py index 13497a233..c07facd37 100644 --- a/gui/fitCommands/guiMetaSwap.py +++ b/gui/fitCommands/guiMetaSwap.py @@ -12,6 +12,7 @@ from .calc.fitAddCargo import FitAddCargoCommand from .calc.fitReplaceModule import FitReplaceModuleCommand from .calc.fitAddFighter import FitAddFighterCommand from .calc.fitRemoveFighter import FitRemoveFighterCommand +from .calc.fitChangeDroneVariation import FitChangeDroneVariationCommand class GuiMetaSwapCommand(wx.Command): @@ -44,7 +45,9 @@ class GuiMetaSwapCommand(wx.Command): for x in selection: self.data.append(((FitRemoveFighterCommand, fitID, fit.fighters.index(x)), (FitAddFighterCommand, fitID, itemID))) elif context == 'droneItem': - raise NotImplementedError() + for x in selection: + self.data.append(((FitChangeDroneVariationCommand, fitID, fit.drones.index(x), itemID),),) + def Do(self): for cmds in self.data: