mirror of
https://github.com/minetest-mods/skinsdb.git
synced 2024-12-22 23:40:18 +01:00
finished work on private player skins support
This commit is contained in:
parent
50e6c9e2d0
commit
920061c0f1
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,4 @@
|
|||||||
textures/character_*.png
|
textures/character_*.png
|
||||||
|
textures/player_*.png
|
||||||
meta/character_*.txt
|
meta/character_*.txt
|
||||||
|
meta/player_*.txt
|
||||||
|
@ -1 +0,0 @@
|
|||||||
Please run the update_from_db.py script to update the skins.
|
|
5
meta/readme.txt
Normal file
5
meta/readme.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
For each skin in textures folder a metadata file can be applied with "txt" suffilx. See character_1.txt for skin character_1.png for reference.
|
||||||
|
The file contains:
|
||||||
|
Skin name
|
||||||
|
Author
|
||||||
|
License
|
@ -81,7 +81,7 @@ sfinv.register_page("skins:overview", {
|
|||||||
title = "Skins",
|
title = "Skins",
|
||||||
get = function(self, player, context)
|
get = function(self, player, context)
|
||||||
-- collect skins data
|
-- collect skins data
|
||||||
context.skins_list = skins.get_skinlist()
|
context.skins_list = skins.get_skinlist("player:"..player:get_player_name(), true)
|
||||||
context.total_pages = 1
|
context.total_pages = 1
|
||||||
for i, skin in ipairs(context.skins_list ) do
|
for i, skin in ipairs(context.skins_list ) do
|
||||||
local page = math.floor((i-1) / 16)+1
|
local page = math.floor((i-1) / 16)+1
|
||||||
|
45
skinlist.lua
45
skinlist.lua
@ -3,42 +3,65 @@ local skins_dir_list = minetest.get_dir_list(skins.modpath.."/textures")
|
|||||||
local unsorted_skinslist = {}
|
local unsorted_skinslist = {}
|
||||||
local sorted_skinslist
|
local sorted_skinslist
|
||||||
for _, fn in pairs(skins_dir_list) do
|
for _, fn in pairs(skins_dir_list) do
|
||||||
if fn:find("^character_") then
|
local nameparts = string.gsub(fn, "[.]", "_"):split("_")
|
||||||
nameparts = string.gsub(fn, "[.]", "_"):split("_")
|
|
||||||
local id = nameparts[2]
|
local name, sort_id, assignment, is_preview
|
||||||
local name = "character_"..id
|
if nameparts[1] == "character" then
|
||||||
|
sort_id = tonumber(nameparts[2])+5000
|
||||||
|
name = "character_"..nameparts[2]
|
||||||
|
is_preview = (nameparts[3] == "preview")
|
||||||
|
elseif nameparts[1] == "player" then
|
||||||
|
assignment = "player:"..nameparts[2]
|
||||||
|
name = "player_"..nameparts[2]
|
||||||
|
if tonumber(nameparts[3]) then
|
||||||
|
sort_id = tonumber(nameparts[3])
|
||||||
|
is_preview = (nameparts[4] == "preview")
|
||||||
|
name = name.."_"..nameparts[3]
|
||||||
|
else
|
||||||
|
sort_id = 1
|
||||||
|
is_preview = (nameparts[3] == "preview")
|
||||||
|
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 nameparts[3] == "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_meta("_sort_id", sort_id)
|
||||||
|
if assignment then
|
||||||
|
skin_obj:set_meta("assignment", assignment)
|
||||||
|
end
|
||||||
local file = io.open(skins.modpath.."/meta/"..name..".txt", "r")
|
local file = io.open(skins.modpath.."/meta/"..name..".txt", "r")
|
||||||
if file then
|
if file then
|
||||||
local data = string.split(file:read("*all"), "\n", 3)
|
local data = string.split(file:read("*all"), "\n", 3)
|
||||||
file:close()
|
file:close()
|
||||||
skin_obj:set_texture(fn)
|
|
||||||
skin_obj:set_meta("_sort_id", tonumber(id))
|
|
||||||
skin_obj:set_meta("name", data[1])
|
skin_obj:set_meta("name", data[1])
|
||||||
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
|
||||||
|
skin_obj:set_meta("name", name)
|
||||||
end
|
end
|
||||||
table.insert(unsorted_skinslist, skin_obj)
|
table.insert(unsorted_skinslist, skin_obj)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- get skinlist. listname not full implemented at the time: could be "mod:wardrobe" or "player:bell07" in feature
|
-- 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(listname)
|
function skins.get_skinlist(assignment, select_unassigned)
|
||||||
-- sort on demand
|
-- sort on demand
|
||||||
if not sorted_skinslist then
|
if not sorted_skinslist then
|
||||||
table.sort(unsorted_skinslist, function(a,b) return a:get_meta("_sort_id") < b:get_meta("_sort_id") end)
|
table.sort(unsorted_skinslist, function(a,b) return a:get_meta("_sort_id") < b:get_meta("_sort_id") end)
|
||||||
sorted_skinslist = unsorted_skinslist
|
sorted_skinslist = unsorted_skinslist
|
||||||
end
|
end
|
||||||
if not listname then
|
if not assignment then
|
||||||
return sorted_skinslist
|
return sorted_skinslist
|
||||||
else
|
else
|
||||||
local ret = {}
|
local ret = {}
|
||||||
for _, skin in ipairs(sorted_skinslist) do
|
for _, skin in ipairs(sorted_skinslist) do
|
||||||
if skin:get_meta(listname) then
|
if assignment == skin:get_meta("assignment") or
|
||||||
|
(select_unassigned and skin:get_meta("assignment") == nil) then
|
||||||
table.insert(ret, skin)
|
table.insert(ret, skin)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
4
textures/readme.txt
Normal file
4
textures/readme.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
In this folder the skin files could be placed according the next file naming convention
|
||||||
|
character_[number].png - Public skin, available for all users
|
||||||
|
player_[nick].png or player_[nick]_[number].png - one or multiple private skins for player "nick"
|
||||||
|
*_preview.png - Preview files for public and private skins
|
Loading…
Reference in New Issue
Block a user