fixed package so it contains templates, updated config for more control
This commit is contained in:
+157
-39
@@ -5,13 +5,14 @@ local theme = require("gui.core.theme")
|
||||
local fmt = require("fmt")
|
||||
local timer = require("utils")
|
||||
local multi, thread = require("multi"):init()
|
||||
local menu = require("menus.menus")
|
||||
local menu = require("gui.core.menus")
|
||||
|
||||
local timesup = love.audio.newSource("assets/sounds/timesup.mp3", "static")
|
||||
local double = love.audio.newSource("assets/sounds/double.mp3", "static")
|
||||
|
||||
local boardUpdater = gui:getProcessor():newProcessor("board-updater")
|
||||
boardUpdater.Start()
|
||||
local scoreUpdater = gui:getProcessor():newProcessor("score-updater")
|
||||
local qUpdater = gui:getProcessor():newProcessor("question-updater")
|
||||
|
||||
local activePlayer
|
||||
local playerList = {}
|
||||
@@ -50,14 +51,6 @@ local dd_enabled = false
|
||||
local applied_dd = false
|
||||
local board, question
|
||||
|
||||
function gui:cleanup()
|
||||
for i = #self.children, 1, -1 do
|
||||
self.children[i]:destroy()
|
||||
end
|
||||
self.children = {}
|
||||
completed_questions = completed_questions + 1
|
||||
end
|
||||
|
||||
local function pickUniqueIndices(t, count)
|
||||
assert(#t >= count, "Not enough elements to pick " .. count .. " unique items")
|
||||
|
||||
@@ -98,22 +91,32 @@ function applyDD()
|
||||
local dd_list = {}
|
||||
local dds = {pickFiltered(board.children, dd_count)}
|
||||
for i,v in pairs(dds) do
|
||||
print(i,v)
|
||||
v.isDouble = true
|
||||
end
|
||||
applied_dd = true
|
||||
end
|
||||
end
|
||||
|
||||
local qUpdater = gui:getProcessor():newProcessor("question-updater")
|
||||
qUpdater.Start()
|
||||
|
||||
function LoadTemplate(name, path)
|
||||
|
||||
if love.filesystem.getInfo("templates/" .. name .. ".lua") then
|
||||
data = love.filesystem.read("templates/" .. name .. ".lua")
|
||||
elseif love.filesystem.getInfo(path .."/templates/" .. name .. ".lua") then
|
||||
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)
|
||||
gui:newMessageBox({
|
||||
title = "Error!",
|
||||
message = "Unable to load template: " .. name,
|
||||
buttons = { "Yes", "No" },
|
||||
onChoice = function(label, idx)
|
||||
if label == "Yes" then
|
||||
doCallback(selected)
|
||||
pickerWindow.visible = false
|
||||
pickerWindow:setTag("visual")
|
||||
end
|
||||
end,
|
||||
})
|
||||
return
|
||||
end
|
||||
|
||||
local template, err = loadstring(data)
|
||||
@@ -163,22 +166,96 @@ function LoadTemplate(name, path)
|
||||
return isoTemplate()
|
||||
end
|
||||
|
||||
local function manageCosmetics(frame, cosmetics)
|
||||
if cosmetics["bg-img"] then
|
||||
frame:setImage(cosmetics["bg-img"])
|
||||
else
|
||||
frame:setImage("assets/images/background.png")
|
||||
end
|
||||
if type(cosmetics.colors) == "table" then
|
||||
for i,v in pairs(cosmetics.colors) do
|
||||
color.reindexColor((i:gsub("-","_")),v)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function gui:cleanup()
|
||||
for i = #self.children, 1, -1 do
|
||||
self.children[i]:destroy()
|
||||
end
|
||||
self.children = {}
|
||||
completed_questions = completed_questions + 1
|
||||
end
|
||||
|
||||
local reset = boardUpdater:newConnection()
|
||||
|
||||
local default_text = "Pick a Category"
|
||||
|
||||
function Menu(frame, path)
|
||||
local qframe = frame:newFrame(0, 0, 0, 0, .2, .05, .75, .9)
|
||||
qframe.color = color.new("#060ee9")
|
||||
local scoreboard = ScoreBoard(frame, 0, 0, 0, 0, .015, .05, .170, .9)
|
||||
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({
|
||||
title = "Return to the main menu?",
|
||||
message = "Couldn't load file: " .. path,
|
||||
buttons = { "Return", "Quit" },
|
||||
onChoice = function(label, idx)
|
||||
if label == "Return" then
|
||||
return menu.getMenu("title"):visible(true)
|
||||
else
|
||||
os.exit()
|
||||
end
|
||||
end,
|
||||
})
|
||||
return
|
||||
end
|
||||
path = "quiz"
|
||||
end
|
||||
|
||||
-- Start the processors now
|
||||
boardUpdater.Start()
|
||||
qUpdater.Start()
|
||||
scoreUpdater.Start()
|
||||
|
||||
local scoreboard = ScoreBoard(frame, 0, 0, 0, 0, .06, .1, .170, .8)
|
||||
|
||||
local qframe = frame:newFrame(0, 0, 0, 0, .24, .1, .70, .8)
|
||||
|
||||
local label = frame:newTextLabel(default_text, 0, 10, 0, -20, .29, 0, .6, .1)
|
||||
label.visibility = .85
|
||||
label.drawBorder = false
|
||||
label.align = gui.ALIGN_CENTER
|
||||
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)
|
||||
|
||||
local data = loader:new(path)
|
||||
board, question, dailydouble = qframe:newFrame(), qframe:newFrame(), qframe:newImageLabel("assets/images/double.jpg")
|
||||
index = data.index
|
||||
|
||||
local cosmetics = index.cosmetics or {}
|
||||
manageCosmetics(frame, cosmetics)
|
||||
|
||||
board:fullFrame()
|
||||
question:fullFrame()
|
||||
dailydouble:fullFrame()
|
||||
|
||||
dailydouble.visible = false
|
||||
question.visible = false
|
||||
question.color = color.new("#060ce9")
|
||||
question.color = color.question_bg
|
||||
|
||||
local tiers = index.settings.tiers or 5
|
||||
local start = index.settings.start or 100
|
||||
@@ -190,6 +267,29 @@ function Menu(frame, path)
|
||||
min_questions = dd.minQuestions
|
||||
dd_count = dd.count
|
||||
end
|
||||
|
||||
local autoreveal = false
|
||||
if index.dev and index.dev.enabled then
|
||||
if index.dev["auto-reveal"] then
|
||||
autoreveal = true
|
||||
end
|
||||
if type(index.dev.players) == "table" then
|
||||
for i,v in ipairs(index.dev.players) do
|
||||
if type(v) == "string" then
|
||||
scoreboard:AddPlayer(v, 0)
|
||||
elseif type(v) == "table" then
|
||||
scoreboard:AddPlayer(v.name, v.score, v.icon)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
reset(function()
|
||||
question:cleanup()
|
||||
manageCosmetics(frame, cosmetics, true)
|
||||
label.text = default_text
|
||||
end)
|
||||
|
||||
for cat,v in pairs(index.categories) do
|
||||
local c
|
||||
if v.image then
|
||||
@@ -197,26 +297,30 @@ function Menu(frame, path)
|
||||
else
|
||||
c = board:newTextLabel(v.displayName or v.name,0,0,0,0,(1/#index.categories)*(cat-1),0,1/#index.categories,1/(tiers+1))
|
||||
c.align = gui.ALIGN_CENTER
|
||||
c.textColor = color.new("#ffffff")
|
||||
c.color = color.new("#060ce9")
|
||||
c.textColor = color.header_font
|
||||
c.color = color.header_tile
|
||||
end
|
||||
|
||||
c.UUID = multi.generate_uuid7() -- Each otpion gets a unique UUID
|
||||
|
||||
img = c:newImageButton("assets/images/placeholder.jpg")
|
||||
img.visibility = 0
|
||||
if not autoreveal then
|
||||
img = c:newImageButton("assets/images/placeholder.jpg")
|
||||
img.visibility = 0
|
||||
|
||||
img:OnReleased(function(self)
|
||||
self.visible = false
|
||||
end)
|
||||
img:OnReleased(function(self)
|
||||
self.visible = false
|
||||
end)
|
||||
|
||||
img:fullFrame()
|
||||
end
|
||||
|
||||
img:fullFrame()
|
||||
table.insert(manage,c)
|
||||
|
||||
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))
|
||||
t.textColor = color.new("#9b9024")
|
||||
t.textColor = color.tile_font
|
||||
t.align = gui.ALIGN_CENTER
|
||||
t.color = color.new("#060ce9")
|
||||
t.color = color.tile_bg
|
||||
t.category = v.name
|
||||
t.index = tier
|
||||
t.price = start + inc*(tier-1)
|
||||
@@ -226,8 +330,22 @@ function Menu(frame, path)
|
||||
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
|
||||
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
|
||||
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.cosmetics then
|
||||
manageCosmetics(frame, q.cosmetics)
|
||||
end
|
||||
self.textVisibility = 0
|
||||
local template = LoadTemplate(q.template, path)
|
||||
question.visible = true
|
||||
@@ -255,7 +373,8 @@ function Menu(frame, path)
|
||||
end)
|
||||
end
|
||||
local finished = false
|
||||
template.index(question, q, function(ans)
|
||||
template.index(question, q, function(ans, m)
|
||||
local m = m or 1
|
||||
if finished then return end
|
||||
player = GetActivePlayer()
|
||||
if tm then
|
||||
@@ -263,17 +382,17 @@ function Menu(frame, path)
|
||||
end
|
||||
stop = true
|
||||
if ans then
|
||||
player:Add(self.price*mul)
|
||||
player:Add((self.price*mul)*m)
|
||||
finished = true
|
||||
question.visible = false
|
||||
question:cleanup()
|
||||
reset:Fire()
|
||||
elseif ans == false then
|
||||
player:Add(-self.price*mul)
|
||||
player = GetNextPlayer()
|
||||
else
|
||||
finished = true
|
||||
question.visible = false
|
||||
question:cleanup()
|
||||
reset:Fire()
|
||||
end -- nil is a valid option where you weren't right or wrong, you just skipped
|
||||
self.text = ""
|
||||
end)
|
||||
@@ -296,8 +415,7 @@ function Menu(frame, path)
|
||||
return background
|
||||
end
|
||||
|
||||
scoreUpdater = gui:getProcessor():newProcessor("score-updater")
|
||||
scoreUpdater.Start()
|
||||
|
||||
|
||||
function GetActivePlayer()
|
||||
if not activePlayer then return end
|
||||
@@ -407,7 +525,7 @@ function ScoreBoard(frame, x, y, w, h, sx, sy, sw, sh)
|
||||
function scoreboard:AddPlayer(name, score, icon)
|
||||
local player = {
|
||||
Name = name,
|
||||
Score = score,
|
||||
Score = score or 0,
|
||||
Icon = icon,
|
||||
UUID = multi.generate_uuid7(),
|
||||
Add = function(self, amt)
|
||||
|
||||
Reference in New Issue
Block a user