diff --git a/gui/builtinContextMenus/graphDmgDroneMode.py b/gui/builtinContextMenus/graphDmgDroneMode.py index 3ec31dba1..7e17de9ed 100644 --- a/gui/builtinContextMenus/graphDmgDroneMode.py +++ b/gui/builtinContextMenus/graphDmgDroneMode.py @@ -6,6 +6,7 @@ import wx import gui.globalEvents as GE import gui.mainFrame from gui.contextMenu import ContextMenuUnconditional +from service.const import GraphDpsDroneMode from service.settings import GraphSettings @@ -22,10 +23,10 @@ class TargetResists(ContextMenuUnconditional): return 'Drone Mode' def handleModeSwitch(self, event): - optionName = self.idOptionMap[event.Id] - if optionName == self.settings.get('mobileDroneMode'): + option = self.idOptionMap[event.Id] + if option == self.settings.get('mobileDroneMode'): return - self.settings.set('mobileDroneMode', optionName) + self.settings.set('mobileDroneMode', option) wx.PostEvent(self.mainFrame, GE.GraphOptionChanged()) def getSubMenu(self, context, rootMenu, i, pitem): @@ -35,14 +36,17 @@ class TargetResists(ContextMenuUnconditional): else: bindmenu = m self.idOptionMap = {} - optionMap = OrderedDict([('auto', 'Auto'), ('followSelf', 'Stick to attacker'), ('followTgt', 'Stick to target')]) - for optionName, label in optionMap.items(): + optionMap = OrderedDict([ + (GraphDpsDroneMode.auto, 'Auto'), + (GraphDpsDroneMode.followAttacker, 'Stick to attacker'), + (GraphDpsDroneMode.followTarget, 'Stick to target')]) + for option, label in optionMap.items(): menuId = ContextMenuUnconditional.nextID() item = wx.MenuItem(m, menuId, label, kind=wx.ITEM_CHECK) bindmenu.Bind(wx.EVT_MENU, self.handleModeSwitch, item) m.Append(item) - item.Check(optionName == self.settings.get('mobileDroneMode')) - self.idOptionMap[menuId] = optionName + item.Check(option == self.settings.get('mobileDroneMode')) + self.idOptionMap[menuId] = option return m diff --git a/gui/builtinGraphs/fitDamageStats/calc.py b/gui/builtinGraphs/fitDamageStats/calc.py index 8f579953e..159e08b73 100644 --- a/gui/builtinGraphs/fitDamageStats/calc.py +++ b/gui/builtinGraphs/fitDamageStats/calc.py @@ -21,6 +21,7 @@ import math from functools import lru_cache +from service.const import GraphDpsDroneMode from service.settings import GraphSettings @@ -105,7 +106,11 @@ def getDroneMult(drone, fit, tgt, atkSpeed, atkAngle, distance, tgtSpeed, tgtAng # Hard to simulate drone behavior, so assume chance to hit is 1 for mobile drones # which catch up with target droneOpt = GraphSettings.getInstance().get('mobileDroneMode') - if droneSpeed > 1 and ((droneOpt == 'auto' and droneSpeed >= tgtSpeed) or droneOpt == 'followTgt'): + if ( + droneSpeed > 1 and ( + (droneOpt == GraphDpsDroneMode.auto and droneSpeed >= tgtSpeed) or + droneOpt == GraphDpsDroneMode.followTarget) + ): cth = 1 # Otherwise put the drone into center of the ship, move it at its max speed or ship's speed # (whichever is lower) towards direction of attacking ship and see how well it projects @@ -141,7 +146,7 @@ def getFighterAbilityMult(fighter, ability, fit, distance, tgtSpeed, tgtSigRadiu tgtSigRadius=tgtSigRadius) droneOpt = GraphSettings.getInstance().get('mobileDroneMode') # It's regular missile-based attack - if (droneOpt == 'auto' and fighterSpeed >= tgtSpeed) or droneOpt == 'followTgt': + if (droneOpt == GraphDpsDroneMode.auto and fighterSpeed >= tgtSpeed) or droneOpt == GraphDpsDroneMode.followTarget: rangeFactor = 1 # Same as with drones, if fighters are slower - put them to center of # the ship and see how they apply diff --git a/service/const.py b/service/const.py index 5fa2b671f..3348e37d5 100644 --- a/service/const.py +++ b/service/const.py @@ -110,3 +110,10 @@ class GuiAttrGroup(IntEnum): PROPULSIONS = auto() FIGHTERS = auto() SHIP_GROUP = auto() + + +@unique +class GraphDpsDroneMode(IntEnum): + auto = 1 + followAttacker = 2 + followTarget = 3 diff --git a/service/settings.py b/service/settings.py index 3c90a5ea0..edc18c858 100644 --- a/service/settings.py +++ b/service/settings.py @@ -23,9 +23,12 @@ import urllib.request import urllib.error import urllib.parse +from logbook import Logger + import config import eos.config -from logbook import Logger +from service.const import GraphDpsDroneMode + pyfalog = Logger(__name__) @@ -514,7 +517,7 @@ class GraphSettings: def __init__(self): defaults = { - 'mobileDroneMode': 'auto', + 'mobileDroneMode': GraphDpsDroneMode.auto, 'ignoreResists': True} self.settings = SettingsProvider.getInstance().getSettings('graphSettings', defaults)