aboutsummaryrefslogtreecommitdiff
path: root/advtrains/debugitems.lua
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains/debugitems.lua')
-rw-r--r--advtrains/debugitems.lua86
1 files changed, 86 insertions, 0 deletions
diff --git a/advtrains/debugitems.lua b/advtrains/debugitems.lua
index e672308..2236cba 100644
--- a/advtrains/debugitems.lua
+++ b/advtrains/debugitems.lua
@@ -51,3 +51,89 @@ minetest.register_chatcommand("atyaw",
end
end,
})
+
+minetest.register_tool("advtrains:wagonpos_tester",
+{
+ description = "Wagon position tester",
+ groups = {cracky=1}, -- key=name, value=rating; rating=1..3.
+ inventory_image = "drwho_screwdriver.png",
+ wield_image = "drwho_screwdriver.png",
+ stack_max = 1,
+ range = 7.0,
+
+ on_place = function(itemstack, placer, pointed_thing)
+
+ end,
+ --[[
+ ^ Shall place item and return the leftover itemstack
+ ^ default: minetest.item_place ]]
+ on_use = function(itemstack, user, pointed_thing)
+ if pointed_thing.type=="node" then
+ local pos = pointed_thing.under
+ local trains = advtrains.occ.get_trains_at(pos)
+ for train_id, index in pairs(trains) do
+ local wagon_num, wagon_id, wagon_data, offset_from_center = advtrains.get_wagon_at_index(train_id, index)
+ if wagon_num then
+ atdebug(wagon_num, wagon_id, offset_from_center)
+ end
+ end
+ end
+ end,
+}
+)
+
+
+local function trackitest(initial_pos, initial_connid)
+ local ti, pos, connid, ok
+ ti = advtrains.get_track_iterator(initial_pos, initial_connid, 500, true)
+ atdebug("Starting at pos:",initial_pos,initial_connid)
+ while ti:has_next_branch() do
+ pos, connid = ti:next_branch() -- in first iteration, this will be the node at initial_pos. In subsequent iterations this will be the switch node from which we are branching off
+ atdebug("Next Branch:",pos, connid)
+ ok = true
+ while ok do
+ ok, pos, connid = ti:next_track()
+ atdebug("Next Track:", ok, pos, connid)
+ end
+ end
+ atdebug("End of traverse. Visited: ",table.concat(ti.visited, ","))
+end
+
+minetest.register_tool("advtrains:trackitest",
+{
+ description = "Track Iterator Tester (leftclick conn 1, rightclick conn 2)",
+ groups = {cracky=1}, -- key=name, value=rating; rating=1..3.
+ inventory_image = "advtrains_track_swlcr_45.png",
+ wield_image = "advtrains_track_swlcr_45.png",
+ stack_max = 1,
+ range = 7.0,
+
+ on_place = function(itemstack, placer, pointed_thing)
+ if pointed_thing.type ~= "node" then return end
+ trackitest(pointed_thing.under, 2)
+ end,
+ on_use = function(itemstack, user, pointed_thing)
+ if pointed_thing.type ~= "node" then return end
+ trackitest(pointed_thing.under, 1)
+ end,
+}
+)
+
+minetest.register_chatcommand("at_trackdef_audit",
+ {
+ params = "",
+ description = "Performs an audit of all track definitions currently loaded and checks for potential problems",
+ func = function(name, param)
+ for name, ndef in pairs(minetest.registered_nodes) do
+ --TODO finish this!
+ if ndef.at_conns then
+ -- check if conn_map is there and if it has enough entries
+ if #ndef.at_conns > 2 then
+ if #ndef.at_conn_map < #ndef.at_conns then
+ atwarn("AUDIT: Node",name,"- Not enough connmap entries! Check ndef:",ndef)
+ end
+ end
+ end
+ end
+ end,
+})