diff options
author | Alexander Weber <web.alexander@web.de> | 2018-01-07 14:50:22 +0100 |
---|---|---|
committer | Alexander Weber <web.alexander@web.de> | 2018-01-07 14:50:22 +0100 |
commit | 7df6363aa0247068205a09815721164813849b19 (patch) | |
tree | 838b88f355c0c50aacea7fc7e00589a9eb9f9886 /skinlist.lua | |
parent | 71e05bbd6863ca91db16c386c671da77e8f9e9eb (diff) |
Rework private skins handling
-add skin:is_applicable_for_player(playername) method
- hide private skins in unified_inventory since not supported
- check player assignment in skins.assign_player_skin() + inherited to skins.set_player_skin()
Diffstat (limited to 'skinlist.lua')
-rw-r--r-- | skinlist.lua | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/skinlist.lua b/skinlist.lua index 5d29fe4..889b531 100644 --- a/skinlist.lua +++ b/skinlist.lua @@ -4,7 +4,7 @@ local skins_dir_list = minetest.get_dir_list(skins.modpath.."/textures") for _, fn in pairs(skins_dir_list) do local nameparts = string.gsub(fn, "[.]", "_"):split("_") - local name, sort_id, assignment, is_preview + local name, sort_id, assignment, is_preview, playername if nameparts[1] == "character" then if tonumber(nameparts[2]) == nil then --default skin character.png sort_id = 5000 @@ -16,8 +16,9 @@ for _, fn in pairs(skins_dir_list) do is_preview = (nameparts[3] == "preview") end elseif nameparts[1] == "player" then - assignment = "player:"..nameparts[2] + assignment = "player:"..nameparts[2] --TODO: remove all assignment handling name = "player_"..nameparts[2] + playername = nameparts[2] if tonumber(nameparts[3]) then sort_id = tonumber(nameparts[3]) is_preview = (nameparts[4] == "preview") @@ -38,6 +39,9 @@ for _, fn in pairs(skins_dir_list) do if assignment then skin_obj:set_meta("assignment", assignment) end + if playername then + skin_obj:set_meta("playername", playername) + end local file = io.open(skins.modpath.."/meta/"..name..".txt", "r") if file then local data = string.split(file:read("*all"), "\n", 3) @@ -52,8 +56,9 @@ for _, fn in pairs(skins_dir_list) do end end --- get skinlist. If assignment given ("mod:wardrobe" or "player:bell07") select skins matches the assignment. select_unassigned selects the skins without any assignment too +-- (obsolete) get skinlist. If assignment given ("mod:wardrobe" or "player:bell07") select skins matches the assignment. select_unassigned selects the skins without any assignment too function skins.get_skinlist(assignment, select_unassigned) + minetest.log("deprecated", "skins.get_skinlist() is deprecated. Use skins.get_skinlist_for_player() instead") local skinslist = {} for _, skin in pairs(skins.meta) do if not assignment or @@ -65,3 +70,15 @@ function skins.get_skinlist(assignment, select_unassigned) table.sort(skinslist, function(a,b) return a:get_meta("_sort_id") < b:get_meta("_sort_id") end) return skinslist end + +-- Get skinlist for player. If no player given, public skins only selected +function skins.get_skinlist_for_player(playername) + local skinslist = {} + for _, skin in pairs(skins.meta) do + if skin:is_applicable_for_player(playername) then + table.insert(skinslist, skin) + end + end + table.sort(skinslist, function(a,b) return a:get_meta("_sort_id") < b:get_meta("_sort_id") end) + return skinslist +end |