Adapt pyfa scripts to latest Phobos changes

This commit is contained in:
DarkPhoenix
2014-10-25 17:39:33 +04:00
parent 23906d5824
commit f78e2ed405
5 changed files with 110 additions and 72 deletions

View File

@@ -53,9 +53,8 @@ mapper(Item, items_table,
"name" : synonym("typeName"), "name" : synonym("typeName"),
"description" : deferred(items_table.c.description), "description" : deferred(items_table.c.description),
"traits" : relation(Traits, "traits" : relation(Traits,
primaryjoin = traits_table.c.typeID == items_table.c.typeID, primaryjoin = traits_table.c.typeID == items_table.c.typeID,
order_by = traits_table.c.typeID, uselist = False)
uselist = True)
}) })
Item.category = association_proxy("group", "category") Item.category = association_proxy("group", "category")

View File

@@ -1,22 +1,11 @@
from sqlalchemy import Column, Table, Integer, String, ForeignKey, and_, select from sqlalchemy import Column, Table, Integer, String, ForeignKey
from sqlalchemy.orm import mapper, column_property from sqlalchemy.orm import mapper
from eos.types import Item, Traits from eos.types import Traits
from eos.db import gamedata_meta from eos.db import gamedata_meta
traits_table = Table("invtraits", gamedata_meta, traits_table = Table("invtraits", gamedata_meta,
Column("typeID", Integer, ForeignKey("invtypes.typeID"), primary_key=True), Column("typeID", Integer, ForeignKey("invtypes.typeID"), primary_key=True),
Column("skillID", Integer, ForeignKey("invtypes.typeID"), primary_key=True), Column("traitText", String))
Column("bonusText", String, primary_key=True))
mapper(Traits, traits_table);
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
)))
});

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python3 #!/usr/bin/env python
#====================================================================== #======================================================================
# Copyright (C) 2012 Diego Duclos # Copyright (C) 2012 Diego Duclos
# #
@@ -25,7 +25,6 @@ import sys
path = os.path.dirname(unicode(__file__, sys.getfilesystemencoding())) path = os.path.dirname(unicode(__file__, sys.getfilesystemencoding()))
sys.path.append(os.path.realpath(os.path.join(path, "..", "..", ".."))) sys.path.append(os.path.realpath(os.path.join(path, "..", "..", "..")))
import sqlite3
import json import json
import argparse import argparse
@@ -50,27 +49,102 @@ if __name__ == "__main__":
eos.db.gamedata_meta.create_all() eos.db.gamedata_meta.create_all()
# Config dict # Config dict
tables = {"dgmattribs": eos.gamedata.AttributeInfo, tables = {
"dgmeffects": eos.gamedata.EffectInfo, "dgmattribs": eos.gamedata.AttributeInfo,
"dgmtypeattribs": eos.gamedata.Attribute, "dgmeffects": eos.gamedata.EffectInfo,
"dgmtypeeffects": eos.gamedata.Effect, "dgmtypeattribs": eos.gamedata.Attribute,
"dgmunits": eos.gamedata.Unit, "dgmtypeeffects": eos.gamedata.Effect,
"icons": eos.gamedata.Icon, "dgmunits": eos.gamedata.Unit,
"invcategories": eos.gamedata.Category, "icons": eos.gamedata.Icon,
"invgroups": eos.gamedata.Group, "invcategories": eos.gamedata.Category,
"invmetagroups": eos.gamedata.MetaGroup, "invgroups": eos.gamedata.Group,
"invmetatypes": eos.gamedata.MetaType, "invmetagroups": eos.gamedata.MetaGroup,
"invtypes": eos.gamedata.Item, "invmetatypes": eos.gamedata.MetaType,
"phobostraits": eos.gamedata.Traits, "invtypes": eos.gamedata.Item,
"marketProxy()_GetMarketGroups()": eos.gamedata.MarketGroup} "phbtraits": eos.gamedata.Traits,
"mapbulk_marketGroups": eos.gamedata.MarketGroup
fieldMapping = {"icons": {"id": "iconID"}} }
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"<b>{}</b>".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"<br />\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"<br />\n<br />\n".join(typeLines)
newRow = {"typeID": typeId, "traitText": traitLine}
newData.append(newRow)
return newData
data = {} data = {}
# Dump all data to memory so we can easely cross check ignored rows # Dump all data to memory so we can easely cross check ignored rows
for jsonName, cls in tables.iteritems(): for jsonName, cls in tables.iteritems():
f = open(os.path.join(jsonPath, "{}.json".format(jsonName))) with open(os.path.join(jsonPath, "{}.json".format(jsonName))) as f:
data[jsonName] = json.load(f, encoding='cp1252') 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 # Do some preprocessing to make our job easier
invTypes = set() invTypes = set()
@@ -92,21 +166,21 @@ if __name__ == "__main__":
return False return False
# Loop through each json file and write it away, checking ignored rows # Loop through each json file and write it away, checking ignored rows
for jsonName, table in data.iteritems(): for jsonName, table in data.iteritems():
fieldMap = fieldMapping.get(jsonName, {}) fieldMap = fieldMapping.get(jsonName, {})
print "processing {}".format(jsonName) print "processing {}".format(jsonName)
for row in table: for row in table:
# We don't care about some kind of rows, filter it out if so # We don't care about some kind of rows, filter it out if so
if not isIgnored(jsonName, row): if not isIgnored(jsonName, row):
instance = tables[jsonName]() instance = tables[jsonName]()
# fix for issue 80 # fix for issue 80
if jsonName is "icons" and "res:/UI/Texture/Icons/" in str(row['iconFile']): if jsonName is "icons" and "res:/UI/Texture/Icons/" in str(row["iconFile"]):
row['iconFile'] = row['iconFile'].replace('res:/UI/Texture/Icons/','').replace('.png','') row["iconFile"] = row["iconFile"].replace("res:/UI/Texture/Icons/","").replace(".png", "")
for k, v in row.iteritems(): for k, v in row.iteritems():
setattr(instance, fieldMap.get(k, k), v) setattr(instance, fieldMap.get(k, k), v)
eos.db.gamedata_session.add(instance) eos.db.gamedata_session.add(instance)
eos.db.gamedata_session.commit() eos.db.gamedata_session.commit()
print("done") print("done")

