Changed file management to native lua instead of love.filesystem

This commit is contained in:
bizcochito 2022-02-08 10:23:42 +01:00
parent e7aa34d5c2
commit ef58a6e383
2 changed files with 19 additions and 19 deletions

View File

@ -94,5 +94,5 @@ function logPrint(string)
end
function logWrite(string)
if logging then love.filesystem.append(logFile, string.."\n") end
if logging then logFile:write(string.."\n") end
end

View File

@ -1,40 +1,42 @@
function ExportLevel(levelname)
filename = "output.lua"
function ExportLevel(levelname, filename)
filename = filename or "output.lua"
exportFile = io.open(filename, "a+")
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 .. "\",")
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
love.filesystem.append(filename, "\n tileset = tileset." .. k .. ",")
exportFile:write("\n tileset = tileset." .. k .. ",")
logPrint("- tileset")
end
end
love.filesystem.append(filename, "\n tiles = {")
exportFile:write("\n tiles = {")
logPrint("- tiles")
local rows = #LevelTiles
for i = 1, #LevelTiles do
love.filesystem.append(filename, "\n { ")
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
love.filesystem.append(filename, ", ")
exportFile:write(", ")
end
love.filesystem.append(filename, tostring(LevelTiles[i][j].id))
exportFile:write(tostring(LevelTiles[i][j].id))
end
love.filesystem.append(filename, "}")
exportFile:write("}")
if i ~= #LevelTiles then
love.filesystem.append(filename, ", ")
exportFile:write(", ")
end
end
logPrint(" - All rows 100%")
love.filesystem.append(filename, "\n },")
love.filesystem.append(filename, "\n objects = {}")
exportFile:write("\n },")
exportFile:write("\n objects = {}")
logPrint("- objects")
love.filesystem.append(filename, "\n}")
exportFile:write("\n}")
logPrint("Exporting complete.")
exportFile:close()
end
end
@ -54,6 +56,4 @@ return {
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
logFile = io.open("mothback_"..os.date("%Y-%m-%d_%H-%M-%S")..".log", "a+")