ham_radio/digiline.lua
2019-12-08 18:42:40 +02:00

47 lines
1.5 KiB
Lua

ham_radio.digiline_effector = function(pos, _, channel, msg)
local command_channel = ham_radio.settings.digiline_channel -- static channel
local broadcast_channel = ham_radio.settings.digiline_broadcast_channel
if channel ~= command_channel and channel ~= broadcast_channel then
return
end
local meta = minetest.get_meta(pos)
-- broadcast channel - text message
if channel == broadcast_channel then
if type(msg) == "string" then
meta:set_string("broadcast_message", msg)
ham_radio.transmitter_update_infotext(meta)
ham_radio.save_transmitter(pos, meta)
end
return
end
-- command channel
if type(msg) ~= "table" then
return
end
if msg.command == "get" then
digilines.receptor_send(pos, digilines.rules.default, digiline_channel, {
frequency = meta:get_string("frequency"),
broadcast_message = meta:get_string("broadcast_message"),
})
elseif msg.command == "frequency" then
local new_frequency = msg.value
if ham_radio.validate_frequency(new_frequency) then
meta:set_string("frequency", new_frequency)
ham_radio.transmitter_update_infotext(meta)
ham_radio.save_transmitter(pos, meta)
end
elseif msg.command == "rds" or msg.command == "message" or msg.command == "rds_message" then
meta:set_string("broadcast_message", msg.value)
ham_radio.transmitter_update_infotext(meta)
ham_radio.save_transmitter(pos, meta)
end
end