forked from mtcontrib/pipeworks
new flow logic: implement post-transition hook with mesecons support, add mesecons transition rules for flow sensor
This commit is contained in:
parent
ce0983d239
commit
d5e3f1cf68
@ -526,7 +526,7 @@ new_flow_logic_register.simple(nodename_sensor_empty)
|
|||||||
new_flow_logic_register.simple(nodename_sensor_loaded)
|
new_flow_logic_register.simple(nodename_sensor_loaded)
|
||||||
-- activate flow sensor at roughly half the pressure pumps drive pipes
|
-- activate flow sensor at roughly half the pressure pumps drive pipes
|
||||||
local sensor_pressure_set = { { nodename_sensor_empty, 0.0 }, { nodename_sensor_loaded, 1.0 } }
|
local sensor_pressure_set = { { nodename_sensor_empty, 0.0 }, { nodename_sensor_loaded, 1.0 } }
|
||||||
new_flow_logic_register.transition_simple_set(sensor_pressure_set)
|
new_flow_logic_register.transition_simple_set(sensor_pressure_set, { mesecons=pipeworks.mesecons_rules })
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -111,6 +111,7 @@ flowlogic.run = function(pos, node)
|
|||||||
local newnode = flowlogic.run_transition(node, currentpressure)
|
local newnode = flowlogic.run_transition(node, currentpressure)
|
||||||
--pipeworks.logger("flowlogic.run()@"..formatvec(pos).." transition, new node name = "..dump(newnode).." pressure "..tostring(currentpressure))
|
--pipeworks.logger("flowlogic.run()@"..formatvec(pos).." transition, new node name = "..dump(newnode).." pressure "..tostring(currentpressure))
|
||||||
minetest.swap_node(pos, newnode)
|
minetest.swap_node(pos, newnode)
|
||||||
|
flowlogic.run_transition_post(pos, newnode)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- set the new pressure
|
-- set the new pressure
|
||||||
@ -289,3 +290,26 @@ flowlogic.run_transition = function(node, currentpressure)
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- post-update hook for run_transition
|
||||||
|
-- among other things, updates mesecons if present.
|
||||||
|
-- node here means the new node, returned from run_transition() above
|
||||||
|
flowlogic.run_transition_post = function(pos, node)
|
||||||
|
local mesecons_def = minetest.registered_nodes[node.name].mesecons
|
||||||
|
local mesecons_rules = pipeworks.flowables.transitions.mesecons[node.name]
|
||||||
|
if minetest.global_exists("mesecon") and (mesecons_def ~= nil) and mesecons_rules then
|
||||||
|
if type(mesecons_def) ~= "table" then
|
||||||
|
pipeworks.logger("flowlogic.run_transition_post() BUG mesecons def for "..node.name.."not a table: got "..tostring(mesecons_def))
|
||||||
|
else
|
||||||
|
local receptor = mesecons_def.receptor
|
||||||
|
if receptor then
|
||||||
|
local state = receptor.state
|
||||||
|
if state == mesecon.state.on then
|
||||||
|
mesecon.receptor_on(pos, mesecons_rules)
|
||||||
|
elseif state == mesecon.state.off then
|
||||||
|
mesecon.receptor_off(pos, mesecons_rules)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@ -32,6 +32,7 @@ pipeworks.flowables.outputs.list = {}
|
|||||||
pipeworks.flowables.transitions = {}
|
pipeworks.flowables.transitions = {}
|
||||||
pipeworks.flowables.transitions.list = {} -- master list
|
pipeworks.flowables.transitions.list = {} -- master list
|
||||||
pipeworks.flowables.transitions.simple = {} -- nodes that change based purely on pressure
|
pipeworks.flowables.transitions.simple = {} -- nodes that change based purely on pressure
|
||||||
|
pipeworks.flowables.transitions.mesecons = {} -- table of mesecons rules to apply on transition
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -145,8 +145,9 @@ local simpleseterror = function(msg)
|
|||||||
end
|
end
|
||||||
local simple_transitions = pipeworks.flowables.transitions.simple
|
local simple_transitions = pipeworks.flowables.transitions.simple
|
||||||
|
|
||||||
register.transition_simple_set = function(nodeset)
|
register.transition_simple_set = function(nodeset, extras)
|
||||||
local set = {}
|
local set = {}
|
||||||
|
if extras == nil then extras = {} end
|
||||||
|
|
||||||
local length = #nodeset
|
local length = #nodeset
|
||||||
if length < 2 then simpleseterror("nodeset needs at least two elements!") end
|
if length < 2 then simpleseterror("nodeset needs at least two elements!") end
|
||||||
@ -175,4 +176,13 @@ register.transition_simple_set = function(nodeset)
|
|||||||
--pipeworks.logger("register.transition_simple_set() after sort: nodename "..element.nodename.." value "..tostring(element.threshold))
|
--pipeworks.logger("register.transition_simple_set() after sort: nodename "..element.nodename.." value "..tostring(element.threshold))
|
||||||
simple_transitions[element.nodename] = set
|
simple_transitions[element.nodename] = set
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- handle extra options
|
||||||
|
-- if mesecons rules table was passed, set for each node
|
||||||
|
if extras.mesecons then
|
||||||
|
local mesecons_rules = pipeworks.flowables.transitions.mesecons
|
||||||
|
for _, element in ipairs(set) do
|
||||||
|
mesecons_rules[element.nodename] = extras.mesecons
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user