love2d-signage/main.lua

113 lines
3.0 KiB
Lua

local debugGraph = require 'vendor.debugGraph'
local inspect = require 'vendor.inspect'
local push = require 'vendor.push'
local lurker = require 'vendor.lurker'
local config = require('config')
environment = os.getenv('ENV')
local gameWidth, gameHeight = 1280, 720
local windowWidth, windowHeight = love.window.getDesktopDimensions()
windowWidth, windowHeight = windowWidth*.5, windowHeight*.5 --make the window a bit smaller than the screen itself
if environment == 'DEV' then
push:setupScreen(gameWidth, gameHeight, windowWidth, windowHeight, {fullscreen = false, resizable = true})
else
push:setupScreen(gameWidth, gameHeight, gameWidth, gameHeight, {fullscreen = true})
end
function love.resize(w, h)
push:resize(w, h)
secondaryCanvas = love.graphics.newCanvas(push:getWidth(), push:getHeight())
end
function love.load()
state = {
currentScreen = 1,
transitioning = false,
stateCounter = 0,
}
love.mouse.setVisible( false )
secondaryCanvas = love.graphics.newCanvas(push:getWidth(), push:getHeight())
fpsGraph = debugGraph:new('fps', 0, 0)
memGraph = debugGraph:new('mem', 0, 30)
for key, node in ipairs(config.screens) do
node.load()
end
lurker.quiet = true
end
function lurker.preswap(f)
if f:match('_thread.lua') then
print("Preventing _thread update!")
return false
end
end
function getw() return push:getWidth() end
function geth() return push:getHeight() end
function love.draw()
push:start()
-- Patch love.graphics.getWidth/Height to account for push
oldw, oldh = love.graphics.getWidth, love.graphics.getHeight
love.graphics.getWidth, love.graphics.getHeight = getw, geth
config.screens[state.currentScreen].render()
if state.transitioning then
-- Render next screen into canvas and fade accordingly
secondaryCanvas:renderTo(config.screens[state.currentScreen % #config.screens + 1].render)
love.graphics.setColor(255, 255, 255, 255 * (state.stateCounter / config.transitionTime)) -- red, green, blue, opacity (this would be white with 20% opacity)
love.graphics.draw(secondaryCanvas, 0, 0)
end
-- Draw graphs
love.graphics.setColor(255, 255, 255, 128)
-- love.graphics.setNewFont(10)
-- love.graphics.print(inspect(state), 0, 60, 0)
fpsGraph:draw()
memGraph:draw()
love.graphics.getWidth, love.graphics.getHeight = oldw, oldh
push:finish()
end
function love.update(dt)
config.screens[state.currentScreen].update(dt)
if state.transitioning then
config.screens[state.currentScreen % #config.screens + 1].update(dt)
end
state.stateCounter = state.stateCounter + dt
if state.transitioning then
if state.stateCounter >= config.transitionTime then
state.stateCounter = 0
state.transitioning = false
state.currentScreen = (state.currentScreen % #config.screens) + 1
end
else
if state.stateCounter >= config.cycleTime then
state.stateCounter = 0
state.transitioning = true
end
end
-- Update the graphs
fpsGraph:update(dt)
memGraph:update(dt)
lurker.update()
end