new flow logic: change simple transition set logic to take list of key-value pairs, add set registration for flow sensor pipe

This commit is contained in:
thetaepsilon-gamedev 2017-10-08 15:07:12 +01:00
parent e98e4e268b
commit 32a24730f1
2 changed files with 9 additions and 3 deletions

View File

@ -524,6 +524,9 @@ minetest.register_node(nodename_sensor_loaded, {
-- FIXME requires-directionality -- FIXME requires-directionality
new_flow_logic_register.simple(nodename_sensor_empty) 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
local sensor_pressure_set = { { nodename_sensor_empty, 0.0 }, { nodename_sensor_loaded, 2.0 } }
new_flow_logic_register.transition_simple_set(sensor_pressure_set)

View File

@ -147,8 +147,11 @@ local simple_transitions = pipeworks.flowables.transitions.simple
register.transition_simple_set = function(nodeset) register.transition_simple_set = function(nodeset)
local set = {} local set = {}
for nodename, value in pairs(nodeset) do for index, element in ipairs(nodeset) do
if type(nodename) ~= "string" then simpleseterror("nodename key "..tostring(nodename).."was not a string!") end if type(element) ~= "table" then simpleseterror("element "..tostring(index).." in nodeset was not table!") end
local nodename = element[1]
local value = element[2]
if type(nodename) ~= "string" then simpleseterror("nodename "..tostring(nodename).."was not a string!") end
if type(value) ~= "number" then simpleseterror("pressure value "..tostring(value).."was not a number!") end if type(value) ~= "number" then simpleseterror("pressure value "..tostring(value).."was not a number!") end
insert_transition_base(nodename) insert_transition_base(nodename)
if simple_transitions[nodename] then duplicateerr("simple transition set", nodename) end if simple_transitions[nodename] then duplicateerr("simple transition set", nodename) end
@ -159,7 +162,7 @@ register.transition_simple_set = function(nodeset)
-- sort pressure values, smallest first -- sort pressure values, smallest first
local smallest_first = function(a, b) local smallest_first = function(a, b)
return a.value < b.value return a.threshold < b.threshold
end end
table.sort(set, smallest_first) table.sort(set, smallest_first)