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 end
function logWrite(string) function logWrite(string)
if logging then love.filesystem.append(logFile, string.."\n") end if logging then logFile:write(string.."\n") end
end end

View File

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