mirror of
https://github.com/technix/ham_radio.git
synced 2024-08-19 20:54:07 +02:00
rename broadcast to RDS
This commit is contained in:
parent
6c7449761c
commit
a4160c1563
@ -1,55 +0,0 @@
|
|||||||
function ham_radio.get_broadcast_messages(frequency)
|
|
||||||
local transmitters = ham_radio.find_transmitters(frequency)
|
|
||||||
local broadcasts = {}
|
|
||||||
for position, transmitter in pairs(transmitters) do
|
|
||||||
if transmitter.broadcast_message ~= "" then
|
|
||||||
-- construct message
|
|
||||||
local message = table.concat({
|
|
||||||
'[ Radio | ',
|
|
||||||
transmitter.operated_by,
|
|
||||||
' ] ',
|
|
||||||
transmitter.broadcast_message,
|
|
||||||
}, "")
|
|
||||||
table.insert(broadcasts, message)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return broadcasts
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function ham_radio:update_broadcast(player)
|
|
||||||
local name = player:get_player_name()
|
|
||||||
local item = player:get_wielded_item()
|
|
||||||
|
|
||||||
if item:get_name() ~= "ham_radio:handheld_receiver" then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local meta = item:get_meta()
|
|
||||||
local frequency = meta:get_string("frequency")
|
|
||||||
local broadcast_disabled = meta:get_string("broadcast_disabled")
|
|
||||||
|
|
||||||
if frequency == "" then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if broadcast_disabled == "true" then
|
|
||||||
-- disabled receiving broadcast messages
|
|
||||||
ham_radio.player_broadcasts[name] = nil
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if ham_radio.player_broadcasts[name] == nil then
|
|
||||||
ham_radio.player_broadcasts[name] = ham_radio.get_broadcast_messages(frequency)
|
|
||||||
end
|
|
||||||
|
|
||||||
local message = table.remove(ham_radio.player_broadcasts[name])
|
|
||||||
if message ~= nil then
|
|
||||||
minetest.chat_send_player(player:get_player_name(), minetest.colorize(ham_radio.settings.broadcast_color, message))
|
|
||||||
|
|
||||||
-- when all broadcast messages are shown, reload them again
|
|
||||||
if not next(ham_radio.player_broadcasts[name]) then
|
|
||||||
ham_radio.player_broadcasts[name] = ham_radio.get_broadcast_messages(frequency)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
10
config.lua
10
config.lua
@ -1,8 +1,8 @@
|
|||||||
ham_radio.settings = {
|
ham_radio.settings = {
|
||||||
-- color of broadcast messages
|
-- color of RDS messages
|
||||||
broadcast_color = '#607d8b',
|
rds_color = '#607d8b',
|
||||||
-- interval between broadcasts (seconds)
|
-- interval between RDS messages (seconds)
|
||||||
broadcast_interval = 10,
|
rds_interval = 10,
|
||||||
-- receiver hud position
|
-- receiver hud position
|
||||||
hud_pos = { x = 0.5, y = 0.8 },
|
hud_pos = { x = 0.5, y = 0.8 },
|
||||||
-- radio frequency range
|
-- radio frequency range
|
||||||
@ -22,5 +22,5 @@ ham_radio.settings = {
|
|||||||
},
|
},
|
||||||
-- digiline config
|
-- digiline config
|
||||||
digiline_channel = "ham_radio",
|
digiline_channel = "ham_radio",
|
||||||
digiline_broadcast_channel = "ham_radio_rds",
|
digiline_rds_channel = "ham_radio_rds",
|
||||||
}
|
}
|
||||||
|
14
digiline.lua
14
digiline.lua
@ -1,17 +1,17 @@
|
|||||||
ham_radio.digiline_effector = function(pos, _, channel, msg)
|
ham_radio.digiline_effector = function(pos, _, channel, msg)
|
||||||
local command_channel = ham_radio.settings.digiline_channel -- static channel
|
local command_channel = ham_radio.settings.digiline_channel -- static channel
|
||||||
local broadcast_channel = ham_radio.settings.digiline_broadcast_channel
|
local rds_channel = ham_radio.settings.digiline_rds_channel
|
||||||
|
|
||||||
if channel ~= command_channel and channel ~= broadcast_channel then
|
if channel ~= command_channel and channel ~= rds_channel then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
|
||||||
-- broadcast channel - text message
|
-- RDS channel - text message
|
||||||
if channel == broadcast_channel then
|
if channel == rds_channel then
|
||||||
if type(msg) == "string" then
|
if type(msg) == "string" then
|
||||||
meta:set_string("broadcast_message", msg)
|
meta:set_string("rds_message", msg)
|
||||||
ham_radio.transmitter_update_infotext(meta)
|
ham_radio.transmitter_update_infotext(meta)
|
||||||
ham_radio.save_transmitter(pos, meta)
|
ham_radio.save_transmitter(pos, meta)
|
||||||
end
|
end
|
||||||
@ -27,7 +27,7 @@ ham_radio.digiline_effector = function(pos, _, channel, msg)
|
|||||||
if msg.command == "get" then
|
if msg.command == "get" then
|
||||||
digilines.receptor_send(pos, digilines.rules.default, digiline_channel, {
|
digilines.receptor_send(pos, digilines.rules.default, digiline_channel, {
|
||||||
frequency = meta:get_string("frequency"),
|
frequency = meta:get_string("frequency"),
|
||||||
broadcast_message = meta:get_string("broadcast_message"),
|
rds_message = meta:get_string("rds_message"),
|
||||||
})
|
})
|
||||||
|
|
||||||
elseif msg.command == "frequency" then
|
elseif msg.command == "frequency" then
|
||||||
@ -39,7 +39,7 @@ ham_radio.digiline_effector = function(pos, _, channel, msg)
|
|||||||
end
|
end
|
||||||
|
|
||||||
elseif msg.command == "rds" or msg.command == "message" or msg.command == "rds_message" then
|
elseif msg.command == "rds" or msg.command == "message" or msg.command == "rds_message" then
|
||||||
meta:set_string("broadcast_message", msg.value)
|
meta:set_string("rds_message", msg.value)
|
||||||
ham_radio.transmitter_update_infotext(meta)
|
ham_radio.transmitter_update_infotext(meta)
|
||||||
ham_radio.save_transmitter(pos, meta)
|
ham_radio.save_transmitter(pos, meta)
|
||||||
|
|
||||||
|
16
hud.lua
16
hud.lua
@ -3,7 +3,7 @@ function ham_radio.toggle_hud(player)
|
|||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local item = player:get_wielded_item()
|
local item = player:get_wielded_item()
|
||||||
|
|
||||||
-- remove hud and broadcasts if user does not wield a receiver
|
-- remove hud and RDS if user does not wield a receiver
|
||||||
if item:get_name() ~= "ham_radio:handheld_receiver" then
|
if item:get_name() ~= "ham_radio:handheld_receiver" then
|
||||||
if ham_radio.is_receiver_wielded[name] then
|
if ham_radio.is_receiver_wielded[name] then
|
||||||
for hud_id, hud_handler in pairs(ham_radio.playerhuds[name]) do
|
for hud_id, hud_handler in pairs(ham_radio.playerhuds[name]) do
|
||||||
@ -11,7 +11,7 @@ function ham_radio.toggle_hud(player)
|
|||||||
end
|
end
|
||||||
ham_radio.playerhuds[name] = nil
|
ham_radio.playerhuds[name] = nil
|
||||||
ham_radio.is_receiver_wielded[name] = false
|
ham_radio.is_receiver_wielded[name] = false
|
||||||
ham_radio.player_broadcasts[name] = nil
|
ham_radio.player_rds[name] = nil
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -44,7 +44,7 @@ function ham_radio.toggle_hud(player)
|
|||||||
number = 0x999999,
|
number = 0x999999,
|
||||||
scale= { x = 100, y = 20 },
|
scale= { x = 100, y = 20 },
|
||||||
}),
|
}),
|
||||||
broadcast = player:hud_add({
|
rds = player:hud_add({
|
||||||
hud_elem_type = "text",
|
hud_elem_type = "text",
|
||||||
text = "",
|
text = "",
|
||||||
position = hud_pos,
|
position = hud_pos,
|
||||||
@ -104,12 +104,12 @@ function ham_radio:update_hud_display(player)
|
|||||||
player:hud_change(self.playerhuds[name].frequency, "number", "0xFCAD00")
|
player:hud_change(self.playerhuds[name].frequency, "number", "0xFCAD00")
|
||||||
end
|
end
|
||||||
|
|
||||||
if meta:get_string("broadcast_disabled") == "" then
|
if meta:get_string("rds_disabled") == "" then
|
||||||
player:hud_change(self.playerhuds[name].broadcast, "text", "RDS ON")
|
player:hud_change(self.playerhuds[name].rds, "text", "RDS ON")
|
||||||
player:hud_change(self.playerhuds[name].broadcast, "number", "0xFCAD00")
|
player:hud_change(self.playerhuds[name].rds, "number", "0xFCAD00")
|
||||||
else
|
else
|
||||||
player:hud_change(self.playerhuds[name].broadcast, "text", "RDS off")
|
player:hud_change(self.playerhuds[name].rds, "text", "RDS off")
|
||||||
player:hud_change(self.playerhuds[name].broadcast, "number", "0x999999")
|
player:hud_change(self.playerhuds[name].rds, "number", "0x999999")
|
||||||
end
|
end
|
||||||
|
|
||||||
player:hud_change(
|
player:hud_change(
|
||||||
|
18
init.lua
18
init.lua
@ -5,7 +5,7 @@ ham_radio = rawget(_G, "ham_radio") or {}
|
|||||||
|
|
||||||
ham_radio = {
|
ham_radio = {
|
||||||
playerhuds = {},
|
playerhuds = {},
|
||||||
player_broadcasts = {},
|
player_rds = {},
|
||||||
is_receiver_wielded = {},
|
is_receiver_wielded = {},
|
||||||
transmitters = {},
|
transmitters = {},
|
||||||
}
|
}
|
||||||
@ -19,7 +19,7 @@ end
|
|||||||
function ham_radio.save_transmitter(pos, meta)
|
function ham_radio.save_transmitter(pos, meta)
|
||||||
local transmitter_properties = {
|
local transmitter_properties = {
|
||||||
frequency = meta:get_string("frequency"),
|
frequency = meta:get_string("frequency"),
|
||||||
broadcast_message = meta:get_string("broadcast_message"),
|
rds_message = meta:get_string("rds_message"),
|
||||||
operated_by = meta:get_string("operated_by")
|
operated_by = meta:get_string("operated_by")
|
||||||
}
|
}
|
||||||
local key = minetest.pos_to_string(pos, 0)
|
local key = minetest.pos_to_string(pos, 0)
|
||||||
@ -41,7 +41,7 @@ dofile(modpath.."/digiline.lua")
|
|||||||
dofile(modpath.."/transmitter.lua")
|
dofile(modpath.."/transmitter.lua")
|
||||||
dofile(modpath.."/receiver.lua")
|
dofile(modpath.."/receiver.lua")
|
||||||
dofile(modpath.."/beacon.lua")
|
dofile(modpath.."/beacon.lua")
|
||||||
dofile(modpath.."/broadcast.lua")
|
dofile(modpath.."/rds.lua")
|
||||||
dofile(modpath.."/hud.lua")
|
dofile(modpath.."/hud.lua")
|
||||||
|
|
||||||
-- globals
|
-- globals
|
||||||
@ -56,22 +56,22 @@ minetest.register_on_leaveplayer(function(player)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
local updatetimer = 0
|
local updatetimer = 0
|
||||||
local broadcasttimer = 0
|
local rds_timer = 0
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
updatetimer = updatetimer + dtime
|
updatetimer = updatetimer + dtime
|
||||||
broadcasttimer = broadcasttimer + dtime
|
rds_timer = rds_timer + dtime
|
||||||
if updatetimer > 0.1 then
|
if updatetimer > 0.1 then
|
||||||
local players = minetest.get_connected_players()
|
local players = minetest.get_connected_players()
|
||||||
for i=1, #players do
|
for i=1, #players do
|
||||||
ham_radio:update_hud_display(players[i])
|
ham_radio:update_hud_display(players[i])
|
||||||
end
|
end
|
||||||
updatetimer = 0
|
updatetimer = 0
|
||||||
-- broadcast timer
|
-- rds update timer
|
||||||
if broadcasttimer > ham_radio.settings.broadcast_interval then
|
if rds_timer > ham_radio.settings.rds_interval then
|
||||||
for i=1, #players do
|
for i=1, #players do
|
||||||
ham_radio:update_broadcast(players[i])
|
ham_radio:update_rds(players[i])
|
||||||
end
|
end
|
||||||
broadcasttimer = 0
|
rds_timer = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
55
rds.lua
Normal file
55
rds.lua
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
function ham_radio.get_rds_messages(frequency)
|
||||||
|
local transmitters = ham_radio.find_transmitters(frequency)
|
||||||
|
local rds_messages = {}
|
||||||
|
for position, transmitter in pairs(transmitters) do
|
||||||
|
if transmitter.rds_message ~= "" then
|
||||||
|
-- construct message
|
||||||
|
local message = table.concat({
|
||||||
|
'[ Radio | ',
|
||||||
|
transmitter.operated_by,
|
||||||
|
' ] ',
|
||||||
|
transmitter.rds_message,
|
||||||
|
}, "")
|
||||||
|
table.insert(rds_messages, message)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return rds_messages
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function ham_radio:update_rds(player)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local item = player:get_wielded_item()
|
||||||
|
|
||||||
|
if item:get_name() ~= "ham_radio:handheld_receiver" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local meta = item:get_meta()
|
||||||
|
local frequency = meta:get_string("frequency")
|
||||||
|
local rds_disabled = meta:get_string("rds_disabled")
|
||||||
|
|
||||||
|
if frequency == "" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if rds_disabled == "true" then
|
||||||
|
-- disabled receiving RDS messages
|
||||||
|
ham_radio.player_rds[name] = nil
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if ham_radio.player_rds[name] == nil then
|
||||||
|
ham_radio.player_rds[name] = ham_radio.get_rds_messages(frequency)
|
||||||
|
end
|
||||||
|
|
||||||
|
local message = table.remove(ham_radio.player_rds[name])
|
||||||
|
if message ~= nil then
|
||||||
|
minetest.chat_send_player(player:get_player_name(), minetest.colorize(ham_radio.settings.rds_color, message))
|
||||||
|
|
||||||
|
-- when all RDS messages are shown, reload them again
|
||||||
|
if not next(ham_radio.player_rds[name]) then
|
||||||
|
ham_radio.player_rds[name] = ham_radio.get_rds_messages(frequency)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
12
receiver.lua
12
receiver.lua
@ -23,11 +23,11 @@ minetest.register_tool("ham_radio:handheld_receiver", {
|
|||||||
-- right click - RDS on/off
|
-- right click - RDS on/off
|
||||||
on_secondary_use = function(itemstack, user, pointed_thing)
|
on_secondary_use = function(itemstack, user, pointed_thing)
|
||||||
local meta = itemstack:get_meta()
|
local meta = itemstack:get_meta()
|
||||||
local is_broadcast_disabled = meta:get_string("broadcast_disabled")
|
local is_rds_disabled = meta:get_string("rds_disabled")
|
||||||
if is_broadcast_disabled == "" then
|
if is_rds_disabled == "" then
|
||||||
meta:set_string("broadcast_disabled", "true")
|
meta:set_string("rds_disabled", "true")
|
||||||
else
|
else
|
||||||
meta:set_string("broadcast_disabled", "")
|
meta:set_string("rds_disabled", "")
|
||||||
end
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
@ -45,8 +45,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
meta:set_string("frequency", fields.frequency)
|
meta:set_string("frequency", fields.frequency)
|
||||||
-- replace wielded item with new metadata
|
-- replace wielded item with new metadata
|
||||||
player:set_wielded_item(item)
|
player:set_wielded_item(item)
|
||||||
-- reset broadcast messages
|
-- reset rds messages
|
||||||
ham_radio.player_broadcasts[player:get_player_name()] = nil
|
ham_radio.player_rds[player:get_player_name()] = nil
|
||||||
return true
|
return true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -1,15 +1,20 @@
|
|||||||
|
|
||||||
ham_radio.transmitter_update_infotext = function(meta)
|
ham_radio.transmitter_update_infotext = function(meta)
|
||||||
|
local operated_by = meta:get_string("operated_by")
|
||||||
local frequency = meta:get_string("frequency")
|
local frequency = meta:get_string("frequency")
|
||||||
local broadcast_message = meta:get_string("broadcast_message")
|
local rds_message = meta:get_string("rds_message")
|
||||||
if frequency == "" then
|
if frequency == "" then
|
||||||
frequency = "--"
|
frequency = "--"
|
||||||
broadcast_message = ""
|
rds_message = ""
|
||||||
end
|
end
|
||||||
local infotext = {'Frequency: ', frequency}
|
local infotext = {
|
||||||
if broadcast_message ~= "" then
|
'Radio Transmitter\n',
|
||||||
table.insert(infotext, '\nBroadcast: "')
|
'Operated by: ', operated_by, '\n',
|
||||||
table.insert(infotext, broadcast_message)
|
'Frequency: ', frequency
|
||||||
|
}
|
||||||
|
if rds_message ~= "" then
|
||||||
|
table.insert(infotext, '\nRDS message: "')
|
||||||
|
table.insert(infotext, rds_message)
|
||||||
table.insert(infotext, '"')
|
table.insert(infotext, '"')
|
||||||
end
|
end
|
||||||
meta:set_string("infotext", table.concat(infotext, ''))
|
meta:set_string("infotext", table.concat(infotext, ''))
|
||||||
@ -33,7 +38,7 @@ minetest.register_node("ham_radio:transmitter", {
|
|||||||
local meta = minetest.get_meta(pos);
|
local meta = minetest.get_meta(pos);
|
||||||
local name = placer:get_player_name()
|
local name = placer:get_player_name()
|
||||||
meta:set_string('operated_by', name)
|
meta:set_string('operated_by', name)
|
||||||
meta:set_string('broadcast_message', "")
|
meta:set_string('rds_message', "")
|
||||||
meta:set_string("formspec",
|
meta:set_string("formspec",
|
||||||
table.concat({
|
table.concat({
|
||||||
"size[7,5]",
|
"size[7,5]",
|
||||||
@ -43,11 +48,11 @@ 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;broadcast_message;RDS message;${broadcast_message}]",
|
"field[0.25,3.5;7,1;rds_message;RDS message;${rds_message}]",
|
||||||
"button_exit[2,4.5;3,1;;Done]"
|
"button_exit[2,4.5;3,1;;Done]"
|
||||||
},'')
|
},'')
|
||||||
)
|
)
|
||||||
meta:set_string("infotext", '')
|
ham_radio.transmitter_update_infotext(meta)
|
||||||
end,
|
end,
|
||||||
on_receive_fields = function(pos, formname, fields, sender)
|
on_receive_fields = function(pos, formname, fields, sender)
|
||||||
if not minetest.is_player(sender) then
|
if not minetest.is_player(sender) then
|
||||||
@ -64,7 +69,7 @@ minetest.register_node("ham_radio:transmitter", {
|
|||||||
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("frequency", fields.frequency)
|
meta:set_string("frequency", fields.frequency)
|
||||||
meta:set_string("broadcast_message", fields.broadcast_message)
|
meta:set_string("rds_message", fields.rds_message)
|
||||||
ham_radio.transmitter_update_infotext(meta)
|
ham_radio.transmitter_update_infotext(meta)
|
||||||
ham_radio.save_transmitter(pos, meta)
|
ham_radio.save_transmitter(pos, meta)
|
||||||
end,
|
end,
|
||||||
|
Loading…
Reference in New Issue
Block a user