forked from minetest-mods/mesecons
Merge branch 'master' of github.com:Jeija/minetest-mod-mesecons
This commit is contained in:
commit
70e9db28bc
@ -20,7 +20,6 @@ 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.receptors={}
|
mesecon.receptors={}
|
||||||
mesecon.receptors_off={}
|
|
||||||
mesecon.effectors={}
|
mesecon.effectors={}
|
||||||
mesecon.rules={}
|
mesecon.rules={}
|
||||||
mesecon.conductors={}
|
mesecon.conductors={}
|
||||||
@ -33,25 +32,26 @@ dofile(minetest.get_modpath("mesecons").."/internal.lua");
|
|||||||
|
|
||||||
-- API API API API API API API API API API API API API API API API API API
|
-- API API API API API API API API API API API API API API API API API API
|
||||||
|
|
||||||
function mesecon:add_receptor_node(name, rules, get_rules) --rules table is optional; if rules depend on param2 pass (nodename, nil, function get_rules)
|
function mesecon:register_receptor(onstate, offstate, rules, get_rules)
|
||||||
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
|
||||||
table.insert(mesecon.receptors, {name = name, rules = rules, get_rules = get_rules})
|
table.insert(mesecon.receptors,
|
||||||
end
|
{onstate = onstate,
|
||||||
|
offstate = offstate,
|
||||||
function mesecon:add_receptor_node_off(name, rules, get_rules)
|
rules = rules,
|
||||||
if get_rules==nil and rules==nil then
|
get_rules = get_rules})
|
||||||
rules=mesecon:get_rules("default")
|
|
||||||
end
|
|
||||||
table.insert(mesecon.receptors_off, {name = name, rules = rules, get_rules = get_rules})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function mesecon:register_effector(onstate, offstate, input_rules, get_input_rules)
|
function mesecon:register_effector(onstate, offstate, input_rules, get_input_rules)
|
||||||
if get_input_rules==nil and input_rules==nil then
|
if get_input_rules==nil and input_rules==nil then
|
||||||
rules=mesecon:get_rules("default")
|
rules=mesecon:get_rules("default")
|
||||||
end
|
end
|
||||||
table.insert(mesecon.effectors, {onstate = onstate, offstate = offstate, input_rules = input_rules, get_input_rules = get_input_rules})
|
table.insert(mesecon.effectors,
|
||||||
|
{onstate = onstate,
|
||||||
|
offstate = offstate,
|
||||||
|
input_rules = input_rules,
|
||||||
|
get_input_rules = get_input_rules})
|
||||||
end
|
end
|
||||||
|
|
||||||
function mesecon:receptor_on(pos, rules)
|
function mesecon:receptor_on(pos, rules)
|
||||||
@ -130,3 +130,5 @@ dofile(minetest.get_modpath("mesecons").."/wires.lua");
|
|||||||
|
|
||||||
--Services like turnoff receptor on dignode and so on
|
--Services like turnoff receptor on dignode and so on
|
||||||
dofile(minetest.get_modpath("mesecons").."/services.lua");
|
dofile(minetest.get_modpath("mesecons").."/services.lua");
|
||||||
|
--Deprecated stuff
|
||||||
|
dofile(minetest.get_modpath("mesecons").."/legacy.lua");
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
function mesecon:is_receptor_node(nodename)
|
function mesecon:is_receptor_node(nodename)
|
||||||
local i = 1
|
local i = 1
|
||||||
for i, receptor in ipairs(mesecon.receptors) do
|
for i, receptor in ipairs(mesecon.receptors) do
|
||||||
if receptor.name == nodename then
|
if receptor.onstate == nodename then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
i = i + 1
|
i = i + 1
|
||||||
@ -14,8 +14,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
|
||||||
for i, receptor in ipairs(mesecon.receptors_off) do
|
for i, receptor in ipairs(mesecon.receptors) do
|
||||||
if receptor.name == nodename then
|
if receptor.offstate == nodename then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
i = i + 1
|
i = i + 1
|
||||||
@ -25,7 +25,7 @@ end
|
|||||||
|
|
||||||
function mesecon:receptor_get_rules(node)
|
function mesecon:receptor_get_rules(node)
|
||||||
for i, receptor in ipairs(mesecon.receptors) do
|
for i, receptor in ipairs(mesecon.receptors) do
|
||||||
if receptor.name == node.name then
|
if receptor.onstate == node.name or receptor.offstate == node.name then
|
||||||
if receptor.get_rules ~= nil then
|
if receptor.get_rules ~= nil then
|
||||||
return receptor.get_rules(node.param2)
|
return receptor.get_rules(node.param2)
|
||||||
elseif mesecon.receptors[i].rules ~=nil then
|
elseif mesecon.receptors[i].rules ~=nil then
|
||||||
@ -35,18 +35,6 @@ function mesecon:receptor_get_rules(node)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for i, receptor in ipairs(mesecon.receptors_off) do
|
|
||||||
if receptor.name == node.name then
|
|
||||||
if receptor.get_rules ~= nil then
|
|
||||||
return receptor.get_rules(node.param2)
|
|
||||||
elseif mesecon.receptors_off[i].rules ~=nil then
|
|
||||||
return receptor.rules
|
|
||||||
else
|
|
||||||
return mesecon:get_rules("default")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
13
mesecons/legacy.lua
Normal file
13
mesecons/legacy.lua
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
function mesecon:add_receptor_node(name, rules, get_rules)
|
||||||
|
if get_rules==nil and rules==nil then
|
||||||
|
rules=mesecon:get_rules("default")
|
||||||
|
end
|
||||||
|
table.insert(mesecon.receptors, {onstate = name, rules = rules, get_rules = get_rules})
|
||||||
|
end
|
||||||
|
|
||||||
|
function mesecon:add_receptor_node_off(name, rules, get_rules)
|
||||||
|
if get_rules==nil and rules==nil then
|
||||||
|
rules=mesecon:get_rules("default")
|
||||||
|
end
|
||||||
|
table.insert(mesecon.receptors, {offstate = name, rules = rules, get_rules = get_rules})
|
||||||
|
end
|
@ -15,8 +15,7 @@ minetest.register_node("mesecons_switch:mesecon_switch_on", {
|
|||||||
description="Switch",
|
description="Switch",
|
||||||
})
|
})
|
||||||
|
|
||||||
mesecon:add_receptor_node("mesecons_switch:mesecon_switch_on")
|
mesecon:register_receptor("mesecons_switch:mesecon_switch_on", "mesecons_switch:mesecon_switch_off")
|
||||||
mesecon:add_receptor_node_off("mesecons_switch:mesecon_switch_off")
|
|
||||||
|
|
||||||
minetest.register_on_punchnode(function(pos, node, puncher)
|
minetest.register_on_punchnode(function(pos, node, puncher)
|
||||||
if node.name == "mesecons_switch:mesecon_switch_on" then
|
if node.name == "mesecons_switch:mesecon_switch_on" then
|
||||||
|
Loading…
Reference in New Issue
Block a user