diff --git a/.vscode/settings.json b/.vscode/settings.json index 93c0adf..6f4ea8e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,6 +7,7 @@ "core", "scenes", "utils", - "birb" + "birb", + "enum" ] } diff --git a/sonic-radiance.love/birb/core/debug.lua b/sonic-radiance.love/birb/core/debug.lua index dda8b20..372b7f4 100644 --- a/sonic-radiance.love/birb/core/debug.lua +++ b/sonic-radiance.love/birb/core/debug.lua @@ -25,9 +25,18 @@ local DebugSystem = Object:extend() local lovebird = require "birb.libs.lovebird" -function DebugSystem:new(controller, active) +local Levels = enum { + "ERROR", + "WARNING", + "INFO", + "DEBUG" +} + +function DebugSystem:new(controller) self.controller = controller - self.active = active or false + + self.debugLevel = self.controller.conf.debugLevel or Levels.INFO + self.active = (self.debugLevel == Levels.DEBUG) if (self.active) then lovebird.update() end @@ -42,27 +51,39 @@ end -- PRINT FUNCTIONS -- Print and log debug string +function DebugSystem:debug(context, string) + self:log(Levels.DEBUG, context, string) +end + function DebugSystem:print(context, string) - if (self.active) then - print(self:getLogLine("DEBUG", context, string)) - end + self:log(Levels.INFO, context, string) end function DebugSystem:warning(context, string) - if (self.active) then - print(self:getLogLine("WARNING", context, string)) - end + self:log(Levels.WARNING, context, string) end function DebugSystem:error(context, string) - error(self:getLogLine("ERROR", context, string)) + self:log(Levels.ERROR, context, string) + error(self:getMessage(": ", context, string)) end -function DebugSystem:getLogLine(type, string1, string2) +function DebugSystem:log(level, context, string) + if (self.debugLevel >= level) then + print(self:getLogLine(Levels[level], context, string)) + end +end + +function DebugSystem:getLogLine(type, context, string) + local head = self.controller:getIdentity(false) .. "|" .. os.date("%x-%X") .. "|" .. type .. "|" + return head .. self:getMessage("|", context, string) +end + +function DebugSystem:getMessage(separator, string1, string2) if (string2 == nil) then - return "[" .. type .. "] " .. string1 + return string1 else - return "[" .. type .. "] " .. string1 .. ": " .. string2 + return string1 .. separator .. string2 end end diff --git a/sonic-radiance.love/birb/core/init.lua b/sonic-radiance.love/birb/core/init.lua index dcfbcf8..0895755 100644 --- a/sonic-radiance.love/birb/core/init.lua +++ b/sonic-radiance.love/birb/core/init.lua @@ -38,10 +38,10 @@ local SceneManager = require(cwd .. "scenemanager") -- INIT FUNCTIONS -- Initialize and configure the core object -function CoreSystem:new(isDebug) +function CoreSystem:new() self:setDefaultConf() - self.debug = DebugSystem(self, isDebug) + self.debug = DebugSystem(self) self.options = Options(self) self.input = Input(self) self.screen = Screen(self) diff --git a/sonic-radiance.love/birb/init.lua b/sonic-radiance.love/birb/init.lua index dd35cec..0f13883 100644 --- a/sonic-radiance.love/birb/init.lua +++ b/sonic-radiance.love/birb/init.lua @@ -29,18 +29,19 @@ birb = {} Object = require("birb.libs.classic") utils = require("birb.utils") +enum = require("birb.utils.enum") birb.Core = require("birb.core") -function birb.start(gamemodule, isDebug) - birb.startCore((isDebug == true)) +function birb.start(gamemodule) + birb.startCore() if (gamemodule ~= nil) then birb.startGame(gamemodule) end end -function birb.startCore(isDebug) - core = birb.Core(isDebug) +function birb.startCore() + core = birb.Core() end function birb.startGame(gamemodule) diff --git a/sonic-radiance.love/main.lua b/sonic-radiance.love/main.lua index 9d35653..52abe33 100644 --- a/sonic-radiance.love/main.lua +++ b/sonic-radiance.love/main.lua @@ -26,6 +26,6 @@ require "birb" scenes = require "scenes" function love.load() - birb.start("game", false) + birb.start("game") scenes.title() end \ No newline at end of file