API enhancements, player-attribute according naming convention

This commit is contained in:
Alexander Weber 2017-06-19 16:36:53 +02:00
parent 57b815f91f
commit 897ac2c97b
2 changed files with 18 additions and 11 deletions

22
api.lua
View File

@ -1,11 +1,11 @@
-- get current skin
skins.get_player_skin = function(player)
local skin = player:get_attribute("skin")
function skins.get_player_skin(player)
local skin = player:get_attribute("skinsdb:skin_key")
return skins.get(skin) or skins.get(skins.default)
end
-- Set skin
skins.set_player_skin = function(player, skin)
-- Assign skin to player
function skins.assign_player_skin(player, skin)
local skin_obj
local skin_key
if type(skin) == "string" then
@ -13,18 +13,22 @@ skins.set_player_skin = function(player, skin)
else
skin_obj = skin
end
skin_key = skin:get_meta("_key")
skin_key = skin_obj:get_key()
if skin_key == skins.default then
skin_key = ""
end
player:set_attribute("skin", skin_key)
skins.update_player_skin(player)
player:set_attribute("skinsdb:skin_key", skin_key)
end
-- update visuals
skins.update_player_skin = function(player)
function skins.update_player_skin(player)
local skin = skins.get_player_skin(player)
skin:set_skin(player)
end
-- Assign and update
function skins.set_player_skin(player, skin)
skins.assign_player_skin(player, skin)
skins.update_player_skin(player)
end

View File

@ -26,6 +26,10 @@ end
-- Skin methods
-- In this implementation it is just access to attrubutes wrapped
-- but this way allow to redefine the functionality for more complex skins provider
function skin_class:get_key()
return self._key
end
function skin_class:set_meta(key, value)
self[key] = value
end
@ -35,10 +39,9 @@ function skin_class:get_meta(key)
end
function skin_class:get_meta_string(key)
return tostring(self[key] or "")
return tostring(self:get_meta(key) or "")
end
function skin_class:set_texture(value)
self._texture = value
end