mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-22 10:31:06 +01:00
Added time_override to FOV API
time_override can be used when applying or removing modifiers
This commit is contained in:
parent
394b090c83
commit
b6484a6d15
1 changed files with 9 additions and 7 deletions
|
@ -75,7 +75,7 @@ minetest.register_on_respawnplayer(function(player)
|
||||||
mcl_fovapi.remove_all_modifiers(player)
|
mcl_fovapi.remove_all_modifiers(player)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
function mcl_fovapi.apply_modifier(player, modifier_name)
|
function mcl_fovapi.apply_modifier(player, modifier_name, time_override)
|
||||||
if not player or not modifier_name then
|
if not player or not modifier_name then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -106,13 +106,14 @@ function mcl_fovapi.apply_modifier(player, modifier_name)
|
||||||
minetest.log("FOV::Modifier applied to player:" .. player_name .. " modifier: " .. modifier_name)
|
minetest.log("FOV::Modifier applied to player:" .. player_name .. " modifier: " .. modifier_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local time = time_override or modifier.time
|
||||||
-- modifier apply code.
|
-- modifier apply code.
|
||||||
if modifier.exclusive == true then
|
if modifier.exclusive == true then
|
||||||
-- if exclusive, reset the player's fov, and apply the new fov.
|
-- if exclusive, reset the player's fov, and apply the new fov.
|
||||||
if modifier.is_multiplier then
|
if modifier.is_multiplier then
|
||||||
player:set_fov(0, false, 0)
|
player:set_fov(0, false, 0)
|
||||||
end
|
end
|
||||||
player:set_fov(modifier.fov_factor, modifier.is_multiplier, modifier.time)
|
player:set_fov(modifier.fov_factor, modifier.is_multiplier, time)
|
||||||
else
|
else
|
||||||
-- not exclusive? let's apply it in the mix.
|
-- not exclusive? let's apply it in the mix.
|
||||||
local fov_factor, is_mult = player:get_fov()
|
local fov_factor, is_mult = player:get_fov()
|
||||||
|
@ -126,15 +127,15 @@ function mcl_fovapi.apply_modifier(player, modifier_name)
|
||||||
fov_factor = (fov_factor + modifier.fov_factor) / 2
|
fov_factor = (fov_factor + modifier.fov_factor) / 2
|
||||||
end
|
end
|
||||||
if modifier.is_multiplier and is_mult then
|
if modifier.is_multiplier and is_mult then
|
||||||
player:set_fov(fov_factor, true, modifier.time)
|
player:set_fov(fov_factor, true, time)
|
||||||
else
|
else
|
||||||
player:set_fov(fov_factor, false, modifier.time)
|
player:set_fov(fov_factor, false, time)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function mcl_fovapi.remove_modifier(player, modifier_name)
|
function mcl_fovapi.remove_modifier(player, modifier_name, time_override)
|
||||||
if not player or not modifier_name then
|
if not player or not modifier_name then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -159,9 +160,10 @@ function mcl_fovapi.remove_modifier(player, modifier_name)
|
||||||
applied[k] = mcl_fovapi.registered_modifiers[k]
|
applied[k] = mcl_fovapi.registered_modifiers[k]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local time = time_override or modifier.reset_time
|
||||||
local elem = next
|
local elem = next
|
||||||
if elem(applied) == nil then
|
if elem(applied) == nil then
|
||||||
player:set_fov(0, false, modifier.reset_time)
|
player:set_fov(0, false, time)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local exc = false
|
local exc = false
|
||||||
|
@ -191,7 +193,7 @@ function mcl_fovapi.remove_modifier(player, modifier_name)
|
||||||
fov_factor = fov_factor * x.fov_factor
|
fov_factor = fov_factor * x.fov_factor
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
player:set_fov(fov_factor, not non_multiplier_added, modifier.reset_time)
|
player:set_fov(fov_factor, not non_multiplier_added, time)
|
||||||
end
|
end
|
||||||
|
|
||||||
if mcl_fovapi.registered_modifiers[modifier_name].on_end then
|
if mcl_fovapi.registered_modifiers[modifier_name].on_end then
|
||||||
|
|
Loading…
Reference in a new issue