added logging support

This commit is contained in:
2026-06-08 20:29:59 -07:00
parent 0c90ab885e
commit 6b864a2d9b
15 changed files with 1736 additions and 1073 deletions
+20 -10
View File
@@ -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
+7
View File
@@ -7,12 +7,15 @@ local APP_VERSION = love.filesystem.read("version.txt")
local board = require("menus.board")
local titleLog = log:child("title")
function Menu(frame)
local background = frame:newImageLabel("assets/images/background.jpg")
background:fullFrame()
local title = background:newTextLabel("Jeopardy",0,0,0,0,0,.1,1,.25)
title:setFont("assets/fonts/gyparody.ttf",300)
titleLog:debug("Setting title shader")
title:setShader(gui.SHADERS.vignette,{
intensity = .5,
smoothness = .8
@@ -23,6 +26,7 @@ function Menu(frame)
title.textColor = color.title_font
title.drawBorder = false
titleLog:debug("Creating font thread")
proc:newThread(function()
local function enabled()
return background.visible
@@ -64,17 +68,20 @@ function Menu(frame)
},play,settings,quit)
play:OnReleased(function()
titleLog:debug("Play button pressed")
if love.filesystem.getInfo("quiz") then
menu.getMenu("board"):visible(true, "quiz")
return
else
gui:newFilePicker("File picker test",nil, {".zip"}, function(file)
titleLog:info("File picked: %s", file)
menu.getMenu("board"):visible(true, file:gsub("\\","/"):gsub(love.filesystem.getSaveDirectory(),""):sub(2,-1))
end)
end
end)
quit:OnReleased(function()
titleLog:debug("Quit button pressed")
local f = frame:newFrame()
f:fullFrame()
f.visibility = .8