diff --git a/config.lua b/config.lua index caa25bc..f7cf736 100644 --- a/config.lua +++ b/config.lua @@ -172,3 +172,61 @@ yl_speak_up.standard_text_if_action_failed_too_often = "You have tried so many t yl_speak_up.standard_text_if_action_repeated_too_soon = "I don't have infinite ressources. If you lost ".. "something I gave you - come back later and we may talk again.\n$TEXT$" + +-- reading textures for your land NPCs +local function read_skins_and_capes_from_folders(races) + local temp = {} + + -- get the files out of modpath + local mp_list = minetest.get_dir_list(yl_speak_up.modpath .. DIR_DELIM .. "textures", false) + + -- get the files out of worlddir + local wp_list = + minetest.get_dir_list( + yl_speak_up.worldpath .. DIR_DELIM .. "worldmods" .. DIR_DELIM .. "yl_npc" .. DIR_DELIM .. "textures", + false + ) + + -- Let's join both lists. + table.insert_all(temp, mp_list) + table.insert_all(temp, wp_list) + + --[[ Let's see if the files are the ones we want. Format is + yl_npc_main_name.png <-- Those are the ones we want + yl_npc_cape_name.png + yl_npc_item_name.png + ]]-- + + for _, race in ipairs(races) do + if(not(yl_speak_up.mob_skins["yl_speak_up:"..race])) then + yl_speak_up.mob_skins["yl_speak_up:"..race] = {} + end + if(not(yl_speak_up.mob_capes["yl_speak_up:"..race])) then + yl_speak_up.mob_capes["yl_speak_up:"..race] = {} + end + end + + for _, v in pairs(temp) do + local s = string.split(v, "_") + if s[1] == "yl" and s[2] == "npc" and s[3] == "main" then + for i, race in ipairs(races) do + table.insert(yl_speak_up.mob_skins["yl_speak_up:"..race], v) + end + end + if s[1] == "yl" and s[2] == "npc" and s[3] == "cape" then + for i, race in ipairs(races) do + table.insert(yl_speak_up.mob_capes["yl_speak_up:"..race], v) + end + end + end + + for _, race in ipairs(races) do + if(#yl_speak_up.mob_skins["yl_speak_up:"..race] < 1) then + yl_speak_up.mob_skins["yl_speak_up:"..race] = {"yl_speak_up_main_default.png"} + end + if(#yl_speak_up.mob_capes["yl_speak_up:"..race] < 1) then + yl_speak_up.mob_capes["yl_speak_up:"..race] = {"yl_npc_cape_default.png"} + end + end +end +read_skins_and_capes_from_folders({"dwarf","elf","goblin","human","npc","orc"})