mirror of
https://github.com/joe7575/tubelib2.git
synced 2024-07-04 15:05:23 +02:00
Add debug callback function
This commit is contained in:
parent
1a441d0284
commit
b333780792
@ -78,8 +78,12 @@ function Tube:del_from_cache(pos, dir)
|
||||
local key2 = S(pos2)
|
||||
if self.connCache[key2] and self.connCache[key2][dir2] then
|
||||
self.connCache[key2][dir2] = nil
|
||||
if self.debug_info then self.debug_info(pos2, "del") end
|
||||
end
|
||||
self.connCache[key][dir] = nil
|
||||
if self.debug_info then self.debug_info(pos, "del") end
|
||||
else
|
||||
if self.debug_info then self.debug_info(pos, "noc") end
|
||||
end
|
||||
end
|
||||
|
||||
@ -90,6 +94,7 @@ function Tube:add_to_cache(pos1, dir1, pos2, dir2)
|
||||
self.connCache[key] = {}
|
||||
end
|
||||
self.connCache[key][dir1] = {pos2 = pos2, dir2 = dir2}
|
||||
if self.debug_info then self.debug_info(pos1, "add") end
|
||||
end
|
||||
|
||||
-- pos/dir are the pos of the secondary nodes pointing to the head tube nodes.
|
||||
|
@ -182,6 +182,7 @@ function Tube:new(attr)
|
||||
pairingList = {}, -- teleporting nodes
|
||||
connCache = {}, -- connection cache {pos1 = {dir1 = {pos2 = pos2, dir2 = dir2},...}
|
||||
special_node_names = {}, -- use add_special_node_names() to register nodes
|
||||
debug_info = attr.debug_info, -- debug_info(pos, text)
|
||||
}
|
||||
o.valid_dirs = Tbl(o.dirs_to_check)
|
||||
setmetatable(o, self)
|
||||
|
@ -19,6 +19,44 @@ local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||
local P = minetest.string_to_pos
|
||||
local M = minetest.get_meta
|
||||
|
||||
|
||||
-- Marker entities for debugging purposes
|
||||
local function debug_info(pos, text)
|
||||
local marker = minetest.add_entity(pos, "tubelib2:marker_cube")
|
||||
if marker ~= nil then
|
||||
if text == "add" then
|
||||
marker:set_nametag_attributes({color = "#FF0000", text = "add__________"})
|
||||
elseif text == "del" then
|
||||
marker:set_nametag_attributes({color = "#00FF00", text = "_____del_____"})
|
||||
elseif text == "noc" then
|
||||
marker:set_nametag_attributes({color = "#0000FF", text = "__________noc"})
|
||||
end
|
||||
minetest.after(6, marker.remove, marker)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_entity(":tubelib2:marker_cube", {
|
||||
initial_properties = {
|
||||
visual = "cube",
|
||||
textures = {
|
||||
"tubelib2_marker_cube.png",
|
||||
"tubelib2_marker_cube.png",
|
||||
"tubelib2_marker_cube.png",
|
||||
"tubelib2_marker_cube.png",
|
||||
"tubelib2_marker_cube.png",
|
||||
"tubelib2_marker_cube.png",
|
||||
},
|
||||
physical = false,
|
||||
visual_size = {x = 1.1, y = 1.1},
|
||||
collisionbox = {-0.55,-0.55,-0.55, 0.55,0.55,0.55},
|
||||
glow = 8,
|
||||
},
|
||||
on_punch = function(self)
|
||||
self.object:remove()
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
-- Test tubes
|
||||
|
||||
local Tube = tubelib2.Tube:new({
|
||||
@ -34,6 +72,7 @@ local Tube = tubelib2.Tube:new({
|
||||
after_place_tube = function(pos, param2, tube_type, num_tubes, tbl)
|
||||
minetest.swap_node(pos, {name = "tubelib2:tube"..tube_type, param2 = param2})
|
||||
end,
|
||||
debug_info = debug_info,
|
||||
})
|
||||
|
||||
Tube:register_on_tube_update(function(node, pos, out_dir, peer_pos, peer_in_dir)
|
||||
|
Loading…
Reference in New Issue
Block a user