mirror of
https://github.com/technix/ham_radio.git
synced 2025-01-21 03:21:27 +01:00
validate frequency
This commit is contained in:
parent
5c199f251c
commit
139370227d
10
helpers.lua
Normal file
10
helpers.lua
Normal file
@ -0,0 +1,10 @@
|
||||
function ham_radio.validate_frequency(frequency)
|
||||
if frequency == nil then
|
||||
return false
|
||||
end
|
||||
local num_freq = math.floor(tonumber(frequency))
|
||||
local freq = tostring(num_freq)
|
||||
return freq == frequency
|
||||
and num_freq >= ham_radio.settings.frequency.min
|
||||
and num_freq <= ham_radio.settings.frequency.max
|
||||
end
|
5
init.lua
5
init.lua
@ -9,6 +9,10 @@ ham_radio = {
|
||||
transmitters = {},
|
||||
settings = {
|
||||
hud_pos = { x = 0.5, y = 0.8 },
|
||||
frequency = {
|
||||
min = 0,
|
||||
max = 1000000
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,6 +44,7 @@ function ham_radio.delete_transmitter(pos)
|
||||
mod_storage:set_string(key, '') -- storage
|
||||
end
|
||||
|
||||
dofile(modpath.."/helpers.lua")
|
||||
dofile(modpath.."/craft.lua")
|
||||
dofile(modpath.."/transmitter.lua")
|
||||
dofile(modpath.."/receiver.lua")
|
||||
|
@ -22,7 +22,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname ~= "ham_radio:configure_receiver" or not minetest.is_player(player) then
|
||||
return false
|
||||
end
|
||||
if fields.frequency == "" or fields.frequency == nil then
|
||||
if not ham_radio.validate_frequency(fields.frequency) then
|
||||
return false
|
||||
end
|
||||
local item = player:get_wielded_item()
|
||||
|
@ -2,12 +2,12 @@
|
||||
minetest.register_node("ham_radio:transmitter", {
|
||||
description = "Ham Radio Transmitter",
|
||||
tiles = {
|
||||
"ham_radio_transmitter_top.png",
|
||||
"ham_radio_transmitter_top.png",
|
||||
"ham_radio_transmitter_side.png",
|
||||
"ham_radio_transmitter_side.png",
|
||||
"ham_radio_transmitter_side.png",
|
||||
"ham_radio_transmitter_front.png"
|
||||
"ham_radio_transmitter_top.png",
|
||||
"ham_radio_transmitter_top.png",
|
||||
"ham_radio_transmitter_side.png",
|
||||
"ham_radio_transmitter_side.png",
|
||||
"ham_radio_transmitter_side.png",
|
||||
"ham_radio_transmitter_front.png"
|
||||
},
|
||||
groups = {cracky=2,oddly_breakable_by_hand=2},
|
||||
sounds = default.node_sound_metal_defaults(),
|
||||
@ -32,7 +32,7 @@ minetest.register_node("ham_radio:transmitter", {
|
||||
if fields.quit ~= "true" then
|
||||
return
|
||||
end
|
||||
if fields.frequency ~= nil and fields.frequency ~= '' then
|
||||
if ham_radio.validate_frequency(fields.frequency) then
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("frequency", fields.frequency)
|
||||
meta:set_string("infotext", 'Frequency: '..fields.frequency)
|
||||
|
Loading…
Reference in New Issue
Block a user