2022-02-08 09:23:42 +00:00
|
|
|
function ExportLevel(levelname, filename)
|
2022-02-08 09:52:37 +00:00
|
|
|
os.execute( "mkdir \"./Mothback/export\"" )
|
2022-02-08 09:23:42 +00:00
|
|
|
filename = filename or "output.lua"
|
2022-02-08 09:52:37 +00:00
|
|
|
filename = "Mothback/export/"..filename
|
2022-02-08 09:53:53 +00:00
|
|
|
exportFile = io.open(filename, "w+")
|
2022-02-08 09:52:37 +00:00
|
|
|
if exportFile then
|
2022-02-08 09:23:42 +00:00
|
|
|
exportFile:write("return {")
|
|
|
|
logPrint("Exporting level \"".. levelname .. "\"...")
|
|
|
|
exportFile:write("\n name = \"" .. levelname .. "\",")
|
2022-02-08 07:40:17 +00:00
|
|
|
logPrint("- level name")
|
2022-01-30 10:31:18 +00:00
|
|
|
for k, v in pairs(tileset) do
|
|
|
|
if v == LevelData.tileset then
|
2022-02-08 09:23:42 +00:00
|
|
|
exportFile:write("\n tileset = tileset." .. k .. ",")
|
2022-02-08 07:40:17 +00:00
|
|
|
logPrint("- tileset")
|
2022-01-30 10:31:18 +00:00
|
|
|
end
|
|
|
|
end
|
2022-02-08 09:23:42 +00:00
|
|
|
exportFile:write("\n tiles = {")
|
2022-02-08 07:40:17 +00:00
|
|
|
logPrint("- tiles")
|
|
|
|
local rows = #LevelTiles
|
2022-01-30 10:31:18 +00:00
|
|
|
for i = 1, #LevelTiles do
|
2022-02-08 09:23:42 +00:00
|
|
|
exportFile:write("\n { ")
|
2022-02-08 07:40:17 +00:00
|
|
|
logPrint(" - Row "..i.."/"..rows.." "..math.floor(100*((i-1)*100/rows))/100 .."%")
|
2022-01-30 10:31:18 +00:00
|
|
|
for j = 1, #LevelTiles[i] do
|
|
|
|
if j ~= 1 then
|
2022-02-08 09:23:42 +00:00
|
|
|
exportFile:write(", ")
|
2022-01-30 10:31:18 +00:00
|
|
|
end
|
2022-02-08 09:23:42 +00:00
|
|
|
exportFile:write(tostring(LevelTiles[i][j].id))
|
2022-01-30 10:31:18 +00:00
|
|
|
end
|
2022-02-08 09:23:42 +00:00
|
|
|
exportFile:write("}")
|
2022-01-30 10:31:18 +00:00
|
|
|
if i ~= #LevelTiles then
|
2022-02-08 09:23:42 +00:00
|
|
|
exportFile:write(", ")
|
2022-01-30 10:31:18 +00:00
|
|
|
end
|
|
|
|
end
|
2022-02-08 07:40:17 +00:00
|
|
|
logPrint(" - All rows 100%")
|
2022-02-08 09:23:42 +00:00
|
|
|
exportFile:write("\n },")
|
|
|
|
exportFile:write("\n objects = {}")
|
2022-02-08 07:40:17 +00:00
|
|
|
logPrint("- objects")
|
2022-02-08 09:23:42 +00:00
|
|
|
exportFile:write("\n}")
|
2022-02-08 07:40:17 +00:00
|
|
|
logPrint("Exporting complete.")
|
2022-02-08 09:23:42 +00:00
|
|
|
exportFile:close()
|
2022-01-30 10:31:18 +00:00
|
|
|
end
|
2021-10-16 23:06:11 +00:00
|
|
|
end
|
2022-01-30 10:31:18 +00:00
|
|
|
|
|
|
|
--[[
|
|
|
|
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 = {}
|
|
|
|
}
|
|
|
|
]]
|
2022-02-08 09:52:37 +00:00
|
|
|
-- Make log stuff
|
|
|
|
os.execute( "mkdir \"./Mothback/logs\"" )
|
|
|
|
logFile = io.open("Mothback/logs/mothback_"..os.date("%Y-%m-%d_%H-%M-%S")..".log", "a+")
|