function ExportLevel(levelname, filename) os.execute( "mkdir \"./Mothback/export\"" ) filename = filename or "output.lua" filename = "Mothback/export/"..filename exportFile = io.open(filename, "w+") if exportFile then exportFile:write("return {") logPrint("Exporting level \"".. levelname .. "\"...") exportFile:write("\n name = \"" .. levelname .. "\",") logPrint("- level name") for k, v in pairs(tileset) do if v == LevelData.tileset then exportFile:write("\n tileset = tileset." .. k .. ",") logPrint("- tileset") end end exportFile:write("\n tiles = {") logPrint("- tiles") local rows = #LevelTiles for i = 1, #LevelTiles do exportFile:write("\n { ") logPrint(" - Row "..i.."/"..rows.." "..math.floor(100*((i-1)*100/rows))/100 .."%") for j = 1, #LevelTiles[i] do if j ~= 1 then exportFile:write(", ") end exportFile:write(tostring(LevelTiles[i][j].id)) end exportFile:write("}") if i ~= #LevelTiles then exportFile:write(", ") end end logPrint(" - All rows 100%") exportFile:write("\n },") exportFile:write("\n objects = {}") logPrint("- objects") exportFile:write("\n}") logPrint("Exporting complete.") exportFile:close() end end -- Source https://stackoverflow.com/a/11130774 function scandir(directory) local i, t, popen = 0, {}, io.popen local pfile = popen('ls "'..directory..'"') for filename in pfile:lines() do i = i + 1 t[i] = filename end pfile:close() return t 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 = {} } ]] if logging then -- Make log stuff os.execute( "mkdir \"./Mothback/logs\"" ) logFile = io.open("Mothback/logs/mothback_"..os.date("%Y-%m-%d_%H-%M-%S")..".log", "a+") end