Move cinecam config into settings

Instead of using mod_storage and privs to control
cinecam, just use settings.  The priv checks every
globalstep per player, in particular, were expensive,
and using "/grantme all" with the mod installed
would cause the player to teleport as a camera
player.
This commit is contained in:
Aaron Suen 2022-09-29 18:09:28 -04:00
parent 079c21a58b
commit 12f4fc4f15

View File

@ -1,29 +1,26 @@
-- LUALOCALS < ---------------------------------------------------------
local ipairs, math, minetest, pairs, setmetatable, table, tonumber,
type
= ipairs, math, minetest, pairs, setmetatable, table, tonumber,
type
local ipairs, math, minetest, pairs, tonumber, type
= ipairs, math, minetest, pairs, tonumber, type
local math_atan2, math_ceil, math_cos, math_pi, math_random, math_sin,
math_sqrt, table_concat
math_sqrt
= math.atan2, math.ceil, math.cos, math.pi, math.random, math.sin,
math.sqrt, table.concat
math.sqrt
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
local modstore = minetest.get_mod_storage()
local defaults = {
cycletime = 20, -- time between cycles
hudtime = 4, -- duration to display HUD
hudreshow = 60, -- interval to re-display HUD
hudmargin = 2, -- bottom margin for HUD
hudmargin = 0, -- bottom margin for HUD
dummyradius = 64, -- max radius for dummy cam
dummyheight = 64, -- max height for dummy cam
dummyradius = 80, -- max radius for dummy cam
dummyheight = 32, -- max height for dummy cam
dummymin = 0.25, -- min radius (of max) for dummy cam
dummyclear = 16, -- min clear sight for dummy cam
vellead = -2, -- ratio of player vel for camera pos "leading/chasing"
vellead = -4, -- ratio of player vel for camera pos "leading/chasing"
facelead = -2, -- ratio of player facing for camera pos lead/chase
camdistset = 4, -- initial target distance from player to set camera
camdistmin = 1, -- min distance from player to allow camera
@ -33,56 +30,34 @@ local defaults = {
camlocktime = 1, -- min time to lock camera after moving
minlight = 4, -- min light level to not affect cam time
maxidle = 10, -- max idle time before penalty
idlepenalty = 4, -- extra countdown speed for being idle
idlepenalty = 6, -- extra countdown speed for being idle
actvig = 0.25, -- vignette when active
actvig = 0.5, -- vignette when active
actdark = 0, -- darken when active
dummyvig = 0.75, -- vignette when dummycam
dummydark = 0.3, -- darken when dummycam
}
local config = {}
setmetatable(config, {__index = defaults})
local config
local enabled_players
do
local s = modstore:get_string("config") or ""
s = s and minetest.deserialize(s) or {}
for k, v in pairs(s) do
if defaults[k] then
config[k] = v
end
local function reconfigure()
config = {}
for k in pairs(defaults) do
config[k] = tonumber(minetest.settings:get(modname .. "_" .. k)) or defaults[k]
end
enabled_players = {}
for _, n in pairs((minetest.settings:get(modname .. "_players") or ""):split(',')) do
enabled_players[n] = true
end
return true, modname .. " config reloaded"
end
minetest.register_privilege(modname, {
description = "experimental cinematic camera",
give_to_singleplayer = false,
give_to_admin = false
})
minetest.register_privilege(modname .. "_admin", {
description = "cinematic camera admin",
give_to_singleplayer = false,
give_to_admin = true
})
reconfigure()
minetest.register_chatcommand(modname, {
description = "set or query config",
privs = {[modname .. "_admin"] = true},
func = function(_, param)
for _, s in ipairs(param:split(" ")) do
local p = s:split("=")
if #p == 2 then
config[p[1]] = tonumber(p[2])
end
end
modstore:set_string("config", minetest.serialize(config))
local t = {}
for k, v in pairs(defaults) do
t[#t + 1] = k .. (config[k] and "=" or "~") .. (config[k] or v)
end
return true, table_concat(t, ", ")
end
description = "Reload " .. modname .. " config from settings",
privs = {server = true},
func = reconfigure
})
local function setcamera(player, pos, target)
@ -389,7 +364,7 @@ minetest.register_globalstep(function(dtime)
data.idlelook = look
end
for _, player in ipairs(players) do
if minetest.check_player_privs(player, modname) then
if enabled_players[player:get_player_name()] then
camcheck(player, dtime)
end
end