From a7c395abc666342ca3d2f767d69ef6372f8721f7 Mon Sep 17 00:00:00 2001 From: Alexander Weber Date: Mon, 25 May 2020 07:47:31 +0200 Subject: [PATCH] add skins - player skin manager for sfinv --- mods/skins/README.txt | 12 ++++ mods/skins/init.lua | 81 +++++++++++++++++++++++++ mods/skins/license.txt | 32 ++++++++++ mods/skins/meta/character_1.txt | 2 + mods/skins/meta/character_2.txt | 2 + mods/skins/meta/player_jordach.txt | 2 + mods/skins/mod.conf | 3 + mods/skins/textures/character_1.png | Bin 0 -> 951 bytes mods/skins/textures/character_2.png | Bin 0 -> 246 bytes mods/skins/textures/player_jordach.png | Bin 0 -> 1136 bytes 10 files changed, 134 insertions(+) create mode 100644 mods/skins/README.txt create mode 100644 mods/skins/init.lua create mode 100644 mods/skins/license.txt create mode 100644 mods/skins/meta/character_1.txt create mode 100644 mods/skins/meta/character_2.txt create mode 100644 mods/skins/meta/player_jordach.txt create mode 100644 mods/skins/mod.conf create mode 100644 mods/skins/textures/character_1.png create mode 100644 mods/skins/textures/character_2.png create mode 100644 mods/skins/textures/player_jordach.png diff --git a/mods/skins/README.txt b/mods/skins/README.txt new file mode 100644 index 00000000..06a55e7a --- /dev/null +++ b/mods/skins/README.txt @@ -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 diff --git a/mods/skins/init.lua b/mods/skins/init.lua new file mode 100644 index 00000000..5f65ff64 --- /dev/null +++ b/mods/skins/init.lua @@ -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() diff --git a/mods/skins/license.txt b/mods/skins/license.txt new file mode 100644 index 00000000..e196716d --- /dev/null +++ b/mods/skins/license.txt @@ -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 diff --git a/mods/skins/meta/character_1.txt b/mods/skins/meta/character_1.txt new file mode 100644 index 00000000..c8843534 --- /dev/null +++ b/mods/skins/meta/character_1.txt @@ -0,0 +1,2 @@ +name = "Original Sam", +author = "Jordach", diff --git a/mods/skins/meta/character_2.txt b/mods/skins/meta/character_2.txt new file mode 100644 index 00000000..b04689b8 --- /dev/null +++ b/mods/skins/meta/character_2.txt @@ -0,0 +1,2 @@ +name = "Oerkki", +author = "jmf", diff --git a/mods/skins/meta/player_jordach.txt b/mods/skins/meta/player_jordach.txt new file mode 100644 index 00000000..533000c9 --- /dev/null +++ b/mods/skins/meta/player_jordach.txt @@ -0,0 +1,2 @@ +name = "Jordach", +author = "Jordach", diff --git a/mods/skins/mod.conf b/mods/skins/mod.conf new file mode 100644 index 00000000..b4d79f53 --- /dev/null +++ b/mods/skins/mod.conf @@ -0,0 +1,3 @@ +name = skins +description = Simple skins manager for sfinv +depends = player_api,sfinv diff --git a/mods/skins/textures/character_1.png b/mods/skins/textures/character_1.png new file mode 100644 index 0000000000000000000000000000000000000000..d7f3d35f753e1332c4b4b9a2c04eb85e036a9a4a GIT binary patch literal 951 zcmV;o14#UdP)Xa^00001bW%=J06^y0W&i*J zrAb6VR7l62lmT~|Kn%wv=k;<&<)*lD+;bqVo2|3Mu0rR#2mSuvYJrKmXItqK@gdLr z^GhyaFxZ>Nl;$WjBJ-usRgxrw?&@X8xTlry6>uQ~95!Le-g}vl2qPbXu{_T=QnuL} z?-@Tp!4=mmaJzhyKNe+6kbHmugknsftliK2F)!TT$Rz3A0|ruRHsnRI+2kANl0ALj z3I%sixX zhbD}p2a*9w&+rJ=uq;4}!5Gv+f4q!NfDP+DGY9tZ%!WePo4amj&m znrAH-DAa+vDByX>7#|5&QR@q*w333hLMf_40>9h?U-**wu5vFoReAH`ICX>2!NZ~W z%rsseAgMIg)vj_agL5E!0IiWq2?Smy7)eAzFDh3(Jy8*blhO|mw9u^SO|Kz}tg&g9 zeeHhV-Zm(!gLThW%hj@2m+LbD8^zH)TVy8!G>_*36u+t;cIN^n3JnpYM*-?a^*X^r zv94YrFg8oG`B9*zroK+_P_NxT!P96;W)AjkNlpUJ{b+9+Kir)75&!yn98(iaY}?Q3 zuJP|>@%wJo`ReZ64+7(>tFeix1{=-dIJWx?_xC61-X*Z(v5k$1V%rc{+hsUS_b!2% zMiIr?M!?Qy9l>(hn}F(%XH%*n3~ls31eDlLCQ-{VnS7iew1zUrR6^Vy#)krn)U$fdp)4HebMadws6&!7XKiSrfIgAFXr literal 0 HcmV?d00001 diff --git a/mods/skins/textures/character_2.png b/mods/skins/textures/character_2.png new file mode 100644 index 0000000000000000000000000000000000000000..3f61b31b06d09e96c7c59c5ccbae651d9a724201 GIT binary patch literal 246 zcmeAS@N?(olHy`uVBq!ia0vp^4nVBH!VDw>HYaZfQqloFA+A9BKLdjs81RZ+1ag6V zea=9j;OWJtmw;T>k|4ie21X`kw%xMMK0tw1PZ!4!i_>o>9OP|K;Bl4q=Xs)ag5?p* ziLLh}qNOHqB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