2019-12-06 14:58:49 +01:00
|
|
|
local modpath = minetest.get_modpath("ham_radio")
|
|
|
|
local mod_storage = minetest.get_mod_storage()
|
|
|
|
|
|
|
|
ham_radio = rawget(_G, "ham_radio") or {}
|
|
|
|
|
|
|
|
ham_radio = {
|
2019-12-06 15:25:03 +01:00
|
|
|
playerhuds = {},
|
2019-12-08 18:07:18 +01:00
|
|
|
player_rds = {},
|
2019-12-07 10:42:08 +01:00
|
|
|
is_receiver_wielded = {},
|
2019-12-07 20:04:13 +01:00
|
|
|
transmitters = {},
|
2019-12-06 14:58:49 +01:00
|
|
|
}
|
|
|
|
|
2019-12-07 20:04:13 +01:00
|
|
|
-- preload transmitter data
|
|
|
|
local all_transmitters = mod_storage:to_table().fields
|
|
|
|
for key, transmitter_data in pairs(all_transmitters) do
|
|
|
|
ham_radio.transmitters[key] = minetest.parse_json(transmitter_data)
|
2019-12-06 14:58:49 +01:00
|
|
|
end
|
|
|
|
|
2019-12-08 00:05:39 +01:00
|
|
|
function ham_radio.save_transmitter(pos, meta)
|
|
|
|
local transmitter_properties = {
|
|
|
|
frequency = meta:get_string("frequency"),
|
2019-12-08 18:07:18 +01:00
|
|
|
rds_message = meta:get_string("rds_message"),
|
2019-12-08 00:05:39 +01:00
|
|
|
operated_by = meta:get_string("operated_by")
|
|
|
|
}
|
2019-12-07 20:04:13 +01:00
|
|
|
local key = minetest.pos_to_string(pos, 0)
|
|
|
|
ham_radio.transmitters[key] = transmitter_properties -- cache
|
|
|
|
mod_storage:set_string(key, minetest.write_json(transmitter_properties)) -- storage
|
2019-12-06 14:58:49 +01:00
|
|
|
end
|
|
|
|
|
2019-12-07 19:40:42 +01:00
|
|
|
function ham_radio.delete_transmitter(pos)
|
2019-12-07 20:04:13 +01:00
|
|
|
local key = minetest.pos_to_string(pos, 0)
|
|
|
|
ham_radio.transmitters[key] = nil -- cache
|
|
|
|
mod_storage:set_string(key, '') -- storage
|
2019-12-06 14:58:49 +01:00
|
|
|
end
|
|
|
|
|
2019-12-08 19:27:24 +01:00
|
|
|
function ham_radio.play_tuning_sound(player)
|
|
|
|
minetest.sound_play(
|
|
|
|
{name = "ham_radio_tuning"..math.random(1,5)},
|
|
|
|
{to_player = player:get_player_name()}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2019-12-08 20:32:14 +01:00
|
|
|
function ham_radio.errormsg(player, message)
|
|
|
|
minetest.chat_send_player(player:get_player_name(), minetest.colorize("#FCAD00", message))
|
|
|
|
end
|
|
|
|
|
2019-12-08 16:17:28 +01:00
|
|
|
dofile(modpath.."/config.lua")
|
|
|
|
|
2019-12-07 20:24:49 +01:00
|
|
|
dofile(modpath.."/helpers.lua")
|
2019-12-06 16:30:45 +01:00
|
|
|
dofile(modpath.."/craft.lua")
|
2019-12-08 00:29:27 +01:00
|
|
|
dofile(modpath.."/digiline.lua")
|
2019-12-06 14:58:49 +01:00
|
|
|
dofile(modpath.."/transmitter.lua")
|
2019-12-07 21:54:19 +01:00
|
|
|
dofile(modpath.."/receiver.lua")
|
2019-12-08 02:10:27 +01:00
|
|
|
dofile(modpath.."/beacon.lua")
|
2019-12-08 18:07:18 +01:00
|
|
|
dofile(modpath.."/rds.lua")
|
2019-12-06 14:58:49 +01:00
|
|
|
dofile(modpath.."/hud.lua")
|
|
|
|
|
2019-12-07 21:54:19 +01:00
|
|
|
-- globals
|
|
|
|
|
|
|
|
minetest.register_on_newplayer(ham_radio.toggle_hud)
|
|
|
|
minetest.register_on_joinplayer(ham_radio.toggle_hud)
|
|
|
|
|
|
|
|
minetest.register_on_leaveplayer(function(player)
|
2019-12-08 01:15:39 +01:00
|
|
|
local name = player:get_player_name()
|
2019-12-07 21:54:19 +01:00
|
|
|
ham_radio.is_receiver_wielded[name] = false
|
2019-12-08 01:15:39 +01:00
|
|
|
ham_radio.playerhuds[name] = nil
|
2019-12-07 21:54:19 +01:00
|
|
|
end)
|
|
|
|
|
|
|
|
local updatetimer = 0
|
2019-12-08 18:07:18 +01:00
|
|
|
local rds_timer = 0
|
2019-12-07 21:54:19 +01:00
|
|
|
minetest.register_globalstep(function(dtime)
|
|
|
|
updatetimer = updatetimer + dtime
|
2019-12-08 18:07:18 +01:00
|
|
|
rds_timer = rds_timer + dtime
|
2019-12-07 21:54:19 +01:00
|
|
|
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
|
2019-12-08 18:07:18 +01:00
|
|
|
-- rds update timer
|
|
|
|
if rds_timer > ham_radio.settings.rds_interval then
|
2019-12-08 16:14:52 +01:00
|
|
|
for i=1, #players do
|
2019-12-08 18:07:18 +01:00
|
|
|
ham_radio:update_rds(players[i])
|
2019-12-08 16:14:52 +01:00
|
|
|
end
|
2019-12-08 18:07:18 +01:00
|
|
|
rds_timer = 0
|
2019-12-07 21:54:19 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|