added logging support
This commit is contained in:
+20
-10
@@ -1,9 +1,9 @@
|
||||
local gui = require("gui")
|
||||
local color = require("gui.core.color")
|
||||
local loader = require("loader")
|
||||
local loader = require("utils/loader")
|
||||
local theme = require("gui.core.theme")
|
||||
local fmt = require("fmt")
|
||||
local timer = require("utils")
|
||||
local fmt = require("utils/fmt")
|
||||
local timer = require("utils/utils")
|
||||
local multi, thread = require("multi"):init()
|
||||
local menu = require("gui.core.menus")
|
||||
|
||||
@@ -22,7 +22,10 @@ local scoreboard = {}
|
||||
-- Create a table to manage GUI elements
|
||||
local manage = {}
|
||||
|
||||
local boardLog = log:child("board")
|
||||
|
||||
-- Function to resize fonts for all managed elements
|
||||
boardLog:debug("Creating resize fonts handler")
|
||||
local function resizeFonts()
|
||||
-- Use multi-threading to improve performance
|
||||
multi:newThread(function()
|
||||
@@ -87,6 +90,7 @@ end
|
||||
|
||||
function applyDD()
|
||||
if not applied_dd and completed_questions > min_questions then
|
||||
boardLog:debug("Creating double jeopardy questions: %d",dd_count)
|
||||
local dd = 0
|
||||
local dd_list = {}
|
||||
local dds = {pickFiltered(board.children, dd_count)}
|
||||
@@ -97,13 +101,15 @@ function applyDD()
|
||||
end
|
||||
end
|
||||
|
||||
local templateLog = log:child("template")
|
||||
function LoadTemplate(name, path)
|
||||
boardLog:debug("Loading Template: %s", name)
|
||||
if love.filesystem.getInfo(path .."/templates/" .. name .. ".lua") then
|
||||
data = love.filesystem.read(path .."/templates/" .. name .. ".lua")
|
||||
elseif love.filesystem.getInfo("templates/" .. name .. ".lua") then
|
||||
data = love.filesystem.read("templates/" .. name .. ".lua")
|
||||
else
|
||||
print("Error Loading Template: " .. name, path)
|
||||
boardLog:error("Error Loading Template: %s", name)
|
||||
gui:newMessageBox({
|
||||
title = "Error!",
|
||||
message = "Unable to load template: " .. name,
|
||||
@@ -157,7 +163,8 @@ function LoadTemplate(name, path)
|
||||
gui = gui,
|
||||
timer = timer,
|
||||
-- love stuff
|
||||
newSource = love.audio.newSource
|
||||
newSource = love.audio.newSource,
|
||||
log = templateLog
|
||||
}
|
||||
|
||||
env._G = env
|
||||
@@ -167,6 +174,7 @@ function LoadTemplate(name, path)
|
||||
end
|
||||
|
||||
local function manageCosmetics(frame, cosmetics)
|
||||
boardLog:debug("Managing cosmetics")
|
||||
if cosmetics["bg-img"] then
|
||||
frame:setImage(cosmetics["bg-img"])
|
||||
else
|
||||
@@ -192,9 +200,9 @@ local reset = boardUpdater:newConnection()
|
||||
local default_text = "Pick a Category"
|
||||
|
||||
function Menu(frame, path)
|
||||
boardLog:info("Building board")
|
||||
if path:match(".zip") then
|
||||
-- local basename = path:match("([^/\\]+)$")
|
||||
print(path)
|
||||
local success = love.filesystem.mount(path, "quiz", true)
|
||||
if not success then
|
||||
gui:newMessageBox({
|
||||
@@ -215,6 +223,7 @@ function Menu(frame, path)
|
||||
end
|
||||
|
||||
-- Start the processors now
|
||||
boardLog:debug("Starting processors")
|
||||
boardUpdater.Start()
|
||||
qUpdater.Start()
|
||||
scoreUpdater.Start()
|
||||
@@ -329,20 +338,21 @@ function Menu(frame, path)
|
||||
if dd_enabled then
|
||||
applyDD() -- check and run DD if conditions meet
|
||||
end
|
||||
if index.categories[cat].questions == nil then fmt.Printf("Question not defined: File: %v Category: %v - %v\n",path,index.categories[cat].name,start + inc*(tier-1)) return end
|
||||
if index.categories[cat].questions == nil then boardLog:info("Question not defined: File: %s Category: %s - %s\n",path,index.categories[cat].name,start + inc*(tier-1)) return end
|
||||
local globals = index.categories[cat].global
|
||||
if not globals then
|
||||
globals = {}
|
||||
end
|
||||
local q = index.categories[cat].questions[self.index]
|
||||
if not q then return end
|
||||
label.text = t.category .. ": " .. t.price
|
||||
label.text = t.category .. " - " .. t.price
|
||||
boardLog:debug("Displaying question for: %s - %s", t.category, t.price)
|
||||
local mt = debug.getmetatable(q)
|
||||
if mt then
|
||||
mt.__metatable = nil
|
||||
end
|
||||
setmetatable(q, {__index = globals})
|
||||
if q == nil then fmt.Printf("Question contains no data: File: %v Category: %v Tier: %v\n",path,index.categories[cat].name,start + inc*(tier-1)) return end
|
||||
if q == nil then boardLog:info("Question contains no data: File: %s Category: %s Tier: %s\n",path,index.categories[cat].name,start + inc*(tier-1)) return end
|
||||
if q.cosmetics then
|
||||
manageCosmetics(frame, q.cosmetics)
|
||||
end
|
||||
@@ -352,7 +362,7 @@ function Menu(frame, path)
|
||||
local player = GetActivePlayer()
|
||||
local tm
|
||||
local stop
|
||||
fmt.Printf("--------------------\nQuestion: %v \nAnswer: %v\n--------------------\n",q["title"],q["answer"])
|
||||
boardLog:info("Question: '%s' Answer: '%s'",q["title"],q["answer"])
|
||||
local mul = 1
|
||||
boardUpdater:newThread(function()
|
||||
if self.isDouble then
|
||||
|
||||
Reference in New Issue
Block a user