improve character sprites loading

This commit is contained in:
cidoku 2025-06-19 18:23:16 -04:00
parent 6044f350dd
commit f9a11ceeab

View File

@ -331,93 +331,110 @@ class AOCharMovie(QtGui.QLabel):
p_char = p_char.lower() p_char = p_char.lower()
p_emote = p_emote.lower() p_emote = p_emote.lower()
original_path = test_path(
AOpath+"characters/"+p_char+"/"+emote_prefix+p_emote+".gif",
AOpath+"characters/"+p_char+"/"+emote_prefix+"/"+p_emote+".gif",
AOpath+"characters/"+p_char+"/"+p_emote+".gif",
AOpath+"characters/"+p_char+"/(a)"+p_emote+".gif"
)
alt_path = test_path(
AOpath+"characters/"+p_char+"/"+emote_prefix+p_emote+".png",
AOpath+"characters/"+p_char+"/"+emote_prefix+"/"+p_emote+".png",
AOpath+"characters/"+p_char+"/"+p_emote+".png",
AOpath+"characters/"+p_char+"/(a)"+p_emote+".png"
)
apng_path = test_path( apng_path = test_path(
AOpath+"characters/"+p_char+"/"+emote_prefix+p_emote+".apng", AOpath+"characters/"+p_char+"/"+emote_prefix+p_emote+".apng",
AOpath+"characters/"+p_char+"/"+emote_prefix+"/"+p_emote+".apng", AOpath+"characters/"+p_char+"/"+emote_prefix+"/"+p_emote+".apng",
AOpath+"characters/"+p_char+"/"+p_emote+".apng", AOpath+"characters/"+p_char+"/"+p_emote+".apng",
AOpath+"characters/"+p_char+"/(a)"+p_emote+".apng" AOpath+"characters/"+p_char+"/(a)"+p_emote+".apng",
) AOpath+"characters/"+p_char+"/(b)"+p_emote+".apng",
webp_path = test_path( AOpath+"characters/"+p_char+"/(a)/"+p_emote+".apng",
AOpath+"characters/"+p_char+"/"+emote_prefix+p_emote+".webp", AOpath+"characters/"+p_char+"/(b)/"+p_emote+".apng"
AOpath+"characters/"+p_char+"/"+emote_prefix+"/"+p_emote+".webp",
AOpath+"characters/"+p_char+"/"+p_emote+".webp",
AOpath+"characters/"+p_char+"/(a)"+p_emote+".webp"
) )
placeholder_path = AO2XPpath+"themes/default/oldplaceholder.gif" placeholder_path = AO2XPpath+"themes/default/oldplaceholder.gif"
gif_path = ""
img_path = ""
if apng_path: if apng_path:
gif_path = apng_path img_path = apng_path
self.use_pillow = 1 self.use_pillow = 1
else: else:
if ini.read_ini_bool("AO2XP.ini", "General", "download characters"): if ini.read_ini_bool("AO2XP.ini", "General", "download characters"):
url = "base/characters/"+p_char.lower()+"/"+emote_prefix+p_emote.lower()+".apng" url = "base/characters/"+p_char.lower()+"/"+emote_prefix+p_emote.lower()+".apng"
url = url.replace(" ", "%20") url = url.replace(" ", "%20")
thread.start_new_thread(download_thread, (url, apng_path)) thread.start_new_thread(download_thread, (url, apng_path))
png_path = test_path(
AOpath+"characters/"+p_char+"/"+emote_prefix+p_emote+".png",
AOpath+"characters/"+p_char+"/"+emote_prefix+"/"+p_emote+".png",
AOpath+"characters/"+p_char+"/"+p_emote+".png",
AOpath+"characters/"+p_char+"/(a)"+p_emote+".png",
AOpath+"characters/"+p_char+"/(b)"+p_emote+".png",
AOpath+"characters/"+p_char+"/(a)/"+p_emote+".png",
AOpath+"characters/"+p_char+"/(b)/"+p_emote+".png"
)
if webp_path: if png_path:
gif_path = webp_path img_path = png_path
self.use_pillow = 2 self.use_pillow = 0
else: else:
if ini.read_ini_bool("AO2XP.ini", "General", "download characters"): if ini.read_ini_bool("AO2XP.ini", "General", "download characters"):
url = "base/characters/"+p_char.lower()+"/"+p_emote.lower()+".webp" url = "base/characters/"+p_char.lower()+"/"+emote_prefix+p_emote.lower()+".png"
url = url.replace(" ", "%20") url = url.replace(" ", "%20")
thread.start_new_thread(download_thread, (url, webp_path)) thread.start_new_thread(download_thread, (url, alt_path))
if original_path: webp_path = test_path(
gif_path = original_path AOpath+"characters/"+p_char+"/"+emote_prefix+p_emote+".webp",
self.use_pillow = 0 AOpath+"characters/"+p_char+"/"+emote_prefix+"/"+p_emote+".webp",
AOpath+"characters/"+p_char+"/"+p_emote+".webp",
AOpath+"characters/"+p_char+"/(a)"+p_emote+".webp",
AOpath+"characters/"+p_char+"/(b)"+p_emote+".webp",
AOpath+"characters/"+p_char+"/(a)/"+p_emote+".webp",
AOpath+"characters/"+p_char+"/(b)/"+p_emote+".webp"
)
if webp_path:
img_path = webp_path
self.use_pillow = 2
else: else:
if ini.read_ini_bool("AO2XP.ini", "General", "download characters"): if ini.read_ini_bool("AO2XP.ini", "General", "download characters"):
url = "base/characters/"+p_char.lower()+"/"+emote_prefix+p_emote.lower()+".gif" url = "base/characters/"+p_char.lower()+"/"+p_emote.lower()+".webp"
url = url.replace(" ", "%20") url = url.replace(" ", "%20")
thread.start_new_thread(download_thread, (url, original_path)) thread.start_new_thread(download_thread, (url, webp_path))
if alt_path: gif_path = test_path(
gif_path = alt_path AOpath+"characters/"+p_char+"/"+emote_prefix+p_emote+".gif",
AOpath+"characters/"+p_char+"/"+emote_prefix+"/"+p_emote+".gif",
AOpath+"characters/"+p_char+"/"+p_emote+".gif",
AOpath+"characters/"+p_char+"/(a)"+p_emote+".gif",
AOpath+"characters/"+p_char+"/(b)"+p_emote+".gif",
AOpath+"characters/"+p_char+"/(a)/"+p_emote+".gif",
AOpath+"characters/"+p_char+"/(b)/"+p_emote+".gif"
)
if gif_path:
img_path = gif_path
self.use_pillow = 0 self.use_pillow = 0
else: else:
if ini.read_ini_bool("AO2XP.ini", "General", "download characters"): if ini.read_ini_bool("AO2XP.ini", "General", "download characters"):
url = "base/characters/"+p_char.lower()+"/"+emote_prefix+p_emote.lower()+".png" url = "base/characters/"+p_char.lower()+"/"+emote_prefix+p_emote.lower()+".gif"
url = url.replace(" ", "%20") url = url.replace(" ", "%20")
thread.start_new_thread(download_thread, (url, alt_path)) thread.start_new_thread(download_thread, (url, gif_path))
if exists(placeholder_path): if exists(placeholder_path):
gif_path = placeholder_path img_path = placeholder_path
print "[debug] Sprite not found: ", p_char, p_emote, emote_prefix, original_path, alt_path, apng_path print "[debug] Sprite not found: ", p_char, p_emote, emote_prefix, gif_path, alt_path, apng_path
else: else:
gif_path = "" img_path = ""
self.use_pillow = 0 self.use_pillow = 0
if gif_path == "": if img_path == "":
gif_path = self.prev_gif_path img_path = self.prev_gif_path
# Second check just in case # Second check just in case
if gif_path == "": if img_path == "":
if exists(placeholder_path): if exists(placeholder_path):
gif_path = placeholder_path img_path = placeholder_path
print "[debug] Sprite not found: ", p_char, p_emote, emote_prefix, original_path, alt_path, apng_path print "[debug] Sprite not found: ", p_char, p_emote, emote_prefix, gif_path, alt_path, apng_path
else: else:
gif_path = "" img_path = ""
else: else:
self.prev_gif_path = gif_path self.prev_gif_path = img_path
#print "[debug]", p_char, emote_prefix, p_emote, "(!) path is null!" if gif_path == "" else gif_path #print "[debug]", p_char, emote_prefix, p_emote, "(!) path is null!" if img_path == "" else img_path
if not self.use_pillow: if not self.use_pillow:
self.m_movie.stop() self.m_movie.stop()
self.m_movie.setFileName(gif_path) self.m_movie.setFileName(img_path)
self.m_movie.start() self.m_movie.start()
elif self.use_pillow == 1: # apng elif self.use_pillow == 1: # apng
self.pillow_frames = images.load_apng(apng_path) self.pillow_frames = images.load_apng(apng_path)