Code cleanup

This commit is contained in:
Jeija 2012-08-13 12:03:36 +02:00
parent b8ba13a17a
commit 955b8254dd
2 changed files with 28 additions and 28 deletions

@ -83,8 +83,8 @@ mesecon={} -- contains all functions and all global variables
mesecon.actions_on={} -- Saves registered function callbacks for mesecon on
mesecon.actions_off={} -- Saves registered function callbacks for mesecon off
mesecon.actions_change={} -- Saves registered function callbacks for mesecon change
mesecon.pwr_srcs={}
mesecon.pwr_srcs_off={}
mesecon.receptors={}
mesecon.receptors_off={}
mesecon.effectors={}
mesecon.rules={}
mesecon.conductors={}
@ -100,31 +100,31 @@ dofile(minetest.get_modpath("mesecons").."/internal.lua");
function mesecon:add_receptor_node(nodename, rules, get_rules) --rules table is optional; if rules depend on param2 pass (nodename, nil, function get_rules)
local i=1
repeat
if mesecon.pwr_srcs[i]==nil then break end
if mesecon.receptors[i]==nil then break end
i=i+1
until false
if get_rules==nil and rules==nil then
rules=mesecon:get_rules("default")
end
mesecon.pwr_srcs[i]={}
mesecon.pwr_srcs[i].name=nodename
mesecon.pwr_srcs[i].rules=rules
mesecon.pwr_srcs[i].get_rules=get_rules
mesecon.receptors[i]={}
mesecon.receptors[i].name=nodename
mesecon.receptors[i].rules=rules
mesecon.receptors[i].get_rules=get_rules
end
function mesecon:add_receptor_node_off(nodename, rules, get_rules)
local i=1
repeat
if mesecon.pwr_srcs_off[i]==nil then break end
if mesecon.receptors_off[i]==nil then break end
i=i+1
until false
if get_rules==nil and rules==nil then
rules=mesecon:get_rules("default")
end
mesecon.pwr_srcs_off[i]={}
mesecon.pwr_srcs_off[i].name=nodename
mesecon.pwr_srcs_off[i].rules=rules
mesecon.pwr_srcs_off[i].get_rules=get_rules
mesecon.receptors_off[i]={}
mesecon.receptors_off[i].name=nodename
mesecon.receptors_off[i].rules=rules
mesecon.receptors_off[i].get_rules=get_rules
end
function mesecon:receptor_on(pos, rules)

@ -2,8 +2,8 @@
function mesecon:is_receptor_node(nodename)
local i = 1
while mesecon.pwr_srcs[i] ~= nil do
if mesecon.pwr_srcs[i].name == nodename then
while mesecon.receptors[i] ~= nil do
if mesecon.receptors[i].name == nodename then
return true
end
i = i + 1
@ -13,8 +13,8 @@ end
function mesecon:is_receptor_node_off(nodename, pos, ownpos)
local i = 1
while mesecon.pwr_srcs_off[i] ~= nil do
if mesecon.pwr_srcs_off[i].name == nodename then
while mesecon.receptors_off[i] ~= nil do
if mesecon.receptors_off[i].name == nodename then
return true
end
i = i + 1
@ -24,12 +24,12 @@ end
function mesecon:receptor_get_rules(node)
local i = 1
while(mesecon.pwr_srcs[i] ~= nil) do
if mesecon.pwr_srcs[i].name == node.name then
if mesecon.pwr_srcs[i].get_rules ~= nil then
return mesecon.pwr_srcs[i].get_rules(node.param2)
elseif mesecon.pwr_srcs[i].rules ~=nil then
return mesecon.pwr_srcs[i].rules
while(mesecon.receptors[i] ~= nil) do
if mesecon.receptors[i].name == node.name then
if mesecon.receptors[i].get_rules ~= nil then
return mesecon.receptors[i].get_rules(node.param2)
elseif mesecon.receptors[i].rules ~=nil then
return mesecon.receptors[i].rules
else
return mesecon:get_rules("default")
end
@ -37,12 +37,12 @@ function mesecon:receptor_get_rules(node)
i = i + 1
end
while(mesecon.pwr_srcs_off[i] ~= nil) do
if mesecon.pwr_srcs_off[i].name == node.name then
if mesecon.pwr_srcs_off[i].get_rules ~= nil then
return mesecon.pwr_srcs_off[i].get_rules(node.param2)
elseif mesecon.pwr_srcs_off[i].rules ~=nil then
return mesecon.pwr_srcs_off[i].rules
while(mesecon.receptors_off[i] ~= nil) do
if mesecon.receptors_off[i].name == node.name then
if mesecon.receptors_off[i].get_rules ~= nil then
return mesecon.receptors_off[i].get_rules(node.param2)
elseif mesecon.receptors_off[i].rules ~=nil then
return mesecon.receptors_off[i].rules
else
return mesecon:get_rules("default")
end