wmlunits: Make base_unit work recursively...
...(one unit in EE needed that) and write lots of verbose error about missing attack icons :P
This commit is contained in:
parent
01bfe0c1b6
commit
846688cbe6
2 changed files with 32 additions and 24 deletions
|
@ -79,7 +79,6 @@ class ImageCollector:
|
|||
bases = [os.path.join(self.datadir, "core/images")]
|
||||
else:
|
||||
bases = [os.path.join(self.datadir, "core/images")]
|
||||
bases += [os.path.join(self.datadir, "core/images/attacks")]
|
||||
binpaths = self.pathes_per_campaign.get(c, [])
|
||||
binpaths.reverse()
|
||||
for x in binpaths:
|
||||
|
@ -93,11 +92,12 @@ class ImageCollector:
|
|||
if os.path.exists(ipath): return ipath, None
|
||||
return None, bases
|
||||
|
||||
def add_image(self, campaign, path):
|
||||
if (campaign, path) in self.notfound: return self.notfound[(campaign, path)]
|
||||
def add_image_check(self, campaign, path):
|
||||
if (campaign, path) in self.notfound:
|
||||
return self.notfound[(campaign, path)], True
|
||||
ipath, error = self.find_image(path, campaign)
|
||||
if ipath in self.ipathes:
|
||||
return self.ipathes[ipath]
|
||||
return self.ipathes[ipath], False
|
||||
|
||||
name = "%05d_" % self.id
|
||||
name += os.path.basename(path)
|
||||
|
@ -106,8 +106,13 @@ class ImageCollector:
|
|||
self.images[name] = ipath, path, campaign, error
|
||||
if ipath:
|
||||
self.ipathes[ipath] = name
|
||||
return name, False
|
||||
else:
|
||||
self.notfound[(campaign, path)] = name
|
||||
return name, True
|
||||
|
||||
def add_image(self, campaign, path):
|
||||
name, error = self.add_image_check(campaign, path)
|
||||
return name
|
||||
|
||||
def copy_and_color_images(self, target_path):
|
||||
|
|
|
@ -497,8 +497,6 @@ class HTMLOutput:
|
|||
write(html_header % {"path" : "../"})
|
||||
self.write_navbar()
|
||||
|
||||
base_unit = self.wesnoth.get_base_unit(unit)
|
||||
|
||||
# Write unit name, picture and description.
|
||||
uid = unit.get_text_val("id")
|
||||
uname = self.wesnoth.get_unit_value(unit, "name")
|
||||
|
@ -599,22 +597,27 @@ class HTMLOutput:
|
|||
if isinstance(c, wmldata.DataText):
|
||||
copy_to.set_text_val(c.name, c.data)
|
||||
|
||||
# Use attacks of base_units as base, if we have one.
|
||||
attacks = []
|
||||
if base_unit:
|
||||
attacks = base_unit.get_all("attack")
|
||||
for i, attack in enumerate(unit.get_all("attack")):
|
||||
aid = attack.get_text_val("name")
|
||||
if aid:
|
||||
for already in attacks:
|
||||
if already.get_text_val("name") == aid:
|
||||
copy_attributes(attack, already)
|
||||
break
|
||||
def get_recursive_attacks(this_unit):
|
||||
# Use attacks of base_units as base, if we have one.
|
||||
base_unit = self.wesnoth.get_base_unit(this_unit)
|
||||
attacks = []
|
||||
if base_unit:
|
||||
attacks = get_recursive_attacks(base_unit)
|
||||
|
||||
for i, attack in enumerate(this_unit.get_all("attack")):
|
||||
aid = attack.get_text_val("name")
|
||||
if aid:
|
||||
for already in attacks:
|
||||
if already.get_text_val("name") == aid:
|
||||
copy_attributes(attack, already)
|
||||
break
|
||||
else:
|
||||
attacks.append(attack)
|
||||
else:
|
||||
attacks.append(attack)
|
||||
else:
|
||||
copy_attributes(attack, attacks[i])
|
||||
copy_attributes(attack, attacks[i])
|
||||
return attacks
|
||||
|
||||
attacks = get_recursive_attacks(unit)
|
||||
for attack in attacks:
|
||||
write("<tr>")
|
||||
|
||||
|
@ -624,11 +627,11 @@ class HTMLOutput:
|
|||
icon = attack.get_text_val("icon")
|
||||
if not icon:
|
||||
icon = "attacks/%s.png" % aid
|
||||
|
||||
if not icon:
|
||||
sys.stderr.write("Warning: " + uid + " has attack icon.\n")
|
||||
|
||||
picname = image_collector.add_image(unit.campaign, icon)
|
||||
picname, error = image_collector.add_image_check(unit.campaign, icon)
|
||||
if error:
|
||||
sys.stderr.write("Error: No attack icon '%s' found for '%s'.\n" % (
|
||||
icon, uid))
|
||||
icon = os.path.join("../pics", picname)
|
||||
write("<td><img src=\"%s\" alt=\"(image)\"/></td>" % icon)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue