Merge pull request #1031 from Ebag333/tooltip_capacitor_neut_resistance
Tooltip for capacitor neut resistance
This commit is contained in:
@@ -19,6 +19,9 @@
|
||||
|
||||
import collections
|
||||
from math import exp
|
||||
# TODO: This needs to be moved out, we shouldn't have *ANY* dependencies back to other modules/methods inside eos.
|
||||
# This also breaks writing any tests. :(
|
||||
from eos.db.gamedata.queries import getAttributeInfo
|
||||
|
||||
defaultValuesCache = {}
|
||||
cappingAttrKeyCache = {}
|
||||
@@ -26,22 +29,26 @@ cappingAttrKeyCache = {}
|
||||
|
||||
class ItemAttrShortcut(object):
|
||||
def getModifiedItemAttr(self, key, default=None):
|
||||
if key in self.itemModifiedAttributes:
|
||||
return self.itemModifiedAttributes[key]
|
||||
else:
|
||||
return default
|
||||
return_value = self.itemModifiedAttributes.get(key)
|
||||
|
||||
if return_value is None and default is not None:
|
||||
return_value = default
|
||||
|
||||
return return_value
|
||||
|
||||
|
||||
class ChargeAttrShortcut(object):
|
||||
def getModifiedChargeAttr(self, key, default=None):
|
||||
if key in self.chargeModifiedAttributes:
|
||||
return self.chargeModifiedAttributes[key]
|
||||
else:
|
||||
return default
|
||||
return_value = self.chargeModifiedAttributes.get(key)
|
||||
|
||||
if return_value is None and default is not None:
|
||||
return_value = default
|
||||
|
||||
return return_value
|
||||
|
||||
|
||||
class ModifiedAttributeDict(collections.MutableMapping):
|
||||
OVERRIDES = False
|
||||
overrides_enabled = False
|
||||
|
||||
class CalculationPlaceholder(object):
|
||||
def __init__(self):
|
||||
@@ -98,15 +105,23 @@ class ModifiedAttributeDict(collections.MutableMapping):
|
||||
|
||||
def __getitem__(self, key):
|
||||
# Check if we have final calculated value
|
||||
if key in self.__modified:
|
||||
if self.__modified[key] == self.CalculationPlaceholder:
|
||||
self.__modified[key] = self.__calculateValue(key)
|
||||
return self.__modified[key]
|
||||
key_value = self.__modified.get(key)
|
||||
if key_value is self.CalculationPlaceholder:
|
||||
key_value = self.__modified[key] = self.__calculateValue(key)
|
||||
|
||||
if key_value is not None:
|
||||
return key_value
|
||||
|
||||
# Then in values which are not yet calculated
|
||||
elif key in self.__intermediary:
|
||||
return self.__intermediary[key]
|
||||
# Original value is the least priority
|
||||
if self.__intermediary:
|
||||
val = self.__intermediary.get(key)
|
||||
else:
|
||||
val = None
|
||||
|
||||
if val is not None:
|
||||
return val
|
||||
else:
|
||||
# Original value is the least priority
|
||||
return self.getOriginal(key)
|
||||
|
||||
def __delitem__(self, key):
|
||||
@@ -115,12 +130,18 @@ class ModifiedAttributeDict(collections.MutableMapping):
|
||||
if key in self.__intermediary:
|
||||
del self.__intermediary[key]
|
||||
|
||||
def getOriginal(self, key):
|
||||
if self.OVERRIDES and key in self.__overrides:
|
||||
return self.__overrides.get(key).value
|
||||
val = self.__original.get(key)
|
||||
def getOriginal(self, key, default=None):
|
||||
if self.overrides_enabled and self.overrides:
|
||||
val = self.overrides.get(key, None)
|
||||
else:
|
||||
val = None
|
||||
|
||||
if val is None:
|
||||
return None
|
||||
if self.original:
|
||||
val = self.original.get(key, None)
|
||||
|
||||
if val is None and val != default:
|
||||
val = default
|
||||
|
||||
return val.value if hasattr(val, "value") else val
|
||||
|
||||
@@ -128,12 +149,12 @@ class ModifiedAttributeDict(collections.MutableMapping):
|
||||
self.__intermediary[key] = val
|
||||
|
||||
def __iter__(self):
|
||||
all = dict(self.__original, **self.__modified)
|
||||
return (key for key in all)
|
||||
all_dict = dict(self.original, **self.__modified)
|
||||
return (key for key in all_dict)
|
||||
|
||||
def __contains__(self, key):
|
||||
return (self.__original is not None and key in self.__original) or \
|
||||
key in self.__modified or key in self.__intermediary
|
||||
return (self.original is not None and key in self.original) or \
|
||||
key in self.__modified or key in self.__intermediary
|
||||
|
||||
def __placehold(self, key):
|
||||
"""Create calculation placeholder in item's modified attribute dict"""
|
||||
@@ -141,7 +162,7 @@ class ModifiedAttributeDict(collections.MutableMapping):
|
||||
|
||||
def __len__(self):
|
||||
keys = set()
|
||||
keys.update(self.__original.iterkeys())
|
||||
keys.update(self.original.iterkeys())
|
||||
keys.update(self.__modified.iterkeys())
|
||||
keys.update(self.__intermediary.iterkeys())
|
||||
return len(keys)
|
||||
@@ -152,7 +173,6 @@ class ModifiedAttributeDict(collections.MutableMapping):
|
||||
try:
|
||||
cappingKey = cappingAttrKeyCache[key]
|
||||
except KeyError:
|
||||
from eos.db.gamedata.queries import getAttributeInfo
|
||||
attrInfo = getAttributeInfo(key)
|
||||
if attrInfo is None:
|
||||
cappingId = cappingAttrKeyCache[key] = None
|
||||
@@ -166,12 +186,8 @@ class ModifiedAttributeDict(collections.MutableMapping):
|
||||
cappingKey = None if cappingAttrInfo is None else cappingAttrInfo.name
|
||||
|
||||
if cappingKey:
|
||||
if cappingKey in self.original:
|
||||
# some items come with their own caps (ie: carriers). If they do, use this
|
||||
cappingValue = self.original.get(cappingKey).value
|
||||
else:
|
||||
# If not, get info about the default value
|
||||
cappingValue = self.__calculateValue(cappingKey)
|
||||
cappingValue = self.original.get(cappingKey, self.__calculateValue(cappingKey))
|
||||
cappingValue = cappingValue.value if hasattr(cappingValue, "value") else cappingValue
|
||||
else:
|
||||
cappingValue = None
|
||||
|
||||
@@ -183,25 +199,28 @@ class ModifiedAttributeDict(collections.MutableMapping):
|
||||
force = min(force, cappingValue)
|
||||
return force
|
||||
# Grab our values if they're there, otherwise we'll take default values
|
||||
preIncrease = self.__preIncreases[key] if key in self.__preIncreases else 0
|
||||
multiplier = self.__multipliers[key] if key in self.__multipliers else 1
|
||||
penalizedMultiplierGroups = self.__penalizedMultipliers[key] if key in self.__penalizedMultipliers else {}
|
||||
postIncrease = self.__postIncreases[key] if key in self.__postIncreases else 0
|
||||
preIncrease = self.__preIncreases.get(key, 0)
|
||||
multiplier = self.__multipliers.get(key, 1)
|
||||
penalizedMultiplierGroups = self.__penalizedMultipliers.get(key, {})
|
||||
postIncrease = self.__postIncreases.get(key, 0)
|
||||
|
||||
# Grab initial value, priorities are:
|
||||
# Results of ongoing calculation > preAssign > original > 0
|
||||
try:
|
||||
default = defaultValuesCache[key]
|
||||
except KeyError:
|
||||
from eos.db.gamedata.queries import getAttributeInfo
|
||||
attrInfo = getAttributeInfo(key)
|
||||
if attrInfo is None:
|
||||
default = defaultValuesCache[key] = 0.0
|
||||
else:
|
||||
dv = attrInfo.defaultValue
|
||||
default = defaultValuesCache[key] = dv if dv is not None else 0.0
|
||||
val = self.__intermediary[key] if key in self.__intermediary else self.__preAssigns[
|
||||
key] if key in self.__preAssigns else self.getOriginal(key) if key in self.__original else default
|
||||
|
||||
val = self.__intermediary.get(key,
|
||||
self.__preAssigns.get(key,
|
||||
self.getOriginal(key, default)
|
||||
)
|
||||
)
|
||||
|
||||
# We'll do stuff in the following order:
|
||||
# preIncrease > multiplier > stacking penalized multipliers > postIncrease
|
||||
@@ -254,7 +273,7 @@ class ModifiedAttributeDict(collections.MutableMapping):
|
||||
return skill.level
|
||||
|
||||
def getAfflictions(self, key):
|
||||
return self.__affectedBy[key] if key in self.__affectedBy else {}
|
||||
return self.__affectedBy.get(key, {})
|
||||
|
||||
def iterAfflictions(self):
|
||||
return self.__affectedBy.__iter__()
|
||||
@@ -360,6 +379,6 @@ class ModifiedAttributeDict(collections.MutableMapping):
|
||||
|
||||
|
||||
class Affliction(object):
|
||||
def __init__(self, type, amount):
|
||||
self.type = type
|
||||
def __init__(self, affliction_type, amount):
|
||||
self.type = affliction_type
|
||||
self.amount = amount
|
||||
|
||||
@@ -114,6 +114,10 @@ class CapacitorViewFull(StatsView):
|
||||
("label%sCapacitorRecharge", lambda: fit.capRecharge, 3, 0, 0),
|
||||
("label%sCapacitorDischarge", lambda: fit.capUsed, 3, 0, 0),
|
||||
)
|
||||
if fit:
|
||||
neut_resist = fit.ship.getModifiedItemAttr("energyWarfareResistance", 0)
|
||||
else:
|
||||
neut_resist = 0
|
||||
|
||||
panel = "Full"
|
||||
for labelName, value, prec, lowest, highest in stats:
|
||||
@@ -127,6 +131,12 @@ class CapacitorViewFull(StatsView):
|
||||
label.SetLabel(formatAmount(value, prec, lowest, highest))
|
||||
label.SetToolTip(wx.ToolTip("%.1f" % value))
|
||||
|
||||
if labelName == "label%sCapacitorDischarge":
|
||||
if neut_resist:
|
||||
neut_resist = 100 - (neut_resist * 100)
|
||||
label_tooltip = "Neut Resistance: {0:.0f}%".format(neut_resist)
|
||||
label.SetToolTip(wx.ToolTip(label_tooltip))
|
||||
|
||||
capState = fit.capState if fit is not None else 0
|
||||
capStable = fit.capStable if fit is not None else False
|
||||
lblNameTime = "label%sCapacitorTime"
|
||||
|
||||
@@ -1043,7 +1043,7 @@ class ItemAffectedBy(wx.Panel):
|
||||
container = {}
|
||||
for attrName in attributes.iterAfflictions():
|
||||
# if value is 0 or there has been no change from original to modified, return
|
||||
if attributes[attrName] == (attributes.getOriginal(attrName) or 0):
|
||||
if attributes[attrName] == (attributes.getOriginal(attrName, 0)):
|
||||
continue
|
||||
|
||||
for fit, afflictors in attributes.getAfflictions(attrName).iteritems():
|
||||
@@ -1170,7 +1170,7 @@ class ItemAffectedBy(wx.Panel):
|
||||
container = {}
|
||||
for attrName in attributes.iterAfflictions():
|
||||
# if value is 0 or there has been no change from original to modified, return
|
||||
if attributes[attrName] == (attributes.getOriginal(attrName) or 0):
|
||||
if attributes[attrName] == (attributes.getOriginal(attrName, 0)):
|
||||
continue
|
||||
|
||||
for fit, afflictors in attributes.getAfflictions(attrName).iteritems():
|
||||
|
||||
@@ -651,11 +651,11 @@ class MainFrame(wx.Frame):
|
||||
dlg.Show()
|
||||
|
||||
def toggleOverrides(self, event):
|
||||
ModifiedAttributeDict.OVERRIDES = not ModifiedAttributeDict.OVERRIDES
|
||||
ModifiedAttributeDict.overrides_enabled = not ModifiedAttributeDict.overrides_enabled
|
||||
wx.PostEvent(self, GE.FitChanged(fitID=self.getActiveFit()))
|
||||
menu = self.GetMenuBar()
|
||||
menu.SetLabel(menu.toggleOverridesId,
|
||||
"Turn Overrides Off" if ModifiedAttributeDict.OVERRIDES else "Turn Overrides On")
|
||||
"Turn Overrides Off" if ModifiedAttributeDict.overrides_enabled else "Turn Overrides On")
|
||||
|
||||
def saveChar(self, event):
|
||||
sChr = Character.getInstance()
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
import copy
|
||||
from logbook import Logger
|
||||
from time import time
|
||||
|
||||
import eos.db
|
||||
from eos.saveddata.booster import Booster as es_Booster
|
||||
@@ -1089,9 +1090,12 @@ class Fit(object):
|
||||
self.recalc(fit)
|
||||
|
||||
def recalc(self, fit, withBoosters=True):
|
||||
start_time = time()
|
||||
pyfalog.info("=" * 10 + "recalc" + "=" * 10)
|
||||
if fit.factorReload is not self.serviceFittingOptions["useGlobalForceReload"]:
|
||||
fit.factorReload = self.serviceFittingOptions["useGlobalForceReload"]
|
||||
fit.clear()
|
||||
|
||||
fit.calculateModifiedAttributes(withBoosters=False)
|
||||
|
||||
pyfalog.info("=" * 10 + "recalc time: " + str(time() - start_time) + "=" * 10)
|
||||
|
||||
Reference in New Issue
Block a user