From 9e6031edf241344bc092a6a6d911f5463b4763cf Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Sat, 13 Apr 2019 20:53:26 +0300 Subject: [PATCH] Get rid of drone variation command --- eos/saveddata/drone.py | 4 -- .../calc/fitChangeDroneVariation.py | 39 ------------------- gui/fitCommands/calc/fitRebaseItem.py | 27 ++++++++----- gui/fitCommands/guiMetaSwap.py | 3 +- 4 files changed, 20 insertions(+), 53 deletions(-) delete mode 100644 gui/fitCommands/calc/fitChangeDroneVariation.py diff --git a/eos/saveddata/drone.py b/eos/saveddata/drone.py index 65ef5d327..889a7f56e 100644 --- a/eos/saveddata/drone.py +++ b/eos/saveddata/drone.py @@ -178,10 +178,6 @@ class Drone(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut): self.__baseRemoteReps = (rrType, rrAmount) return self.__baseRemoteReps - def changeType(self, typeID): - self.itemID = typeID - self.init() - @property def miningStats(self): if self.__miningyield is None: diff --git a/gui/fitCommands/calc/fitChangeDroneVariation.py b/gui/fitCommands/calc/fitChangeDroneVariation.py deleted file mode 100644 index 7f277895a..000000000 --- a/gui/fitCommands/calc/fitChangeDroneVariation.py +++ /dev/null @@ -1,39 +0,0 @@ -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/calc/fitRebaseItem.py b/gui/fitCommands/calc/fitRebaseItem.py index 1fb44b266..40c861069 100644 --- a/gui/fitCommands/calc/fitRebaseItem.py +++ b/gui/fitCommands/calc/fitRebaseItem.py @@ -2,7 +2,8 @@ import wx from logbook import Logger -import eos.db +from service.fit import Fit +from service.market import Market pyfalog = Logger(__name__) @@ -10,22 +11,30 @@ pyfalog = Logger(__name__) class FitRebaseItemCommand(wx.Command): - def __init__(self, fitID, containerName, position, newTypeID): - wx.Command.__init__(self, True, "Rebase Item") + def __init__(self, fitID, containerName, position, itemID): + wx.Command.__init__(self, True, 'Rebase Item') self.fitID = fitID self.containerName = containerName self.position = position - self.newTypeID = newTypeID - self.oldTypeID = None + self.itemID = itemID + self.savedItemID = None def Do(self): - fit = eos.db.getFit(self.fitID) + pyfalog.debug('Doing rebase of item in {} at position {} to {}'.format(self.containerName, self.position, self.itemID)) + fit = Fit.getInstance().getFit(self.fitID) obj = getattr(fit, self.containerName)[self.position] - self.oldTypeID = getattr(obj.item, "ID", None) - newItem = eos.db.getItem(self.newTypeID) + self.savedItemID = getattr(obj.item, 'ID', None) + if self.savedItemID is None: + pyfalog.warning('Unable to get old item ID') + return False + newItem = Market.getInstance().getItem(self.itemID) + if newItem is None: + pyfalog.warning('Unable to fetch new item') + return False obj.rebase(newItem) return True def Undo(self): - cmd = FitRebaseItemCommand(self.fitID, self.containerName, self.position, self.oldTypeID) + pyfalog.debug('Undoing rebase of item in {} at position {} to {}'.format(self.containerName, self.position, self.itemID)) + cmd = FitRebaseItemCommand(self.fitID, self.containerName, self.position, self.savedItemID) return cmd.Do() diff --git a/gui/fitCommands/guiMetaSwap.py b/gui/fitCommands/guiMetaSwap.py index 99a7c4c54..9a4f017b6 100644 --- a/gui/fitCommands/guiMetaSwap.py +++ b/gui/fitCommands/guiMetaSwap.py @@ -13,6 +13,7 @@ from .calc.fitReplaceModule import FitReplaceModuleCommand from .calc.fitAddFighter import FitAddFighterCommand from .calc.fitRemoveFighter import FitRemoveFighterCommand from .calc.fitChangeDroneVariation import FitChangeDroneVariationCommand +from .calc.fitRebaseItem import FitRebaseItemCommand class GuiMetaSwapCommand(wx.Command): @@ -51,7 +52,7 @@ class GuiMetaSwapCommand(wx.Command): self.data.append(((FitRemoveFighterCommand, fitID, fit.fighters.index(x)), (FitAddFighterCommand, fitID, fighterInfo))) elif context == 'droneItem': for x in selection: - self.data.append(((FitChangeDroneVariationCommand, fitID, fit.drones.index(x), itemID),),) + self.data.append(((FitRebaseItemCommand, fitID, 'drones', fit.drones.index(x), itemID),),) def Do(self): for cmds in self.data: