Visualization for access locations

This commit is contained in:
Aaron Suen 2020-07-02 21:28:04 -04:00
parent 86f0680114
commit 417ba13531
4 changed files with 73 additions and 4 deletions

View File

@ -21,6 +21,8 @@ Compatible with NodeCore (and probably/maybe a lot of other Minetest games)
- Punch things again to toggle access back off. Check the totals to make sure they match expectations.
- You will be able to see markings surrounding nodes for which access has been granted. Note that for some, particularly the "exact" type, you will only see the markings if the node is *currently* accessible based on the rule, e.g. there may be "exact" match types that are not currently visible because the node currently in that position does not match.
- If you screw up and want to start over again, `/puzzelmapreset`. Note that this will remove *all* access and require you to re-permit everything from scratch, and there is no confirmation on reset.
- Make use of fly, noclip, etc. to bypass your mechanisms so you can leave them in a ready-to-play state.

14
api.lua
View File

@ -28,13 +28,19 @@ function api.savedb()
modstore:set_string("db", minetest.serialize(api.db))
end
local function match(pos, node)
local poskey = minetest.pos_to_string(pos)
local nodename = node and node.name or minetest.get_node(pos).name
if api.db.exact[poskey] == nodename then return "exact" end
if api.db.pos[poskey] then return "pos" end
if api.db.node[nodename] then return "node" end
end
api.match = match
local oldprot = minetest.is_protected
function minetest.is_protected(pos, name, ...)
if minetest.check_player_privs(name, "protection_bypass") then
return oldprot(pos, name, ...)
end
local poskey = minetest.pos_to_string(pos)
local nodename = minetest.get_node(pos).name
return (not api.db.pos[poskey]) and (not api.db.node[nodename])
and (api.db.exact[poskey] ~= nodename) or oldprot(pos, name, ...)
return (not match(pos)) or oldprot(pos, name, ...)
end

View File

@ -11,3 +11,4 @@ end
inc("api")
inc("tools")
inc("cmd")
inc("visual")

60
visual.lua Normal file
View File

@ -0,0 +1,60 @@
-- LUALOCALS < ---------------------------------------------------------
local minetest, pairs, rawget, vector
= minetest, pairs, rawget, vector
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
local api = rawget(_G, modname)
local zero = {x = 0, y = 0, z = 0}
local pr = 0.55
local function showfx(x, y, z, txr, pname)
for _, pos in pairs({
{x = x, y = y, z = z},
{x = x - pr, y = y, z = z},
{x = x + pr, y = y, z = z},
{x = x, y = y - pr, z = z},
{x = x, y = y + pr, z = z},
{x = x, y = y, z = z - pr},
{x = x, y = y, z = z + pr}
}) do
minetest.add_particle({
pos = pos,
velocity = zero,
acceleration = zero,
expirationtime = 1.25,
glow = 14,
size = 1,
texture = txr,
playername = pname
})
end
end
local radius = 5
local function doplayer(player)
local pos = player:get_pos()
pos.y = pos.y + player:get_properties().eye_height
pos = vector.round(pos)
local match = api.match
local pname = player:get_player_name()
for z = pos.z - radius, pos.z + radius do
for y = pos.y - radius, pos.y + radius do
for x = pos.x - radius, pos.x + radius do
local m = match({x = x, y = y, z = z})
local tool = m and minetest.registered_items[modname .. ":tool_" .. m]
if tool then showfx(x, y, z, tool.inventory_image, pname) end
end
end
end
end
local function timer()
minetest.after(1, timer)
for _, player in pairs(minetest.get_connected_players()) do
if minetest.check_player_privs(player, modname) then
doplayer(player)
end
end
end
minetest.after(0, timer)