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-07 10:42:08 +01:00
|
|
|
is_receiver_wielded = {},
|
2019-12-07 20:04:13 +01:00
|
|
|
transmitters = {},
|
2019-12-06 15:25:03 +01:00
|
|
|
settings = {
|
2019-12-07 10:42:08 +01:00
|
|
|
hud_pos = { x = 0.5, y = 0.8 },
|
2019-12-07 20:24:49 +01:00
|
|
|
frequency = {
|
|
|
|
min = 0,
|
2019-12-07 20:54:48 +01:00
|
|
|
max = 9999999
|
2019-12-07 20:24:49 +01:00
|
|
|
}
|
2019-12-06 15:25:03 +01:00
|
|
|
}
|
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-07 20:04:13 +01:00
|
|
|
function ham_radio.save_transmitter(pos, transmitter_properties)
|
|
|
|
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.find_transmitters(frequency)
|
|
|
|
local transmitter_list = {}
|
2019-12-07 20:04:13 +01:00
|
|
|
for key, transmitter in pairs(ham_radio.transmitters) do
|
2019-12-07 19:40:42 +01:00
|
|
|
if transmitter.frequency == frequency then
|
|
|
|
transmitter_list[key] = transmitter
|
2019-12-07 18:48:07 +01:00
|
|
|
end
|
|
|
|
end
|
2019-12-07 19:40:42 +01:00
|
|
|
return transmitter_list
|
|
|
|
end
|
|
|
|
|
|
|
|
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-07 20:24:49 +01:00
|
|
|
dofile(modpath.."/helpers.lua")
|
2019-12-06 16:30:45 +01:00
|
|
|
dofile(modpath.."/craft.lua")
|
2019-12-06 14:58:49 +01:00
|
|
|
dofile(modpath.."/transmitter.lua")
|
|
|
|
dofile(modpath.."/receiver.lua")
|
|
|
|
dofile(modpath.."/hud.lua")
|
|
|
|
|
|
|
|
-- TODO: craft transmitter
|
|
|
|
-- TODO: configure transmitter
|
|
|
|
-- TODO: craft pelengator
|
|
|
|
-- TODO: set pelengator frequency
|