Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add camera and detector visualizations #59

Merged
merged 1 commit into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ globals = {

read_globals = {
-- Builtin
table = {fields = {"copy"}},

"table.copy",
"vector",
"ItemStack",
"DIR_DELIM",
Expand All @@ -19,7 +18,8 @@ read_globals = {
"default",
"mesecon",
"screwdriver",
"QoS"
"QoS",
"vizlib",
}

exclude_files = {
Expand Down
24 changes: 21 additions & 3 deletions camera.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand All @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down
10 changes: 10 additions & 0 deletions detector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion mod.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading