aboutsummaryrefslogtreecommitdiff
path: root/advtrains_trackmap/fsrender.lua
blob: 607f3cde7a0105c758b52262c06e259e2ee65efa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
-- fsrender.lua
-- Rendering of a grid of characters into a formspec

local tm = advtrains.trackmap

function tm.render_grid(grid, origin_pos, width, height)
	local s = {"label[0,0;"}
	for z=height-1, 0, -1 do
		-- render a row
		for x=0,width-1 do
			local apos_x = origin_pos.x + x
			local apos_z = origin_pos.z + z
			local chr = "░"
			if grid[apos_x] and grid[apos_x][apos_z] then
				chr = grid[apos_x][apos_z]
			end
			table.insert(s, chr)
		end
		table.insert(s,"\n")
	end
	table.insert(s, "]")
	return table.concat(s)
end