Skip to content
Snippets Groups Projects
Commit 1a9ae590 authored by dg's avatar dg
Browse files

Allow the Static generator to read table of tables instead of table of strings

git-svn-id: http://svn.net-core.org/repos/t-engine4@1712 51575b47-30f0-44d4-a5cc-537603b46e54
parent 0ea94800
No related branches found
No related tags found
No related merge requests found
......@@ -88,25 +88,37 @@ function _M:loadMap(file)
if not ret and err then error(err) end
if type(ret) == "string" then ret = ret:split("\n") end
local m = { w=ret[1]:len(), h=#ret }
local m = { w=#(ret[1]), h=#ret }
local function populate(i, j, c)
local ii, jj = i, j
if rotate == "flipx" then ii, jj = m.w - i + 1, j
elseif rotate == "flipy" then ii, jj = i, m.h - j + 1
elseif rotate == "90" then ii, jj = j, m.w - i + 1
elseif rotate == "180" then ii, jj = m.w - i + 1, m.h - j + 1
elseif rotate == "270" then ii, jj = m.h - j + 1, i
end
m[ii] = m[ii] or {}
m[ii][jj] = c
end
-- Read the map
local rotate = util.getval(g.rotates or "default")
for j, line in ipairs(ret) do
local i = 1
for c in line:gmatch(".") do
local ii, jj = i, j
if rotate == "flipx" then ii, jj = m.w - i + 1, j
elseif rotate == "flipy" then ii, jj = i, m.h - j + 1
elseif rotate == "90" then ii, jj = j, m.w - i + 1
elseif rotate == "180" then ii, jj = m.w - i + 1, m.h - j + 1
elseif rotate == "270" then ii, jj = m.h - j + 1, i
if type(ret[1]) == "string" then
for j, line in ipairs(ret) do
local i = 1
for c in line:gmatch(".") do
populate(i, j, c)
i = i + 1
end
end
else
for j, line in ipairs(ret) do
for i, c in ipairs(line) do
populate(i, j, c)
end
m[ii] = m[ii] or {}
m[ii][jj] = c
i = i + 1
end
end
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment