summaryrefslogtreecommitdiff
path: root/api.lua
diff options
context:
space:
mode:
authorAlexander Weber <web.alexander@web.de>2017-06-16 23:00:36 +0200
committerAlexander Weber <web.alexander@web.de>2017-06-16 23:00:36 +0200
commit28d28390ce5d67f47db184cbbbc4ecd74be77eb2 (patch)
tree2dde0e088559a878d6006fa3f3779b5ac3adb1b0 /api.lua
parentb267cf26579623565f5a85bee9e8584a5467a85f (diff)
started work on skin_meta_api
Diffstat (limited to 'api.lua')
-rw-r--r--api.lua33
1 files changed, 15 insertions, 18 deletions
diff --git a/api.lua b/api.lua
index 6037d75..b77c7c4 100644
--- a/api.lua
+++ b/api.lua
@@ -1,18 +1,25 @@
-- 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
+ return skins.get(skin) or skins.get(skins.default)
end
-- Set skin
skins.set_player_skin = function(player, skin)
- if skin == skins.default then
- 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:get_meta("_key")
+
+ if skin_key == skins.default then
+ skin_key = ""
end
- player:set_attribute("skin", skin)
+
+ player:set_attribute("skin", skin_key)
skins.update_player_skin(player)
end
@@ -20,7 +27,7 @@ end
skins.update_player_skin = function(player)
local skin = skins.get_player_skin(player)
player:set_properties({
- textures = {skins.textures[skin]},
+ textures = {skin:get_texture()},
})
end
@@ -28,13 +35,3 @@ end
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