From 9e84763478218430c52ee925bf1099ef4e0276f7 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 5 Mar 2019 14:19:57 +0100 Subject: [PATCH] mcl_skins: USe fallback if no preview img --- mods/PLAYER/mcl_skins/init.lua | 23 +++++++++++++++--- .../mcl_skins/textures/player_dummy.png | Bin 0 -> 982 bytes 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 mods/PLAYER/mcl_skins/textures/player_dummy.png diff --git a/mods/PLAYER/mcl_skins/init.lua b/mods/PLAYER/mcl_skins/init.lua index d8d4ebba..53e73f97 100644 --- a/mods/PLAYER/mcl_skins/init.lua +++ b/mods/PLAYER/mcl_skins/init.lua @@ -1,7 +1,7 @@ -- Skins for MineClone 2 mcl_skins = { - skins = {}, list = {}, previews = {}, meta = {}, + skins = {}, list = {}, previews = {}, meta = {}, has_preview = {}, modpath = minetest.get_modpath("mcl_skins"), skin_count = 0, -- counter of _custom_ skins (all skins except character.png) } @@ -18,10 +18,12 @@ while true do if id == 0 then skin = "character" + mcl_skins.has_preview[id] = true else skin = "character_" .. id + local preview = "player_" .. id - -- does skin file exist ? + -- Does skin file exist? f = io.open(mcl_skins.modpath .. "/textures/" .. skin .. ".png") -- escape loop if not found @@ -29,6 +31,16 @@ while true do break end f:close() + + -- Does skin preview file exist? + local file_preview = io.open(mcl_skins.modpath .. "/textures/" .. preview .. ".png") + if file_preview == nil then + minetest.log("warning", "[mcl_skins] Player skin #"..id.." does not have preview image (player_"..id..".png)") + mcl_skins.has_preview[id] = false + else + mcl_skins.has_preview[id] = true + file_preview:close() + end end mcl_skins.list[id] = skin @@ -78,7 +90,12 @@ mcl_skins.set_player_skin = function(player, skin_id) preview = "player" else skin = "character_" .. tostring(skin_id) - preview = "player_" .. tostring(skin_id) + if mcl_skins.has_preview[skin_id] then + preview = "player_" .. tostring(skin_id) + else + -- Fallback preview image if preview image is missing + preview = "player_dummy" + end end skin_file = skin .. ".png" mcl_skins.skins[playername] = skin diff --git a/mods/PLAYER/mcl_skins/textures/player_dummy.png b/mods/PLAYER/mcl_skins/textures/player_dummy.png new file mode 100644 index 0000000000000000000000000000000000000000..d1f7dc20aa3dd99924ce8f2f65a2d010c90a9246 GIT binary patch literal 982 zcmeAS@N?(olHy`uVBq!ia0y~yU=UznU{K&-V_;yA?)-6vfq_|~DkP#LD6w3jpeR2r zGbdG{q_QAYA+;hije()!*4wGE)0EYDTJJ}?P79bMAar`6hK0KIjHl0?9@c+XdHdyY zLu|mN9SwGk&cDBw^Vcs7_#&}r*77-*+JuVF#9a9JRwvy%dd~T;n_{i_za5w^FQMkB z{X9GC^!@|uwlj)NudUz0zS{fvbb;8`^ofR_U+CM%I~`g+_geLd?3m8-+mZ3>yvsW6 z_q#hA@U_k>c%Y^tJxw4py*+L~b4>PklOiUZ>{D$J zNX$E$V>bmTabU&g|=Y|lwam!?cwTIen++`VktnKQc4g&$wMI(hc) z=ILi53tBV%ZaRINQ>-~-i^Hyjl16t;>-U?E$9~^(`(5=tZ`WT}BDOBex|+T2=>umz zng7bNVtn?W0;Nos1a1a&IIdbde zsdsMgw%=(wmS6aI{fXAbcj_lv8}lYsKmFErEAW|pmyg3^k-iyumkKv-J!EG$cW<`s z?+vduWxd%kaoX3Nxl7k>d|3CP`?mR!L!Z6uM7iId-DW4q{r&f!x}Ln;ALi}1$&oIW?*38EbxddW?;}$24TjErS@eE3=Hfgp1!W^kC|C{IVGO) z{8VCKV6gXeaSZV|o@`^hzK>BdXV3rt_RMk*)}J`haV9-!fk2Oxfdo&2qR9If46%PR s6#AqLVm>idNt#Eg^+_2x@iH*<<_YfF%zR#gfq{X+)78&qol`;+0O?W70RR91 literal 0 HcmV?d00001