Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 691c3adb37 | |||
| ae97703bb4 |
@@ -3,7 +3,7 @@ return {
|
|||||||
name = 'Jeopardy', -- name of the game for your executable
|
name = 'Jeopardy', -- name of the game for your executable
|
||||||
developer = 'Ryan Ward', -- dev name used in metadata of the file
|
developer = 'Ryan Ward', -- dev name used in metadata of the file
|
||||||
output = 'bin', -- output location for your game, defaults to $SAVE_DIRECTORY
|
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
|
version = '1.0.4', -- 'version' of your game, used to name the folder in output
|
||||||
love = '11.5', -- version of LÖVE to use, must match github releases
|
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
|
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
|
icon = 'assets/icon.png', -- 256x256px PNG icon for game, will be converted for you
|
||||||
|
|||||||
+1
-1
Submodule gui updated: c4cf5cbc9e...27995af07f
@@ -1,11 +1,10 @@
|
|||||||
local logger = require("utils/logger")
|
local logger = require("utils/logger")
|
||||||
local lovehandler = require("utils/love_file_handler")
|
local lovehandler = require("utils/love_file_handler")
|
||||||
|
local zip = require("utils/zip")
|
||||||
|
|
||||||
multi, thread = require("multi"):init({priority=true})
|
local multi, thread = require("multi"):init({priority=true})
|
||||||
multi.setClock(require("socket").gettime) -- When on linux os.clock doesn't reture actual seconds the program has elapsed for
|
multi.setClock(require("socket").gettime) -- When on linux os.clock doesn't reture actual seconds the program has elapsed for
|
||||||
GLOBAL, THREAD = require("multi.integration.loveManager"):init()
|
local GLOBAL, THREAD = require("multi.integration.loveManager"):init()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local fileHandler, logCtrl = lovehandler.new("logs/jeopardy.log", {
|
local fileHandler, logCtrl = lovehandler.new("logs/jeopardy.log", {
|
||||||
max_size = 512 * 1024, -- rotate at 512 KB
|
max_size = 512 * 1024, -- rotate at 512 KB
|
||||||
@@ -16,7 +15,7 @@ local fileHandler, logCtrl = lovehandler.new("logs/jeopardy.log", {
|
|||||||
lovehandler.auto_flush_on_quit(logCtrl)
|
lovehandler.auto_flush_on_quit(logCtrl)
|
||||||
|
|
||||||
log = logger.new("jeopardy", {
|
log = logger.new("jeopardy", {
|
||||||
level = logger.LEVELS.DEBUG,
|
level = logger.LEVELS.INFO,
|
||||||
handlers = {
|
handlers = {
|
||||||
logger.handlers.ConsoleHandler({ colours = true }),
|
logger.handlers.ConsoleHandler({ colours = true }),
|
||||||
fileHandler,
|
fileHandler,
|
||||||
@@ -36,6 +35,12 @@ color.indexColor("title_font","#b16d24")
|
|||||||
color.indexColor("question_bg","#363ac8")
|
color.indexColor("question_bg","#363ac8")
|
||||||
color.indexColor("tile_font","#ffffff")
|
color.indexColor("tile_font","#ffffff")
|
||||||
color.indexColor("header_font","#fef6eeda")
|
color.indexColor("header_font","#fef6eeda")
|
||||||
|
color.indexColor("correct", "#52b11b")
|
||||||
|
color.indexColor("skip", "#5d5d5d")
|
||||||
|
color.indexColor("wrong", "#bd2626")
|
||||||
|
color.indexColor("shaderColA","rgb01(0.10, 0.12, 0.38)")
|
||||||
|
color.indexColor("shaderColB","rgb01(0.20, 0.22, 0.58)")
|
||||||
|
color.indexColor("shaderColC","rgb01(0.55, 0.58, 0.78)")
|
||||||
|
|
||||||
require("gui.addons")
|
require("gui.addons")
|
||||||
|
|
||||||
@@ -53,7 +58,19 @@ multi.error = function(self, err)
|
|||||||
love.quit()
|
love.quit()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function readFileData(path)
|
||||||
|
return io.open(path,"r"):read("*a")
|
||||||
|
end
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
|
-- local z = zip.new()
|
||||||
|
-- z:add("main.lua",readFileData("main.lua"))
|
||||||
|
-- z:add("package.bat",readFileData("package.bat"))
|
||||||
|
-- local data = z:build()
|
||||||
|
-- local file = io.open("test.zip","wb")
|
||||||
|
-- file:write(data)
|
||||||
|
-- file:close()
|
||||||
|
|
||||||
loadLog:info("Starting Jeopardy Game")
|
loadLog:info("Starting Jeopardy Game")
|
||||||
loadLog:debug("Setting game identity to jeopardy")
|
loadLog:debug("Setting game identity to jeopardy")
|
||||||
for i,v in ipairs(color.listColors(showAllColors)) do
|
for i,v in ipairs(color.listColors(showAllColors)) do
|
||||||
@@ -89,3 +106,75 @@ function love.draw()
|
|||||||
gui.draw()
|
gui.draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- custom shaders
|
||||||
|
|
||||||
|
gui.NewShader("background", [[
|
||||||
|
extern float time;
|
||||||
|
extern vec2 size;
|
||||||
|
extern vec3 colA;
|
||||||
|
extern vec3 colB;
|
||||||
|
extern vec3 colC;
|
||||||
|
|
||||||
|
// Hash function (pseudo-random from 2D input)
|
||||||
|
float hash(vec2 p) {
|
||||||
|
p = fract(p * vec2(127.1, 311.7));
|
||||||
|
p += dot(p, p + 19.19);
|
||||||
|
return fract(p.x * p.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Smooth value noise
|
||||||
|
float noise(vec2 p) {
|
||||||
|
vec2 i = floor(p);
|
||||||
|
vec2 f = fract(p);
|
||||||
|
// Quintic smoothstep
|
||||||
|
vec2 u = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);
|
||||||
|
|
||||||
|
float a = hash(i);
|
||||||
|
float b = hash(i + vec2(1.0, 0.0));
|
||||||
|
float c = hash(i + vec2(0.0, 1.0));
|
||||||
|
float d = hash(i + vec2(1.0, 1.0));
|
||||||
|
|
||||||
|
return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fractional Brownian Motion – layers of noise at different scales
|
||||||
|
float fbm(vec2 p) {
|
||||||
|
float value = 0.0;
|
||||||
|
float amplitude = 0.5;
|
||||||
|
float frequency = 1.0;
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
value += amplitude * noise(p * frequency);
|
||||||
|
frequency *= 2.0;
|
||||||
|
amplitude *= 0.5;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 effect(vec4 color, Image tex, vec2 texCoord, vec2 screenCoord) {
|
||||||
|
// Normalized UV with aspect ratio correction
|
||||||
|
vec2 uv = screenCoord / size;
|
||||||
|
|
||||||
|
// Slow, asymmetric time offsets per axis for lava-lamp feel
|
||||||
|
float t1 = time * 0.008;
|
||||||
|
float t2 = time * 0.005;
|
||||||
|
|
||||||
|
// Domain-warped FBM: feed FBM output back into itself
|
||||||
|
// This creates the bulging, self-folding blob shapes.
|
||||||
|
vec2 q = vec2(
|
||||||
|
fbm(uv + vec2(0.0, 0.0) + t1),
|
||||||
|
fbm(uv + vec2(5.2, 1.3) + t2)
|
||||||
|
);
|
||||||
|
|
||||||
|
vec2 r = vec2(
|
||||||
|
fbm(uv + 4.0 * q + vec2(1.7, 9.2) + t1 * 0.7),
|
||||||
|
fbm(uv + 4.0 * q + vec2(8.3, 2.8) + t2 * 0.9)
|
||||||
|
);
|
||||||
|
|
||||||
|
float n = fbm(uv + 4.0 * r + t1 * 0.4);
|
||||||
|
|
||||||
|
vec3 col = mix(colA, colB, clamp(n * 2.0, 0.0, 1.0));
|
||||||
|
col = mix(col, colC, clamp(n * 2.0 - 0.6, 0.0, 1.0));
|
||||||
|
|
||||||
|
return vec4(col, 1.0);
|
||||||
|
}
|
||||||
|
]])
|
||||||
+212
-34
@@ -6,6 +6,8 @@ local fmt = require("utils/fmt")
|
|||||||
local timer = require("utils/utils")
|
local timer = require("utils/utils")
|
||||||
local multi, thread = require("multi"):init()
|
local multi, thread = require("multi"):init()
|
||||||
local menu = require("gui.core.menus")
|
local menu = require("gui.core.menus")
|
||||||
|
local transition = require("gui.core.transitions")
|
||||||
|
local logger = require("utils/logger")
|
||||||
|
|
||||||
local timesup = love.audio.newSource("assets/sounds/timesup.mp3", "static")
|
local timesup = love.audio.newSource("assets/sounds/timesup.mp3", "static")
|
||||||
local double = love.audio.newSource("assets/sounds/double.mp3", "static")
|
local double = love.audio.newSource("assets/sounds/double.mp3", "static")
|
||||||
@@ -18,12 +20,17 @@ local activePlayer
|
|||||||
local playerList = {}
|
local playerList = {}
|
||||||
local playerStaticList = {}
|
local playerStaticList = {}
|
||||||
local scoreboard = {}
|
local scoreboard = {}
|
||||||
|
local handler
|
||||||
|
local handler_conn = boardUpdater:newConnection()
|
||||||
|
local reference
|
||||||
|
local multiply
|
||||||
|
|
||||||
|
local reset = boardUpdater:newConnection()
|
||||||
|
|
||||||
|
local default_text = "Pick a Category"
|
||||||
|
|
||||||
local boardLog = log:child("board")
|
local boardLog = log:child("board")
|
||||||
|
|
||||||
-- Function to resize fonts for all managed elements
|
|
||||||
boardLog:debug("Creating resize fonts handler")
|
|
||||||
|
|
||||||
local completed_questions = 0
|
local completed_questions = 0
|
||||||
local min_questions = 0
|
local min_questions = 0
|
||||||
local dd_count = 0
|
local dd_count = 0
|
||||||
@@ -31,6 +38,28 @@ local dd_enabled = false
|
|||||||
local applied_dd = false
|
local applied_dd = false
|
||||||
local board, question
|
local board, question
|
||||||
|
|
||||||
|
local function cleanUp(frameRef)
|
||||||
|
boardLog:debug("Cleaning up state and returning to title screen")
|
||||||
|
scoreboard:removeAllPlayers()
|
||||||
|
activePlayer = nil
|
||||||
|
handler_conn:Remove()
|
||||||
|
playerList = {}
|
||||||
|
playerStaticList = {}
|
||||||
|
scoreboard = {}
|
||||||
|
handler = nil
|
||||||
|
reference = nil
|
||||||
|
multiply = nil
|
||||||
|
reset:Remove()
|
||||||
|
default_text = "Pick a Category"
|
||||||
|
completed_questions = 0
|
||||||
|
min_questions = 0
|
||||||
|
dd_enabled = false
|
||||||
|
applied_dd = false
|
||||||
|
board = nil
|
||||||
|
question = nil
|
||||||
|
frameRef:destroy()
|
||||||
|
end
|
||||||
|
|
||||||
local function pickUniqueIndices(t, count)
|
local function pickUniqueIndices(t, count)
|
||||||
assert(#t >= count, "Not enough elements to pick " .. count .. " unique items")
|
assert(#t >= count, "Not enough elements to pick " .. count .. " unique items")
|
||||||
|
|
||||||
@@ -78,6 +107,15 @@ function applyDD()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function setMultiplier(m)
|
||||||
|
multiply = m
|
||||||
|
end
|
||||||
|
|
||||||
|
local function useDefaultHandler(callback)
|
||||||
|
handler.visible = true
|
||||||
|
reference = handler_conn(callback)
|
||||||
|
end
|
||||||
|
|
||||||
local templateLog = log:child("template")
|
local templateLog = log:child("template")
|
||||||
function LoadTemplate(name, path)
|
function LoadTemplate(name, path)
|
||||||
boardLog:debug("Loading Template: %s", name)
|
boardLog:debug("Loading Template: %s", name)
|
||||||
@@ -139,9 +177,11 @@ function LoadTemplate(name, path)
|
|||||||
theme = theme,
|
theme = theme,
|
||||||
gui = gui,
|
gui = gui,
|
||||||
timer = timer,
|
timer = timer,
|
||||||
|
useDefaultHandler = useDefaultHandler,
|
||||||
|
setMultiplier = setMultiplier,
|
||||||
-- love stuff
|
-- love stuff
|
||||||
newSource = love.audio.newSource,
|
newSource = love.audio.newSource,
|
||||||
log = templateLog
|
log = templateLog,
|
||||||
}
|
}
|
||||||
|
|
||||||
env._G = env
|
env._G = env
|
||||||
@@ -152,16 +192,23 @@ end
|
|||||||
|
|
||||||
local function manageCosmetics(frame, cosmetics)
|
local function manageCosmetics(frame, cosmetics)
|
||||||
boardLog:debug("Managing cosmetics")
|
boardLog:debug("Managing 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
|
if type(cosmetics.colors) == "table" then
|
||||||
for i,v in pairs(cosmetics.colors) do
|
for i,v in pairs(cosmetics.colors) do
|
||||||
color.reindexColor((i:gsub("-","_")),v)
|
color.reindexColor((i:gsub("-","_")),v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if cosmetics["bg-img"] then
|
||||||
|
frame:setImage(cosmetics["bg-img"])
|
||||||
|
frame:setShader()
|
||||||
|
else
|
||||||
|
-- frame:setImage("assets/images/background.png")
|
||||||
|
frame:setImage(nil)
|
||||||
|
frame:setShader(gui.SHADERS.background,{
|
||||||
|
colA = color.shaderColA,
|
||||||
|
colB = color.shaderColB,
|
||||||
|
colC = color.shaderColC
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function gui:cleanup()
|
function gui:cleanup()
|
||||||
@@ -172,14 +219,11 @@ function gui:cleanup()
|
|||||||
completed_questions = completed_questions + 1
|
completed_questions = completed_questions + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
local reset = boardUpdater:newConnection()
|
function Menu(frame, path, deb)
|
||||||
|
local frameRef = frame:newImageLabel():fullFrame()
|
||||||
local default_text = "Pick a Category"
|
frameRef.visibility = 0
|
||||||
|
|
||||||
function Menu(frame, path)
|
|
||||||
boardLog:info("Building board")
|
boardLog:info("Building board")
|
||||||
if path:match(".zip") then
|
if path:match(".zip") then
|
||||||
-- local basename = path:match("([^/\\]+)$")
|
|
||||||
local success = love.filesystem.mount(path, "quiz", true)
|
local success = love.filesystem.mount(path, "quiz", true)
|
||||||
if not success then
|
if not success then
|
||||||
gui:newMessageBox({
|
gui:newMessageBox({
|
||||||
@@ -199,23 +243,134 @@ function Menu(frame, path)
|
|||||||
path = "quiz"
|
path = "quiz"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local scoreboard = ScoreBoard(frameRef, 0, 0, 0, 0, .06, .1, .170, .8)
|
||||||
|
|
||||||
|
local qframe = frameRef:newFrame(0, 0, 0, 0, .24, .1, .70, .8)
|
||||||
|
|
||||||
|
local dframe = frameRef:newTextLabel("",0, 0, 0, 0, .24, .1, .7, .8)
|
||||||
|
dframe:scaleFont(.075)
|
||||||
|
dframe:centerFont()
|
||||||
|
dframe.align = gui.ALIGN_CENTER
|
||||||
|
dframe.color = color.bg
|
||||||
|
dframe.visible = false
|
||||||
|
dframe:OnReleased(function(self)
|
||||||
|
if self.click then
|
||||||
|
boardUpdater:newThread(function()
|
||||||
|
thread.skip(1)
|
||||||
|
dframe.visible = false
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
if deb then
|
||||||
|
boardLog.level = logger.LEVELS.DEBUG
|
||||||
|
templateLog.level = logger.LEVELS.DEBUG
|
||||||
|
boardLog:debug("Debug mode is activated when quiz directory is in the save directory")
|
||||||
|
local refresh = frameRef:newTextButton("Refresh", 0, -30, 140, 30, 0, 1)
|
||||||
|
refresh:centerFont()
|
||||||
|
refresh:scaleFont(.9)
|
||||||
|
refresh.align = gui.ALIGN_CENTER
|
||||||
|
refresh.color = color.green
|
||||||
|
refresh:OnReleased(function()
|
||||||
|
cleanUp(frameRef)
|
||||||
|
menu.getMenu("title"):visible(true)
|
||||||
|
menu.getMenu("board"):visible(frame, path, deb)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
-- Start the processors now
|
-- Start the processors now
|
||||||
boardLog:debug("Starting processors")
|
boardLog:debug("Starting processors")
|
||||||
boardUpdater.Start()
|
boardUpdater.Start()
|
||||||
|
boardLog:debug("Starting board-updater Started")
|
||||||
qUpdater.Start()
|
qUpdater.Start()
|
||||||
|
boardLog:debug("Starting question-updater Started")
|
||||||
scoreUpdater.Start()
|
scoreUpdater.Start()
|
||||||
|
boardLog:debug("Starting score-updater Started")
|
||||||
|
|
||||||
local scoreboard = ScoreBoard(frame, 0, 0, 0, 0, .06, .1, .170, .8)
|
local glide = transition.glide()
|
||||||
|
|
||||||
local qframe = frame:newFrame(0, 0, 0, 0, .24, .1, .70, .8)
|
local function displayAnswer(q)
|
||||||
|
dframe.text = q.answer
|
||||||
|
dframe.textColor = color.white
|
||||||
|
|
||||||
|
dframe.visible = true
|
||||||
|
dframe.click = q["display-mode"] == "click"
|
||||||
|
local sleep = 5
|
||||||
|
local fade = 1
|
||||||
|
if type(q["display-mode"]) == "number" then
|
||||||
|
sleep = q["display-mode"]
|
||||||
|
end
|
||||||
|
if type(q["display-fade"]) == "number" and q["display-fade"] > 0 then
|
||||||
|
fade = q["display-fade"]
|
||||||
|
end
|
||||||
|
if not dframe.click then
|
||||||
|
boardUpdater:newThread(function()
|
||||||
|
thread.sleep(sleep)
|
||||||
|
local handle = glide(1,0,fade)
|
||||||
|
handle:OnStep(function(p)
|
||||||
|
dframe.textVisibility = p
|
||||||
|
dframe.visibility = p
|
||||||
|
end)
|
||||||
|
handle:OnStop(function()
|
||||||
|
dframe.visible = false
|
||||||
|
dframe.textVisibility = 1
|
||||||
|
dframe.visibility = 1
|
||||||
|
handle.OnStep:Remove()
|
||||||
|
handle.OnStop:Remove()
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local label = frameRef:newTextLabel(default_text, 0, 10, 0, -20, .29, 0, .6, .1)
|
||||||
|
handler = frameRef:newFrame(0, 10, 0, -20, .29, .9, .6, .1)
|
||||||
|
handler.visible = false
|
||||||
|
local correct = handler:newTextButton("Correct", 5,0,-10,0,0,.1,1/3,.8)
|
||||||
|
correct.color = color.correct
|
||||||
|
local skip = handler:newTextButton("Skip", 8,0,-15,0,1/3,.1,1/3,.8)
|
||||||
|
skip.color = color.skip
|
||||||
|
local wrong = handler:newTextButton("Wrong", 5,0,-10,0,2/3,.1,1/3,.8)
|
||||||
|
wrong.color = color.wrong
|
||||||
|
|
||||||
|
gui.apply({
|
||||||
|
setRoundness = {15,15,60},
|
||||||
|
centerFont = {},
|
||||||
|
scaleFont = {1/2},
|
||||||
|
align = gui.ALIGN_CENTER,
|
||||||
|
OnEnter = function(self)
|
||||||
|
self:setShader(gui.SHADERS.glow)
|
||||||
|
end,
|
||||||
|
OnExit = function(self)
|
||||||
|
self:setShader()
|
||||||
|
end,
|
||||||
|
shaderTime = {true},
|
||||||
|
OnReleased=function(self)
|
||||||
|
if self.text == "Skip" then
|
||||||
|
handler_conn:Fire()
|
||||||
|
reference:Unconnect()
|
||||||
|
handler.visible = false
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local val = self.text == "Correct"
|
||||||
|
handler_conn:Fire(val, multiply)
|
||||||
|
if val then
|
||||||
|
if reference then
|
||||||
|
reference:Unconnect()
|
||||||
|
end
|
||||||
|
handler.visible = false
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
},correct,skip,wrong)
|
||||||
|
|
||||||
local label = frame:newTextLabel(default_text, 0, 10, 0, -20, .29, 0, .6, .1)
|
|
||||||
label.visibility = .85
|
label.visibility = .85
|
||||||
label.drawBorder = false
|
label.drawBorder = false
|
||||||
label.align = gui.ALIGN_CENTER
|
label.align = gui.ALIGN_CENTER
|
||||||
label.color = color.bg
|
label.color = color.bg
|
||||||
label.textColor = color.status_font
|
label.textColor = color.status_font
|
||||||
label:setRoundness(20,20,60)
|
label:setRoundness(20,20,60)
|
||||||
|
handler:setRoundness(20,20,60)
|
||||||
|
handler.visibility = .9
|
||||||
|
handler.color = color.bg
|
||||||
label:scaleFont(2/3)
|
label:scaleFont(2/3)
|
||||||
label:centerFont()
|
label:centerFont()
|
||||||
|
|
||||||
@@ -224,7 +379,16 @@ function Menu(frame, path)
|
|||||||
index = data.index
|
index = data.index
|
||||||
|
|
||||||
local cosmetics = index.cosmetics or {}
|
local cosmetics = index.cosmetics or {}
|
||||||
manageCosmetics(frame, cosmetics)
|
cosmetics.colors = cosmetics.colors or {}
|
||||||
|
|
||||||
|
for i,v in pairs(color.listColors()) do
|
||||||
|
if not cosmetics.colors[v] then
|
||||||
|
cosmetics.colors[v] = color.rgbToHex(color[v])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
frameRef:shaderTime()
|
||||||
|
manageCosmetics(frameRef, cosmetics)
|
||||||
|
|
||||||
board:fullFrame()
|
board:fullFrame()
|
||||||
question:fullFrame()
|
question:fullFrame()
|
||||||
@@ -261,10 +425,13 @@ function Menu(frame, path)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
reset(function()
|
reset(function(q)
|
||||||
question:cleanup()
|
question:cleanup()
|
||||||
manageCosmetics(frame, cosmetics, true)
|
manageCosmetics(frameRef, cosmetics)
|
||||||
label.text = default_text
|
label.text = default_text
|
||||||
|
if q["display-answer"] then
|
||||||
|
displayAnswer(q)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
for cat,v in pairs(index.categories) do
|
for cat,v in pairs(index.categories) do
|
||||||
@@ -302,12 +469,19 @@ function Menu(frame, path)
|
|||||||
t.category = v.name
|
t.category = v.name
|
||||||
t.index = tier
|
t.index = tier
|
||||||
t.price = start + inc*(tier-1)
|
t.price = start + inc*(tier-1)
|
||||||
|
t:OnEnter(function(self)
|
||||||
|
self:setShader(gui.SHADERS.glow)
|
||||||
|
end)
|
||||||
|
t:OnExit(function(self)
|
||||||
|
self:setShader()
|
||||||
|
end)
|
||||||
|
t:shaderTime(true)
|
||||||
t:OnReleased(boardUpdater:newFunction(function(self)
|
t:OnReleased(boardUpdater:newFunction(function(self)
|
||||||
if self.text == "" or GetActivePlayer() == nil then return end
|
if self.text == "" or GetActivePlayer() == nil then return end
|
||||||
if dd_enabled then
|
if dd_enabled then
|
||||||
applyDD() -- check and run DD if conditions meet
|
applyDD() -- check and run DD if conditions meet
|
||||||
end
|
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
|
if index.categories[cat].questions == nil then boardLog:debug("Question not defined: File: %s Category: %s - %s",path,index.categories[cat].name,start + inc*(tier-1)) return end
|
||||||
local globals = index.categories[cat].global
|
local globals = index.categories[cat].global
|
||||||
if not globals then
|
if not globals then
|
||||||
globals = {}
|
globals = {}
|
||||||
@@ -321,9 +495,9 @@ function Menu(frame, path)
|
|||||||
mt.__metatable = nil
|
mt.__metatable = nil
|
||||||
end
|
end
|
||||||
setmetatable(q, {__index = globals})
|
setmetatable(q, {__index = globals})
|
||||||
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 == nil then boardLog:debug("Question contains no data: File: %s Category: %s Tier: %s",path,index.categories[cat].name,start + inc*(tier-1)) return end
|
||||||
if q.cosmetics then
|
if q.cosmetics then
|
||||||
manageCosmetics(frame, q.cosmetics)
|
manageCosmetics(frameRef, q.cosmetics)
|
||||||
end
|
end
|
||||||
self.textVisibility = 0
|
self.textVisibility = 0
|
||||||
local template = LoadTemplate(q.template, path)
|
local template = LoadTemplate(q.template, path)
|
||||||
@@ -364,14 +538,14 @@ function Menu(frame, path)
|
|||||||
player:Add((self.price*mul)*m)
|
player:Add((self.price*mul)*m)
|
||||||
finished = true
|
finished = true
|
||||||
question.visible = false
|
question.visible = false
|
||||||
reset:Fire()
|
reset:Fire(q)
|
||||||
elseif ans == false then
|
elseif ans == false then
|
||||||
player:Add(-self.price*mul)
|
player:Add(-self.price*mul)
|
||||||
player = GetNextPlayer()
|
player = GetNextPlayer()
|
||||||
else
|
else
|
||||||
finished = true
|
finished = true
|
||||||
question.visible = false
|
question.visible = false
|
||||||
reset:Fire()
|
reset:Fire(q)
|
||||||
end -- nil is a valid option where you weren't right or wrong, you just skipped
|
end -- nil is a valid option where you weren't right or wrong, you just skipped
|
||||||
self.text = ""
|
self.text = ""
|
||||||
end)
|
end)
|
||||||
@@ -488,13 +662,10 @@ function ScoreBoard(frame, x, y, w, h, sx, sy, sw, sh)
|
|||||||
textColor = C_TEXT_MUTED,
|
textColor = C_TEXT_MUTED,
|
||||||
}, headernum, headerplayer, headerscore)
|
}, headernum, headerplayer, headerscore)
|
||||||
|
|
||||||
local updateList = {headernum, headerplayer, headerscore}
|
local updateList = {headernum, headerplayer, headerscore, header}
|
||||||
|
|
||||||
header:centerFont()
|
|
||||||
header:scaleFont(2/3)
|
|
||||||
|
|
||||||
for _,object in pairs(updateList) do
|
for _,object in pairs(updateList) do
|
||||||
object:fitFont(nil, nil, {scale = 5/6})
|
object:scaleFont(2/3)
|
||||||
object:centerFont()
|
object:centerFont()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -533,10 +704,12 @@ function ScoreBoard(frame, x, y, w, h, sx, sy, sw, sh)
|
|||||||
local add_player = leaderboard:newFrame(5,-5,-10,0,0,1-PLAYER_HEIGHT,1,PLAYER_HEIGHT)
|
local add_player = leaderboard:newFrame(5,-5,-10,0,0,1-PLAYER_HEIGHT,1,PLAYER_HEIGHT)
|
||||||
local edit_player = leaderboard:newFrame(5,-10,-10,0,0,1-2*PLAYER_HEIGHT,1,PLAYER_HEIGHT)
|
local edit_player = leaderboard:newFrame(5,-10,-10,0,0,1-2*PLAYER_HEIGHT,1,PLAYER_HEIGHT)
|
||||||
local remove_player = leaderboard:newTextButton("Remove Selected",5,-15,-10,0,0,1-3*PLAYER_HEIGHT,1,PLAYER_HEIGHT)
|
local remove_player = leaderboard:newTextButton("Remove Selected",5,-15,-10,0,0,1-3*PLAYER_HEIGHT,1,PLAYER_HEIGHT)
|
||||||
remove_player:setFont(20)
|
|
||||||
remove_player.align = gui.ALIGN_CENTER
|
remove_player.align = gui.ALIGN_CENTER
|
||||||
local embededWatch = {remove_player}
|
local embededWatch = {remove_player}
|
||||||
remove_player:centerFont()
|
gui.apply({
|
||||||
|
centerFont = {},
|
||||||
|
scaleFont = {.5}
|
||||||
|
},add_player,edit_player,remove_player)
|
||||||
|
|
||||||
local function embedTextEdit(reference, default, but_text, callback)
|
local function embedTextEdit(reference, default, but_text, callback)
|
||||||
reference.color = C_BORDER_NRM
|
reference.color = C_BORDER_NRM
|
||||||
@@ -555,7 +728,7 @@ function ScoreBoard(frame, x, y, w, h, sx, sy, sw, sh)
|
|||||||
callback(textbox)
|
callback(textbox)
|
||||||
end)
|
end)
|
||||||
gui.apply({
|
gui.apply({
|
||||||
setFont = {20},
|
scaleFont = {.5},
|
||||||
align = gui.ALIGN_CENTER,
|
align = gui.ALIGN_CENTER,
|
||||||
centerFont = {},
|
centerFont = {},
|
||||||
},textbox,button,reference)
|
},textbox,button,reference)
|
||||||
@@ -593,6 +766,11 @@ function ScoreBoard(frame, x, y, w, h, sx, sy, sw, sh)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
function scoreboard:removeAllPlayers()
|
||||||
|
playerList = {}
|
||||||
|
playerStaticList = {}
|
||||||
|
end
|
||||||
|
|
||||||
function scoreboard:RenderPlayer(list)
|
function scoreboard:RenderPlayer(list)
|
||||||
for index, player in ipairs(list) do
|
for index, player in ipairs(list) do
|
||||||
if player.Ref then
|
if player.Ref then
|
||||||
|
|||||||
+9
-2
@@ -4,6 +4,13 @@ local menu = require("gui.core.menus")
|
|||||||
-- local proc = gui:getProcessor():newProcessor("settings")
|
-- local proc = gui:getProcessor():newProcessor("settings")
|
||||||
|
|
||||||
function Menu(frame)
|
function Menu(frame)
|
||||||
local background = frame:newImageLabel("assets/images/background.jpg")
|
local background = frame:newFrame():fullFrame()
|
||||||
background:fullFrame()
|
background:setShader(gui.SHADERS.background,{
|
||||||
|
colA = color.shaderColA,
|
||||||
|
colB = color.shaderColB,
|
||||||
|
colC = color.shaderColC
|
||||||
|
})
|
||||||
|
background:shaderTime()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return menu.registerMenu("settings", Menu)
|
||||||
+9
-3
@@ -5,7 +5,8 @@ local proc = gui:getProcessor():newProcessor("main-title")
|
|||||||
|
|
||||||
local APP_VERSION = love.filesystem.read("version.txt")
|
local APP_VERSION = love.filesystem.read("version.txt")
|
||||||
|
|
||||||
local board = require("menus.board")
|
local boardMenu = require("menus.board")
|
||||||
|
local settingsMenu = require("menus.settings")
|
||||||
|
|
||||||
local titleLog = log:child("title")
|
local titleLog = log:child("title")
|
||||||
|
|
||||||
@@ -59,16 +60,21 @@ function Menu(frame)
|
|||||||
play:OnReleased(function()
|
play:OnReleased(function()
|
||||||
titleLog:debug("Play button pressed")
|
titleLog:debug("Play button pressed")
|
||||||
if love.filesystem.getInfo("quiz") then
|
if love.filesystem.getInfo("quiz") then
|
||||||
menu.getMenu("board"):visible(true, "quiz")
|
boardMenu:visible(true, "quiz", true)
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
gui:newFilePicker("File picker test",nil, {".zip"}, function(file)
|
gui:newFilePicker("File picker test",nil, {".zip"}, function(file)
|
||||||
titleLog:info("File picked: %s", file)
|
titleLog:info("File picked: %s", file)
|
||||||
menu.getMenu("board"):visible(true, file:gsub("\\","/"):gsub(love.filesystem.getSaveDirectory(),""):sub(2,-1))
|
boardMenu:visible(true, file:gsub("\\","/"):gsub(love.filesystem.getSaveDirectory(),""):sub(2,-1))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
settings:OnReleased(function()
|
||||||
|
titleLog:debug("Settings button pressed")
|
||||||
|
settingsMenu:visible(true)
|
||||||
|
end)
|
||||||
|
|
||||||
quit:OnReleased(function(self, x, y)
|
quit:OnReleased(function(self, x, y)
|
||||||
print("Quit Pressed",x,y,self:getAbsolutes())
|
print("Quit Pressed",x,y,self:getAbsolutes())
|
||||||
titleLog:debug("Quit button pressed")
|
titleLog:debug("Quit button pressed")
|
||||||
|
|||||||
+4
-21
@@ -10,8 +10,9 @@ local function index(window, q, callback)
|
|||||||
label.align = ALIGN_CENTER
|
label.align = ALIGN_CENTER
|
||||||
label.textColor = color.white
|
label.textColor = color.white
|
||||||
label.color = color.new("#363ac8")
|
label.color = color.new("#363ac8")
|
||||||
label.borderColor = color.new("#363ac8")
|
label.drawBorder = false
|
||||||
label:scaleFont(.075)
|
label:scaleFont(.4)
|
||||||
|
label:centerFont()
|
||||||
|
|
||||||
if not q.imageA or q.imageA == "" then
|
if not q.imageA or q.imageA == "" then
|
||||||
error("Missing 'imageA' field for question!")
|
error("Missing 'imageA' field for question!")
|
||||||
@@ -38,29 +39,11 @@ local function index(window, q, callback)
|
|||||||
imageHolder2:setAspectSize(imageHolder2.imageWidth, imageHolder2.imageHeight)
|
imageHolder2:setAspectSize(imageHolder2.imageWidth, imageHolder2.imageHeight)
|
||||||
imageHolder2:setDualDim(0, 0, 0, 0, .6, 0, .4, 1)
|
imageHolder2:setDualDim(0, 0, 0, 0, .6, 0, .4, 1)
|
||||||
|
|
||||||
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({
|
window.apply({
|
||||||
centerY = {true},
|
centerY = {true},
|
||||||
}, imageHolder, plusLabel, imageHolder2)
|
}, imageHolder, plusLabel, imageHolder2)
|
||||||
|
|
||||||
window.apply({
|
useDefaultHandler(callback)
|
||||||
scaleFont={.7},
|
|
||||||
centerFont={},
|
|
||||||
align=window.ALIGN_CENTER,
|
|
||||||
OnReleased=function(self)
|
|
||||||
if self.text == "Skip" then
|
|
||||||
callback()
|
|
||||||
return
|
|
||||||
end
|
|
||||||
callback(self.text == "Correct")
|
|
||||||
end,
|
|
||||||
}, correct, wrong, skip)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function update(dt)
|
local function update(dt)
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ local function index(window, q, callback)
|
|||||||
label:setFont(50)
|
label:setFont(50)
|
||||||
label:centerFont()
|
label:centerFont()
|
||||||
label:scaleFont(2/3)
|
label:scaleFont(2/3)
|
||||||
|
label.drawBorder = false
|
||||||
|
|
||||||
local choices = window:newFrame(noOf(0,.3,1,.7))
|
local choices = window:newFrame(noOf(0,.3,1,.7))
|
||||||
choices.color = color.new("#363ac8")
|
choices.color = color.new("#363ac8")
|
||||||
|
|||||||
+5
-20
@@ -10,14 +10,15 @@ local label
|
|||||||
local imageHolder
|
local imageHolder
|
||||||
|
|
||||||
local function index(window, q, callback)
|
local function index(window, q, callback)
|
||||||
frame = window:newFrame(0,0,0,-200,0,.2,1,.8)
|
frame = window:newFrame(0,0,0,0,0,.2,1,.8)
|
||||||
frame.visibility = 0
|
frame.visibility = 0
|
||||||
label = window:newTextLabel(" " ..q.title.. " ",0,0,0,0,0,0,1,.2)
|
label = window:newTextLabel(" " ..q.title.. " ",0,0,0,0,0,0,1,.2)
|
||||||
label.align = ALIGN_CENTER
|
label.align = ALIGN_CENTER
|
||||||
label.textColor = color.white
|
label.textColor = color.white
|
||||||
label.color = color.new("#363ac8")
|
label.color = color.new("#363ac8")
|
||||||
label:scaleFont(.5)
|
label:scaleFont(.4)
|
||||||
label:centerFont()
|
label:centerFont()
|
||||||
|
label.drawBorder = false
|
||||||
if not q.image or q.image == "" then
|
if not q.image or q.image == "" then
|
||||||
error("Missing 'image' field for question!")
|
error("Missing 'image' field for question!")
|
||||||
end
|
end
|
||||||
@@ -26,24 +27,8 @@ local function index(window, q, callback)
|
|||||||
imageHolder:centerX(true)
|
imageHolder:centerX(true)
|
||||||
imageHolder:centerY(true)
|
imageHolder:centerY(true)
|
||||||
imageHolder:setDualDim(0,0,imageHolder.imageWidth,imageHolder.imageHeight)
|
imageHolder:setDualDim(0,0,imageHolder.imageWidth,imageHolder.imageHeight)
|
||||||
local correct = window:newTextButton("Correct",0,-200,0,100,0,1,.5)
|
|
||||||
correct.color = color.new("#52b11b")
|
useDefaultHandler(callback)
|
||||||
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")
|
|
||||||
end,
|
|
||||||
},correct,wrong,skip)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function update(dt) -- time in seconds that has passed since
|
local function update(dt) -- time in seconds that has passed since
|
||||||
|
|||||||
+3
-18
@@ -16,24 +16,9 @@ local function index(window, q, callback)
|
|||||||
label.color = color.new("#363ac8")
|
label.color = color.new("#363ac8")
|
||||||
label:centerFont()
|
label:centerFont()
|
||||||
label:scaleFont(.075)
|
label:scaleFont(.075)
|
||||||
local correct = window:newTextButton("Correct",0,-200,0,100,0,1,.5)
|
label.drawBorder = false
|
||||||
correct.color = color.new("#52b11b")
|
|
||||||
local wrong = window:newTextButton("Wrong",0,-200,0,100,.5,1,.5)
|
useDefaultHandler(callback)
|
||||||
wrong.color = color.new("#bd2626")
|
|
||||||
local skip = window:newTextButton("Skip",0,-100,0,100,.25,1,.5)
|
|
||||||
skip.color = color.new("#5d5d5d")
|
|
||||||
gui.apply({
|
|
||||||
scaleFont={.7},
|
|
||||||
centerFont={},
|
|
||||||
align=gui.ALIGN_CENTER,
|
|
||||||
OnReleased=function(self)
|
|
||||||
if self.text == "Skip" then
|
|
||||||
callback()
|
|
||||||
return
|
|
||||||
end
|
|
||||||
callback(self.text == "Correct")
|
|
||||||
end,
|
|
||||||
},correct,wrong,skip)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function update(dt) -- time in seconds that has passed since
|
local function update(dt) -- time in seconds that has passed since
|
||||||
|
|||||||
+9
-22
@@ -15,13 +15,17 @@ local function index(window, q, callback)
|
|||||||
callback()
|
callback()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
frame = window:newFrame(0,0,0,-200,0,.2,1,.8)
|
frame = window:newFrame(0,0,0,0,0,.2,1,.8)
|
||||||
frame.visibility = 0
|
frame.visibility = 0
|
||||||
label = window:newTextLabel(" " ..q.title.. " ",0,0,0,0,0,0,1,.2)
|
label = window:newTextLabel(" " ..q.title.. " ",0,0,0,0,0,0,1,.2)
|
||||||
label.align = ALIGN_CENTER
|
label.align = ALIGN_CENTER
|
||||||
label.textColor = color.white
|
label.textColor = color.white
|
||||||
label.color = color.new("#363ac8")
|
label.color = color.new("#363ac8")
|
||||||
imageHolder = frame:newImageButton("assets/images/speaker.png",0,0,0,0,0,0,.3,.4)
|
label:scaleFont(.4)
|
||||||
|
label:centerFont()
|
||||||
|
label.drawBorder = false
|
||||||
|
imageHolder = frame:newImageButton("assets/images/speaker.png",0,0,0,0,0,0,.3,.3)
|
||||||
|
imageHolder.scale = "h"
|
||||||
imageHolder:setAspectSize(imageHolder.imageWidth,imageHolder.imageHeight)
|
imageHolder:setAspectSize(imageHolder.imageWidth,imageHolder.imageHeight)
|
||||||
imageHolder:centerX(true)
|
imageHolder:centerX(true)
|
||||||
imageHolder:centerY(true)
|
imageHolder:centerY(true)
|
||||||
@@ -38,29 +42,12 @@ local function index(window, q, callback)
|
|||||||
sound:seek(0)
|
sound:seek(0)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
local correct = window:newTextButton("Correct",0,-200,0,100,0,1,.5)
|
|
||||||
correct.color = color.new("#52b11b")
|
useDefaultHandler(callback)
|
||||||
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({
|
|
||||||
fitFont={},
|
|
||||||
align=window.ALIGN_CENTER,
|
|
||||||
OnReleased=function(self)
|
|
||||||
sound:stop()
|
|
||||||
if self.text == "Skip" then
|
|
||||||
callback()
|
|
||||||
return
|
|
||||||
end
|
|
||||||
callback(self.text == "Correct")
|
|
||||||
end,
|
|
||||||
},correct,wrong,skip)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function update(dt) -- time in seconds that has passed since
|
local function update(dt) -- time in seconds that has passed since
|
||||||
label:fitFont()
|
|
||||||
label:centerFont()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
+4
-20
@@ -22,7 +22,8 @@ local function index(window, q, callback)
|
|||||||
label.textColor = color.white
|
label.textColor = color.white
|
||||||
label.color = color.new("#363ac8")
|
label.color = color.new("#363ac8")
|
||||||
label:centerFont()
|
label:centerFont()
|
||||||
label:scaleFont(.5)
|
label:scaleFont(.4)
|
||||||
|
label.drawBorder = false
|
||||||
local holder = frame:newFrame(-300, -200, 600, 400, .5, .5)
|
local holder = frame:newFrame(-300, -200, 600, 400, .5, .5)
|
||||||
holder:centerX(true)
|
holder:centerX(true)
|
||||||
holder:centerY(true)
|
holder:centerY(true)
|
||||||
@@ -33,25 +34,8 @@ local function index(window, q, callback)
|
|||||||
video:play()
|
video:play()
|
||||||
end)
|
end)
|
||||||
video.XButton.visible = false
|
video.XButton.visible = false
|
||||||
local correct = window:newTextButton("Correct",0,-200,0,100,0,1,.5)
|
|
||||||
correct.color = color.new("#52b11b")
|
useDefaultHandler(callback)
|
||||||
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)
|
|
||||||
video:stop()
|
|
||||||
if self.text == "Skip" then
|
|
||||||
callback()
|
|
||||||
return
|
|
||||||
end
|
|
||||||
callback(self.text == "Correct")
|
|
||||||
end,
|
|
||||||
},correct,wrong,skip)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function update(dt) -- time in seconds that has passed since
|
local function update(dt) -- time in seconds that has passed since
|
||||||
|
|||||||
+11
-22
@@ -10,14 +10,16 @@ local label
|
|||||||
local imageHolder
|
local imageHolder
|
||||||
|
|
||||||
local function index(window, q, callback)
|
local function index(window, q, callback)
|
||||||
frame = window:newFrame(0,0,0,-200,0,.2,1,.8)
|
frame = window:newFrame(0,0,0,0,0,.2,1,.8)
|
||||||
frame.visibility = 0
|
frame.visibility = 0
|
||||||
label = window:newTextLabel(" " ..q.title.. " ",0,0,0,0,0,0,1,.2)
|
label = window:newTextLabel(" " ..q.title.. " ",0,0,0,0,0,0,1,.2)
|
||||||
label.align = ALIGN_CENTER
|
label.align = ALIGN_CENTER
|
||||||
label.textColor = color.white
|
label.textColor = color.white
|
||||||
label.color = color.new("#363ac8")
|
label.color = color.new("#363ac8")
|
||||||
label:scaleFont(.5)
|
label:scaleFont(.4)
|
||||||
label:centerFont()
|
label:centerFont()
|
||||||
|
label.drawBorder = false
|
||||||
|
|
||||||
local errors = {}
|
local errors = {}
|
||||||
|
|
||||||
if type(q.zoom) ~= "string" and q.zoom ~= "" then
|
if type(q.zoom) ~= "string" and q.zoom ~= "" then
|
||||||
@@ -33,7 +35,7 @@ local function index(window, q, callback)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local zooms = {q.zoom, q.minzoom, q.fullimage}
|
local zooms = {q.zoom, q.minzoom, q.fullimage}
|
||||||
print(q.fullimage)
|
|
||||||
local index = 1
|
local index = 1
|
||||||
local mul = 1
|
local mul = 1
|
||||||
|
|
||||||
@@ -55,35 +57,22 @@ local function index(window, q, callback)
|
|||||||
|
|
||||||
imageHolder:OnReleased(function()
|
imageHolder:OnReleased(function()
|
||||||
index = index + 1
|
index = index + 1
|
||||||
print(index)
|
|
||||||
if index == 2 then
|
if index == 2 then
|
||||||
|
if q["zoom-deduct"] then
|
||||||
mul = .5
|
mul = .5
|
||||||
|
end
|
||||||
elseif index == 3 then
|
elseif index == 3 then
|
||||||
|
if q["zoom-deduct"] then
|
||||||
mul = .25
|
mul = .25
|
||||||
|
end
|
||||||
else
|
else
|
||||||
index = 3
|
index = 3
|
||||||
end
|
end
|
||||||
imageHolder:setImage(zooms[index])
|
imageHolder:setImage(zooms[index])
|
||||||
|
setMultiplier(mul)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local correct = window:newTextButton("Correct",0,-200,0,100,0,1,.5)
|
useDefaultHandler(callback)
|
||||||
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
|
end
|
||||||
|
|
||||||
local function update(dt) -- time in seconds that has passed since
|
local function update(dt) -- time in seconds that has passed since
|
||||||
|
|||||||
+217
@@ -0,0 +1,217 @@
|
|||||||
|
--[[
|
||||||
|
zip.lua — A zip writer module for LÖVE 2D
|
||||||
|
==========================================
|
||||||
|
Uses love.math.compress (zlib/DEFLATE) and a pure-Lua CRC-32 table.
|
||||||
|
No external dependencies required.
|
||||||
|
|
||||||
|
Requires: LÖVE 11.0+
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
local Zip = require("zip")
|
||||||
|
|
||||||
|
local z = Zip.new()
|
||||||
|
z:add("level1.lua", love.filesystem.read("level1.lua"))
|
||||||
|
z:add("tiles/grass.png", love.filesystem.read("tiles/grass.png"))
|
||||||
|
local data = z:build()
|
||||||
|
love.filesystem.write("levels.zip", data)
|
||||||
|
|
||||||
|
API:
|
||||||
|
Zip.new() → creates a new Zip writer
|
||||||
|
zip:add(path, data) → adds a file entry (path uses forward slashes)
|
||||||
|
zip:build() → returns the zip file as a string
|
||||||
|
]]
|
||||||
|
|
||||||
|
local Zip = {}
|
||||||
|
Zip.__index = Zip
|
||||||
|
|
||||||
|
-- ── helpers ──────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
--- Pack bytes into a little-endian binary string.
|
||||||
|
local function pack_u16(n)
|
||||||
|
return string.char(n % 256, math.floor(n / 256) % 256)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function pack_u32(n)
|
||||||
|
return string.char(
|
||||||
|
n % 256,
|
||||||
|
math.floor(n / 256) % 256,
|
||||||
|
math.floor(n / 65536) % 256,
|
||||||
|
math.floor(n / 16777216) % 256
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- LuaJIT (used by LOVE) provides the 'bit' library for bitwise operations.
|
||||||
|
local bxor = bit.bxor
|
||||||
|
local band = bit.band
|
||||||
|
local rshift = bit.rshift
|
||||||
|
|
||||||
|
--- CRC-32 lookup table (standard IEEE 802.3 polynomial 0xEDB88320, reflected).
|
||||||
|
local _crc_table = (function()
|
||||||
|
local t = {}
|
||||||
|
for i = 0, 255 do
|
||||||
|
local c = i
|
||||||
|
for _ = 1, 8 do
|
||||||
|
if band(c, 1) == 1 then
|
||||||
|
c = bxor(rshift(c, 1), 0xEDB88320)
|
||||||
|
else
|
||||||
|
c = rshift(c, 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
t[i] = c
|
||||||
|
end
|
||||||
|
return t
|
||||||
|
end)()
|
||||||
|
|
||||||
|
--- Compute CRC-32 of a string (LuaJIT / LOVE compatible).
|
||||||
|
local function crc32(data)
|
||||||
|
local crc = 0xFFFFFFFF
|
||||||
|
for i = 1, #data do
|
||||||
|
local idx = band(bxor(crc, data:byte(i)), 0xFF)
|
||||||
|
crc = bxor(rshift(crc, 8), _crc_table[idx])
|
||||||
|
end
|
||||||
|
return band(bxor(crc, 0xFFFFFFFF), 0xFFFFFFFF)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Deflate-compress data using love.math.compress.
|
||||||
|
--- Returns compressed_string, or nil if compression made it larger.
|
||||||
|
local function deflate(data)
|
||||||
|
-- "zlib" wraps DEFLATE with a 2-byte header and 4-byte Adler-32 checksum.
|
||||||
|
-- For ZIP we need raw DEFLATE, which we get by stripping the zlib envelope.
|
||||||
|
-- love.math.compress( rawstring, format, level )
|
||||||
|
-- love.data.compress( container, format, rawstring, level )
|
||||||
|
local zlib_data = love.data.compress("string", "zlib", data, 6) -- level 6 = default
|
||||||
|
|
||||||
|
-- Strip the 2-byte zlib header and 4-byte Adler-32 trailer
|
||||||
|
local raw_deflate = zlib_data:sub(3, -5)
|
||||||
|
|
||||||
|
if #raw_deflate >= #data then
|
||||||
|
return nil -- not worth compressing
|
||||||
|
end
|
||||||
|
return raw_deflate
|
||||||
|
end
|
||||||
|
|
||||||
|
--- MS-DOS date/time encoding for the current time.
|
||||||
|
local function dos_datetime()
|
||||||
|
local t = os.date("*t")
|
||||||
|
local date = ((t.year - 1980) * 512) + (t.month * 32) + t.day
|
||||||
|
local time = (t.hour * 2048) + (t.min * 32) + math.floor(t.sec / 2)
|
||||||
|
return pack_u16(time), pack_u16(date)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- ── Zip writer ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
--- Create a new Zip writer instance.
|
||||||
|
function Zip.new()
|
||||||
|
return setmetatable({ _entries = {}, _offset = 0 }, Zip)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Add a file to the zip.
|
||||||
|
-- @param path string Archive path, e.g. "maps/level1.lua". Use '/' separators.
|
||||||
|
-- @param data string Raw file contents.
|
||||||
|
function Zip:add(path, data)
|
||||||
|
assert(type(path) == "string", "path must be a string")
|
||||||
|
assert(type(data) == "string", "data must be a string")
|
||||||
|
assert(not path:match("^/"), "path must not start with '/'")
|
||||||
|
|
||||||
|
local crc = crc32(data)
|
||||||
|
local original = #data
|
||||||
|
local compressed, method
|
||||||
|
|
||||||
|
local deflated = deflate(data)
|
||||||
|
if deflated then
|
||||||
|
compressed = deflated
|
||||||
|
method = 8 -- DEFLATE
|
||||||
|
else
|
||||||
|
compressed = data
|
||||||
|
method = 0 -- Stored
|
||||||
|
end
|
||||||
|
|
||||||
|
table.insert(self._entries, {
|
||||||
|
path = path,
|
||||||
|
data = data, -- uncompressed (kept for the central dir)
|
||||||
|
compressed = compressed,
|
||||||
|
method = method,
|
||||||
|
crc = crc,
|
||||||
|
size_orig = original,
|
||||||
|
size_comp = #compressed,
|
||||||
|
offset = self._offset,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Local file header = 30 bytes + filename length + compressed data length
|
||||||
|
self._offset = self._offset + 30 + #path + #compressed
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Build and return the full zip file as a binary string.
|
||||||
|
function Zip:build()
|
||||||
|
local parts = {}
|
||||||
|
|
||||||
|
-- ── Local file headers + data ────────────────────────────────────────────
|
||||||
|
for _, e in ipairs(self._entries) do
|
||||||
|
local dos_time, dos_date = dos_datetime()
|
||||||
|
|
||||||
|
-- Local file header signature
|
||||||
|
parts[#parts+1] = "\x50\x4B\x03\x04" -- PK\3\4
|
||||||
|
parts[#parts+1] = "\x14\x00" -- version needed: 2.0
|
||||||
|
parts[#parts+1] = "\x00\x00" -- general purpose bit flag
|
||||||
|
parts[#parts+1] = pack_u16(e.method)
|
||||||
|
parts[#parts+1] = dos_time
|
||||||
|
parts[#parts+1] = dos_date
|
||||||
|
parts[#parts+1] = pack_u32(e.crc)
|
||||||
|
parts[#parts+1] = pack_u32(e.size_comp)
|
||||||
|
parts[#parts+1] = pack_u32(e.size_orig)
|
||||||
|
parts[#parts+1] = pack_u16(#e.path) -- filename length
|
||||||
|
parts[#parts+1] = "\x00\x00" -- extra field length
|
||||||
|
parts[#parts+1] = e.path
|
||||||
|
parts[#parts+1] = e.compressed
|
||||||
|
end
|
||||||
|
|
||||||
|
local central_dir_offset = 0
|
||||||
|
for _, p in ipairs(parts) do central_dir_offset = central_dir_offset + #p end
|
||||||
|
|
||||||
|
-- ── Central directory ────────────────────────────────────────────────────
|
||||||
|
local central_parts = {}
|
||||||
|
for _, e in ipairs(self._entries) do
|
||||||
|
local dos_time, dos_date = dos_datetime()
|
||||||
|
|
||||||
|
central_parts[#central_parts+1] = "\x50\x4B\x01\x02" -- PK\1\2
|
||||||
|
central_parts[#central_parts+1] = "\x14\x00" -- version made by: 2.0
|
||||||
|
central_parts[#central_parts+1] = "\x14\x00" -- version needed: 2.0
|
||||||
|
central_parts[#central_parts+1] = "\x00\x00" -- general purpose bit flag
|
||||||
|
central_parts[#central_parts+1] = pack_u16(e.method)
|
||||||
|
central_parts[#central_parts+1] = dos_time
|
||||||
|
central_parts[#central_parts+1] = dos_date
|
||||||
|
central_parts[#central_parts+1] = pack_u32(e.crc)
|
||||||
|
central_parts[#central_parts+1] = pack_u32(e.size_comp)
|
||||||
|
central_parts[#central_parts+1] = pack_u32(e.size_orig)
|
||||||
|
central_parts[#central_parts+1] = pack_u16(#e.path) -- filename length
|
||||||
|
central_parts[#central_parts+1] = "\x00\x00" -- extra field length
|
||||||
|
central_parts[#central_parts+1] = "\x00\x00" -- file comment length
|
||||||
|
central_parts[#central_parts+1] = "\x00\x00" -- disk number start
|
||||||
|
central_parts[#central_parts+1] = "\x00\x00" -- internal attributes
|
||||||
|
central_parts[#central_parts+1] = "\x00\x00\x00\x00" -- external attributes
|
||||||
|
central_parts[#central_parts+1] = pack_u32(e.offset) -- offset of local header
|
||||||
|
central_parts[#central_parts+1] = e.path
|
||||||
|
end
|
||||||
|
|
||||||
|
local central_dir_size = 0
|
||||||
|
for _, p in ipairs(central_parts) do central_dir_size = central_dir_size + #p end
|
||||||
|
|
||||||
|
-- ── End of central directory record ─────────────────────────────────────
|
||||||
|
local num_entries = #self._entries
|
||||||
|
local eocd = table.concat({
|
||||||
|
"\x50\x4B\x05\x06", -- PK\5\6 (EOCD signature)
|
||||||
|
"\x00\x00", -- disk number
|
||||||
|
"\x00\x00", -- disk with central dir start
|
||||||
|
pack_u16(num_entries), -- entries on this disk
|
||||||
|
pack_u16(num_entries), -- total entries
|
||||||
|
pack_u32(central_dir_size), -- central dir size
|
||||||
|
pack_u32(central_dir_offset), -- central dir offset
|
||||||
|
"\x00\x00", -- comment length
|
||||||
|
})
|
||||||
|
|
||||||
|
return table.concat(parts)
|
||||||
|
.. table.concat(central_parts)
|
||||||
|
.. eocd
|
||||||
|
end
|
||||||
|
|
||||||
|
return Zip
|
||||||
+1
-1
@@ -1 +1 @@
|
|||||||
1.0.3
|
1.0.4
|
||||||
Reference in New Issue
Block a user