aboutsummaryrefslogtreecommitdiff
path: root/advtrains_trackmap/viewer.lua
blob: 7752991f893d1e422c5f154841ba3c1de1961f23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
-- viewer.lua
-- standalone chatcommand/tool trackmap viewer window

local tm = advtrains.trackmap

local function node_left_click(pos, pname)
	local node_ok, conns, rail_y=advtrains.get_rail_info_at(pos)
	if not node_ok then
		minetest.chat_send_player(pname, "Node is not a track!")
		return
	end
	
	local function node_callback()
		return nil
	end

	local gridtbl = tm.generate_grid_map(pos, node_callback)
	local fslabel = tm.render_grid(gridtbl.grid, {x=pos.x-30, z=pos.z-25}, 60, 50)
	
	minetest.show_formspec(pname, "advtrains_trackmap:test", "size[20,20]"..fslabel)
end


minetest.register_craftitem("advtrains_trackmap:tool",{
	description = "Trackmap Tool\nPunch: Show map",
	groups = {cracky=1}, -- key=name, value=rating; rating=1..3.
	inventory_image = "at_il_tool.png",
	wield_image = "at_il_tool.png",
	stack_max = 1,
	on_use = function(itemstack, player, pointed_thing)
		local pname = player:get_player_name()
		if not pname then
			return
		end
		if pointed_thing.type=="node" then
			local pos=pointed_thing.under
			node_left_click(pos, pname)
		end
	end
})