add skins - player skin manager for sfinv

This commit is contained in:
Alexander Weber 2020-05-25 07:47:31 +02:00
parent 9c8b220ddb
commit a7c395abc6
10 changed files with 134 additions and 0 deletions

12
mods/skins/README.txt Normal file
View file

@ -0,0 +1,12 @@
Minetest Game mod: skins
========================
See license.txt for license information.
Authors of source code
----------------------
Tenplus1 (MIT) based on code by Zeg9 (WTFPL)
paramat (MIT)
Authors of media (textures)
---------------------------
TODO

81
mods/skins/init.lua Normal file
View file

@ -0,0 +1,81 @@
-- Skin selection page
local skins_formspec_main = function(name, context)
local formspec = "label[0.0,1.5;" .. "Select Player Skin:" .. "]"
.. "textlist[0.0,2.0;5.8,6.7;skins_set;"
local skins_list = {}
context.skins_list = skins_list
for _, skin in pairs(player_api.registered_skins) do
if skin.in_inventory_list ~= false and
(not skin.playername or (name and skin.playername:lower() == name:lower())) then
table.insert(skins_list, skin)
end
end
table.sort(skins_list, function(a,b) return tostring(a.sort_id or a.description or a.name or "") <
tostring(b.sort_id or b.description or b.name or "") end)
local current_skin_name = player_api.get_skin(minetest.get_player_by_name(name))
local selected_skin = player_api.registered_skins[current_skin_name]
local selected = 1
for i = 1, #skins_list do
local skin = skins_list[i]
formspec = formspec .. (skin.description or skin.name)
if i < #skins_list then
formspec = formspec .. ","
end
if skin.name == current_skin_name then
selected = i
end
end
formspec = formspec .. ";" .. selected .. ";false]"
if selected_skin then
if selected_skin.description then
formspec = formspec .. "label[0.0,0.0;" .. "Current skin: " .. selected_skin.description .. "]"
end
if selected_skin.author then
formspec = formspec .. "label[0.0,0.5;" .. "Author: " .. selected_skin.author .. "]"
end
if selected_skin.license then
formspec = formspec .. "label[0.0,1;" .. "License: " .. selected_skin.license .. "]"
end
end
return formspec
end
-- Register sfinv tab
local formspec_size_and_pos = table.concat({
"size[6.0,8.6]",
"position[0.05,0.5]",
"anchor[0.0,0.5]",
"bgcolor[#00000000;false]",
"background[5,5;1,1;gui_formbg.png;true]"
},"")
sfinv.register_page("skins:skins", {
title = "Skins",
get = function(self, player, context)
local name = player:get_player_name()
return sfinv.make_formspec(player, context, skins_formspec_main(name, context),
false, formspec_size_and_pos)
end,
on_player_receive_fields = function(self, player, context, fields)
local event = minetest.explode_textlist_event(fields["skins_set"])
if event.type == "CHG" then
local selected_skin = context.skins_list[event.index]
if selected_skin then
player_api.set_skin(player, selected_skin.name)
end
end
end,
})
player_api.register_on_skin_change(function(player, model_name, skin_name)
if sfinv.enabled then
sfinv.set_player_inventory_formspec(player)
end
end)
player_api.read_textures_and_meta()

32
mods/skins/license.txt Normal file
View file

@ -0,0 +1,32 @@
License of source code
----------------------
The MIT License (MIT)
Copyright (c) 2016-2017 TenPlus1
Copyright (c) 2017 paramat
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
For more details:
https://opensource.org/licenses/MIT
Licenses of media (textures)
----------------------------
TODO

View file

@ -0,0 +1,2 @@
name = "Original Sam",
author = "Jordach",

View file

@ -0,0 +1,2 @@
name = "Oerkki",
author = "jmf",

View file

@ -0,0 +1,2 @@
name = "Jordach",
author = "Jordach",

3
mods/skins/mod.conf Normal file
View file

@ -0,0 +1,3 @@
name = skins
description = Simple skins manager for sfinv
depends = player_api,sfinv

Binary file not shown.

After

Width:  |  Height:  |  Size: 951 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB