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 00000000..d7f3d35f Binary files /dev/null and b/mods/skins/textures/character_1.png differ diff --git a/mods/skins/textures/character_2.png b/mods/skins/textures/character_2.png new file mode 100644 index 00000000..3f61b31b Binary files /dev/null and b/mods/skins/textures/character_2.png differ diff --git a/mods/skins/textures/player_jordach.png b/mods/skins/textures/player_jordach.png new file mode 100644 index 00000000..686ec239 Binary files /dev/null and b/mods/skins/textures/player_jordach.png differ