mirror of
https://github.com/technix/ham_radio.git
synced 2024-08-18 20:24:07 +02:00
better data format
This commit is contained in:
parent
7c40bd0c19
commit
ee047a6266
9
hud.lua
9
hud.lua
@ -74,12 +74,11 @@ function ham_radio:update_hud_display(player)
|
|||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local meta = player:get_wielded_item():get_meta()
|
local meta = player:get_wielded_item():get_meta()
|
||||||
local frequency = meta:get_string("frequency")
|
local frequency = meta:get_string("frequency")
|
||||||
|
|
||||||
if frequency ~= nil and frequency ~= "" then
|
if frequency ~= nil and frequency ~= "" then
|
||||||
local transmitters = self.read_transmitters(frequency)
|
local transmitters = self.find_transmitters(frequency)
|
||||||
|
for position, transmitter in pairs(transmitters) do
|
||||||
for key, transmitter in pairs(transmitters) do
|
local transmitter_signal = self:locate_transmitter(player, minetest.string_to_pos(position))
|
||||||
local transmitter_signal = self:locate_transmitter(player, transmitter.pos)
|
|
||||||
if transmitter_signal > signal_power then
|
if transmitter_signal > signal_power then
|
||||||
-- use max power from transmitters nearby
|
-- use max power from transmitters nearby
|
||||||
signal_power = transmitter_signal
|
signal_power = transmitter_signal
|
||||||
|
48
init.lua
48
init.lua
@ -11,35 +11,31 @@ ham_radio = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function ham_radio.save_transmitter(frequency, pos, transmitter_properties)
|
function ham_radio.save_transmitter(pos, transmitter_properties)
|
||||||
local transmitters = mod_storage:get_string(tostring(frequency))
|
mod_storage:set_string(
|
||||||
|
minetest.pos_to_string(pos, 0),
|
||||||
|
minetest.write_json(transmitter_properties)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ham_radio.read_transmitter(pos)
|
||||||
|
return mod_storage:get_string(minetest.pos_to_string(pos, 0))
|
||||||
|
end
|
||||||
|
|
||||||
|
function ham_radio.find_transmitters(frequency)
|
||||||
local transmitter_list = {}
|
local transmitter_list = {}
|
||||||
if transmitters ~= "" then
|
local all_transmitters = mod_storage:to_table().fields
|
||||||
transmitter_list = minetest.parse_json(transmitters)
|
for key, transmitter_data in pairs(all_transmitters) do
|
||||||
end
|
local transmitter = minetest.parse_json(transmitter_data)
|
||||||
transmitter_list[minetest.pos_to_string(pos, 0)] = transmitter_properties
|
if transmitter.frequency == frequency then
|
||||||
mod_storage:set_string(tostring(frequency), minetest.write_json(transmitter_list))
|
transmitter_list[key] = transmitter
|
||||||
end
|
|
||||||
|
|
||||||
function ham_radio.read_transmitters(frequency)
|
|
||||||
local transmitters = mod_storage:get_string(tostring(frequency))
|
|
||||||
if transmitters ~= "" then
|
|
||||||
return minetest.parse_json(transmitters)
|
|
||||||
end
|
|
||||||
return {}
|
|
||||||
end
|
|
||||||
|
|
||||||
function ham_radio.delete_transmitter(frequency, pos)
|
|
||||||
local transmitters = mod_storage:get_string(tostring(frequency))
|
|
||||||
if transmitters ~= "" then
|
|
||||||
local transmitter_list = minetest.parse_json(transmitters)
|
|
||||||
transmitter_list[minetest.pos_to_string(pos, 0)] = nil
|
|
||||||
if next(transmitter_list) == nil then
|
|
||||||
mod_storage:set_string(tostring(frequency),"")
|
|
||||||
else
|
|
||||||
mod_storage:set_string(tostring(frequency), minetest.write_json(transmitter_list))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return transmitter_list
|
||||||
|
end
|
||||||
|
|
||||||
|
function ham_radio.delete_transmitter(pos)
|
||||||
|
mod_storage:set_string(minetest.pos_to_string(pos, 0), '')
|
||||||
end
|
end
|
||||||
|
|
||||||
dofile(modpath.."/craft.lua")
|
dofile(modpath.."/craft.lua")
|
||||||
|
@ -37,10 +37,9 @@ minetest.register_node("ham_radio:transmitter", {
|
|||||||
meta:set_string("frequency", fields.frequency)
|
meta:set_string("frequency", fields.frequency)
|
||||||
meta:set_string("infotext", 'Frequency: '..fields.frequency)
|
meta:set_string("infotext", 'Frequency: '..fields.frequency)
|
||||||
ham_radio.save_transmitter(
|
ham_radio.save_transmitter(
|
||||||
fields.frequency,
|
|
||||||
pos,
|
pos,
|
||||||
{
|
{
|
||||||
pos = pos,
|
frequency = fields.frequency,
|
||||||
broadcast_message = "Test Ham Radio Broadcast!",
|
broadcast_message = "Test Ham Radio Broadcast!",
|
||||||
operated_by = meta:get_string('operated_by')
|
operated_by = meta:get_string('operated_by')
|
||||||
}
|
}
|
||||||
@ -54,6 +53,6 @@ minetest.register_node("ham_radio:transmitter", {
|
|||||||
return inv:is_empty("main") and not minetest.is_protected(pos, name)
|
return inv:is_empty("main") and not minetest.is_protected(pos, name)
|
||||||
end,
|
end,
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, player)
|
after_dig_node = function(pos, oldnode, oldmetadata, player)
|
||||||
ham_radio.delete_transmitter(oldmetadata.fields.frequency, pos)
|
ham_radio.delete_transmitter(pos)
|
||||||
end
|
end
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user