mirror of
https://github.com/minetest-mods/skinsdb.git
synced 2024-12-23 07:50:18 +01:00
Merge pull request #2 from bell07/pr_private_skins
Rework private skins handling
This commit is contained in:
commit
c6ee5c2d5b
20
API.md
20
API.md
@ -16,12 +16,14 @@ skins.update_player_skin(player)
|
||||
```
|
||||
|
||||
## skins.get_skinlist(assignment, select_unassigned)
|
||||
Get a list of skin objects matching to the assignment.
|
||||
Obsolete - use get_skinlist_for_player() or get_skinlist_with_meta() instead
|
||||
|
||||
Supported assignments:
|
||||
- "player:"..playername - Skins directly assigned to a player
|
||||
## skins.get_skinlist_for_player(playername)
|
||||
Get all allowed skins for player. All public and all player's private skins. If playername not given only public skins returned
|
||||
|
||||
select_unassigned - Select all skins without assignment too (usually the "character_*" skins)
|
||||
## skins.get_skinlist_with_meta(key, value)
|
||||
Get all skins with metadata key is set to value. Example:
|
||||
skins.get_skinlist_with_meta("playername", playername) - Get all private skins (w.o. public) for playername
|
||||
|
||||
|
||||
## skins.new(key, object)
|
||||
@ -68,11 +70,17 @@ Add a meta information to the skin object
|
||||
Note: the information is not stored, therefore should be filled each time during skins registration
|
||||
|
||||
## skin:get_meta(key)
|
||||
The next metadata keys are usually filled
|
||||
The next metadata keys are filled or/and used interally in skinsdb framework
|
||||
- name - A name for the skin
|
||||
- author - The skin author
|
||||
- license - THe skin texture license
|
||||
- assignment - is "player:playername" in case the skin is assigned to be privat for a player
|
||||
- assignment - (obsolete) is "player:playername" in case the skin is assigned to be privat for a player
|
||||
- playername - Player assignment for private skin. Set false for skins not usable by all players (like NPC-Skins), true or nothing for all player skins
|
||||
- in_inventory_list - If set to false the skin is not visible in inventory skins selection but can be still applied to the player
|
||||
- _sort_id - Thi skins lists are sorted by this field for output (internal key)
|
||||
|
||||
## skin:get_meta_string(key)
|
||||
Same as get_meta() but does return "" instead of nil if the meta key does not exists
|
||||
|
||||
## skin:is_applicable_for_player(playername)
|
||||
Returns whether this skin is applicable for player "playername" or not, like private skins
|
||||
|
5
api.lua
5
api.lua
@ -7,19 +7,20 @@ end
|
||||
-- Assign skin to player
|
||||
function skins.assign_player_skin(player, skin)
|
||||
local skin_obj
|
||||
local skin_key
|
||||
if type(skin) == "string" then
|
||||
skin_obj = skins.get(skin) or skins.get(skins.default)
|
||||
else
|
||||
skin_obj = skin
|
||||
end
|
||||
skin_key = skin_obj:get_key()
|
||||
|
||||
if skin_obj:is_applicable_for_player(player:get_player_name()) then
|
||||
local skin_key = skin_obj:get_key()
|
||||
if skin_key == skins.default then
|
||||
skin_key = ""
|
||||
end
|
||||
player:set_attribute("skinsdb:skin_key", skin_key)
|
||||
end
|
||||
end
|
||||
|
||||
-- update visuals
|
||||
function skins.update_player_skin(player)
|
||||
|
@ -84,7 +84,7 @@ sfinv.register_page("skins:overview", {
|
||||
title = "Skins",
|
||||
get = function(self, player, context)
|
||||
-- collect skins data
|
||||
context.skins_list = skins.get_skinlist("player:"..player:get_player_name(), true)
|
||||
context.skins_list = skins.get_skinlist_for_player(player:get_player_name())
|
||||
context.total_pages = 1
|
||||
for i, skin in ipairs(context.skins_list ) do
|
||||
local page = math.floor((i-1) / 16)+1
|
||||
|
@ -69,3 +69,10 @@ function skin_class:set_skin(player)
|
||||
textures = {self:get_texture()},
|
||||
})
|
||||
end
|
||||
|
||||
function skin_class:is_applicable_for_player(playername)
|
||||
local assigned_player = self:get_meta("playername")
|
||||
return assigned_player == nil or
|
||||
assigned_player == playername or
|
||||
assigned_player == true
|
||||
end
|
||||
|
36
skinlist.lua
36
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,28 @@ 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) and skin:get_meta("in_inventory_list") ~= false 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
|
||||
|
||||
-- Get skinlist selected by metadata
|
||||
function skins.get_skinlist_with_meta(key, value)
|
||||
assert(key, "key parameter for skins.get_skinlist_with_meta() missed")
|
||||
local skinslist = {}
|
||||
for _, skin in pairs(skins.meta) do
|
||||
if skin:get_meta(key) == value 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
|
||||
|
@ -7,7 +7,7 @@ end
|
||||
|
||||
local dropdown_values = {}
|
||||
local skins_reftab = {}
|
||||
local skins_list = skins.get_skinlist()
|
||||
local skins_list = skins.get_skinlist_for_player() --public only
|
||||
unified_inventory.register_page("skins", {
|
||||
get_formspec = function(player)
|
||||
local name = player:get_player_name()
|
||||
|
Loading…
Reference in New Issue
Block a user