Visual update fixes if skin change externally (with and without 3d armor)

API updated also
This commit is contained in:
Alexander Weber 2018-05-13 00:37:19 +02:00
parent b12aefbe4f
commit e6516d2982
4 changed files with 20 additions and 16 deletions

15
API.md
View File

@ -1,20 +1,17 @@
# Skinsdb Interface # Skinsdb Interface
## skins.get_player_skin(player) ## skins.get_player_skin(player)
Return the skin object assigned to the player. Returns defaout if nothins assigned Return the skin object assigned to the player. Returns default if nothing assigned
## skins.assign_player_skin(player, skin) ## skins.assign_player_skin(player, skin)
Select the skin for the player. The "skin" parameter could be the skin key or the skin object Check if allowed and assign the skin for the player without visual updates. The "skin" parameter could be the skin key or the skin object
Returns false if skin is not valid or applicable to player Returns false if skin is not valid or applicable to player
## skins.update_player_skin(player) ## skins.update_player_skin(player)
Update selected skin visuals on player Update selected skin visuals on player
## skins.set_player_skin(player, skin) ## skins.set_player_skin(player, skin)
``` Function for external usage on skin selection. This function assign the skin, call the skin:set_skin(player) hook to update dynamic skins, then update the visuals
skins.assign_player_skin(player, skin)
skins.update_player_skin(player)
```
## skins.get_skin_format(file) ## skins.get_skin_format(file)
Returns the skin format version ("1.0" or "1.8"). File is an open file handle to the texture file Returns the skin format version ("1.0" or "1.8"). File is an open file handle to the texture file
@ -67,11 +64,11 @@ Get the skin preview
Could be redefined for dynamic preview texture generation Could be redefined for dynamic preview texture generation
## skin:set_skin(player) ## skin:set_skin(player)
Apply the skin to the player and do some resets. Hook for dynamic skins updates on select. Is called in skins.set_player_skin()
Is called if skin selection started, in skins.update_player_skin() for examlpe In skinsdb the default implementation for this function is empty.
skin:apply_skin_to_player(player) skin:apply_skin_to_player(player)
Apply the skin to the player. Is called in set_skin() and other places the skin needs to be updated Apply the skin to the player. Called in skins.update_player_skin() to update visuals
## skin:set_meta(key, value) ## skin:set_meta(key, value)
Add a meta information to the skin object Add a meta information to the skin object

15
api.lua
View File

@ -31,14 +31,23 @@ end
-- update visuals -- update visuals
function skins.update_player_skin(player) function skins.update_player_skin(player)
local skin = skins.get_player_skin(player) if skins.armor_loaded then
skin:set_skin(player) -- all needed is wrapped and implemented in 3d_armor mod
armor:set_player_armor(player)
else
-- do updates manually without 3d_armor
skins.get_player_skin(player):apply_skin_to_player(player)
if minetest.global_exists("sfinv") and sfinv.enabled then
sfinv.set_player_inventory_formspec(player)
end
end
end end
-- Assign and update -- Assign and update - should be used on selection externally
function skins.set_player_skin(player, skin) function skins.set_player_skin(player, skin)
local success = skins.assign_player_skin(player, skin) local success = skins.assign_player_skin(player, skin)
if success then if success then
skins.get_player_skin(player):set_skin(player)
skins.update_player_skin(player) skins.update_player_skin(player)
end end
return success return success

View File

@ -32,6 +32,7 @@ end
-- 3d_armor compatibility -- 3d_armor compatibility
if minetest.global_exists("armor") then if minetest.global_exists("armor") then
skins.armor_loaded = true
armor.get_player_skin = function(self, name) armor.get_player_skin = function(self, name)
local skin = skins.get_player_skin(minetest.get_player_by_name(name)) local skin = skins.get_player_skin(minetest.get_player_by_name(name))
return skin:get_texture() return skin:get_texture()

View File

@ -59,8 +59,6 @@ function skin_class:get_preview()
return self._preview or "player.png" return self._preview or "player.png"
end end
local armor_loaded = minetest.global_exists("armor")
function skin_class:apply_skin_to_player(player) function skin_class:apply_skin_to_player(player)
local ver = self:get_meta("format") or "1.0" local ver = self:get_meta("format") or "1.0"
default.player_set_model(player, "skinsdb_3d_armor_character.b3d") default.player_set_model(player, "skinsdb_3d_armor_character.b3d")
@ -76,7 +74,7 @@ function skin_class:apply_skin_to_player(player)
v10_texture = self:get_texture() v10_texture = self:get_texture()
end end
if armor_loaded then if skins.armor_loaded then
local armor_textures = armor.textures[player:get_player_name()] local armor_textures = armor.textures[player:get_player_name()]
if armor_textures then if armor_textures then
armor_texture = armor_textures.armor armor_texture = armor_textures.armor
@ -103,7 +101,6 @@ function skin_class:set_skin(player)
-- The set_skin is used on skins selection -- The set_skin is used on skins selection
-- This means the method could be redefined to start an furmslec -- This means the method could be redefined to start an furmslec
-- See character_creator for example -- See character_creator for example
self:apply_skin_to_player(player)
end end
function skin_class:is_applicable_for_player(playername) function skin_class:is_applicable_for_player(playername)