wmlunits: Use transparent/ portraits where available, and omit sprite bg

We don't need the upscaled sprite background behind portraits, whether
they are transparent or not (for transparent portraits it just looks
bad).

[ci skip]
This commit is contained in:
Ignacio R. Morelle 2017-08-29 17:25:15 -03:00
parent 863f31c628
commit 290cb4c2d2
2 changed files with 20 additions and 10 deletions

View file

@ -50,7 +50,7 @@ class ImageCollector:
self.binary_paths_per_addon[addon] = []
self.binary_paths_per_addon[addon].append(path)
def _find_image(self, addon, name):
def _find_image(self, addon, name, check_transparent):
tilde = name.find("~")
if tilde >= 0:
name = name[:tilde]
@ -62,21 +62,29 @@ class ImageCollector:
bases.append(os.path.join(self.datadir, path, idir))
bases.append(os.path.join(self.userdir, path, idir))
bases = [os.path.join("%s" % base, name) for base in bases]
if not check_transparent:
bases = [os.path.join("%s" % base, name) for base in bases]
else:
dirname, filename = os.path.split(name)
new_bases = []
for base in bases:
new_bases.append(os.path.join("%s" % base, dirname, "transparent", filename))
new_bases.append(os.path.join("%s" % base, name))
bases = new_bases
for ipath in bases:
if os.path.exists(ipath):
return ipath, bases
return None, bases
def add_image_check(self, addon, name, no_tc=False):
def add_image_check(self, addon, name, no_tc=False, check_transparent=False):
if (addon, name) in self.images_by_addon_name:
image = self.images_by_addon_name[(addon, name)]
if addon not in image.addons:
image.addons.add(addon)
return image
ipath, bases = self._find_image(addon, name)
ipath, bases = self._find_image(addon, name, check_transparent)
if ipath in self.images_by_ipath:
image = self.images_by_ipath[ipath]
if addon not in image.addons:
@ -115,8 +123,8 @@ class ImageCollector:
return image
def add_image(self, addon, path, no_tc=False):
image = self.add_image_check(addon, path, no_tc)
def add_image(self, addon, path, no_tc=False, check_transparent=False):
image = self.add_image_check(addon, path, no_tc, check_transparent)
return image.id_name
def copy_and_color_images(self, target_path):

View file

@ -721,7 +721,10 @@ class HTMLOutput:
picname = icpic.id_name
image = os.path.join(PICS_LOCATION, picname)
if portrait:
picname = image_collector.add_image(self.addon, portrait, no_tc=True)
picname = image_collector.add_image(self.addon,
portrait,
no_tc=True,
check_transparent=True)
portrait = os.path.join(PICS_LOCATION, picname)
return image, portrait
@ -1043,12 +1046,11 @@ class HTMLOutput:
simage = image
sportrait = portrait
style = "background-image:url('%s');" % cleanurl(simage)
write('<div class="portrait">')
write('<div style="%s">&nbsp;</div>' % style)
if portrait:
write('<img src="%s" alt="(portrait)" />\n' % cleanurl(sportrait))
else:
write('<div style="background-image:url(\'%s\')">&nbsp;</div>' % cleanurl(simage))
write('</div>')
write('</div>\n')