View File

@@ -154,7 +154,7 @@ class ItemStatsContainer ( wx.Panel ):
self.nbContainer = wx.Notebook( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0 ) self.nbContainer = wx.Notebook( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0 )
mainSizer.Add( self.nbContainer, 1, wx.EXPAND |wx.ALL, 2 ) 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.traits = ItemTraits(self.nbContainer, stuff, item)
self.nbContainer.AddPage(self.traits, "Traits") self.nbContainer.AddPage(self.traits, "Traits")
@@ -221,32 +221,8 @@ class ItemTraits ( wx.Panel ):
self.SetSizer(mainSizer) self.SetSizer(mainSizer)
self.traits = wx.html.HtmlWindow(self) self.traits = wx.html.HtmlWindow(self)
print(item.traits)
# Format: {skill name: [bonus text]} self.traits.SetPage(item.traits.traitText)
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'<br />'.join(sectionRows)
textRows = []
for skillName in sorted(traitData):
# Skills always go 1st
if skillName is None:
continue
header = u"<b>{} bonuses (per skill level):</b>".format(skillName)
textRows.append(getSection(header, traitData[skillName]))
if None in traitData:
textRows.append(getSection("<b>Role Bonus:</b>", traitData[None]))
fullText = u"<br /><br />".join(textRows)
self.traits.SetPage(fullText)
mainSizer.Add(self.traits, 1, wx.ALL|wx.EXPAND, 0) mainSizer.Add(self.traits, 1, wx.ALL|wx.EXPAND, 0)
self.Layout() self.Layout()

Binary file not shown.