mirror of
https://github.com/minetest/minetest_game.git
synced 2024-12-22 15:00:18 +01:00
Allow overriding the loop flag on player_api.set_animation
(#3097)
Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com>
This commit is contained in:
parent
472997b4aa
commit
222afb0cf0
@ -71,7 +71,7 @@ function player_api.set_model(player, model_name)
|
|||||||
player_data.model = model_name
|
player_data.model = model_name
|
||||||
-- Clear animation data as the model has changed
|
-- Clear animation data as the model has changed
|
||||||
-- (required for setting the `stand` animation not to be a no-op)
|
-- (required for setting the `stand` animation not to be a no-op)
|
||||||
player_data.animation, player_data.animation_speed = nil, nil
|
player_data.animation, player_data.animation_speed, player_data.animation_loop = nil, nil, nil
|
||||||
|
|
||||||
local model = models[model_name]
|
local model = models[model_name]
|
||||||
if model then
|
if model then
|
||||||
@ -116,20 +116,27 @@ function player_api.set_texture(player, index, texture)
|
|||||||
player_api.set_textures(player, textures)
|
player_api.set_textures(player, textures)
|
||||||
end
|
end
|
||||||
|
|
||||||
function player_api.set_animation(player, anim_name, speed)
|
function player_api.set_animation(player, anim_name, speed, loop)
|
||||||
local player_data = get_player_data(player)
|
local player_data = get_player_data(player)
|
||||||
local model = models[player_data.model]
|
local model = models[player_data.model]
|
||||||
if not (model and model.animations[anim_name]) then
|
if not (model and model.animations[anim_name]) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
speed = speed or model.animation_speed
|
speed = speed or model.animation_speed
|
||||||
if player_data.animation == anim_name and player_data.animation_speed == speed then
|
if loop == nil then
|
||||||
|
loop = true
|
||||||
|
end
|
||||||
|
if player_data.animation == anim_name
|
||||||
|
and player_data.animation_speed == speed
|
||||||
|
and player_data.animation_loop == loop
|
||||||
|
then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local previous_anim = model.animations[player_data.animation] or {}
|
local previous_anim = model.animations[player_data.animation] or {}
|
||||||
local anim = model.animations[anim_name]
|
local anim = model.animations[anim_name]
|
||||||
player_data.animation = anim_name
|
player_data.animation = anim_name
|
||||||
player_data.animation_speed = speed
|
player_data.animation_speed = speed
|
||||||
|
player_data.animation_loop = loop
|
||||||
-- If necessary change the local animation (only seen by the client of *that* player)
|
-- If necessary change the local animation (only seen by the client of *that* player)
|
||||||
-- `override_local` <=> suspend local animations while this one is active
|
-- `override_local` <=> suspend local animations while this one is active
|
||||||
-- (this is basically a hack, proper engine feature needed...)
|
-- (this is basically a hack, proper engine feature needed...)
|
||||||
@ -146,7 +153,7 @@ function player_api.set_animation(player, anim_name, speed)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Set the animation seen by everyone else
|
-- Set the animation seen by everyone else
|
||||||
player:set_animation(anim, speed, animation_blend)
|
player:set_animation(anim, speed, animation_blend, loop)
|
||||||
-- Update related properties if they changed
|
-- Update related properties if they changed
|
||||||
if anim._equals ~= previous_anim._equals then
|
if anim._equals ~= previous_anim._equals then
|
||||||
player:set_properties({
|
player:set_properties({
|
||||||
|
Loading…
Reference in New Issue
Block a user