Start implementing support for mutaplasmids.

* There's a new table `mutators` that has an FK back to a module, and links to an attribute ID with it's new value
* Fixes an issue in the item state where the "base" value showed the literal base value for the attribute, regardless of override / mutators
* If there is an override and a mutated attribute, mutated value takes effect
This commit is contained in:
blitzmann
2018-05-24 01:26:49 -04:00
parent 33d4a8a691
commit fabf759aa7
8 changed files with 132 additions and 9 deletions

View File

@@ -33,6 +33,14 @@ class ItemAttrShortcut(object):
return return_value or default
def getBaseAttrValue(self, key, default=0):
'''
Gets base value in this order:
Mutated value > override value > attribute value
'''
return_value = self.itemModifiedAttributes.getOriginal(key)
return return_value or default
class ChargeAttrShortcut(object):
def getModifiedChargeAttr(self, key, default=0):
@@ -59,8 +67,10 @@ class ModifiedAttributeDict(collections.MutableMapping):
self.__modified = {}
# Affected by entities
self.__affectedBy = {}
# Overrides
# Overrides (per item)
self.__overrides = {}
# Mutators (per module)
self.__mutators = {}
# Dictionaries for various value modification types
self.__forced = {}
self.__preAssigns = {}
@@ -100,6 +110,14 @@ class ModifiedAttributeDict(collections.MutableMapping):
def overrides(self, val):
self.__overrides = val
@property
def mutators(self):
return {x.attr.name: x for x in self.__mutators}
@mutators.setter
def mutators(self, val):
self.__mutators = val
def __getitem__(self, key):
# Check if we have final calculated value
key_value = self.__modified.get(key)
@@ -128,14 +146,16 @@ class ModifiedAttributeDict(collections.MutableMapping):
del self.__intermediary[key]
def getOriginal(self, key, default=None):
val = None
if self.overrides_enabled and self.overrides:
val = self.overrides.get(key, None)
else:
val = None
val = self.overrides.get(key, val)
# mutators are overriden by overrides. x_x
val = self.mutators.get(key, val)
if val is None:
if self.original:
val = self.original.get(key, None)
val = self.original.get(key, val)
if val is None and val != default:
val = default