forked from minetest-mods/mesecons
Code cleanup
This commit is contained in:
parent
b8ba13a17a
commit
955b8254dd
@ -83,8 +83,8 @@ mesecon={} -- contains all functions and all global variables
|
|||||||
mesecon.actions_on={} -- Saves registered function callbacks for mesecon on
|
mesecon.actions_on={} -- Saves registered function callbacks for mesecon on
|
||||||
mesecon.actions_off={} -- Saves registered function callbacks for mesecon off
|
mesecon.actions_off={} -- Saves registered function callbacks for mesecon off
|
||||||
mesecon.actions_change={} -- Saves registered function callbacks for mesecon change
|
mesecon.actions_change={} -- Saves registered function callbacks for mesecon change
|
||||||
mesecon.pwr_srcs={}
|
mesecon.receptors={}
|
||||||
mesecon.pwr_srcs_off={}
|
mesecon.receptors_off={}
|
||||||
mesecon.effectors={}
|
mesecon.effectors={}
|
||||||
mesecon.rules={}
|
mesecon.rules={}
|
||||||
mesecon.conductors={}
|
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)
|
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
|
local i=1
|
||||||
repeat
|
repeat
|
||||||
if mesecon.pwr_srcs[i]==nil then break end
|
if mesecon.receptors[i]==nil then break end
|
||||||
i=i+1
|
i=i+1
|
||||||
until false
|
until false
|
||||||
if get_rules==nil and rules==nil then
|
if get_rules==nil and rules==nil then
|
||||||
rules=mesecon:get_rules("default")
|
rules=mesecon:get_rules("default")
|
||||||
end
|
end
|
||||||
mesecon.pwr_srcs[i]={}
|
mesecon.receptors[i]={}
|
||||||
mesecon.pwr_srcs[i].name=nodename
|
mesecon.receptors[i].name=nodename
|
||||||
mesecon.pwr_srcs[i].rules=rules
|
mesecon.receptors[i].rules=rules
|
||||||
mesecon.pwr_srcs[i].get_rules=get_rules
|
mesecon.receptors[i].get_rules=get_rules
|
||||||
end
|
end
|
||||||
|
|
||||||
function mesecon:add_receptor_node_off(nodename, rules, get_rules)
|
function mesecon:add_receptor_node_off(nodename, rules, get_rules)
|
||||||
local i=1
|
local i=1
|
||||||
repeat
|
repeat
|
||||||
if mesecon.pwr_srcs_off[i]==nil then break end
|
if mesecon.receptors_off[i]==nil then break end
|
||||||
i=i+1
|
i=i+1
|
||||||
until false
|
until false
|
||||||
if get_rules==nil and rules==nil then
|
if get_rules==nil and rules==nil then
|
||||||
rules=mesecon:get_rules("default")
|
rules=mesecon:get_rules("default")
|
||||||
end
|
end
|
||||||
mesecon.pwr_srcs_off[i]={}
|
mesecon.receptors_off[i]={}
|
||||||
mesecon.pwr_srcs_off[i].name=nodename
|
mesecon.receptors_off[i].name=nodename
|
||||||
mesecon.pwr_srcs_off[i].rules=rules
|
mesecon.receptors_off[i].rules=rules
|
||||||
mesecon.pwr_srcs_off[i].get_rules=get_rules
|
mesecon.receptors_off[i].get_rules=get_rules
|
||||||
end
|
end
|
||||||
|
|
||||||
function mesecon:receptor_on(pos, rules)
|
function mesecon:receptor_on(pos, rules)
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
function mesecon:is_receptor_node(nodename)
|
function mesecon:is_receptor_node(nodename)
|
||||||
local i = 1
|
local i = 1
|
||||||
while mesecon.pwr_srcs[i] ~= nil do
|
while mesecon.receptors[i] ~= nil do
|
||||||
if mesecon.pwr_srcs[i].name == nodename then
|
if mesecon.receptors[i].name == nodename then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
i = i + 1
|
i = i + 1
|
||||||
@ -13,8 +13,8 @@ end
|
|||||||
|
|
||||||
function mesecon:is_receptor_node_off(nodename, pos, ownpos)
|
function mesecon:is_receptor_node_off(nodename, pos, ownpos)
|
||||||
local i = 1
|
local i = 1
|
||||||
while mesecon.pwr_srcs_off[i] ~= nil do
|
while mesecon.receptors_off[i] ~= nil do
|
||||||
if mesecon.pwr_srcs_off[i].name == nodename then
|
if mesecon.receptors_off[i].name == nodename then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
i = i + 1
|
i = i + 1
|
||||||
@ -24,12 +24,12 @@ end
|
|||||||
|
|
||||||
function mesecon:receptor_get_rules(node)
|
function mesecon:receptor_get_rules(node)
|
||||||
local i = 1
|
local i = 1
|
||||||
while(mesecon.pwr_srcs[i] ~= nil) do
|
while(mesecon.receptors[i] ~= nil) do
|
||||||
if mesecon.pwr_srcs[i].name == node.name then
|
if mesecon.receptors[i].name == node.name then
|
||||||
if mesecon.pwr_srcs[i].get_rules ~= nil then
|
if mesecon.receptors[i].get_rules ~= nil then
|
||||||
return mesecon.pwr_srcs[i].get_rules(node.param2)
|
return mesecon.receptors[i].get_rules(node.param2)
|
||||||
elseif mesecon.pwr_srcs[i].rules ~=nil then
|
elseif mesecon.receptors[i].rules ~=nil then
|
||||||
return mesecon.pwr_srcs[i].rules
|
return mesecon.receptors[i].rules
|
||||||
else
|
else
|
||||||
return mesecon:get_rules("default")
|
return mesecon:get_rules("default")
|
||||||
end
|
end
|
||||||
@ -37,12 +37,12 @@ function mesecon:receptor_get_rules(node)
|
|||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
while(mesecon.pwr_srcs_off[i] ~= nil) do
|
while(mesecon.receptors_off[i] ~= nil) do
|
||||||
if mesecon.pwr_srcs_off[i].name == node.name then
|
if mesecon.receptors_off[i].name == node.name then
|
||||||
if mesecon.pwr_srcs_off[i].get_rules ~= nil then
|
if mesecon.receptors_off[i].get_rules ~= nil then
|
||||||
return mesecon.pwr_srcs_off[i].get_rules(node.param2)
|
return mesecon.receptors_off[i].get_rules(node.param2)
|
||||||
elseif mesecon.pwr_srcs_off[i].rules ~=nil then
|
elseif mesecon.receptors_off[i].rules ~=nil then
|
||||||
return mesecon.pwr_srcs_off[i].rules
|
return mesecon.receptors_off[i].rules
|
||||||
else
|
else
|
||||||
return mesecon:get_rules("default")
|
return mesecon:get_rules("default")
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user