attribute.py (4135B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\info\attribute.py 2 import dogma.data as dogma_data 3 from carbon.common.script.util import mathCommon 4 from dogma.attributes import format 5 MIN_IN_MS = 60000 6 CLOSE_ENOUGH_TOLERANCE = 1e-06 7 8 def FloatCloseEnough(a, b): 9 return mathCommon.FloatCloseEnough(a, b, CLOSE_ENOUGH_TOLERANCE) 10 11 12 def CreateAttribute(attributeID, value, baseValue = None): 13 if baseValue is None: 14 attribute = Attribute(attributeID, value) 15 else: 16 attribute = ModifiedAttribute(Attribute(attributeID, baseValue), value) 17 return attribute 18 19 20 def IsModified(attribute): 21 return hasattr(attribute, 'baseValue') 22 23 24 def IsMutated(attribute): 25 return hasattr(attribute, 'sourceValue') 26 27 28 class Attribute(object): 29 30 def __init__(self, attributeID, value): 31 self.attributeID = attributeID 32 self.value = value 33 self._info = dogma_data.get_attribute(attributeID) 34 35 @property 36 def displayName(self): 37 return dogma_data.get_attribute_display_name(self.attributeID) 38 39 @property 40 def displayValue(self): 41 return self.Format(self.value) 42 43 @property 44 def highIsGood(self): 45 return self._info.highIsGood 46 47 @property 48 def iconID(self): 49 return self._info.iconID 50 51 @property 52 def unitID(self): 53 return self._info.unitID 54 55 @property 56 def isPublished(self): 57 return self._info.published 58 59 def Format(self, value): 60 if self._info.unitID == const.unitMilliseconds and value >= 5 * MIN_IN_MS: 61 info = format.GetFormattedAttributeAndValueAllowZero(self.attributeID, value / MIN_IN_MS / 60, const.unitHour) 62 else: 63 info = format.GetFormattedAttributeAndValueAllowZero(self.attributeID, value) 64 return info.value 65 66 def FormatDiff(self, diff): 67 return format.GetFormattedDiff(self.attributeID, diff) 68 69 70 class ModifiedAttribute(object): 71 72 def __init__(self, attribute, value): 73 self._attribute = attribute 74 self.value = value 75 76 def __getattr__(self, name): 77 return getattr(self._attribute, name) 78 79 @property 80 def baseValue(self): 81 return self._attribute.value 82 83 @property 84 def displayBaseValue(self): 85 return self.Format(self.baseValue) 86 87 @property 88 def isSame(self): 89 return FloatCloseEnough(self.value, self.baseValue) 90 91 @property 92 def isBetter(self): 93 if self.isSame: 94 return False 95 elif self.highIsGood: 96 return self.value > self.baseValue 97 else: 98 return self.value < self.baseValue 99 100 101 class MutatedAttribute(object): 102 103 def __init__(self, attribute, sourceValue, minValue, maxValue, highIsGood = None): 104 self._attribute = attribute 105 self._highIsGood = highIsGood 106 self._maxValue = max(minValue, maxValue) 107 self._minValue = min(minValue, maxValue) 108 self.sourceValue = sourceValue 109 110 def __getattr__(self, name): 111 return getattr(self._attribute, name) 112 113 @property 114 def highIsGood(self): 115 if self._highIsGood is not None: 116 return self._highIsGood 117 else: 118 return self._attribute.highIsGood 119 120 @property 121 def mutationMax(self): 122 return self._maxValue 123 124 @property 125 def mutationMin(self): 126 return self._minValue 127 128 @property 129 def mutationHigh(self): 130 if self.highIsGood: 131 return self._maxValue 132 else: 133 return self._minValue 134 135 @property 136 def mutationLow(self): 137 if self.highIsGood: 138 return self._minValue 139 else: 140 return self._maxValue 141 142 @property 143 def displaySourceValue(self): 144 return self.Format(self.sourceValue) 145 146 @property 147 def displayMutationHigh(self): 148 return self.Format(self.mutationHigh) 149 150 @property 151 def displayMutationLow(self): 152 return self.Format(self.mutationLow) 153 154 @property 155 def isMutationPositive(self): 156 return self.highIsGood and self.value > self.sourceValue or not self.highIsGood and self.value < self.sourceValue