Rework traits support. Also support getting traits out of the client via phobos

This commit is contained in:
DarkPhoenix
2014-02-16 22:06:54 +04:00
parent b4aca7ae90
commit c1ea161060
4 changed files with 38 additions and 59 deletions

View File

@@ -1,31 +1,22 @@
from sqlalchemy import Column, Table, Integer, Float, String, ForeignKey, and_, select
from sqlalchemy import Column, Table, Integer, String, ForeignKey, and_, select
from sqlalchemy.orm import mapper, column_property
from eos.types import Item, Traits
from eos.db import gamedata_meta
traits_table = Table("invtraits", gamedata_meta,
Column("traitID", Integer, primary_key=True),
Column("typeID", Integer, ForeignKey("invtypes.typeID")),
Column("skillID", Integer, ForeignKey("invtypes.typeID")),
Column("bonus", Float),
Column("bonusText", String),
Column("unitID", Integer))
Column("typeID", Integer, ForeignKey("invtypes.typeID"), primary_key=True),
Column("skillID", Integer, ForeignKey("invtypes.typeID"), primary_key=True),
Column("bonusText", String, primary_key=True))
from .item import items_table
from .unit import groups_table
mapper(Traits, traits_table,
properties = {"skillName" : column_property(
properties = {"skillName" : column_property(
select([items_table.c.typeName],
and_(
items_table.c.typeID == traits_table.c.skillID,
traits_table.c.skillID != -1
))),
"unit" : column_property(
select([groups_table.c.displayName],
and_(
groups_table.c.unitID == traits_table.c.unitID
)))
});
});

View File

@@ -59,6 +59,7 @@ if __name__ == "__main__":
"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"}}

View File

@@ -194,53 +194,40 @@ class AutoListCtrlNoHighlight(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listm
###########################################################################
class ItemTraits ( wx.Panel ):
def __init__(self, parent, stuff, item):
wx.Panel.__init__ (self, parent)
mainSizer = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(mainSizer)
bgcolor = wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW)
fgcolor = wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOWTEXT)
self.traits = wx.html.HtmlWindow(self)
traitsMap = OrderedDict()
for trait in item.traits:
text = ""
bonusText = re.sub("<( *)a(.*?)>(?P<inside>.*?)<( *)/( *)a( *)>", "\g<inside>", trait.bonusText)
bonusAmountText = str(trait.bonus)
if trait.skillName is not None:
skillText = trait.skillName + " bonuses (per skill level):"
else:
skillText = "Role Bonus:"
if bonusAmountText == "":
bonusAmountText = ""
else:
bonusAmountText += trait.unit
text += bonusAmountText + " " + bonusText
if skillText in traitsMap:
traitsMap[skillText].append(text)
else:
traitsMap[skillText] = [text]
fullText = ""
firstSkill = True
for skill in traitsMap:
if firstSkill:
firstSkill = False
else:
fullText += "<br>"
fullText += "<b>" + skill + "</b><br>"
for t in traitsMap[skill]:
fullText += t + "<br>"
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'<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)
self.Layout()

Binary file not shown.