From f1eb040c7649d47304d239ca4eef40a07ff02e57 Mon Sep 17 00:00:00 2001 From: "Ignacio R. Morelle" Date: Sun, 27 Aug 2017 13:41:15 -0300 Subject: [PATCH] wmlunits: Skip writing attack list sections when a unit has no attacks --- data/tools/unit_tree/html_output.py | 132 +++++++++++++++------------- 1 file changed, 69 insertions(+), 63 deletions(-) diff --git a/data/tools/unit_tree/html_output.py b/data/tools/unit_tree/html_output.py index a6110ea3168..558adcb48bd 100644 --- a/data/tools/unit_tree/html_output.py +++ b/data/tools/unit_tree/html_output.py @@ -896,30 +896,34 @@ class HTMLOutput: write('') # Write info about attacks. - write('\n
') 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) + if attacks: + write('\n
') + first_attack = True + for attack in attacks: + if not first_attack: + write('
') + 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)) + 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('
') - write('
') + 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('
') write('') write('\n') @@ -1110,57 +1114,59 @@ class HTMLOutput: write('\n') # Write info about attacks. - write('

%s (damage %s count)

\n' % - (cleantext(_("unit help^Attacks"), quote=False), - HTML_ENTITY_MULTIPLICATION_SIGN)) - write('\n') - write('') attacks = self.get_recursive_attacks(unit) - for attack in attacks: - write('') + if attacks: + write('

%s (damage %s count)

\n' % + (cleantext(_("unit help^Attacks"), quote=False), + HTML_ENTITY_MULTIPLICATION_SIGN)) + write('
\n') + write('') - aid = attack.get_text_val("name") - aname = T(attack, "description") + for attack in attacks: + write('') - icon = attack.get_text_val("icon") - if not icon: - icon = "attacks/%s.png" % aid + aid = attack.get_text_val("name") + aname = T(attack, "description") - 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('' % cleanurl(icon)) + icon = attack.get_text_val("icon") + if not icon: + icon = "attacks/%s.png" % aid - write('' % cleanurl(icon)) - r = T(attack, "range") - write('
%s' % cleantext(_(r), quote=False)) + write('' % cleantext(_(r), quote=False)) - t = T(attack, "type") - write('
%s' % cleantext(_(t), 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('' % '
'.join(s)) - write('') - write('
(image)%s' % cleantext(aname, quote=False)) + 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('(image)%s' % cleantext(aname, 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('%s' % x) + r = T(attack, "range") + write('
%s
%s' % x) - 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('%s
\n') + t = T(attack, "type") + write('
%s' % 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('%s' % '
'.join(s)) + write('') + write('\n') # Write info about resistances. write('

%s

\n' % _("Resistances: ").strip(" :"))