Skip to content

Commit

Permalink
Add camera and detector visualizations (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
OgelGames authored May 19, 2024
1 parent 54c0f66 commit 2871211
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
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

0 comments on commit 2871211

Please sign in to comment.