From 1cbbe8f4b13c7782dc6fca6f9def5e2364ce3c26 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 11 Feb 2019 17:45:42 +0100 Subject: [PATCH] Refactor playerphysics init --- mods/PLAYER/playerphysics/init.lua | 32 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/mods/PLAYER/playerphysics/init.lua b/mods/PLAYER/playerphysics/init.lua index 0b9420b183..2b7d7df025 100644 --- a/mods/PLAYER/playerphysics/init.lua +++ b/mods/PLAYER/playerphysics/init.lua @@ -1,43 +1,43 @@ playerphysics = {} -local function calculate_physic_product(player, physic) +local function calculate_attribute_product(player, attribute) local a = minetest.deserialize(player:get_attribute("playerphysics:physics")) local product = 1 - if a == nil or a[physic] == nil then + if a == nil or a[attribute] == nil then return product end - local factors = a[physic] + local factors = a[attribute] if type(factors) == "table" then - for id, factor in pairs(factors) do + for _, factor in pairs(factors) do product = product * factor end end return product end -function playerphysics.add_physics_factor(player, physic, id, value) +function playerphysics.add_physics_factor(player, attribute, id, value) local a = minetest.deserialize(player:get_attribute("playerphysics:physics")) if a == nil then - a = { [physic] = { [id] = value } } - elseif a[physic] == nil then - a[physic] = { [id] = value } + a = { [attribute] = { [id] = value } } + elseif a[attribute] == nil then + a[attribute] = { [id] = value } else - a[physic][id] = value + a[attribute][id] = value end player:set_attribute("playerphysics:physics", minetest.serialize(a)) - local raw_value = calculate_physic_product(player, physic) - player:set_physics_override({[physic] = raw_value}) + local raw_value = calculate_attribute_product(player, attribute) + player:set_physics_override({[attribute] = raw_value}) end -function playerphysics.remove_physics_factor(player, physic, id) +function playerphysics.remove_physics_factor(player, attribute, id) local a = minetest.deserialize(player:get_attribute("playerphysics:physics")) - if a == nil or a[physic] == nil then + if a == nil or a[attribute] == nil then -- Nothing to remove return else - a[physic][id] = nil + a[attribute][id] = nil end player:set_attribute("playerphysics:physics", minetest.serialize(a)) - local raw_value = calculate_physic_product(player, physic) - player:set_physics_override({[physic] = raw_value}) + local raw_value = calculate_attribute_product(player, attribute) + player:set_physics_override({[attribute] = raw_value}) end