From 21ea9ce579f5ad693e5cdd4d815a4034d4ac4929 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Fri, 24 Apr 2020 15:10:00 +0300 Subject: [PATCH] "Move" attributes at DB generation time --- db_update.py | 20 +++++++++++++++----- eos/db/gamedata/item.py | 3 --- eos/gamedata.py | 30 ------------------------------ eos/saveddata/fit.py | 4 ++-- eos/saveddata/module.py | 8 ++++---- scripts/itemDiff.py | 12 ------------ 6 files changed, 21 insertions(+), 56 deletions(-) diff --git a/db_update.py b/db_update.py index 185745cb1..a442018dc 100644 --- a/db_update.py +++ b/db_update.py @@ -170,16 +170,26 @@ def update_db(): data = _readData('fsd_binary', 'typedogma', keyIdName='typeID') eveTypeIds = set(r['typeID'] for r in eveTypesData) newData = [] - for row in eveTypesData: - for attrId, attrName in {4: 'mass', 38: 'capacity', 161: 'volume', 162: 'radius'}.items(): - if attrName in row: - newData.append({'typeID': row['typeID'], 'attributeID': attrId, 'value': row[attrName]}) + seenKeys = set() + + def checkKey(key): + if key in seenKeys: + return False + seenKeys.add(key) + return True + for typeData in data: if typeData['typeID'] not in eveTypeIds: continue for row in typeData.get('dogmaAttributes', ()): row['typeID'] = typeData['typeID'] - newData.append(row) + if checkKey((row['typeID'], row['attributeID'])): + newData.append(row) + for row in eveTypesData: + for attrId, attrName in {4: 'mass', 38: 'capacity', 161: 'volume', 162: 'radius'}.items(): + if attrName in row and checkKey((row['typeID'], attrId)): + newData.append({'typeID': row['typeID'], 'attributeID': attrId, 'value': row[attrName]}) + _addRows(newData, eos.gamedata.Attribute) return newData diff --git a/eos/db/gamedata/item.py b/eos/db/gamedata/item.py index d4603b8a1..1da3ea9b5 100644 --- a/eos/db/gamedata/item.py +++ b/eos/db/gamedata/item.py @@ -33,9 +33,6 @@ items_table = Table("invtypes", gamedata_meta, Column("description", String), Column("raceID", Integer), Column("factionID", Integer), - Column("volume", Float), - Column("mass", Float), - Column("capacity", Float), Column("published", Boolean), Column("marketGroupID", Integer, ForeignKey("invmarketgroups.marketGroupID")), Column("iconID", Integer), diff --git a/eos/gamedata.py b/eos/gamedata.py index 4af5f9265..03ec7d367 100644 --- a/eos/gamedata.py +++ b/eos/gamedata.py @@ -209,40 +209,13 @@ class Effect(EqBase): class Item(EqBase): - MOVE_ATTRS = (4, # Mass - 38, # Capacity - 161) # Volume - - MOVE_ATTR_INFO = None - ABYSSAL_TYPES = None - @classmethod - def getMoveAttrInfo(cls): - info = getattr(cls, "MOVE_ATTR_INFO", None) - if info is None: - cls.MOVE_ATTR_INFO = info = [] - for id in cls.MOVE_ATTRS: - info.append(eos.db.getAttributeInfo(id)) - - return info - - def moveAttrs(self): - self.__moved = True - for info in self.getMoveAttrInfo(): - val = getattr(self, info.name, 0) - if val != 0: - attr = Attribute() - attr.info = info - attr.value = val - self.__attributes[info.name] = attr - @reconstructor def init(self): self.__race = None self.__requiredSkills = None self.__requiredFor = None - self.__moved = False self.__offensive = None self.__assistive = None self.__overrides = None @@ -264,9 +237,6 @@ class Item(EqBase): @property def attributes(self): - if not self.__moved: - self.moveAttrs() - return self.__attributes @property diff --git a/eos/saveddata/fit.py b/eos/saveddata/fit.py index 359bf3818..6b4c1969f 100644 --- a/eos/saveddata/fit.py +++ b/eos/saveddata/fit.py @@ -1145,7 +1145,7 @@ class Fit: def droneBayUsed(self): amount = 0 for d in self.drones: - amount += d.item.volume * d.amount + amount += d.item.attributes['volume'].value * d.amount return amount @@ -1153,7 +1153,7 @@ class Fit: def fighterBayUsed(self): amount = 0 for f in self.fighters: - amount += f.item.volume * f.amount + amount += f.item.attributes['volume'].value * f.amount return amount diff --git a/eos/saveddata/module.py b/eos/saveddata/module.py index 5b54b2838..85476fac3 100644 --- a/eos/saveddata/module.py +++ b/eos/saveddata/module.py @@ -214,8 +214,8 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut): if charge is None: charges = 0 else: - chargeVolume = charge.volume - containerCapacity = self.item.capacity + chargeVolume = charge.attributes['volume'].value + containerCapacity = self.item.attributes['capacity'].value if chargeVolume is None or containerCapacity is None: charges = 0 else: @@ -778,8 +778,8 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut): # Check sizes, if 'charge size > module volume' it won't fit if charge is None: return True - chargeVolume = charge.volume - moduleCapacity = self.item.capacity + chargeVolume = charge.attributes['volume'].value + moduleCapacity = self.item.attributes['capacity'].value if chargeVolume is not None and moduleCapacity is not None and chargeVolume > moduleCapacity: return False diff --git a/scripts/itemDiff.py b/scripts/itemDiff.py index 95f561954..e48506a17 100755 --- a/scripts/itemDiff.py +++ b/scripts/itemDiff.py @@ -226,18 +226,6 @@ def main(old, new, groups=True, effects=True, attributes=True, renames=True): effectSet.add(effectID) if attributes: - # Add base attributes to our data - query = 'SELECT it.typeID, it.mass, it.capacity, it.volume FROM invtypes AS it' - cursor.execute(query) - for row in cursor: - itemid = row[0] - if itemid in dictionary: - attrdict = dictionary[itemid][2] - # Add base attributes: mass (4), capacity (38) and volume (161) - attrdict[4] = row[1] - attrdict[38] = row[2] - attrdict[161] = row[3] - # Add attribute data for other attributes query = 'SELECT dta.typeID, dta.attributeID, dta.value FROM dgmtypeattribs AS dta' cursor.execute(query)