Mothback/data/scripts/in_out.lua

60 lines
2.1 KiB
Lua

function ExportLevel(levelname)
filename = "output.lua"
local success, message = love.filesystem.write(filename, "")
if success then
love.filesystem.append(filename, "return {")
logPrint("Exporting level \"".. filename .. "\"...")
love.filesystem.append(filename, "\n name = \"" .. levelname .. "\",")
logPrint("- level name")
for k, v in pairs(tileset) do
if v == LevelData.tileset then
love.filesystem.append(filename, "\n tileset = tileset." .. k .. ",")
logPrint("- tileset")
end
end
love.filesystem.append(filename, "\n tiles = {")
logPrint("- tiles")
local rows = #LevelTiles
for i = 1, #LevelTiles do
love.filesystem.append(filename, "\n { ")
logPrint(" - Row "..i.."/"..rows.." "..math.floor(100*((i-1)*100/rows))/100 .."%")
for j = 1, #LevelTiles[i] do
if j ~= 1 then
love.filesystem.append(filename, ", ")
end
love.filesystem.append(filename, tostring(LevelTiles[i][j].id))
end
love.filesystem.append(filename, "}")
if i ~= #LevelTiles then
love.filesystem.append(filename, ", ")
end
end
logPrint(" - All rows 100%")
love.filesystem.append(filename, "\n },")
love.filesystem.append(filename, "\n objects = {}")
logPrint("- objects")
love.filesystem.append(filename, "\n}")
logPrint("Exporting complete.")
end
end
--[[
return {
name = "level1",
tileset = tileset.library,
tiles = {
{13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13},
{ 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, 5,25,26, 6,25,26, 7, 0, 5,25,26, 7, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 5,37,38, 6,37,38, 7, 0, 5,37,38, 7, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 5,37,38, 6,37,38, 7, 0, 5,37,38, 7, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 5,49,50, 6,49,50, 7, 0, 5,49,50, 7, 0, 0, 0, 0, 0, 0},
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
},
objects = {}
}
]]
logFile = "mothback_"..os.date("%Y-%m-%d_%H-%M-%S")..".log"
local success, message = love.filesystem.write(logFile, "")
if message ~= nil then print(message) end