From b267cf26579623565f5a85bee9e8584a5467a85f Mon Sep 17 00:00:00 2001 From: Alexander Weber Date: Fri, 16 Jun 2017 21:40:54 +0200 Subject: renamed players.lua -> api.lua; some cleanups --- api.lua | 40 ++++++++++++++++++++++++++++++++++++++++ depends.txt | 1 - init.lua | 20 +------------------- players.lua | 40 ---------------------------------------- 4 files changed, 41 insertions(+), 60 deletions(-) create mode 100644 api.lua delete mode 100644 players.lua diff --git a/api.lua b/api.lua new file mode 100644 index 0000000..6037d75 --- /dev/null +++ b/api.lua @@ -0,0 +1,40 @@ +-- get current skin +skins.get_player_skin = function(player) + local skin = player:get_attribute("skin") + if not skins.textures[skin] then + skin = skins.default + end + return skin +end + +-- Set skin +skins.set_player_skin = function(player, skin) + if skin == skins.default then + skin = "" + end + player:set_attribute("skin", skin) + skins.update_player_skin(player) +end + +-- update visuals +skins.update_player_skin = function(player) + local skin = skins.get_player_skin(player) + player:set_properties({ + textures = {skins.textures[skin]}, + }) +end + +-- Update skin on join +minetest.register_on_joinplayer(function(player) + skins.update_player_skin(player) +end) + +-- 3d_armor compatibility +if minetest.global_exists("armor") then + armor.get_player_skin = function(self, name) + return skins.get_player_skin(minetest.get_player_by_name(name)) + end + armor.get_preview = function(self, name) + return skins.preview[skins.get_player_skin(minetest.get_player_by_name(name))] + end +end diff --git a/depends.txt b/depends.txt index 45a6c66..6fac624 100644 --- a/depends.txt +++ b/depends.txt @@ -1,4 +1,3 @@ -default intllib? unified_inventory? 3d_armor? diff --git a/init.lua b/init.lua index d49335d..953e1b6 100644 --- a/init.lua +++ b/init.lua @@ -9,26 +9,8 @@ skins = {} skins.modpath = minetest.get_modpath(minetest.get_current_modname()) skins.default = "character_1" -skins.type = { SPRITE=0, MODEL=1, ERROR=99 } -skins.get_type = function(texture) - if not skins.is_skin(texture) then - return skins.type.ERROR - end - return skins.type.MODEL -end - -skins.is_skin = function(texture) - if not texture then - return false - end - if not skins.meta[texture] then - return false - end - return true -end - +dofile(skins.modpath.."/api.lua") dofile(skins.modpath.."/skinlist.lua") -dofile(skins.modpath.."/players.lua") -- Unified inventory page/integration if minetest.get_modpath("unified_inventory") then diff --git a/players.lua b/players.lua deleted file mode 100644 index 5b161bd..0000000 --- a/players.lua +++ /dev/null @@ -1,40 +0,0 @@ --- get current skin -skins.get_player_skin = function(player) - local skin = player:get_attribute("skin") - if not skins.is_skin(skin) then - skin = skins.default - end - return skin -end - --- Set skin -skins.set_player_skin = function(player, skin) - if skin == skins.default then - skin = "" - end - player:set_attribute("skin", skin) - skins.update_player_skin(player) -end - --- update visuals -skins.update_player_skin = function(player) - local skin = skins.get_player_skin(player) - player:set_properties({ - textures = {skins.textures[skin]}, - }) -end - --- Update skin on join -minetest.register_on_joinplayer(function(player) - skins.update_player_skin(player) -end) - --- 3d_armor compatibility -if minetest.global_exists("armor") then - armor.get_player_skin = function(self, name) - return skins.get_player_skin(minetest.get_player_by_name(name)) - end - armor.get_preview = function(self, name) - return skins.preview[skins.get_player_skin(minetest.get_player_by_name(name))] - end -end -- cgit v1.2.3