mirror of
https://github.com/technix/ham_radio.git
synced 2025-03-13 11:22:32 +01:00
rename broadcast to RDS
This commit is contained in:
@ -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 = {
|
||||
-- color of broadcast messages
|
||||
broadcast_color = '#607d8b',
|
||||
-- interval between broadcasts (seconds)
|
||||
broadcast_interval = 10,
|
||||
-- color of RDS messages
|
||||
rds_color = '#607d8b',
|
||||
-- interval between RDS messages (seconds)
|
||||
rds_interval = 10,
|
||||
-- receiver hud position
|
||||
hud_pos = { x = 0.5, y = 0.8 },
|
||||
-- radio frequency range
|
||||
@ -22,5 +22,5 @@ ham_radio.settings = {
|
||||
},
|
||||
-- digiline config
|
||||
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)
|
||||
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
|
||||
end
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
-- broadcast channel - text message
|
||||
if channel == broadcast_channel then
|
||||
-- RDS channel - text message
|
||||
if channel == rds_channel 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.save_transmitter(pos, meta)
|
||||
end
|
||||
@ -27,7 +27,7 @@ ham_radio.digiline_effector = function(pos, _, channel, msg)
|
||||
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"),
|
||||
rds_message = meta:get_string("rds_message"),
|
||||
})
|
||||
|
||||
elseif msg.command == "frequency" then
|
||||
@ -39,7 +39,7 @@ ham_radio.digiline_effector = function(pos, _, channel, msg)
|
||||
end
|
||||
|
||||
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.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 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 ham_radio.is_receiver_wielded[name] then
|
||||
for hud_id, hud_handler in pairs(ham_radio.playerhuds[name]) do
|
||||
@ -11,7 +11,7 @@ function ham_radio.toggle_hud(player)
|
||||
end
|
||||
ham_radio.playerhuds[name] = nil
|
||||
ham_radio.is_receiver_wielded[name] = false
|
||||
ham_radio.player_broadcasts[name] = nil
|
||||
ham_radio.player_rds[name] = nil
|
||||
end
|
||||
return false
|
||||
end
|
||||
@ -44,7 +44,7 @@ function ham_radio.toggle_hud(player)
|
||||
number = 0x999999,
|
||||
scale= { x = 100, y = 20 },
|
||||
}),
|
||||
broadcast = player:hud_add({
|
||||
rds = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
text = "",
|
||||
position = hud_pos,
|
||||
@ -104,12 +104,12 @@ function ham_radio:update_hud_display(player)
|
||||
player:hud_change(self.playerhuds[name].frequency, "number", "0xFCAD00")
|
||||
end
|
||||
|
||||
if meta:get_string("broadcast_disabled") == "" then
|
||||
player:hud_change(self.playerhuds[name].broadcast, "text", "RDS ON")
|
||||
player:hud_change(self.playerhuds[name].broadcast, "number", "0xFCAD00")
|
||||
if meta:get_string("rds_disabled") == "" then
|
||||
player:hud_change(self.playerhuds[name].rds, "text", "RDS ON")
|
||||
player:hud_change(self.playerhuds[name].rds, "number", "0xFCAD00")
|
||||
else
|
||||
player:hud_change(self.playerhuds[name].broadcast, "text", "RDS off")
|
||||
player:hud_change(self.playerhuds[name].broadcast, "number", "0x999999")
|
||||
player:hud_change(self.playerhuds[name].rds, "text", "RDS off")
|
||||
player:hud_change(self.playerhuds[name].rds, "number", "0x999999")
|
||||
end
|
||||
|
||||
player:hud_change(
|
||||
|
18
init.lua
18
init.lua
@ -5,7 +5,7 @@ ham_radio = rawget(_G, "ham_radio") or {}
|
||||
|
||||
ham_radio = {
|
||||
playerhuds = {},
|
||||
player_broadcasts = {},
|
||||
player_rds = {},
|
||||
is_receiver_wielded = {},
|
||||
transmitters = {},
|
||||
}
|
||||
@ -19,7 +19,7 @@ end
|
||||
function ham_radio.save_transmitter(pos, meta)
|
||||
local transmitter_properties = {
|
||||
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")
|
||||
}
|
||||
local key = minetest.pos_to_string(pos, 0)
|
||||
@ -41,7 +41,7 @@ dofile(modpath.."/digiline.lua")
|
||||
dofile(modpath.."/transmitter.lua")
|
||||
dofile(modpath.."/receiver.lua")
|
||||
dofile(modpath.."/beacon.lua")
|
||||
dofile(modpath.."/broadcast.lua")
|
||||
dofile(modpath.."/rds.lua")
|
||||
dofile(modpath.."/hud.lua")
|
||||
|
||||
-- globals
|
||||
@ -56,22 +56,22 @@ minetest.register_on_leaveplayer(function(player)
|
||||
end)
|
||||
|
||||
local updatetimer = 0
|
||||
local broadcasttimer = 0
|
||||
local rds_timer = 0
|
||||
minetest.register_globalstep(function(dtime)
|
||||
updatetimer = updatetimer + dtime
|
||||
broadcasttimer = broadcasttimer + dtime
|
||||
rds_timer = rds_timer + dtime
|
||||
if updatetimer > 0.1 then
|
||||
local players = minetest.get_connected_players()
|
||||
for i=1, #players do
|
||||
ham_radio:update_hud_display(players[i])
|
||||
end
|
||||
updatetimer = 0
|
||||
-- broadcast timer
|
||||
if broadcasttimer > ham_radio.settings.broadcast_interval then
|
||||
-- rds update timer
|
||||
if rds_timer > ham_radio.settings.rds_interval then
|
||||
for i=1, #players do
|
||||
ham_radio:update_broadcast(players[i])
|
||||
ham_radio:update_rds(players[i])
|
||||
end
|
||||
broadcasttimer = 0
|
||||
rds_timer = 0
|
||||
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
|
||||
on_secondary_use = function(itemstack, user, pointed_thing)
|
||||
local meta = itemstack:get_meta()
|
||||
local is_broadcast_disabled = meta:get_string("broadcast_disabled")
|
||||
if is_broadcast_disabled == "" then
|
||||
meta:set_string("broadcast_disabled", "true")
|
||||
local is_rds_disabled = meta:get_string("rds_disabled")
|
||||
if is_rds_disabled == "" then
|
||||
meta:set_string("rds_disabled", "true")
|
||||
else
|
||||
meta:set_string("broadcast_disabled", "")
|
||||
meta:set_string("rds_disabled", "")
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
@ -45,8 +45,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
meta:set_string("frequency", fields.frequency)
|
||||
-- replace wielded item with new metadata
|
||||
player:set_wielded_item(item)
|
||||
-- reset broadcast messages
|
||||
ham_radio.player_broadcasts[player:get_player_name()] = nil
|
||||
-- reset rds messages
|
||||
ham_radio.player_rds[player:get_player_name()] = nil
|
||||
return true
|
||||
end)
|
||||
|
||||
|
@ -1,15 +1,20 @@
|
||||
|
||||
ham_radio.transmitter_update_infotext = function(meta)
|
||||
local operated_by = meta:get_string("operated_by")
|
||||
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
|
||||
frequency = "--"
|
||||
broadcast_message = ""
|
||||
rds_message = ""
|
||||
end
|
||||
local infotext = {'Frequency: ', frequency}
|
||||
if broadcast_message ~= "" then
|
||||
table.insert(infotext, '\nBroadcast: "')
|
||||
table.insert(infotext, broadcast_message)
|
||||
local infotext = {
|
||||
'Radio Transmitter\n',
|
||||
'Operated by: ', operated_by, '\n',
|
||||
'Frequency: ', frequency
|
||||
}
|
||||
if rds_message ~= "" then
|
||||
table.insert(infotext, '\nRDS message: "')
|
||||
table.insert(infotext, rds_message)
|
||||
table.insert(infotext, '"')
|
||||
end
|
||||
meta:set_string("infotext", table.concat(infotext, ''))
|
||||
@ -33,7 +38,7 @@ minetest.register_node("ham_radio:transmitter", {
|
||||
local meta = minetest.get_meta(pos);
|
||||
local name = placer:get_player_name()
|
||||
meta:set_string('operated_by', name)
|
||||
meta:set_string('broadcast_message', "")
|
||||
meta:set_string('rds_message', "")
|
||||
meta:set_string("formspec",
|
||||
table.concat({
|
||||
"size[7,5]",
|
||||
@ -43,11 +48,11 @@ minetest.register_node("ham_radio:transmitter", {
|
||||
"tooltip[frequency;Integer number ",
|
||||
ham_radio.settings.frequency.min,"-",
|
||||
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]"
|
||||
},'')
|
||||
)
|
||||
meta:set_string("infotext", '')
|
||||
ham_radio.transmitter_update_infotext(meta)
|
||||
end,
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
if not minetest.is_player(sender) then
|
||||
@ -64,7 +69,7 @@ minetest.register_node("ham_radio:transmitter", {
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
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.save_transmitter(pos, meta)
|
||||
end,
|
||||
|
Reference in New Issue
Block a user