Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode
93 changes: 88 additions & 5 deletions beacon.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
local mod_storage = minetest.get_mod_storage()
local beacon_update_infotext = function(meta)
local operated_by = meta:get_string("operated_by")
local frequency = meta:get_string("frequency")
local rds_message = meta:get_string("rds_message")
if frequency == "" then
frequency = "--"
rds_message = ""
end
local infotext = {
'Radio Beacon\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, ''))
end

local function save_beacon(pos, meta)
local transmitter_properties = {
frequency = meta:get_string("frequency"),
rds_message = meta:get_string("rds_message"),
operated_by = meta:get_string("operated_by"),
handheld = false,
is_beacon = true
}
local key = minetest.pos_to_string(pos, 0)
mod_storage:set_string(key, minetest.write_json(transmitter_properties)) -- storage
end

minetest.register_node("ham_radio:beacon", {
description = "Radio Beacon",
tiles = {
Expand All @@ -8,7 +42,39 @@ minetest.register_node("ham_radio:beacon", {
"ham_radio_transmitter_side.png",
"ham_radio_beacon_front.png"
},
use_texture_alpha = "clip",
on_receive_fields = function(pos, formname, fields, sender)
if not minetest.is_player(sender) then
return
end

if (
fields.quit ~= "true"
or minetest.is_protected(pos, sender:get_player_name())
) then
return
end

local meta = minetest.get_meta(pos)
local transmitter_is_updated = false
local gpsbutton = false
if(fields.engps == "Enable GPS") then
gpsbutton = true
end

meta:set_string("GPS_enabled", "false")
meta:set_string("rds_message" , "This is a beacon at: GPS is disabled")
if gpsbutton == true then
meta:set_string("GPS_enabled", "true")
meta:set_string("rds_message", "This is a beacon at:" .. minetest.pos_to_string(pos))
end
transmitter_is_updated = true

if transmitter_is_updated then
beacon_update_infotext(meta)
save_beacon(pos, meta)
ham_radio.play_tuning_sound(sender)
end
end,
groups = {cracky=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_metal_defaults(),
paramtype2 = "facedir",
Expand All @@ -21,14 +87,31 @@ minetest.register_node("ham_radio:beacon", {
light_source = 3,
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos);
local name = "anonymous"
if minetest.is_player(placer) then
local name = placer:get_player_name()
name = placer:get_player_name()
if name == "" then
name = "anonymous"
end
meta:set_string('operated_by', name)
ham_radio.play_tuning_sound(placer)
end
meta:set_string("frequency", ham_radio.find_free_frequency(ham_radio.settings.beacon_frequency))
ham_radio.transmitter_update_infotext(meta)
ham_radio.save_transmitter(pos, meta)
local freq = ham_radio.find_free_frequency(ham_radio.settings.beacon_frequency)
meta:set_string("frequency", freq)
meta:set_string("rds_message" , "This is a beacon at: GPS is disabled")
meta:set_string("GPS_enabled", "false")
meta:set_string("formspec",
table.concat({
"size[7,6]",
"image[0.25,-1;4,4;ham_radio_beacon_front.png]",
"label[0.25,0;Beacon operated by: ",minetest.formspec_escape(name),"]",
"label[0.25,2.75;Frequency: ", minetest.formspec_escape(freq), "]",
"button_exit[2,4;3,1;engps;Disable GPS]",
"button_exit[2,5;3,1;engps;Enable GPS]"
},'')
)
beacon_update_infotext(meta)
save_beacon(pos, meta)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
Expand Down
1 change: 1 addition & 0 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ ham_radio.settings = {
digiline_channel = "ham_radio",
digiline_rds_channel = "ham_radio_rds",
digiline_receiver_channel = "ham_radio_receiver",
digiline_scanner_channel = "ham_radio_scanner",
}
19 changes: 19 additions & 0 deletions craft.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ minetest.register_craft({
}
})

minetest.register_craft({
output = "ham_radio:handheld_transmitter",
recipe = {
{antenna, antenna, antenna},
{'ham_radio:circuit','ham_radio:circuit', 'ham_radio:circuit'},
{body, body, body}
}
})

minetest.register_craft({
output = "ham_radio:receiver",
recipe = {
Expand All @@ -49,6 +58,16 @@ minetest.register_craft({
}
})


minetest.register_craft({
output = "ham_radio:scanner",
recipe = {
{antenna, antenna, antenna},
{'ham_radio:circuit',antenna, 'ham_radio:circuit'},
{body, body, body}
}
})

minetest.register_craft({
output = "ham_radio:transmitter",
recipe = {
Expand Down
4 changes: 4 additions & 0 deletions depends.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
default
basic_materials?
technic?
digilines?
56 changes: 51 additions & 5 deletions digiline.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
ham_radio.digiline_effector_transmitter = function(pos, _, channel, msg)
-- static channels for transmitter
local command_channel = ham_radio.settings.digiline_channel
local rds_channel = ham_radio.settings.digiline_rds_channel
-- static channels for transmitter
local meta = minetest.get_meta(pos)

local rds_channel = meta:get_string("digiline_channel_rds")
local command_channel = meta:get_string("digiline_channel_command")

if rds_channel == nil or rds_channel == "" then
rds_channel = ham_radio.settings.digiline_rds_channel
end

if command_channel == nil or command_channel == "" then
command_channel = ham_radio.settings.digiline_channel
end

if meta:get_string("digiline_channel_command") ~= "" and meta:get_string("digiline_channel_command") ~= nil then
command_channel = meta:get_string("digiline_channel_command")
end
if meta:get_string("digiline_channel_rds") ~= "" and meta:get_string("digiline_channel_rds") ~= nil then
rds_channel = meta:get_string("digiline_channel_rds")
end
if channel ~= command_channel and channel ~= rds_channel then
return
end

local meta = minetest.get_meta(pos)

-- RDS channel - text message
if channel == rds_channel then
Expand Down Expand Up @@ -59,25 +74,32 @@ end

ham_radio.digiline_effector_receiver = function(pos, _, channel, msg)
-- static channel for receiver
local meta = minetest.get_meta(pos)

local command_channel = ham_radio.settings.digiline_receiver_channel
local block_command_channel = meta:get_string("digiline_channel_command")

if block_command_channel ~= "" and block_command_channel ~= nil then
command_channel = block_command_channel
end
if channel ~= command_channel or type(msg) ~= "table" then
return
end

local meta = minetest.get_meta(pos)

if msg.command == "get" then
digilines.receptor_send(pos, digilines.rules.default, command_channel, {
frequency = meta:get_string("frequency"),
rds_message = meta:get_string("rds_message"),
signal = meta:get_int("signal"),
})

elseif msg.command == "frequency" or msg.command == "set_frequency" then
local new_frequency = msg.value
local validate = ham_radio.validate_frequency(new_frequency, true)
if validate.result then
meta:set_string("frequency", new_frequency)
ham_radio.receiver_update_infotext(meta)
-- load new RDS messages
local poshash = minetest.pos_to_string(pos, 0)
ham_radio.receiver_rds[poshash] = ham_radio.get_rds_messages(new_frequency, true)
Expand All @@ -90,4 +112,28 @@ ham_radio.digiline_effector_receiver = function(pos, _, channel, msg)
})
end

end

ham_radio.digiline_effector_scanner = function(pos, _, channel, msg)
-- static channel for scanner
local meta = minetest.get_meta(pos)

local command_channel = ham_radio.settings.digiline_scanner_channel
local block_command_channel = meta:get_string("digiline_channel_command")

if block_command_channel ~= "" and block_command_channel ~= nil then
command_channel = block_command_channel
end

if channel ~= command_channel or type(msg) ~= "table" then
return
end

if msg.command == "get" then
digilines.receptor_send(pos, digilines.rules.default, command_channel, {
active_frequencies = meta:get_string("active_frequencies"),
transmitter_db = minetest.parse_json(meta:get_string("transmitter_db"))
})
end

end
6 changes: 5 additions & 1 deletion init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ function ham_radio.save_transmitter(pos, meta)
local transmitter_properties = {
frequency = meta:get_string("frequency"),
rds_message = meta:get_string("rds_message"),
operated_by = meta:get_string("operated_by")
operated_by = meta:get_string("operated_by"),
handheld = false,
is_beacon = false
}
local key = minetest.pos_to_string(pos, 0)
mod_storage:set_string(key, minetest.write_json(transmitter_properties)) -- storage
Expand All @@ -54,11 +56,13 @@ dofile(modpath.."/config.lua")
dofile(modpath.."/helpers.lua")
dofile(modpath.."/craft.lua")
dofile(modpath.."/digiline.lua")
dofile(modpath.."/transmitter_station.lua")
dofile(modpath.."/transmitter.lua")
dofile(modpath.."/receiver.lua")
dofile(modpath.."/beacon.lua")
dofile(modpath.."/rds.lua")
dofile(modpath.."/receiver_station.lua")
dofile(modpath.."/scanning_station.lua")
dofile(modpath.."/hud.lua")

-- globals
Expand Down
3 changes: 3 additions & 0 deletions mod.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ name = ham_radio
description = Adds radio transmitters, beacons, and receivers.
depends = default
optional_depends = basic_materials, technic, digilines
release = 5373
author = techniX
title = Ham Radio
6 changes: 0 additions & 6 deletions rds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@ function ham_radio.get_rds_messages(frequency, is_receiver_station)
for rds_message_line in transmitter.rds_message:gmatch("[^\n]+") do
-- construct message
local message = table.concat({
'[ Radio | ',
transmitter.operated_by,
' ] ',
rds_message_line,
}, "")
if is_receiver_station then
message = table.concat({
'[ ',
transmitter.operated_by,
' ] ',
rds_message_line
}, "")
end
Expand Down
Loading