forked from kdx/jtmm2-old
[generate_c.lua] now supports the layer system
This commit is contained in:
parent
316cc26539
commit
58cb48fa75
299
levels/0.jtmm2
299
levels/0.jtmm2
|
@ -1,102 +1,203 @@
|
|||
10
|
||||
51
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
1
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
n
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
1
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
100
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
#!/usr/bin/env lua
|
||||
#!/usr/bin/env luajit
|
||||
|
||||
local function read_level(id)
|
||||
local file = io.open(id..".jtmm2")
|
||||
if not file then
|
||||
return nil
|
||||
else
|
||||
local content = {width = nil, height = nil, tiles = {}}
|
||||
local content = {width = nil, height = nil, layers = {{}}}
|
||||
local line_nb = 0
|
||||
local layer_nb = 1
|
||||
for line in file:lines() do
|
||||
line_nb = line_nb + 1
|
||||
if line_nb < 3 then
|
||||
|
@ -16,7 +17,12 @@ local function read_level(id)
|
|||
content.width = tonumber(line)
|
||||
end
|
||||
else
|
||||
table.insert(content.tiles, line)
|
||||
if line == "n" then
|
||||
layer_nb = layer_nb + 1
|
||||
table.insert(content.layers, {})
|
||||
else
|
||||
table.insert(content.layers[layer_nb], line)
|
||||
end
|
||||
end
|
||||
end
|
||||
file:close()
|
||||
|
@ -27,17 +33,28 @@ end
|
|||
local function create_structure_c(id)
|
||||
local content = read_level(id)
|
||||
if content then
|
||||
-- tiles
|
||||
io.write("const unsigned char tiles_", id, "[] = {")
|
||||
for i, v in ipairs(content.tiles) do
|
||||
io.write(v, ", ")
|
||||
-- layers
|
||||
for i, layer in ipairs(content.layers) do
|
||||
io.write("const unsigned char tiles_", id, "_", i, "[] = {\n\t")
|
||||
for i, v in ipairs(layer) do
|
||||
io.write(v, ", ")
|
||||
if i % 14 == 0 and i ~= #layer then
|
||||
io.write("\n\t")
|
||||
end
|
||||
end
|
||||
io.write("\n};\n");
|
||||
end
|
||||
io.write("};\n");
|
||||
-- array
|
||||
io.write("const unsigned char *layers_", id, "[] = {")
|
||||
for i = 1, #content.layers, 1 do
|
||||
io.write("tiles_", id, "_", i, ", ")
|
||||
end
|
||||
io.write("};\n")
|
||||
-- structure
|
||||
io.write("const Level level_", id, " = {\n")
|
||||
io.write("\t.width = ", content.width, ",\n")
|
||||
io.write("\t.height = ", content.height, ",\n")
|
||||
io.write("\t.tiles = &tiles_", id, "\n")
|
||||
io.write("\t.layers = &layers_", id, "\n")
|
||||
io.write("};\n")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue