Skip to content

Commit

Permalink
wmlunits: Skip writing attack list sections when a unit has no attacks
Browse files Browse the repository at this point in the history
  • Loading branch information
irydacea committed Aug 27, 2017
1 parent 769565b commit f1eb040
Showing 1 changed file with 74 additions and 68 deletions.
142 changes: 74 additions & 68 deletions data/tools/unit_tree/html_output.py
Expand Up @@ -896,30 +896,34 @@ def clean_uval(name):
write('</div>')

# Write info about attacks.
write('\n<div class="attacks">')
attacks = self.get_recursive_attacks(u)
for attack in attacks:
n = T(attack, "number")
x = T(attack, "damage")
x = "%s %s %s " % (cleantext(x, quote=False), HTML_ENTITY_MULTIPLICATION_SIGN, cleantext(n, quote=False))
write(x)

r = T(attack, "range")
t = T(attack, "type")
write(cleantext("%s (%s)" % (_(r), _(t)), quote=False))

s = []
specials = attack.get_all(tag="specials")
if specials:
for special in specials[0].get_all(tag=""):
sname = T(special, "name")
if sname:
s.append(sname)
s = ", ".join(s)
if s:
write(" (%s)" % cleantext(s, quote=False))
write('<br />')
write('</div>')
if attacks:
write('\n<div class="attacks">')
first_attack = True
for attack in attacks:
if not first_attack:
write('<br />')
first_attack = False
n = T(attack, "number")
x = T(attack, "damage")
x = "%s %s %s " % (cleantext(x, quote=False), HTML_ENTITY_MULTIPLICATION_SIGN, cleantext(n, quote=False))
write(x)

r = T(attack, "range")
t = T(attack, "type")
write(cleantext("%s (%s)" % (_(r), _(t)), quote=False))

s = []
specials = attack.get_all(tag="specials")
if specials:
for special in specials[0].get_all(tag=""):
sname = T(special, "name")
if sname:
s.append(sname)
s = ", ".join(s)
if s:
write(" (%s)" % cleantext(s, quote=False))
write('</div>')

write('</div>')
write('</td>\n')
Expand Down Expand Up @@ -1110,57 +1114,59 @@ def clean_uval(name):
write('</table>\n')

# Write info about attacks.
write('<h2>%s <small>(damage %s count)</small></h2>\n' %
(cleantext(_("unit help^Attacks"), quote=False),
HTML_ENTITY_MULTIPLICATION_SIGN))
write('<table class="unitinfo attacks">\n')
write('<colgroup><col class="col0" /><col class="col1" /><col class="col2" /><col class="col3" /></colgroup>')
attacks = self.get_recursive_attacks(unit)
for attack in attacks:
write('<tr>')

aid = attack.get_text_val("name")
aname = T(attack, "description")

icon = attack.get_text_val("icon")
if not icon:
icon = "attacks/%s.png" % aid

image_add = image_collector.add_image_check(self.addon, icon, no_tc=True)
if not image_add.ipath:
error_message("Error: No attack icon '%s' found for '%s'.\n" % (
icon, uid))
icon = os.path.join(PICS_LOCATION, "unit$elves-wood$shaman.png")
else:
icon = os.path.join(PICS_LOCATION, image_add.id_name)
write('<td><img src="%s" alt="(image)"/></td>' % cleanurl(icon))
if attacks:
write('<h2>%s <small>(damage %s count)</small></h2>\n' %
(cleantext(_("unit help^Attacks"), quote=False),
HTML_ENTITY_MULTIPLICATION_SIGN))
write('<table class="unitinfo attacks">\n')
write('<colgroup><col class="col0" /><col class="col1" /><col class="col2" /><col class="col3" /></colgroup>')

for attack in attacks:
write('<tr>')

aid = attack.get_text_val("name")
aname = T(attack, "description")

icon = attack.get_text_val("icon")
if not icon:
icon = "attacks/%s.png" % aid

image_add = image_collector.add_image_check(self.addon, icon, no_tc=True)
if not image_add.ipath:
error_message("Error: No attack icon '%s' found for '%s'.\n" % (
icon, uid))
icon = os.path.join(PICS_LOCATION, "unit$elves-wood$shaman.png")
else:
icon = os.path.join(PICS_LOCATION, image_add.id_name)
write('<td><img src="%s" alt="(image)"/></td>' % cleanurl(icon))

write('<td><b>%s</b>' % cleantext(aname, quote=False))
write('<td><b>%s</b>' % cleantext(aname, quote=False))

r = T(attack, "range")
write('<br/>%s</td>' % cleantext(_(r), quote=False))
r = T(attack, "range")
write('<br/>%s</td>' % cleantext(_(r), quote=False))

n = attack.get_text_val("number")
x = attack.get_text_val("damage")
x = '%s %s %s' % (cleantext(x, quote=False), HTML_ENTITY_MULTIPLICATION_SIGN, cleantext(n, quote=False))
write('<td><i>%s</i>' % x)
n = attack.get_text_val("number")
x = attack.get_text_val("damage")
x = '%s %s %s' % (cleantext(x, quote=False), HTML_ENTITY_MULTIPLICATION_SIGN, cleantext(n, quote=False))
write('<td><i>%s</i>' % x)

t = T(attack, "type")
write('<br/>%s</td>' % cleantext(_(t), quote=False))
t = T(attack, "type")
write('<br/>%s</td>' % cleantext(_(t), quote=False))

s = []
specials = attack.get_all(tag="specials")
if specials:
for special in specials[0].get_all(tag=""):
sname = T(special, "name")
if sname:
s.append(cleantext(sname, quote=False))
else:
error_message("Warning: Weapon special %s has no name for %s.\n" %
(special.name.decode("utf8"), uid))
write('<td>%s</td>' % '<br/>'.join(s))
write('</tr>')
write('</table>\n')
s = []
specials = attack.get_all(tag="specials")
if specials:
for special in specials[0].get_all(tag=""):
sname = T(special, "name")
if sname:
s.append(cleantext(sname, quote=False))
else:
error_message("Warning: Weapon special %s has no name for %s.\n" %
(special.name.decode("utf8"), uid))
write('<td>%s</td>' % '<br/>'.join(s))
write('</tr>')
write('</table>\n')

# Write info about resistances.
write('<h2>%s</h2>\n' % _("Resistances: ").strip(" :"))
Expand Down

0 comments on commit f1eb040

Please sign in to comment.