diff --git a/eos/db/gamedata/item.py b/eos/db/gamedata/item.py index e8283e6aa..761921906 100644 --- a/eos/db/gamedata/item.py +++ b/eos/db/gamedata/item.py @@ -53,9 +53,8 @@ mapper(Item, items_table, "name" : synonym("typeName"), "description" : deferred(items_table.c.description), "traits" : relation(Traits, - primaryjoin = traits_table.c.typeID == items_table.c.typeID, - order_by = traits_table.c.typeID, - uselist = True) + primaryjoin = traits_table.c.typeID == items_table.c.typeID, + uselist = False) }) Item.category = association_proxy("group", "category") diff --git a/eos/db/gamedata/traits.py b/eos/db/gamedata/traits.py index 2eb02b982..907c53247 100644 --- a/eos/db/gamedata/traits.py +++ b/eos/db/gamedata/traits.py @@ -1,22 +1,11 @@ -from sqlalchemy import Column, Table, Integer, String, ForeignKey, and_, select -from sqlalchemy.orm import mapper, column_property -from eos.types import Item, Traits +from sqlalchemy import Column, Table, Integer, String, ForeignKey +from sqlalchemy.orm import mapper +from eos.types import Traits from eos.db import gamedata_meta traits_table = Table("invtraits", gamedata_meta, Column("typeID", Integer, ForeignKey("invtypes.typeID"), primary_key=True), - Column("skillID", Integer, ForeignKey("invtypes.typeID"), primary_key=True), - Column("bonusText", String, primary_key=True)) + Column("traitText", String)) - -from .item import items_table - -mapper(Traits, traits_table, - properties = {"skillName" : column_property( - select([items_table.c.typeName], - and_( - items_table.c.typeID == traits_table.c.skillID, - traits_table.c.skillID != -1 - ))) - }); +mapper(Traits, traits_table); diff --git a/eos/utils/scripts/jsonToSql.py b/eos/utils/scripts/jsonToSql.py index 01cbfeca6..99e38a3ab 100755 --- a/eos/utils/scripts/jsonToSql.py +++ b/eos/utils/scripts/jsonToSql.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python #====================================================================== # Copyright (C) 2012 Diego Duclos # @@ -25,7 +25,6 @@ import sys path = os.path.dirname(unicode(__file__, sys.getfilesystemencoding())) sys.path.append(os.path.realpath(os.path.join(path, "..", "..", ".."))) -import sqlite3 import json import argparse @@ -50,27 +49,102 @@ if __name__ == "__main__": eos.db.gamedata_meta.create_all() # Config dict - tables = {"dgmattribs": eos.gamedata.AttributeInfo, - "dgmeffects": eos.gamedata.EffectInfo, - "dgmtypeattribs": eos.gamedata.Attribute, - "dgmtypeeffects": eos.gamedata.Effect, - "dgmunits": eos.gamedata.Unit, - "icons": eos.gamedata.Icon, - "invcategories": eos.gamedata.Category, - "invgroups": eos.gamedata.Group, - "invmetagroups": eos.gamedata.MetaGroup, - "invmetatypes": eos.gamedata.MetaType, - "invtypes": eos.gamedata.Item, - "phobostraits": eos.gamedata.Traits, - "marketProxy()_GetMarketGroups()": eos.gamedata.MarketGroup} - - fieldMapping = {"icons": {"id": "iconID"}} + tables = { + "dgmattribs": eos.gamedata.AttributeInfo, + "dgmeffects": eos.gamedata.EffectInfo, + "dgmtypeattribs": eos.gamedata.Attribute, + "dgmtypeeffects": eos.gamedata.Effect, + "dgmunits": eos.gamedata.Unit, + "icons": eos.gamedata.Icon, + "invcategories": eos.gamedata.Category, + "invgroups": eos.gamedata.Group, + "invmetagroups": eos.gamedata.MetaGroup, + "invmetatypes": eos.gamedata.MetaType, + "invtypes": eos.gamedata.Item, + "phbtraits": eos.gamedata.Traits, + "mapbulk_marketGroups": eos.gamedata.MarketGroup + } + + fieldMapping = { + "dgmattribs": { + "displayName_en-us": "displayName" + }, + "dgmeffects": { + "displayName_en-us": "displayName", + "description_en-us": "description" + }, + "dgmunits": { + "displayName_en-us": "displayName" + }, + #icons??? + "invcategories": { + "categoryName_en-us": "categoryName" + }, + "invgroups": { + "groupName_en-us": "groupName" + }, + "invmetagroups": { + "metaGroupName_en-us": "metaGroupName" + }, + "invtypes": { + "typeName_en-us": "typeName", + "description_en-us": "description" + }, + #phbtraits??? + "mapbulk_marketGroups": { + "marketGroupName_en-us": "marketGroupName", + "description_en-us": "description" + } + + } + + def convertIcons(data): + new = [] + for k, v in data.items(): + v["iconID"] = k + new.append(v) + return new + + def convertTraits(data): + + def convertSection(sectionData): + sectionLines = [] + headerText = u"{}".format(sectionData["header"]) + sectionLines.append(headerText) + for bonusData in sectionData["bonuses"]: + prefix = u"{} ".format(bonusData["number"]) if "number" in bonusData else "" + bonusText = u"{}{}".format(prefix, bonusData["text"]) + sectionLines.append(bonusText) + sectionLine = u"
\n".join(sectionLines) + return sectionLine + + newData = [] + for row in data: + typeLines = [] + typeId = row["typeID"] + traitData = row["traits_en-us"] + for skillData in sorted(traitData.get("skills", ()), key=lambda i: i["header"]): + typeLines.append(convertSection(skillData)) + if "role" in traitData: + typeLines.append(convertSection(traitData["role"])) + if "misc" in traitData: + typeLines.append(convertSection(traitData["misc"])) + traitLine = u"
\n
\n".join(typeLines) + newRow = {"typeID": typeId, "traitText": traitLine} + newData.append(newRow) + return newData + data = {} # Dump all data to memory so we can easely cross check ignored rows for jsonName, cls in tables.iteritems(): - f = open(os.path.join(jsonPath, "{}.json".format(jsonName))) - data[jsonName] = json.load(f, encoding='cp1252') + with open(os.path.join(jsonPath, "{}.json".format(jsonName))) as f: + tableData = json.load(f) + if jsonName == "icons": + tableData = convertIcons(tableData) + if jsonName == "phbtraits": + tableData = convertTraits(tableData) + data[jsonName] = tableData # Do some preprocessing to make our job easier invTypes = set() @@ -92,21 +166,21 @@ if __name__ == "__main__": return False # Loop through each json file and write it away, checking ignored rows - for jsonName, table in data.iteritems(): - fieldMap = fieldMapping.get(jsonName, {}) + for jsonName, table in data.iteritems(): + fieldMap = fieldMapping.get(jsonName, {}) print "processing {}".format(jsonName) for row in table: # We don't care about some kind of rows, filter it out if so if not isIgnored(jsonName, row): instance = tables[jsonName]() # fix for issue 80 - if jsonName is "icons" and "res:/UI/Texture/Icons/" in str(row['iconFile']): - row['iconFile'] = row['iconFile'].replace('res:/UI/Texture/Icons/','').replace('.png','') - for k, v in row.iteritems(): - setattr(instance, fieldMap.get(k, k), v) + if jsonName is "icons" and "res:/UI/Texture/Icons/" in str(row["iconFile"]): + row["iconFile"] = row["iconFile"].replace("res:/UI/Texture/Icons/","").replace(".png", "") + for k, v in row.iteritems(): + setattr(instance, fieldMap.get(k, k), v) eos.db.gamedata_session.add(instance) eos.db.gamedata_session.commit() - + print("done") diff --git a/gui/itemStats.py b/gui/itemStats.py index c44e7d709..0d8949a3b 100644 --- a/gui/itemStats.py +++ b/gui/itemStats.py @@ -154,7 +154,7 @@ class ItemStatsContainer ( wx.Panel ): self.nbContainer = wx.Notebook( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0 ) mainSizer.Add( self.nbContainer, 1, wx.EXPAND |wx.ALL, 2 ) - if len(item.traits) != 0: + if len(item.traits.traitText) != 0: self.traits = ItemTraits(self.nbContainer, stuff, item) self.nbContainer.AddPage(self.traits, "Traits") @@ -221,32 +221,8 @@ class ItemTraits ( wx.Panel ): self.SetSizer(mainSizer) self.traits = wx.html.HtmlWindow(self) - - # Format: {skill name: [bonus text]} - traitData = {} - for trait in item.traits: - skillData = traitData.setdefault(trait.skillName, []) - skillData.append(trait.bonusText) - - def getSection(header, rows): - sectionRows = [header] - for row in sorted(rows): - sectionRows.append(row) - return u'
'.join(sectionRows) - - textRows = [] - for skillName in sorted(traitData): - # Skills always go 1st - if skillName is None: - continue - header = u"{} bonuses (per skill level):".format(skillName) - textRows.append(getSection(header, traitData[skillName])) - - if None in traitData: - textRows.append(getSection("Role Bonus:", traitData[None])) - - fullText = u"

".join(textRows) - self.traits.SetPage(fullText) + print(item.traits) + self.traits.SetPage(item.traits.traitText) mainSizer.Add(self.traits, 1, wx.ALL|wx.EXPAND, 0) self.Layout() diff --git a/staticdata/eve.db b/staticdata/eve.db index 9de0c0f43..2c4cd5e88 100644 Binary files a/staticdata/eve.db and b/staticdata/eve.db differ