Mothback/code/in_out.lua

88 lines
2.4 KiB
Lua
Raw Normal View History

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