diff --git a/api.lua b/api.lua index 492024f..549e79e 100644 --- a/api.lua +++ b/api.lua @@ -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 diff --git a/skin_meta_api.lua b/skin_meta_api.lua index f01671c..5219e1d 100644 --- a/skin_meta_api.lua +++ b/skin_meta_api.lua @@ -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