tidy code
This commit is contained in:
parent
0de1209966
commit
6696e9ae09
58
init.lua
58
init.lua
@ -8,11 +8,12 @@ pova = {debug = false}
|
|||||||
local pova_list = {}
|
local pova_list = {}
|
||||||
local min, max = math.min, math.max
|
local min, max = math.min, math.max
|
||||||
|
|
||||||
-- time each override loop runs, 0 to disable
|
-- override loop interval, 0 to disable
|
||||||
|
|
||||||
local pova_loop = minetest.settings:get_bool("pova_loop") or 1.0
|
local pova_loop = minetest.settings:get_bool("pova_loop") or 1.0
|
||||||
|
|
||||||
-- if enabled activate main loop that totals override list on timer
|
-- when higher than 0, activate main loop that totals override list on a timer,
|
||||||
|
-- incase we have any rogue mods that don't play well with player physics.
|
||||||
|
|
||||||
if pova_loop > 0 then
|
if pova_loop > 0 then
|
||||||
|
|
||||||
@ -27,7 +28,7 @@ if pova_loop > 0 then
|
|||||||
timer = 0
|
timer = 0
|
||||||
|
|
||||||
-- loop through players and apply overrides
|
-- loop through players and apply overrides
|
||||||
for _,player in ipairs(minetest.get_connected_players()) do
|
for _,player in pairs(minetest.get_connected_players()) do
|
||||||
pova.do_override(player)
|
pova.do_override(player)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@ -35,7 +36,7 @@ end
|
|||||||
|
|
||||||
-- global functions
|
-- global functions
|
||||||
|
|
||||||
pova.add_override = function(name, item, def)
|
function pova.add_override(name, item, def)
|
||||||
|
|
||||||
if not name or not item then return end
|
if not name or not item then return end
|
||||||
|
|
||||||
@ -51,65 +52,68 @@ pova.add_override = function(name, item, def)
|
|||||||
pova_list[name][item] = def
|
pova_list[name][item] = def
|
||||||
end
|
end
|
||||||
|
|
||||||
pova.get_override = function(name, item)
|
function pova.get_override(name, item)
|
||||||
return pova_list[name][item]
|
return pova_list[name][item]
|
||||||
end
|
end
|
||||||
|
|
||||||
pova.del_override = function(name, item)
|
function pova.del_override(name, item)
|
||||||
if name and item and pova_list[name] then
|
if name and item and pova_list[name] then
|
||||||
pova_list[name][item] = nil
|
pova_list[name][item] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
pova.do_override = function(player)
|
function pova.do_override(player)
|
||||||
|
|
||||||
local name = player and player:get_player_name()
|
local name = player and player:get_player_name()
|
||||||
|
|
||||||
-- somehow player is missing on list
|
-- somehow player is missing on list
|
||||||
if not name or not pova_list[name] then return end
|
if not name or not pova_list[name] then return end
|
||||||
|
|
||||||
|
-- store player override list
|
||||||
|
local list = pova_list[name]
|
||||||
|
|
||||||
-- set base defaults
|
-- set base defaults
|
||||||
local speed, jump, gravity = 1, 1, 1
|
local speed, jump, gravity = 1, 1, 1
|
||||||
|
|
||||||
-- check for new defaults
|
-- check for new defaults
|
||||||
if pova_list[name]["default"] then
|
if list["default"] then
|
||||||
speed = pova_list[name]["default"].speed or 1
|
speed = list["default"].speed or 1
|
||||||
jump = pova_list[name]["default"].jump or 1
|
jump = list["default"].jump or 1
|
||||||
gravity = pova_list[name]["default"].gravity or 1
|
gravity = list["default"].gravity or 1
|
||||||
end
|
end
|
||||||
|
|
||||||
-- loop through list of named overrides
|
-- loop through list of named overrides
|
||||||
for id, var in pairs(pova_list[name]) do
|
for id, var in pairs(list) do
|
||||||
|
|
||||||
-- skip any custom names
|
-- skip any custom names
|
||||||
if var and id ~= "default" and id ~= "min" and id ~= "max" and id ~= "force" then
|
if var and id ~= "default" and id ~= "min" and id ~= "max" and id ~= "force" then
|
||||||
|
|
||||||
-- add any additional changes
|
-- add any additional changes
|
||||||
speed = speed + (pova_list[name][id].speed or 0)
|
speed = speed + (list[id].speed or 0)
|
||||||
jump = jump + (pova_list[name][id].jump or 0)
|
jump = jump + (list[id].jump or 0)
|
||||||
gravity = gravity + (pova_list[name][id].gravity or 0)
|
gravity = gravity + (list[id].gravity or 0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- make sure total doesn't go below minimum values
|
-- make sure total doesn't go below minimum values
|
||||||
if pova_list[name]["min"] then
|
if list["min"] then
|
||||||
speed = max(pova_list[name]["min"].speed or 0, speed)
|
speed = max(list["min"].speed or 0, speed)
|
||||||
jump = max(pova_list[name]["min"].jump or 0, jump)
|
jump = max(list["min"].jump or 0, jump)
|
||||||
gravity = max(pova_list[name]["min"].gravity or 0, gravity)
|
gravity = max(list["min"].gravity or 0, gravity)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- make sure total doesn't go above maximum values
|
-- make sure total doesn't go above maximum values
|
||||||
if pova_list[name]["max"] then
|
if list["max"] then
|
||||||
speed = min(pova_list[name]["max"].speed or speed, speed)
|
speed = min(list["max"].speed or speed, speed)
|
||||||
jump = min(pova_list[name]["max"].jump or jump, jump)
|
jump = min(list["max"].jump or jump, jump)
|
||||||
gravity = min(pova_list[name]["max"].gravity or gravity, gravity)
|
gravity = min(list["max"].gravity or gravity, gravity)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- force values (for things like sleeping in bed when speed is 0)
|
-- force values (for things like sleeping in bed when speed is 0)
|
||||||
if pova_list[name]["force"] then
|
if list["force"] then
|
||||||
speed = pova_list[name]["force"].speed or speed
|
speed = list["force"].speed or speed
|
||||||
jump = pova_list[name]["force"].jump or jump
|
jump = list["force"].jump or jump
|
||||||
gravity = pova_list[name]["force"].gravity or gravity
|
gravity = list["force"].gravity or gravity
|
||||||
end
|
end
|
||||||
|
|
||||||
-- for testing only
|
-- for testing only
|
||||||
|
Loading…
x
Reference in New Issue
Block a user