love2d-signage/main.lua

113 lines
3.0 KiB
Lua
Raw Normal View History

2017-01-08 00:11:19 +00:00
local debugGraph = require 'vendor.debugGraph'
local inspect = require 'vendor.inspect'
local push = require 'vendor.push'
2017-01-08 18:16:30 +00:00
local lurker = require 'vendor.lurker'
2017-01-08 00:11:19 +00:00
2017-01-08 21:24:13 +00:00
local config = require('config')
2017-01-07 18:35:38 +00:00
2017-01-08 21:24:13 +00:00
environment = os.getenv('ENV')
2017-01-07 18:35:38 +00:00
2017-01-08 00:11:19 +00:00
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
2017-01-07 18:35:38 +00:00
function love.load()
2017-01-08 21:24:13 +00:00
state = {
currentScreen = 1,
transitioning = false,
stateCounter = 0,
}
2017-01-08 00:11:19 +00:00
love.mouse.setVisible( false )
secondaryCanvas = love.graphics.newCanvas(push:getWidth(), push:getHeight())
2017-01-07 18:35:38 +00:00
fpsGraph = debugGraph:new('fps', 0, 0)
memGraph = debugGraph:new('mem', 0, 30)
2017-01-08 00:11:19 +00:00
2017-01-08 21:24:13 +00:00
for key, node in ipairs(config.screens) do
2017-01-08 00:11:19 +00:00
node.load()
end
2017-01-08 18:16:30 +00:00
lurker.quiet = true
end
function lurker.preswap(f)
if f:match('_thread.lua') then
print("Preventing _thread update!")
return false
end
2017-01-07 18:35:38 +00:00
end
2017-01-08 00:11:19 +00:00
function getw() return push:getWidth() end
function geth() return push:getHeight() end
2017-01-07 18:35:38 +00:00
function love.draw()
2017-01-08 00:11:19 +00:00
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
2017-01-08 21:26:36 +00:00
config.screens[state.currentScreen].render()
2017-01-08 00:11:19 +00:00
2017-01-07 18:35:38 +00:00
if state.transitioning then
2017-01-08 00:11:19 +00:00
-- Render next screen into canvas and fade accordingly
2017-01-08 21:24:13 +00:00
secondaryCanvas:renderTo(config.screens[state.currentScreen % #config.screens + 1].render)
2017-01-08 21:26:36 +00:00
love.graphics.setColor(255, 255, 255, 255 * (state.stateCounter / config.transitionTime)) -- red, green, blue, opacity (this would be white with 20% opacity)
2017-01-07 18:35:38 +00:00
love.graphics.draw(secondaryCanvas, 0, 0)
end
-- Draw graphs
love.graphics.setColor(255, 255, 255, 128)
2017-01-08 00:11:19 +00:00
-- love.graphics.setNewFont(10)
-- love.graphics.print(inspect(state), 0, 60, 0)
2017-01-07 18:35:38 +00:00
fpsGraph:draw()
memGraph:draw()
2017-01-08 00:11:19 +00:00
love.graphics.getWidth, love.graphics.getHeight = oldw, oldh
push:finish()
2017-01-07 18:35:38 +00:00
end
function love.update(dt)
2017-01-08 21:24:13 +00:00
config.screens[state.currentScreen].update(dt)
2017-01-07 18:35:38 +00:00
if state.transitioning then
2017-01-08 21:24:13 +00:00
config.screens[state.currentScreen % #config.screens + 1].update(dt)
2017-01-07 18:35:38 +00:00
end
state.stateCounter = state.stateCounter + dt
if state.transitioning then
2017-01-08 21:24:13 +00:00
if state.stateCounter >= config.transitionTime then
2017-01-07 18:35:38 +00:00
state.stateCounter = 0
state.transitioning = false
2017-01-08 21:24:13 +00:00
state.currentScreen = (state.currentScreen % #config.screens) + 1
2017-01-07 18:35:38 +00:00
end
else
2017-01-08 21:24:13 +00:00
if state.stateCounter >= config.cycleTime then
2017-01-07 18:35:38 +00:00
state.stateCounter = 0
state.transitioning = true
end
end
-- Update the graphs
fpsGraph:update(dt)
memGraph:update(dt)
2017-01-08 18:16:30 +00:00
lurker.update()
2017-01-07 18:35:38 +00:00
end