multiline RDS messages for transmitters

This commit is contained in:
Serhii Mozhaiskyi 2019-12-13 09:35:04 +02:00
parent caf2b884dc
commit 57118bc252
2 changed files with 30 additions and 21 deletions

27
rds.lua

@ -3,23 +3,24 @@ function ham_radio.get_rds_messages(frequency, is_receiver_station)
local rds_messages = {} local rds_messages = {}
for position, transmitter in pairs(transmitters) do for position, transmitter in pairs(transmitters) do
if transmitter.rds_message ~= "" and transmitter.rds_message ~= nil then if transmitter.rds_message ~= "" and transmitter.rds_message ~= nil then
-- construct message for rds_message_line in transmitter.rds_message:gmatch("[^\n]+") do
local message = table.concat({ -- construct message
'[ Radio | ', local message = table.concat({
transmitter.operated_by, '[ Radio | ',
' ] ',
transmitter.rds_message,
}, "")
if is_receiver_station then
message = table.concat({
'[ ',
transmitter.operated_by, transmitter.operated_by,
' ] ', ' ] ',
transmitter.rds_message rds_message_line,
}, "") }, "")
if is_receiver_station then
message = table.concat({
'[ ',
transmitter.operated_by,
' ] ',
rds_message_line
}, "")
end
table.insert(rds_messages, message)
end end
table.insert(rds_messages, message)
end end
end end
return rds_messages return rds_messages

@ -13,8 +13,16 @@ ham_radio.transmitter_update_infotext = function(meta)
'Frequency: ', frequency 'Frequency: ', frequency
} }
if rds_message ~= "" then if rds_message ~= "" then
local display_message = string.sub(
rds_message,
utf8.offset(rds_message,1),
utf8.offset(rds_message,60+1)-1
)
table.insert(infotext, '\nRDS message: "') table.insert(infotext, '\nRDS message: "')
table.insert(infotext, rds_message) table.insert(infotext, display_message)
if display_message:len() < rds_message:len() then
table.insert(infotext, "...")
end
table.insert(infotext, '"') table.insert(infotext, '"')
end end
meta:set_string("infotext", table.concat(infotext, '')) meta:set_string("infotext", table.concat(infotext, ''))
@ -23,12 +31,12 @@ end
minetest.register_node("ham_radio:transmitter", { minetest.register_node("ham_radio:transmitter", {
description = "Radio Transmitter", description = "Radio Transmitter",
tiles = { tiles = {
"ham_radio_transmitter_top.png", "ham_radio_transmitter_top.png",
"ham_radio_transmitter_top.png", "ham_radio_transmitter_top.png",
"ham_radio_transmitter_side.png", "ham_radio_transmitter_side.png",
"ham_radio_transmitter_side.png", "ham_radio_transmitter_side.png",
"ham_radio_transmitter_side.png", "ham_radio_transmitter_side.png",
"ham_radio_transmitter_front.png" "ham_radio_transmitter_front.png"
}, },
groups = {cracky=2,oddly_breakable_by_hand=2}, groups = {cracky=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_metal_defaults(), sounds = default.node_sound_metal_defaults(),
@ -48,7 +56,7 @@ minetest.register_node("ham_radio:transmitter", {
"tooltip[frequency;Integer number ", "tooltip[frequency;Integer number ",
ham_radio.settings.frequency.min,"-", ham_radio.settings.frequency.min,"-",
ham_radio.settings.frequency.max, "]", ham_radio.settings.frequency.max, "]",
"field[0.25,3.5;7,1;rds_message;RDS message;${rds_message}]", "textarea[0.25,3.5;7,6;rds_message;RDS message;${rds_message}]",
"button_exit[2,4.5;3,1;;Done]" "button_exit[2,4.5;3,1;;Done]"
},'') },'')
) )