Skip to content

Instantly share code, notes, and snippets.

@stubb
Created January 2, 2016 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stubb/c807ce3774b7808b7eb7 to your computer and use it in GitHub Desktop.
Save stubb/c807ce3774b7808b7eb7 to your computer and use it in GitHub Desktop.
def get_unit_tooltip(self, unit_id):
"""Tries to identify unit properties to display as tooltip.
#TODO Should be extended later to also include movement speed, etc."""
helptexts = [] # collects all information we will find
unit = Entities.units[unit_id]
try:
comp = unit.get_component_template('StorageComponent')
print 'a'
print type(comp)
print 'b'
storage = comp['PositiveTotalNumSlotsStorage']
# Ship storage properties
helptext = _('{slotnum} slots, {limit}t')
helptext = helptext.format(slotnum=storage['slotnum'],
limit=storage['limit'])
helptexts.append(helptext)
except KeyError: # Component not found, ignore this part
pass
try:
comp = unit.get_component_template('HealthComponent')
helptext = _('Health: {health}')
helptext = helptext.format(health=comp['maxhealth'])
helptexts.append(helptext)
except KeyError: # Component not found, ignore this part
pass
return u'\\n'.join(helptexts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment