Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e8ca768e87 | |||
| 9a908e89ae | |||
| 3109844765 |
+11
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
|
||||
"runtime.version": "LuaJIT",
|
||||
"diagnostics.globals": [
|
||||
"love"
|
||||
],
|
||||
"workspace.library": [
|
||||
"${3rd}/love2d/library"
|
||||
],
|
||||
"workspace.checkThirdParty": false
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"recommendations":
|
||||
["tomblind.local-lua-debugger-vscode",
|
||||
"sumneko.lua",]
|
||||
}
|
||||
Vendored
+28
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "lua-local",
|
||||
"request": "launch",
|
||||
"name": "Debug",
|
||||
"program": {
|
||||
"command": "love"
|
||||
},
|
||||
"args": [
|
||||
".",
|
||||
"debug"
|
||||
],
|
||||
},
|
||||
{
|
||||
"type": "lua-local",
|
||||
"request": "launch",
|
||||
"name": "Release",
|
||||
"program": {
|
||||
"command": "love"
|
||||
},
|
||||
"args": [
|
||||
".",
|
||||
],
|
||||
},
|
||||
]
|
||||
}
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "Build with LÖVE-Build",
|
||||
"type": "shell",
|
||||
"command": "love-build", // Path to Love-build
|
||||
"args": [".main.lua"],
|
||||
"group": "build",
|
||||
}
|
||||
]
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 57 KiB |
@@ -0,0 +1,17 @@
|
||||
return {
|
||||
-- basic settings:
|
||||
name = 'Jeopardy', -- name of the game for your executable
|
||||
developer = 'Ryan Ward', -- dev name used in metadata of the file
|
||||
output = 'bin', -- output location for your game, defaults to $SAVE_DIRECTORY
|
||||
version = '1.0.2', -- 'version' of your game, used to name the folder in output
|
||||
love = '11.5', -- version of LÖVE to use, must match github releases
|
||||
ignore = {'bin', 'love', 'server_test', '.gitignore', '.gitmodules', 'build.lua', 'login_dialog.yaml', 'package.bat', 'README.md'}, -- folders/files to ignore in your project
|
||||
icon = 'assets/icon.png', -- 256x256px PNG icon for game, will be converted for you
|
||||
|
||||
-- optional settings:
|
||||
use32bit = false, -- set true to build windows 32-bit as well as 64-bit
|
||||
identifier = 'net.ddns.epicknex.jeopardy', -- macos team identifier, defaults to game.developer.name
|
||||
libs = {},
|
||||
hooks = {},
|
||||
platforms = {'windows', --[['macos', 'linux', 'steamdeck']]} -- set if you only want to build for a specific platform
|
||||
}
|
||||
+1
-1
Submodule gui updated: fa06733747...c4cf5cbc9e
@@ -1,59 +0,0 @@
|
||||
# login_dialog.yaml
|
||||
type: frame
|
||||
x: 0
|
||||
y: 0
|
||||
scale-size: [0.4, 0.25]
|
||||
scale-pos: [0.3, 0.2]
|
||||
color: "#1e1e2e"
|
||||
border-color: "#4a4a6a"
|
||||
roundness: 12
|
||||
|
||||
children:
|
||||
- type: label
|
||||
text: "Sign In"
|
||||
x: 0
|
||||
y: 20
|
||||
scale-size: [1.0, 0.0]
|
||||
h: 48
|
||||
align: center
|
||||
font: 28
|
||||
text-color: "#cdd6f4"
|
||||
|
||||
- type: textbox
|
||||
x: 30
|
||||
y: 90
|
||||
scale-size: [0.85, 0.0]
|
||||
h: 36
|
||||
text: ""
|
||||
color: "#313244"
|
||||
border-color: "#6c7086"
|
||||
text-color: "#cdd6f4"
|
||||
font: 14
|
||||
on-return: "focusPassword"
|
||||
|
||||
- type: textbox
|
||||
x: 30
|
||||
y: 140
|
||||
scale-size: [0.85, 0.0]
|
||||
h: 36
|
||||
text: ""
|
||||
color: "#313244"
|
||||
border-color: "#6c7086"
|
||||
text-color: "#cdd6f4"
|
||||
font: 14
|
||||
on-return: "submitLogin"
|
||||
|
||||
- type: button
|
||||
text: "Log In"
|
||||
align: "center"
|
||||
fit-font: true
|
||||
x: 30
|
||||
y: 200
|
||||
scale-size: [0.2, 0.0]
|
||||
h: 40
|
||||
color: "#89b4fa"
|
||||
text-color: "#1e1e2e"
|
||||
roundness: 8
|
||||
on-pressed: "submitLogin"
|
||||
on-enter: "highlightButton"
|
||||
on-exit: "unhighlightButton"
|
||||
@@ -49,12 +49,16 @@ local old = multi.error
|
||||
|
||||
multi.error = function(self, err)
|
||||
loadLog:error("Error: %s", err)
|
||||
loadLog:error(debug.traceback())
|
||||
love.quit()
|
||||
end
|
||||
|
||||
function love.load()
|
||||
loadLog:info("Starting Jeopardy Game")
|
||||
loadLog:debug("Setting game identity to jeopardy")
|
||||
for i,v in ipairs(color.listColors(showAllColors)) do
|
||||
loadLog:debug("Indexed color %s",v)
|
||||
end
|
||||
love.filesystem.setIdentity("jeopardy")
|
||||
loadLog:trace("Creating save directory")
|
||||
success = love.filesystem.createDirectory("")
|
||||
|
||||
+49
-93
@@ -19,33 +19,10 @@ local playerList = {}
|
||||
local playerStaticList = {}
|
||||
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()
|
||||
-- Introduce a small delay to avoid too many iterations at once
|
||||
thread.skip(2)
|
||||
-- Iterate over each element in the 'manage' table
|
||||
for i = 1, #manage do
|
||||
local elem = manage[i]
|
||||
|
||||
-- Check if the current element has a centerFont property
|
||||
if elem.centerFont then
|
||||
-- Adjust font size and re-center the text
|
||||
elem:fitFont(nil, nil, {scale = 2/3})
|
||||
elem:centerFont()
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
gui.Events.OnResized(resizeFonts)
|
||||
|
||||
local completed_questions = 0
|
||||
local min_questions = 0
|
||||
@@ -239,17 +216,8 @@ function Menu(frame, path)
|
||||
label.color = color.bg
|
||||
label.textColor = color.status_font
|
||||
label:setRoundness(20,20,60)
|
||||
|
||||
boardUpdater:newThread(function()
|
||||
local test = function()
|
||||
return label.text ~= ""
|
||||
end
|
||||
while true do
|
||||
thread.hold(test)
|
||||
label:centerFont()
|
||||
label:fitFont(nil, nil, {scale = 2/3})
|
||||
end
|
||||
end)
|
||||
label:scaleFont(2/3)
|
||||
label:centerFont()
|
||||
|
||||
local data = loader:new(path)
|
||||
board, question, dailydouble = qframe:newFrame(), qframe:newFrame(), qframe:newImageLabel("assets/images/double.jpg")
|
||||
@@ -323,7 +291,8 @@ function Menu(frame, path)
|
||||
img:fullFrame()
|
||||
end
|
||||
|
||||
table.insert(manage,c)
|
||||
c:scaleFont(.25)
|
||||
c:centerFont()
|
||||
|
||||
for tier = 1,tiers do
|
||||
local t = board:newTextButton("$" .. start + inc*(tier-1),0,0,0,0,(1/#index.categories)*(cat-1),1/(tiers+1)*tier,(1/#index.categories),1/(tiers+1))
|
||||
@@ -409,19 +378,16 @@ function Menu(frame, path)
|
||||
boardUpdater:newThread("QuestionUpdater",function()
|
||||
while true do
|
||||
template.update(dt)
|
||||
thread.yield()
|
||||
thread.sleep(.1)
|
||||
if self.text == "" then return end
|
||||
end
|
||||
end)
|
||||
end)
|
||||
end))
|
||||
table.insert(manage,t)
|
||||
t:centerFont()
|
||||
t:scaleFont(.5)
|
||||
end
|
||||
end
|
||||
|
||||
resizeFonts()
|
||||
resizeFonts()
|
||||
|
||||
return background
|
||||
end
|
||||
|
||||
@@ -460,19 +426,33 @@ end
|
||||
|
||||
function ScoreBoard(frame, x, y, w, h, sx, sy, sw, sh)
|
||||
-- Colors
|
||||
local C_BG_PANEL = color.new("#1a1a2e")
|
||||
local C_BG_HEADER = color.new("#16213e")
|
||||
local C_ACCENT = color.new("#e94560")
|
||||
local C_ROW_TOP = color.new("#1c2641")
|
||||
local C_ROW_NORM = color.new("#121226")
|
||||
local C_BORDER_TOP = color.new("#323c6e")
|
||||
local C_BORDER_NRM = color.new("#1c1c37")
|
||||
local C_BAR_EMPTY = color.new("#232341")
|
||||
local C_TEXT_MUTED = color.new("#786e96")
|
||||
local C_WHITE = color.new("#ffffff")
|
||||
local C_GOLD = color.new("#ffd700")
|
||||
local C_SILVER = color.new("#C0C0C0")
|
||||
local C_BRONZE = color.new("#cd7f32")
|
||||
color.indexColor("scoreboard_panel_bg", "#1a1a2e")
|
||||
color.indexColor("scoreboard_header_bg", "#16213e")
|
||||
color.indexColor("scoreboard_accent_color", "#e94560")
|
||||
color.indexColor("scoreboard_row_top_bg", "#1c2641")
|
||||
color.indexColor("scoreboard_row_norm_bg", "#121226")
|
||||
color.indexColor("scoreboard_border_top_color", "#323c6e")
|
||||
color.indexColor("scoreboard_border_nrm_color", "#1c1c37")
|
||||
color.indexColor("scoreboard_bar_empty_color", "#232341")
|
||||
color.indexColor("scoreboard_text_muted_color", "#786e96")
|
||||
color.indexColor("scoreboard_pure_white", "#ffffff")
|
||||
color.indexColor("scoreboard_precious_gold", "#ffd700")
|
||||
color.indexColor("scoreboard_precious_silver", "#C0C0C0")
|
||||
color.indexColor("scoreboard_precious_bronze", "#cd7f32")
|
||||
|
||||
local C_BG_PANEL = color.scoreboard_panel_bg
|
||||
local C_BG_HEADER = color.scoreboard_header_bg
|
||||
local C_ACCENT = color.scoreboard_accent_color
|
||||
local C_ROW_TOP = color.scoreboard_row_top_bg
|
||||
local C_ROW_NORM = color.scoreboard_row_norm_bg
|
||||
local C_BORDER_TOP = color.scoreboard_border_top_color
|
||||
local C_BORDER_NRM = color.scoreboard_border_nrm_color
|
||||
local C_BAR_EMPTY = color.scoreboard_bar_empty_color
|
||||
local C_TEXT_MUTED = color.scoreboard_text_muted_color
|
||||
local C_WHITE = color.scoreboard_pure_white
|
||||
local C_GOLD = color.scoreboard_precious_gold
|
||||
local C_SILVER = color.scoreboard_precious_silver
|
||||
local C_BRONZE = color.scoreboard_precious_bronze
|
||||
|
||||
-- Config stuff
|
||||
local LEADER_HEIGHT_SCALE = .06
|
||||
@@ -508,30 +488,16 @@ function ScoreBoard(frame, x, y, w, h, sx, sy, sw, sh)
|
||||
textColor = C_TEXT_MUTED,
|
||||
}, headernum, headerplayer, headerscore)
|
||||
|
||||
local updateList = {header, headernum, headerplayer, headerscore}
|
||||
|
||||
local function ScoreResize()
|
||||
scoreUpdater:newThread(function()
|
||||
thread.skip(2)
|
||||
|
||||
for _,object in pairs(updateList) do
|
||||
object:fitFont(nil, nil, {scale = 5/6})
|
||||
object:centerFont()
|
||||
end
|
||||
|
||||
for _,object in pairs(playerList) do
|
||||
if type(object) == "table" and object.Ref then
|
||||
for i, player in pairs(object.Ref) do
|
||||
if player:hasType(gui.TYPE_TEXT) then
|
||||
player:fitFont(nil, nil, {scale = 5/6})
|
||||
player:centerFont()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
local updateList = {headernum, headerplayer, headerscore}
|
||||
|
||||
header:centerFont()
|
||||
header:scaleFont(2/3)
|
||||
|
||||
for _,object in pairs(updateList) do
|
||||
object:fitFont(nil, nil, {scale = 5/6})
|
||||
object:centerFont()
|
||||
end
|
||||
|
||||
function scoreboard:AddPlayer(name, score, icon)
|
||||
local player = {
|
||||
Name = name,
|
||||
@@ -547,13 +513,11 @@ function ScoreBoard(frame, x, y, w, h, sx, sy, sw, sh)
|
||||
return tonumber(a.Score) > tonumber(b.Score)
|
||||
end)
|
||||
scoreboard:RenderPlayer(playerList)
|
||||
ScoreResize()
|
||||
end,
|
||||
}
|
||||
table.insert(playerList, player)
|
||||
table.insert(playerStaticList, player)
|
||||
scoreboard:RenderPlayer(playerList)
|
||||
ScoreResize()
|
||||
return player
|
||||
end
|
||||
|
||||
@@ -572,14 +536,7 @@ function ScoreBoard(frame, x, y, w, h, sx, sy, sw, sh)
|
||||
remove_player:setFont(20)
|
||||
remove_player.align = gui.ALIGN_CENTER
|
||||
local embededWatch = {remove_player}
|
||||
scoreUpdater:newThread(function()
|
||||
while true do
|
||||
thread.sleep(.01)
|
||||
for i,v in pairs(embededWatch) do
|
||||
v:centerFont()
|
||||
end
|
||||
end
|
||||
end)
|
||||
remove_player:centerFont()
|
||||
|
||||
local function embedTextEdit(reference, default, but_text, callback)
|
||||
reference.color = C_BORDER_NRM
|
||||
@@ -599,10 +556,9 @@ function ScoreBoard(frame, x, y, w, h, sx, sy, sw, sh)
|
||||
end)
|
||||
gui.apply({
|
||||
setFont = {20},
|
||||
align = gui.ALIGN_CENTER
|
||||
align = gui.ALIGN_CENTER,
|
||||
centerFont = {},
|
||||
},textbox,button,reference)
|
||||
table.insert(embededWatch,textbox)
|
||||
table.insert(embededWatch,button)
|
||||
end
|
||||
|
||||
remove_player.color = color.new("#a13a3a")
|
||||
@@ -704,7 +660,9 @@ function ScoreBoard(frame, x, y, w, h, sx, sy, sw, sh)
|
||||
gui.apply({
|
||||
visibility = 0,
|
||||
drawBorder = false,
|
||||
textColor = MapColor(index)
|
||||
textColor = MapColor(index),
|
||||
scaleFont = {5/6},
|
||||
centerFont = {}
|
||||
},playernum, playerName, playerScore, playerIcon, playerLine)
|
||||
|
||||
player.Ref = {playerName, playerScore, playernum, playerIcon, playerLine, Frame = playerFrame}
|
||||
@@ -712,8 +670,6 @@ function ScoreBoard(frame, x, y, w, h, sx, sy, sw, sh)
|
||||
end
|
||||
end
|
||||
|
||||
gui.Events.OnResized(ScoreResize)
|
||||
ScoreResize()
|
||||
return scoreboard
|
||||
end
|
||||
|
||||
|
||||
+7
-17
@@ -25,17 +25,9 @@ function Menu(frame)
|
||||
title.visibility = 0
|
||||
title.textColor = color.title_font
|
||||
title.drawBorder = false
|
||||
title:centerFont()
|
||||
|
||||
titleLog:debug("Creating font thread")
|
||||
proc:newThread(function()
|
||||
local function enabled()
|
||||
return background.visible
|
||||
end
|
||||
while true do
|
||||
thread.hold(enabled)
|
||||
title:centerFont()
|
||||
end
|
||||
end)
|
||||
|
||||
local items = 0
|
||||
local MenuOption = function(str)
|
||||
@@ -43,13 +35,10 @@ function Menu(frame)
|
||||
local text = item:newTextLabel(str)
|
||||
text:fullFrame()
|
||||
text.align = gui.ALIGN_CENTER
|
||||
thread:newThread(function()
|
||||
thread.skip(2)
|
||||
text:fitFont(nil,nil,{scale = 1/2})
|
||||
text:centerFont()
|
||||
text.visibility = 0
|
||||
text.textColor = color.new("#24269a")
|
||||
end)
|
||||
text:scaleFont(.4)
|
||||
text:centerFont()
|
||||
text.visibility = 0
|
||||
text.textColor = color.new("#24269a")
|
||||
items = items + 1
|
||||
return item, text
|
||||
end
|
||||
@@ -80,7 +69,8 @@ function Menu(frame)
|
||||
end
|
||||
end)
|
||||
|
||||
quit:OnReleased(function()
|
||||
quit:OnReleased(function(self, x, y)
|
||||
print("Quit Pressed",x,y,self:getAbsolutes())
|
||||
titleLog:debug("Quit button pressed")
|
||||
local f = frame:newFrame()
|
||||
f:fullFrame()
|
||||
|
||||
+1
-1
Submodule multi updated: 0796788fcb...8b5d10cbb6
@@ -11,6 +11,7 @@ local function index(window, q, callback)
|
||||
label.textColor = color.white
|
||||
label.color = color.new("#363ac8")
|
||||
label.borderColor = color.new("#363ac8")
|
||||
label:scaleFont(.075)
|
||||
|
||||
if not q.imageA or q.imageA == "" then
|
||||
error("Missing 'imageA' field for question!")
|
||||
@@ -49,7 +50,8 @@ local function index(window, q, callback)
|
||||
}, imageHolder, plusLabel, imageHolder2)
|
||||
|
||||
window.apply({
|
||||
fitFont={},
|
||||
scaleFont={.7},
|
||||
centerFont={},
|
||||
align=window.ALIGN_CENTER,
|
||||
OnReleased=function(self)
|
||||
if self.text == "Skip" then
|
||||
@@ -62,7 +64,7 @@ local function index(window, q, callback)
|
||||
end
|
||||
|
||||
local function update(dt)
|
||||
label:fitFont()
|
||||
|
||||
end
|
||||
|
||||
return {
|
||||
|
||||
@@ -23,7 +23,10 @@ local function index(window, q, callback)
|
||||
label.textColor = color.white
|
||||
label.color = color.new("#363ac8")
|
||||
label:setFont(50)
|
||||
choices = window:newFrame(noOf(0,.3,1,.7))
|
||||
label:centerFont()
|
||||
label:scaleFont(2/3)
|
||||
|
||||
local choices = window:newFrame(noOf(0,.3,1,.7))
|
||||
choices.color = color.new("#363ac8")
|
||||
|
||||
function choices:newChoice(choice, i)
|
||||
@@ -52,9 +55,8 @@ local function index(window, q, callback)
|
||||
choiceText.textColor = color.white
|
||||
-- choiceText.align = window.ALIGN_CENTER
|
||||
choiceText:setFont(40)
|
||||
table.insert(choiceList,choiceText)
|
||||
choiceText:centerFont()
|
||||
table.insert(allBoxes,box)
|
||||
|
||||
end
|
||||
|
||||
for i,choice in pairs(q.choices) do
|
||||
@@ -84,16 +86,7 @@ local function index(window, q, callback)
|
||||
end
|
||||
|
||||
local function update(dt) -- time in seconds that has passed since
|
||||
-- label:fitFont()
|
||||
label:centerFont()
|
||||
for _, obj in pairs(choiceList) do
|
||||
obj:centerFont()
|
||||
-- obj:fitFont(nil, nil, {scale = 2/3})
|
||||
end
|
||||
confirm:fitFont(nil, nil, {scale = 2/3})
|
||||
confirm:centerFont()
|
||||
-- print(box.parent:getAbsolutes())
|
||||
-- print(box:getAbsolutes())
|
||||
|
||||
end
|
||||
|
||||
return {
|
||||
|
||||
@@ -16,6 +16,8 @@ local function index(window, q, callback)
|
||||
label.align = ALIGN_CENTER
|
||||
label.textColor = color.white
|
||||
label.color = color.new("#363ac8")
|
||||
label:scaleFont(.5)
|
||||
label:centerFont()
|
||||
if not q.image or q.image == "" then
|
||||
error("Missing 'image' field for question!")
|
||||
end
|
||||
@@ -31,7 +33,8 @@ local function index(window, q, callback)
|
||||
local skip = window:newTextButton("Skip",0,-100,0,100,.25,1,.5)
|
||||
skip.color = color.new("#5d5d5d")
|
||||
window.apply({
|
||||
fitFont={},
|
||||
scaleFont={.7},
|
||||
centerFont={},
|
||||
align=window.ALIGN_CENTER,
|
||||
OnReleased=function(self)
|
||||
if self.text == "Skip" then
|
||||
@@ -47,7 +50,6 @@ local function update(dt) -- time in seconds that has passed since
|
||||
_,_,w,h = imageHolder.parent:getAbsolutes()
|
||||
local x,y,w,h = imageHolder:GetSizeAdjustedToAspectRatio(w,h)
|
||||
imageHolder:setDualDim(w,h,x,y)
|
||||
label:fitFont()
|
||||
end
|
||||
|
||||
return {
|
||||
|
||||
@@ -14,6 +14,8 @@ local function index(window, q, callback)
|
||||
label:fullFrame()
|
||||
label.textColor = color.white
|
||||
label.color = color.new("#363ac8")
|
||||
label:centerFont()
|
||||
label:scaleFont(.075)
|
||||
local correct = window:newTextButton("Correct",0,-200,0,100,0,1,.5)
|
||||
correct.color = color.new("#52b11b")
|
||||
local wrong = window:newTextButton("Wrong",0,-200,0,100,.5,1,.5)
|
||||
@@ -21,7 +23,8 @@ local function index(window, q, callback)
|
||||
local skip = window:newTextButton("Skip",0,-100,0,100,.25,1,.5)
|
||||
skip.color = color.new("#5d5d5d")
|
||||
gui.apply({
|
||||
fitFont={},
|
||||
scaleFont={.7},
|
||||
centerFont={},
|
||||
align=gui.ALIGN_CENTER,
|
||||
OnReleased=function(self)
|
||||
if self.text == "Skip" then
|
||||
@@ -31,11 +34,10 @@ local function index(window, q, callback)
|
||||
callback(self.text == "Correct")
|
||||
end,
|
||||
},correct,wrong,skip)
|
||||
label:setFont(60)
|
||||
end
|
||||
|
||||
local function update(dt) -- time in seconds that has passed since
|
||||
label:centerFont()
|
||||
|
||||
end
|
||||
|
||||
return {
|
||||
|
||||
@@ -21,6 +21,8 @@ local function index(window, q, callback)
|
||||
label.align = ALIGN_CENTER
|
||||
label.textColor = color.white
|
||||
label.color = color.new("#363ac8")
|
||||
label:centerFont()
|
||||
label:scaleFont(.5)
|
||||
local holder = frame:newFrame(-300, -200, 600, 400, .5, .5)
|
||||
holder:centerX(true)
|
||||
holder:centerY(true)
|
||||
@@ -38,7 +40,8 @@ local function index(window, q, callback)
|
||||
local skip = window:newTextButton("Skip",0,-100,0,100,.25,1,.5)
|
||||
skip.color = color.new("#5d5d5d")
|
||||
window.apply({
|
||||
fitFont={},
|
||||
scaleFont={.7},
|
||||
centerFont={},
|
||||
align=window.ALIGN_CENTER,
|
||||
OnReleased=function(self)
|
||||
video:stop()
|
||||
@@ -52,8 +55,7 @@ local function index(window, q, callback)
|
||||
end
|
||||
|
||||
local function update(dt) -- time in seconds that has passed since
|
||||
label:fitFont()
|
||||
label:centerFont()
|
||||
|
||||
end
|
||||
|
||||
return {
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
--[[ Constants
|
||||
* (all lua builtins that don't allow io/executing code)
|
||||
color (interface)
|
||||
gui (interface)
|
||||
multi (interface bound to a processor) no thread module
|
||||
|
||||
callback true/false correct/wrong
|
||||
]]
|
||||
local label
|
||||
local imageHolder
|
||||
|
||||
local function index(window, q, callback)
|
||||
frame = window:newFrame(0,0,0,-200,0,.2,1,.8)
|
||||
frame.visibility = 0
|
||||
label = window:newTextLabel(" " ..q.title.. " ",0,0,0,0,0,0,1,.2)
|
||||
label.align = ALIGN_CENTER
|
||||
label.textColor = color.white
|
||||
label.color = color.new("#363ac8")
|
||||
label:scaleFont(.5)
|
||||
label:centerFont()
|
||||
local errors = {}
|
||||
|
||||
if type(q.zoom) ~= "string" and q.zoom ~= "" then
|
||||
table.insert(errors, "Missing 'zoom' fiels for queston! Should be a path to an image.")
|
||||
end
|
||||
|
||||
if type(q.minzoom) ~= "string" and q.minzoom ~= "" then
|
||||
table.insert(errors, "Missing 'minzoom' field for question! Should be a path to an image.")
|
||||
end
|
||||
|
||||
if type(q.fullimage) ~= "string" and q.fullimage ~= "" then
|
||||
table.insert(errors, "Missing 'fullimage' field for question! Should be a path to an image.")
|
||||
end
|
||||
|
||||
local zooms = {q.zoom, q.minzoom, q.fullimage}
|
||||
print(q.fullimage)
|
||||
local index = 1
|
||||
local mul = 1
|
||||
|
||||
imageHolder = frame:newImageLabel(q.zoom)
|
||||
imageHolder:setAspectSize(imageHolder.imageWidth,imageHolder.imageHeight)
|
||||
imageHolder:centerX(true)
|
||||
imageHolder:centerY(true)
|
||||
imageHolder:setDualDim(0,0,imageHolder.imageWidth,imageHolder.imageHeight)
|
||||
|
||||
imageHolder:OnEnter(function(self)
|
||||
self:setShader(gui.SHADERS.glow)
|
||||
end)
|
||||
|
||||
imageHolder:OnExit(function(self)
|
||||
self:setShader()
|
||||
end)
|
||||
|
||||
imageHolder:shaderTime(true)
|
||||
|
||||
imageHolder:OnReleased(function()
|
||||
index = index + 1
|
||||
print(index)
|
||||
if index == 2 then
|
||||
mul = .5
|
||||
elseif index == 3 then
|
||||
mul = .25
|
||||
else
|
||||
index = 3
|
||||
end
|
||||
imageHolder:setImage(zooms[index])
|
||||
end)
|
||||
|
||||
local correct = window:newTextButton("Correct",0,-200,0,100,0,1,.5)
|
||||
correct.color = color.new("#52b11b")
|
||||
local wrong = window:newTextButton("Wrong",0,-200,0,100,.5,1,.5)
|
||||
wrong.color = color.new("#bd2626")
|
||||
local skip = window:newTextButton("Skip",0,-100,0,100,.25,1,.5)
|
||||
skip.color = color.new("#5d5d5d")
|
||||
window.apply({
|
||||
scaleFont={.7},
|
||||
centerFont={},
|
||||
align=window.ALIGN_CENTER,
|
||||
OnReleased=function(self)
|
||||
if self.text == "Skip" then
|
||||
callback()
|
||||
return
|
||||
end
|
||||
callback(self.text == "Correct", mul)
|
||||
end,
|
||||
},correct,wrong,skip)
|
||||
end
|
||||
|
||||
local function update(dt) -- time in seconds that has passed since
|
||||
_,_,w,h = imageHolder.parent:getAbsolutes()
|
||||
local x,y,w,h = imageHolder:GetSizeAdjustedToAspectRatio(w,h)
|
||||
imageHolder:setDualDim(w,h,x,y)
|
||||
end
|
||||
|
||||
return {
|
||||
index = index,
|
||||
update = update
|
||||
}
|
||||
-197
@@ -1,197 +0,0 @@
|
||||
--- test_logger.lua — Demonstrates and tests all logger.lua features
|
||||
|
||||
-- Adjust path if needed
|
||||
package.path = "./?.lua;" .. package.path
|
||||
local Logger = require("utils/logger")
|
||||
|
||||
local PASS = 0
|
||||
local FAIL = 0
|
||||
|
||||
local function test(label, cond)
|
||||
if cond then
|
||||
print(string.format(" [PASS] %s", label))
|
||||
PASS = PASS + 1
|
||||
else
|
||||
io.stderr:write(string.format(" [FAIL] %s\n", label))
|
||||
FAIL = FAIL + 1
|
||||
end
|
||||
end
|
||||
|
||||
print("━━━ logger.lua test suite ━━━\n")
|
||||
|
||||
-- ── 1. Basic levels ────────────────────────────────────────────────────────
|
||||
print("▶ 1. Basic level output (INFO+)")
|
||||
do
|
||||
local handler, get, clear = Logger.handlers.MemoryHandler()
|
||||
local log = Logger.new("basic", { level = Logger.LEVELS.INFO, handlers = { handler } })
|
||||
|
||||
log:trace("should be filtered")
|
||||
log:debug("should be filtered")
|
||||
log:info("hello %s", "world")
|
||||
log:warn("disk %d%%", 90)
|
||||
log:error("boom")
|
||||
log:fatal("catastrophe")
|
||||
|
||||
local records = get()
|
||||
test("TRACE filtered", records[1].level == Logger.LEVELS.INFO)
|
||||
test("INFO captured", records[1].message == "hello world")
|
||||
test("WARN captured", records[2].message == "disk 90%")
|
||||
test("ERROR captured", records[3].level == Logger.LEVELS.ERROR)
|
||||
test("FATAL captured", records[4].level == Logger.LEVELS.FATAL)
|
||||
test("exactly 4 records", #records == 4)
|
||||
end
|
||||
|
||||
-- ── 2. Level filtering ─────────────────────────────────────────────────────
|
||||
print("\n▶ 2. Dynamic level changes")
|
||||
do
|
||||
local handler, get = Logger.handlers.MemoryHandler()
|
||||
local log = Logger.new("dyn", { handlers = { handler } })
|
||||
|
||||
log:set_level(Logger.LEVELS.DEBUG)
|
||||
log:debug("visible")
|
||||
log:set_level(Logger.LEVELS.ERROR)
|
||||
log:info("invisible")
|
||||
log:error("visible again")
|
||||
|
||||
local records = get()
|
||||
test("DEBUG visible at DEBUG level", records[1].message == "visible")
|
||||
test("INFO invisible at ERROR level", records[2].message == "visible again")
|
||||
test("total 2 records", #records == 2)
|
||||
end
|
||||
|
||||
-- ── 3. is_enabled ──────────────────────────────────────────────────────────
|
||||
print("\n▶ 3. is_enabled()")
|
||||
do
|
||||
local log = Logger.new("enabled", { level = Logger.LEVELS.WARN })
|
||||
test("WARN enabled", log:is_enabled(Logger.LEVELS.WARN))
|
||||
test("INFO disabled", not log:is_enabled(Logger.LEVELS.INFO))
|
||||
test("ERROR enabled", log:is_enabled(Logger.LEVELS.ERROR))
|
||||
end
|
||||
|
||||
-- ── 4. Custom format ───────────────────────────────────────────────────────
|
||||
print("\n▶ 4. Custom format string")
|
||||
do
|
||||
local handler, get = Logger.handlers.MemoryHandler()
|
||||
local log = Logger.new("fmt", {
|
||||
format = "{level}|{name}|{message}",
|
||||
handlers = { handler },
|
||||
})
|
||||
log:info("hi")
|
||||
local f = get()[1].formatted
|
||||
test("contains level", f:find("INFO") ~= nil)
|
||||
test("contains name", f:find("fmt") ~= nil)
|
||||
test("contains message", f:find("hi") ~= nil)
|
||||
test("pipe separator", f:find("|") ~= nil)
|
||||
end
|
||||
|
||||
-- ── 5. Filters ─────────────────────────────────────────────────────────────
|
||||
print("\n▶ 5. Custom filter")
|
||||
do
|
||||
local handler, get = Logger.handlers.MemoryHandler()
|
||||
local log = Logger.new("filter", { level = Logger.LEVELS.DEBUG, handlers = { handler } })
|
||||
|
||||
-- only pass records whose message contains "keep"
|
||||
log:add_filter(function(rec) return rec.message:find("keep") ~= nil end)
|
||||
|
||||
log:info("drop this")
|
||||
log:info("keep this")
|
||||
log:warn("also drop")
|
||||
log:debug("keep me too")
|
||||
|
||||
local records = get()
|
||||
test("only 'keep' records pass", #records == 2)
|
||||
test("first kept record", records[1].message == "keep this")
|
||||
test("second kept record", records[2].message == "keep me too")
|
||||
end
|
||||
|
||||
-- ── 6. Multiple handlers ───────────────────────────────────────────────────
|
||||
print("\n▶ 6. Multiple handlers")
|
||||
do
|
||||
local h1, get1 = Logger.handlers.MemoryHandler()
|
||||
local h2, get2 = Logger.handlers.MemoryHandler()
|
||||
local log = Logger.new("multi", { handlers = { h1 } })
|
||||
log:add_handler(h2)
|
||||
|
||||
log:info("broadcast")
|
||||
|
||||
test("handler1 received", #get1() == 1)
|
||||
test("handler2 received", #get2() == 1)
|
||||
test("same message", get1()[1].message == get2()[1].message)
|
||||
end
|
||||
|
||||
-- ── 7. Child loggers ───────────────────────────────────────────────────────
|
||||
print("\n▶ 7. Child loggers")
|
||||
do
|
||||
local handler, get = Logger.handlers.MemoryHandler()
|
||||
local parent = Logger.new("app", { handlers = { handler } })
|
||||
local child = parent:child("db")
|
||||
|
||||
parent:info("parent message")
|
||||
child:info("child message")
|
||||
|
||||
local records = get()
|
||||
test("parent name", records[1].name == "app")
|
||||
test("child name", records[2].name == "app.db")
|
||||
test("child shares handler", #records == 2)
|
||||
end
|
||||
|
||||
-- ── 8. Logger.get() registry ──────────────────────────────────────────────
|
||||
print("\n▶ 8. Logger.get() registry")
|
||||
do
|
||||
local a = Logger.get("svc.auth")
|
||||
local b = Logger.get("svc.auth")
|
||||
test("same instance returned", a == b)
|
||||
|
||||
local c = Logger.get("svc.payments")
|
||||
test("different names differ", a ~= c)
|
||||
end
|
||||
|
||||
-- ── 9. Format with no args ────────────────────────────────────────────────
|
||||
print("\n▶ 9. Message with no format args")
|
||||
do
|
||||
local handler, get = Logger.handlers.MemoryHandler()
|
||||
local log = Logger.new("noargs", { handlers = { handler } })
|
||||
log:info("plain string, no args")
|
||||
test("plain string works", get()[1].message == "plain string, no args")
|
||||
end
|
||||
|
||||
-- ── 10. FileHandler ───────────────────────────────────────────────────────
|
||||
print("\n▶ 10. FileHandler")
|
||||
do
|
||||
local path = "test_logger_output.log"
|
||||
os.remove(path)
|
||||
|
||||
local fh = Logger.handlers.FileHandler({ path = path })
|
||||
local log = Logger.new("file", { handlers = { fh } })
|
||||
log:info("written to file")
|
||||
log:warn("second line")
|
||||
|
||||
local f = io.open(path)
|
||||
local content = f and f:read("*a") or ""
|
||||
if f then f:close() end
|
||||
|
||||
test("file created", content ~= "")
|
||||
test("INFO line present", content:find("written to file") ~= nil)
|
||||
test("WARN line present", content:find("second line") ~= nil)
|
||||
test("two newlines", select(2, content:gsub("\n","")) == 2)
|
||||
end
|
||||
|
||||
-- ── 11. Console handler (visual) ──────────────────────────────────────────
|
||||
print("\n▶ 11. ConsoleHandler — visual check (colours enabled)")
|
||||
do
|
||||
local log = Logger.new("visual", {
|
||||
level = Logger.LEVELS.TRACE,
|
||||
handlers = { Logger.handlers.ConsoleHandler({ colours = true }) },
|
||||
})
|
||||
log:trace("trace message")
|
||||
log:debug("debug message")
|
||||
log:info ("info message")
|
||||
log:warn ("warn message")
|
||||
log:error("error message")
|
||||
log:fatal("fatal message")
|
||||
test("no crash", true)
|
||||
end
|
||||
|
||||
-- ── Summary ────────────────────────────────────────────────────────────────
|
||||
print(string.format("\n━━━ Results: %d passed, %d failed ━━━", PASS, FAIL))
|
||||
if FAIL > 0 then os.exit(1) end
|
||||
@@ -1,2 +0,0 @@
|
||||
[2026-06-08 19:40:49] [INFO ] [file] written to file
|
||||
[2026-06-08 19:40:49] [WARN ] [file] second line
|
||||
+2
-2
@@ -37,6 +37,8 @@ local function startTimer(opt)
|
||||
tlabel.align = gui.ALIGN_CENTER
|
||||
tlabel:fullFrame()
|
||||
tlabel.visibility = 0
|
||||
tlabel:centerFont()
|
||||
tlabel:scaleFont(.5)
|
||||
tpie.color = opt.startColor
|
||||
tpie.visibility = opt.visibility
|
||||
|
||||
@@ -82,8 +84,6 @@ local function startTimer(opt)
|
||||
|
||||
if opt.autoText then
|
||||
tlabel.text = num
|
||||
tlabel:fitFont(nil, nil, {scale=1/2})
|
||||
tlabel:centerFont()
|
||||
end
|
||||
|
||||
if opt.finegrained then
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
1.0.2
|
||||
1.0.3
|
||||
Reference in New Issue
Block a user