From cbcf90de2dcfaf5458e836fa91da7e223cef74aa Mon Sep 17 00:00:00 2001 From: bizcochito Date: Tue, 8 Feb 2022 11:30:59 +0100 Subject: [PATCH] Level list now pulled from "levels", changed log stuff. --- data/scripts/in_out.lua | 20 +++++++++++++++++--- data/scripts/level.lua | 2 +- main.lua | 8 ++++++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/data/scripts/in_out.lua b/data/scripts/in_out.lua index 104be14..031ca07 100644 --- a/data/scripts/in_out.lua +++ b/data/scripts/in_out.lua @@ -41,6 +41,18 @@ function ExportLevel(levelname, filename) 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", @@ -57,6 +69,8 @@ return { objects = {} } ]] --- Make log stuff -os.execute( "mkdir \"./Mothback/logs\"" ) -logFile = io.open("Mothback/logs/mothback_"..os.date("%Y-%m-%d_%H-%M-%S")..".log", "a+") +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 diff --git a/data/scripts/level.lua b/data/scripts/level.lua index 616e0b7..d23a146 100644 --- a/data/scripts/level.lua +++ b/data/scripts/level.lua @@ -1,6 +1,6 @@ function LevelLoadTiles() - LevelData = dofile("Mothback/data/levels/"..currLevel..".lua") + LevelData = dofile("Mothback/data/levels/"..currLevel) --[[ on level format: diff --git a/main.lua b/main.lua index 49c7a3f..9969225 100644 --- a/main.lua +++ b/main.lua @@ -1,6 +1,7 @@ function love.load() logging = true - if logging then print("love: "..collectgarbage("count").." kB") end + loveMemUsage = collectgarbage("count") + loveInitLog = "love: "..loveMemUsage.." kB, time: "..os.clock().." seconds" arrow = 0 menu_type = "no" @@ -26,6 +27,8 @@ function love.load() } require "data/scripts" + logPrint(loveInitLog) + loveInitLog = nil Canvas = { Darkness = CreateDarkness() } @@ -36,9 +39,10 @@ function love.load() Camera.width = game.width Camera.height = game.height - levelList = {"level1","2","3","ewae","tileset"} + levelList = scandir("./Mothback/data/levels") levelNum = 1 currLevel = levelList[levelNum] + logPrint("currLevel: "..currLevel) LoadedEntities = {} LoadedParticles = {} LevelLoadTiles()