mirror of
https://github.com/technix/ham_radio.git
synced 2025-01-23 04:21:26 +01:00
abstract saving transmitter properties
This commit is contained in:
parent
4fb166ebe4
commit
8c56210851
7
init.lua
7
init.lua
@ -25,7 +25,12 @@ for key, transmitter_data in pairs(all_transmitters) do
|
|||||||
ham_radio.transmitters[key] = minetest.parse_json(transmitter_data)
|
ham_radio.transmitters[key] = minetest.parse_json(transmitter_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ham_radio.save_transmitter(pos, transmitter_properties)
|
function ham_radio.save_transmitter(pos, meta)
|
||||||
|
local transmitter_properties = {
|
||||||
|
frequency = meta:get_string("frequency"),
|
||||||
|
broadcast_message = meta:get_string("broadcast_message"),
|
||||||
|
operated_by = meta:get_string("operated_by")
|
||||||
|
}
|
||||||
local key = minetest.pos_to_string(pos, 0)
|
local key = minetest.pos_to_string(pos, 0)
|
||||||
ham_radio.transmitters[key] = transmitter_properties -- cache
|
ham_radio.transmitters[key] = transmitter_properties -- cache
|
||||||
mod_storage:set_string(key, minetest.write_json(transmitter_properties)) -- storage
|
mod_storage:set_string(key, minetest.write_json(transmitter_properties)) -- storage
|
||||||
|
@ -1,4 +1,15 @@
|
|||||||
|
|
||||||
|
ham_radio.transmitter_update_infotext = function(meta)
|
||||||
|
local infotext = {'Frequency: ', meta:get_string("frequency")}
|
||||||
|
local broadcast_message = meta:get_string("broadcast_message")
|
||||||
|
if broadcast_message ~= "" then
|
||||||
|
table.insert(infotext, '\nBroadcast: "')
|
||||||
|
table.insert(infotext, broadcast_message)
|
||||||
|
table.insert(infotext, '"')
|
||||||
|
end
|
||||||
|
meta:set_string("infotext", table.concat(infotext, ''))
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_node("ham_radio:transmitter", {
|
minetest.register_node("ham_radio:transmitter", {
|
||||||
description = "Ham Radio Transmitter",
|
description = "Ham Radio Transmitter",
|
||||||
tiles = {
|
tiles = {
|
||||||
@ -47,24 +58,10 @@ minetest.register_node("ham_radio:transmitter", {
|
|||||||
end
|
end
|
||||||
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local broadcast_message = fields.broadcast_message
|
|
||||||
local infotext = {'Frequency: ',fields.frequency}
|
|
||||||
if broadcast_message ~= "" then
|
|
||||||
table.insert(infotext, '\nBroadcast: "')
|
|
||||||
table.insert(infotext, broadcast_message)
|
|
||||||
table.insert(infotext, '"')
|
|
||||||
end
|
|
||||||
meta:set_string("frequency", fields.frequency)
|
meta:set_string("frequency", fields.frequency)
|
||||||
meta:set_string("broadcast_message", broadcast_message)
|
meta:set_string("broadcast_message", fields.broadcast_message)
|
||||||
meta:set_string("infotext", table.concat(infotext, ''))
|
ham_radio.transmitter_update_infotext(meta)
|
||||||
ham_radio.save_transmitter(
|
ham_radio.save_transmitter(pos, meta)
|
||||||
pos,
|
|
||||||
{
|
|
||||||
frequency = fields.frequency,
|
|
||||||
broadcast_message = broadcast_message,
|
|
||||||
operated_by = meta:get_string('operated_by')
|
|
||||||
}
|
|
||||||
)
|
|
||||||
end,
|
end,
|
||||||
can_dig = function(pos,player)
|
can_dig = function(pos,player)
|
||||||
local meta = minetest.get_meta(pos);
|
local meta = minetest.get_meta(pos);
|
||||||
|
Loading…
Reference in New Issue
Block a user