2020-05-31 23:31:18 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
Signs Bot
|
|
|
|
=========
|
|
|
|
|
2021-05-14 19:50:16 +03:00
|
|
|
Copyright (C) 2019-2021 Joachim Stolberg
|
2020-05-31 23:31:18 +03:00
|
|
|
|
|
|
|
GPL v3
|
|
|
|
See LICENSE.txt for more information
|
2022-09-24 12:01:30 +03:00
|
|
|
|
2020-05-31 23:31:18 +03:00
|
|
|
Signal function
|
|
|
|
|
|
|
|
]]--
|
|
|
|
|
|
|
|
-- for lazy programmers
|
2021-05-14 19:50:16 +03:00
|
|
|
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
|
|
|
local S2P = minetest.string_to_pos
|
2020-05-31 23:31:18 +03:00
|
|
|
local M = minetest.get_meta
|
|
|
|
|
|
|
|
-- Used by the pairing tool
|
|
|
|
function signs_bot.get_node_type(pos)
|
2021-02-07 16:37:07 +03:00
|
|
|
local node = tubelib2.get_node_lvm(pos)
|
2020-05-31 23:31:18 +03:00
|
|
|
local ndef = minetest.registered_nodes[node.name]
|
|
|
|
local is_sensor = minetest.get_item_group(node.name, "sign_bot_sensor") == 1
|
|
|
|
if ndef then
|
|
|
|
if ndef.signs_bot_get_signal and is_sensor then
|
|
|
|
return "repeater"
|
|
|
|
elseif ndef.signs_bot_get_signal then
|
|
|
|
return "actuator"
|
|
|
|
elseif is_sensor then
|
|
|
|
return "sensor"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Used by the pairing tool
|
|
|
|
function signs_bot.get_signal(actuator_pos)
|
|
|
|
if actuator_pos then
|
2021-02-07 16:37:07 +03:00
|
|
|
local node = tubelib2.get_node_lvm(actuator_pos)
|
2020-05-31 23:31:18 +03:00
|
|
|
local ndef = minetest.registered_nodes[node.name]
|
|
|
|
if ndef and ndef.signs_bot_get_signal then
|
|
|
|
return ndef.signs_bot_get_signal(actuator_pos, node)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-09-24 12:01:30 +03:00
|
|
|
|
|
|
|
-- Used by the pairing tool
|
2020-05-31 23:31:18 +03:00
|
|
|
function signs_bot.store_signal(sensor_pos, dest_pos, signal)
|
|
|
|
local meta = sensor_pos and M(sensor_pos)
|
|
|
|
if meta then
|
2021-05-14 19:50:16 +03:00
|
|
|
meta:set_string("signal_pos", P2S(dest_pos))
|
2020-05-31 23:31:18 +03:00
|
|
|
meta:set_string("signal_data", signal)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Send a signal from a sensor to a actuator
|
|
|
|
--
|
|
|
|
function signs_bot.send_signal(sensor_pos)
|
|
|
|
local meta = sensor_pos and M(sensor_pos)
|
|
|
|
if meta then
|
|
|
|
local dest_pos = meta:get_string("signal_pos")
|
|
|
|
local signal = meta:get_string("signal_data")
|
|
|
|
if dest_pos ~= "" and signal ~= "" then
|
2021-05-14 19:50:16 +03:00
|
|
|
local pos = S2P(dest_pos)
|
2021-02-07 16:37:07 +03:00
|
|
|
local node = tubelib2.get_node_lvm(pos)
|
2020-05-31 23:31:18 +03:00
|
|
|
local ndef = minetest.registered_nodes[node.name]
|
|
|
|
if ndef and ndef.signs_bot_on_signal then
|
|
|
|
ndef.signs_bot_on_signal(pos, node, signal)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|