add support for names in skin texture file (character_Skinname, player_playername_skinname)

This commit is contained in:
Alexander Weber 2018-07-16 20:42:54 +02:00
parent 0cb00a3a9b
commit fa5b3029fd
2 changed files with 41 additions and 31 deletions

View File

@ -2,44 +2,50 @@
local skins_dir_list = minetest.get_dir_list(skins.modpath.."/textures") local skins_dir_list = minetest.get_dir_list(skins.modpath.."/textures")
for _, fn in pairs(skins_dir_list) do for _, fn in pairs(skins_dir_list) do
local name, sort_id, assignment, is_preview, playername
local nameparts = string.gsub(fn, "[.]", "_"):split("_") local nameparts = string.gsub(fn, "[.]", "_"):split("_")
local name, sort_id, assignment, is_preview, playername -- check allowed prefix and file extension
if nameparts[1] == "character" then if (nameparts[1] == 'player' or nameparts[1] == 'character') and
if tonumber(nameparts[2]) == nil then --default skin character.png nameparts[#nameparts]:lower() == 'png' then
sort_id = 5000
name = "character" -- cut filename extension
is_preview = (nameparts[2] == "preview") table.remove(nameparts, #nameparts)
else
sort_id = tonumber(nameparts[2])+5000 -- check preview suffix
name = "character_"..nameparts[2] if nameparts[#nameparts] == 'preview' then
is_preview = (nameparts[3] == "preview") is_preview = true
end table.remove(nameparts, #nameparts)
elseif nameparts[1] == "player" then end
assignment = "player:"..nameparts[2] --TODO: remove all assignment handling
name = "player_"..nameparts[2] -- Build technically skin name
playername = nameparts[2] name = table.concat(nameparts, '_')
if tonumber(nameparts[3]) then
sort_id = tonumber(nameparts[3]) -- Handle metadata from file name
is_preview = (nameparts[4] == "preview") if not is_preview then
name = name.."_"..nameparts[3] -- Get player name
else if nameparts[1] == "player" then
sort_id = 1 playername = nameparts[2]
is_preview = (nameparts[3] == "preview") table.remove(nameparts, 1)
end sort_id = 0
end else
sort_id = 5000
end
-- Get sort index
if tonumber(nameparts[#nameparts]) then
sort_id = sort_id + nameparts[#nameparts]
end
end
if name then
local skin_obj = skins.get(name) or skins.new(name) local skin_obj = skins.get(name) or skins.new(name)
if is_preview then if is_preview then
skin_obj:set_preview(fn) skin_obj:set_preview(fn)
else else
skin_obj:set_texture(fn) skin_obj:set_texture(fn)
skin_obj:set_meta("_sort_id", sort_id) skin_obj:set_meta("_sort_id", sort_id)
if assignment then
skin_obj:set_meta("assignment", assignment)
end
if playername then if playername then
skin_obj:set_meta("assignment", "player:"..playername)
skin_obj:set_meta("playername", playername) skin_obj:set_meta("playername", playername)
end end
local file = io.open(skins.modpath.."/textures/"..fn, "r") local file = io.open(skins.modpath.."/textures/"..fn, "r")
@ -53,7 +59,11 @@ for _, fn in pairs(skins_dir_list) do
skin_obj:set_meta("author", data[2]) skin_obj:set_meta("author", data[2])
skin_obj:set_meta("license", data[3]) skin_obj:set_meta("license", data[3])
else else
skin_obj:set_meta("name", name) -- remove player / character prefix if further naming given
if nameparts[2] and not tonumber(nameparts[2]) then
table.remove(nameparts, 1)
end
skin_obj:set_meta("name", table.concat(nameparts, ' '))
end end
end end
end end

View File

@ -1,4 +1,4 @@
In this folder the skin files could be placed according the next file naming convention In this folder the skin files could be placed according the next file naming convention
character_[number].png - Public skin, available for all users character_[number-or-name].png - Public skin, available for all users
player_[nick].png or player_[nick]_[number].png - one or multiple private skins for player "nick" player_[nick].png or player_[nick]_[number-or-name].png - one or multiple private skins for player "nick"
*_preview.png - Preview files for public and private skins *_preview.png - Preview files for public and private skins