Add camera and detector visualizations (#59)

This commit is contained in:
OgelGames 2024-05-20 00:41:36 +10:00 committed by GitHub
parent 54c0f66ae9
commit 2871211ca6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 35 additions and 7 deletions

View File

@ -9,8 +9,7 @@ globals = {
read_globals = {
-- Builtin
table = {fields = {"copy"}},
"table.copy",
"vector",
"ItemStack",
"DIR_DELIM",
@ -19,7 +18,8 @@ read_globals = {
"default",
"mesecon",
"screwdriver",
"QoS"
"QoS",
"vizlib",
}
exclude_files = {

View File

@ -13,8 +13,7 @@ local function get_formspec(enabled)
end
end
local function search_for_players(pos, send_empty)
local meta = minetest.get_meta(pos)
local function get_search_spot(pos, meta)
local distance = meta:get_int("distance")
local dir = minetest.facedir_to_dir(minetest.get_node(pos).param2)
local spot = vector.add(pos, vector.multiply(dir, -distance))
@ -24,8 +23,15 @@ local function search_for_players(pos, send_empty)
node = minetest.get_node(spot)
end
if node.name == "air" or node.name == "ignore" then
return true
-- Default to directly in front of camera if ground is not found.
spot.y = pos.y
end
return spot
end
local function search_for_players(pos, send_empty)
local meta = minetest.get_meta(pos)
local spot = get_search_spot(pos, meta)
local radius = meta:get_int("radius")
local found = {}
for _,player in pairs(minetest.get_connected_players()) do
@ -40,6 +46,17 @@ local function search_for_players(pos, send_empty)
return true
end
local function show_area(pos, node, player)
if not player or player:get_wielded_item():get_name() ~= "" then
-- Only show area when using an empty hand
return
end
local meta = minetest.get_meta(pos)
local spot = get_search_spot(pos, meta)
local radius = meta:get_int("radius")
vizlib.draw_sphere(spot, radius, {player = player})
end
minetest.register_node("digistuff:camera", {
description = "Digilines Camera",
tiles = {
@ -102,6 +119,7 @@ minetest.register_node("digistuff:camera", {
end
end,
on_timer = search_for_players,
on_punch = minetest.get_modpath("vizlib") and show_area or nil,
digiline = {
receptor = {},
effector = {

View File

@ -28,6 +28,15 @@ local function search_for_players(pos, send_empty)
return true
end
local function show_area(pos, node, player)
if not player or player:get_wielded_item():get_name() ~= "" then
-- Only show area when using an empty hand
return
end
local radius = minetest.get_meta(pos):get_int("radius")
vizlib.draw_sphere(pos, radius, {player = player})
end
minetest.register_node("digistuff:detector", {
description = "Digilines Player Detector",
tiles = {
@ -63,6 +72,7 @@ minetest.register_node("digistuff:detector", {
end
end,
on_timer = search_for_players,
on_punch = minetest.get_modpath("vizlib") and show_area or nil,
digiline = {
receptor = {},
effector = {

View File

@ -2,4 +2,4 @@ name = digistuff
title = digistuff
description = Random digilines devices for Minetest
depends = digilines
optional_depends = default,mesecons,mesecons_mvps,screwdriver,pipeworks,qos
optional_depends = default, mesecons, mesecons_mvps, screwdriver, pipeworks, qos, vizlib