mirror of
https://github.com/technix/ham_radio.git
synced 2025-01-07 12:57:29 +01:00
fix indentation and line endings
This commit is contained in:
parent
bb03442083
commit
4626d07702
140
hud.lua
140
hud.lua
@ -1,70 +1,70 @@
|
|||||||
|
|
||||||
function ham_radio.init_hud(player)
|
function ham_radio.init_hud(player)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
ham_radio.playerhuds[name] = player:hud_add({
|
ham_radio.playerhuds[name] = player:hud_add({
|
||||||
hud_elem_type = "text",
|
hud_elem_type = "text",
|
||||||
text = "",
|
text = "",
|
||||||
position = ham_radio.settings.hud_pos,
|
position = ham_radio.settings.hud_pos,
|
||||||
offset = { x = ham_radio.settings.hud_offset.x, y = ham_radio.settings.hud_offset.y },
|
offset = { x = ham_radio.settings.hud_offset.x, y = ham_radio.settings.hud_offset.y },
|
||||||
alignment = ham_radio.settings.hud_alignment,
|
alignment = ham_radio.settings.hud_alignment,
|
||||||
number = 0xFFFFFF,
|
number = 0xFFFFFF,
|
||||||
scale= { x = 100, y = 20 },
|
scale= { x = 100, y = 20 },
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function ham_radio:update_hud_display(player)
|
function ham_radio:update_hud_display(player)
|
||||||
local transmitter_signal = 0
|
local transmitter_signal = 0
|
||||||
|
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local item = player:get_wielded_item()
|
local item = player:get_wielded_item()
|
||||||
|
|
||||||
if item:get_name() ~= "ham_radio:receiver" then
|
if item:get_name() ~= "ham_radio:receiver" then
|
||||||
if self.playerlocators[name] then
|
if self.playerlocators[name] then
|
||||||
player:hud_change(self.playerhuds[name], "text", "")
|
player:hud_change(self.playerhuds[name], "text", "")
|
||||||
self.playerlocators[name] = false
|
self.playerlocators[name] = false
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
self.playerlocators[name] = true
|
self.playerlocators[name] = true
|
||||||
|
|
||||||
local meta = item:get_meta()
|
local meta = item:get_meta()
|
||||||
local frequency = meta:get_string("frequency")
|
local frequency = meta:get_string("frequency")
|
||||||
|
|
||||||
minetest.chat_send_player(player:get_player_name(), "Configured freq:"..frequency)
|
minetest.chat_send_player(player:get_player_name(), "Configured freq:"..frequency)
|
||||||
|
|
||||||
if frequency ~= nil and frequency ~= "" then
|
if frequency ~= nil and frequency ~= "" then
|
||||||
local transmitter = self.read_transmitter(frequency)
|
local transmitter = self.read_transmitter(frequency)
|
||||||
-- minetest.chat_send_player(player:get_player_name(), "Found transmitter:"..minetest.serialize(transmitter))
|
-- minetest.chat_send_player(player:get_player_name(), "Found transmitter:"..minetest.serialize(transmitter))
|
||||||
if transmitter.pos then
|
if transmitter.pos then
|
||||||
transmitter_signal = self:locate_transmitter(player, transmitter.pos)
|
transmitter_signal = self:locate_transmitter(player, transmitter.pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- local target_pos = {x=-407, y = 59, z = 70}
|
-- local target_pos = {x=-407, y = 59, z = 70}
|
||||||
|
|
||||||
--local indicator = string.rep('|', transmitter.distance)..string.rep('|', transmitter.signal)..string.rep(':', 25-(transmitter.distance + transmitter.signal))
|
--local indicator = string.rep('|', transmitter.distance)..string.rep('|', transmitter.signal)..string.rep(':', 25-(transmitter.distance + transmitter.signal))
|
||||||
local indicator = string.rep('|', transmitter_signal)..string.rep(':', 20 - transmitter_signal)
|
local indicator = string.rep('|', transmitter_signal)..string.rep(':', 20 - transmitter_signal)
|
||||||
|
|
||||||
local text = "[ Frequency: "..tostring(meta:get_string("frequency")).." ]"..indicator
|
local text = "[ Frequency: "..tostring(meta:get_string("frequency")).." ]"..indicator
|
||||||
|
|
||||||
player:hud_change(self.playerhuds[name], "text", text)
|
player:hud_change(self.playerhuds[name], "text", text)
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_newplayer(ham_radio.init_hud)
|
minetest.register_on_newplayer(ham_radio.init_hud)
|
||||||
minetest.register_on_joinplayer(ham_radio.init_hud)
|
minetest.register_on_joinplayer(ham_radio.init_hud)
|
||||||
|
|
||||||
minetest.register_on_leaveplayer(function(player)
|
minetest.register_on_leaveplayer(function(player)
|
||||||
ham_radio.playerhuds[player:get_player_name()] = nil
|
ham_radio.playerhuds[player:get_player_name()] = nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local updatetimer = 0
|
local updatetimer = 0
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
updatetimer = updatetimer + dtime
|
updatetimer = updatetimer + dtime
|
||||||
if updatetimer > 0.1 then
|
if updatetimer > 0.1 then
|
||||||
local players = minetest.get_connected_players()
|
local players = minetest.get_connected_players()
|
||||||
for i=1, #players do
|
for i=1, #players do
|
||||||
ham_radio:update_hud_display(players[i])
|
ham_radio:update_hud_display(players[i])
|
||||||
end
|
end
|
||||||
updatetimer = updatetimer - dtime
|
updatetimer = updatetimer - dtime
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
30
init.lua
30
init.lua
@ -4,29 +4,29 @@ local mod_storage = minetest.get_mod_storage()
|
|||||||
ham_radio = rawget(_G, "ham_radio") or {}
|
ham_radio = rawget(_G, "ham_radio") or {}
|
||||||
|
|
||||||
ham_radio = {
|
ham_radio = {
|
||||||
playerhuds = {},
|
playerhuds = {},
|
||||||
playerlocators = {},
|
playerlocators = {},
|
||||||
settings = {
|
settings = {
|
||||||
hud_pos = { x = 0.45, y = 0.7 },
|
hud_pos = { x = 0.45, y = 0.7 },
|
||||||
hud_offset = { x = 15, y = 15 },
|
hud_offset = { x = 15, y = 15 },
|
||||||
hud_alignment = { x = 1, y = 0 }
|
hud_alignment = { x = 1, y = 0 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function ham_radio.save_transmitter(frequency, transmitter_data)
|
function ham_radio.save_transmitter(frequency, transmitter_data)
|
||||||
mod_storage:set_string(tostring(frequency), minetest.write_json(transmitter_data))
|
mod_storage:set_string(tostring(frequency), minetest.write_json(transmitter_data))
|
||||||
end
|
end
|
||||||
|
|
||||||
function ham_radio.read_transmitter(frequency)
|
function ham_radio.read_transmitter(frequency)
|
||||||
local transmitter_data = mod_storage:get_string(tostring(frequency))
|
local transmitter_data = mod_storage:get_string(tostring(frequency))
|
||||||
if transmitter_data ~= nil and transmitter_data ~= "" then
|
if transmitter_data ~= nil and transmitter_data ~= "" then
|
||||||
return minetest.parse_json(transmitter_data)
|
return minetest.parse_json(transmitter_data)
|
||||||
end
|
end
|
||||||
return {}
|
return {}
|
||||||
end
|
end
|
||||||
|
|
||||||
function ham_radio.delete_transmitter(frequency)
|
function ham_radio.delete_transmitter(frequency)
|
||||||
mod_storage:set_string(tostring(frequency), nil)
|
mod_storage:set_string(tostring(frequency), nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
dofile(modpath.."/transmitter.lua")
|
dofile(modpath.."/transmitter.lua")
|
||||||
@ -37,5 +37,3 @@ dofile(modpath.."/hud.lua")
|
|||||||
-- TODO: configure transmitter
|
-- TODO: configure transmitter
|
||||||
-- TODO: craft pelengator
|
-- TODO: craft pelengator
|
||||||
-- TODO: set pelengator frequency
|
-- TODO: set pelengator frequency
|
||||||
|
|
||||||
|
|
||||||
|
127
receiver.lua
127
receiver.lua
@ -1,64 +1,63 @@
|
|||||||
-- minetest.chat_send_player(user:get_player_name(), "Itemstack"..meta:get_string("frequency").."^"..itemstack:get_name())
|
-- minetest.chat_send_player(user:get_player_name(), "Itemstack"..meta:get_string("frequency").."^"..itemstack:get_name())
|
||||||
|
|
||||||
|
|
||||||
minetest.register_tool("ham_radio:receiver", {
|
minetest.register_tool("ham_radio:receiver", {
|
||||||
description = "Ham Radio Receiver",
|
description = "Ham Radio Receiver",
|
||||||
wield_image = "ham_radio_receiver_wield.png",
|
wield_image = "ham_radio_receiver_wield.png",
|
||||||
inventory_image = "ham_radio_receiver_wield.png",
|
inventory_image = "ham_radio_receiver_wield.png",
|
||||||
groups = { disable_repair = 1 },
|
groups = { disable_repair = 1 },
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
local meta = itemstack:get_meta()
|
local meta = itemstack:get_meta()
|
||||||
local frequency = meta:get_string("frequency")
|
local frequency = meta:get_string("frequency")
|
||||||
minetest.show_formspec(user:get_player_name(), "ham_radio:configure_receiver",
|
minetest.show_formspec(user:get_player_name(), "ham_radio:configure_receiver",
|
||||||
"size[4,3]"..
|
"size[4,3]"..
|
||||||
"field[0.25,0.25;3,1;frequency;Frequency;"..tostring(frequency).."]"..
|
"field[0.25,0.25;3,1;frequency;Frequency;"..tostring(frequency).."]"..
|
||||||
"button_exit[0.25,1.5;3,1;;Done]"
|
"button_exit[0.25,1.5;3,1;;Done]"
|
||||||
)
|
)
|
||||||
return itemstack
|
return itemstack
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
if formname ~= "ham_radio:configure_receiver" or not minetest.is_player(player) then
|
if formname ~= "ham_radio:configure_receiver" or not minetest.is_player(player) then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
if fields.frequency == "" or fields.frequency == nil then
|
if fields.frequency == "" or fields.frequency == nil then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
local item = player:get_wielded_item()
|
local item = player:get_wielded_item()
|
||||||
local meta = item:get_meta()
|
local meta = item:get_meta()
|
||||||
meta:set_string("frequency", fields.frequency)
|
meta:set_string("frequency", fields.frequency)
|
||||||
player:set_wielded_item(item) -- replace wielded item with new metadata
|
player:set_wielded_item(item) -- replace wielded item with new metadata
|
||||||
return true
|
return true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
minetest.register_craft({
|
output = "ham_radio:receiver",
|
||||||
output = "ham_radio:receiver",
|
recipe = {
|
||||||
recipe = {
|
{"default:glass"},
|
||||||
{"default:glass"},
|
{"default:steel_ingot"},
|
||||||
{"default:steel_ingot"},
|
{"default:glass"},
|
||||||
{"default:glass"},
|
}
|
||||||
}
|
})
|
||||||
})
|
|
||||||
|
function ham_radio:locate_transmitter(player, transmitter_pos)
|
||||||
function ham_radio:locate_transmitter(player, transmitter_pos)
|
local player_pos = player:get_pos()
|
||||||
local player_pos = player:get_pos()
|
local player_look_vector = player:get_look_dir()
|
||||||
local player_look_vector = player:get_look_dir()
|
local player_direction = vector.add(player_pos, player_look_vector)
|
||||||
local player_direction = vector.add(player_pos, player_look_vector)
|
|
||||||
|
local distance = vector.distance(player_pos, transmitter_pos)
|
||||||
local distance = vector.distance(player_pos, transmitter_pos)
|
|
||||||
|
-- local distance_to_target = 13 - math.floor(math.log(distance*30))
|
||||||
-- local distance_to_target = 13 - math.floor(math.log(distance*30))
|
local distance_to_target = 24 - math.floor(2 * math.log(distance*10))
|
||||||
local distance_to_target = 24 - math.floor(2 * math.log(distance*10))
|
|
||||||
|
local distance2 = vector.distance(player_direction, transmitter_pos)
|
||||||
local distance2 = vector.distance(player_direction, transmitter_pos)
|
local signal_power = 1 - ((1 + distance2 - distance) / 2)
|
||||||
local signal_power = 1 - ((1 + distance2 - distance) / 2)
|
|
||||||
|
return math.floor(distance_to_target * signal_power);
|
||||||
return math.floor(distance_to_target * signal_power);
|
|
||||||
|
--return {
|
||||||
--return {
|
-- distance = distance_to_target,
|
||||||
-- distance = distance_to_target,
|
-- signal = signal_power
|
||||||
-- signal = signal_power
|
-- }
|
||||||
-- }
|
end
|
||||||
end
|
|
||||||
|
101
transmitter.lua
101
transmitter.lua
@ -1,51 +1,50 @@
|
|||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "ham_radio:transmitter",
|
output = "ham_radio:transmitter",
|
||||||
recipe = {
|
recipe = {
|
||||||
{"default:glass"},
|
{"default:glass"},
|
||||||
{"default:mese"},
|
{"default:mese"},
|
||||||
{"default:steel_ingot"},
|
{"default:steel_ingot"},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node("ham_radio:transmitter", {
|
minetest.register_node("ham_radio:transmitter", {
|
||||||
description = "Ham Radio Transmitter",
|
description = "Ham Radio Transmitter",
|
||||||
tiles = {"ham_radio_transmitter_top.png", "ham_radio_transmitter.png"},
|
tiles = {"ham_radio_transmitter_top.png", "ham_radio_transmitter.png"},
|
||||||
groups = {cracky=2,oddly_breakable_by_hand=2},
|
groups = {cracky=2,oddly_breakable_by_hand=2},
|
||||||
sounds = default.node_sound_metal_defaults(),
|
sounds = default.node_sound_metal_defaults(),
|
||||||
light_source = 5,
|
light_source = 5,
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string(
|
meta:set_string(
|
||||||
"formspec",
|
"formspec",
|
||||||
"size[6,8]"..
|
"size[6,8]"..
|
||||||
"field[0.25,0.25;3,1;frequency;Frequency;${frequency}]"..
|
"field[0.25,0.25;3,1;frequency;Frequency;${frequency}]"..
|
||||||
"button_exit[1.5,7.5;3,1;;Done]"
|
"button_exit[1.5,7.5;3,1;;Done]"
|
||||||
)
|
)
|
||||||
meta:set_string("infotext", '')
|
meta:set_string("infotext", '')
|
||||||
end,
|
end,
|
||||||
on_receive_fields = function(pos, formname, fields, sender)
|
on_receive_fields = function(pos, formname, fields, sender)
|
||||||
if fields.quit ~= "true" then
|
if fields.quit ~= "true" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if fields.frequency ~= nil and fields.frequency ~= '' then
|
if fields.frequency ~= nil and fields.frequency ~= '' then
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
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(fields.frequency, {
|
ham_radio.save_transmitter(fields.frequency, {
|
||||||
pos = pos,
|
pos = pos,
|
||||||
broadcast_message = "Test Ham Radio Broadcast!"
|
broadcast_message = "Test Ham Radio Broadcast!"
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
can_dig = function(pos,player)
|
can_dig = function(pos,player)
|
||||||
local meta = minetest.get_meta(pos);
|
local meta = minetest.get_meta(pos);
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
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)
|
ham_radio.delete_transmitter(oldmetadata.fields.frequency)
|
||||||
end
|
end
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
Loading…
Reference in New Issue
Block a user