Created
August 11, 2012 17:06
-
-
Save atomizer/3325746 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, re | |
try: | |
from lxml import etree | |
except ImportError: | |
try: | |
import xml.etree.cElementTree as etree | |
except ImportError: | |
try: | |
import xml.etree.ElementTree as etree | |
except ImportError: | |
try: | |
import cElementTree as etree | |
except ImportError: | |
try: | |
import elementtree.ElementTree as etree | |
except ImportError: | |
print("failed to import ElementTree") | |
sys.exit(1) | |
WRF = '<{0}>{1}</{0}>' | |
HEAD = ['Aesthetics', 'Damage', 'Condition effects', 'Speed', 'Range', 'Comments'] | |
BASE = 'http://dl.dropbox.com/u/52918745/Projectiles/' | |
def goodnum(s): | |
n = float(s) | |
if (round(n) == n): return str(int(round(n))) | |
return str(n) | |
def center(s): | |
return '<div align=center>' + s + '</div>' | |
def b(s): | |
return '<b>' + s + '</b>' | |
def wrap(tag = '', each = 'div', things = []): | |
if each: | |
r = map(lambda x: WRF.format(each, x), things) | |
else: | |
r = things | |
r = '\n'.join(r) | |
if tag: r = WRF.format(tag, r) | |
return r | |
def row(p): | |
d = [] | |
obj = p.find('ObjectId').text | |
if obj == 'Invisible': | |
d.append(center(obj)) | |
else: | |
d.append(center('<img src="{0}" title="{1}">'.format(BASE + obj + '.png', obj))) | |
dam = p.find('Damage') | |
dmin = p.find('MinDamage') | |
dmax = p.find('MaxDamage') | |
s = '' | |
if dam is not None: | |
s = dam.text | |
else: | |
s = dmin.text + '-' + dmax.text | |
if p.find('ArmorPiercing') is not None: | |
s += 'AP' | |
d.append(center(b(s))) | |
cs = p.findall('ConditionEffect') | |
s = [] | |
for c in cs: | |
s.append('<b>{0}</b> for <b>{1}s</b>'.format(c.text, goodnum(c.get('duration')))) | |
d.append(center('\n'.join(s))) | |
# s = p.find('Size') | |
# if s is None: | |
# d.append(center('100')) | |
# else: | |
# d.append(center(s.text)) | |
d.append(center(p.find('Speed').text)) | |
s = float(p.find('Speed').text) | |
l = float(p.find('LifetimeMS').text) | |
d.append(center(goodnum(str(round(s * l / 1e3) / 10.0)))) | |
s = [] | |
if p.find('MultiHit') is not None: | |
s.append('Goes through players') | |
if p.find('PassesCover') is not None: | |
s.append('Passes cover') | |
if p.find('Boomerang') is not None: | |
s.append('Boomerang') | |
if p.find('Parametric') is not None: | |
s.append('Parametric') | |
if p.find('Wavy') is not None: | |
s.append('Wavy') | |
d.append('\n'.join(s)) | |
return wrap('tr', 'td', d) | |
def process(e): | |
id = e.get('id') | |
ps = e.findall('Projectile') | |
rows = [wrap('tr', 'th', map(center, HEAD))] | |
for p in ps: | |
rows.append(row(p)) | |
r = wrap('table', '', rows) | |
with open('attacks/' + id + '.txt', 'w') as f: | |
f.write(r) | |
if __name__ == '__main__': | |
objects = etree.parse('objects.xml').getroot() | |
for item in objects: | |
if item.find('Enemy') is None or item.find('Projectile') is None: | |
continue | |
process(item) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment