Add at screen
parent
6d74bedd83
commit
805a4273aa
|
@ -2,6 +2,7 @@ return {
|
|||
transitionTime = 1,
|
||||
cycleTime = 5,
|
||||
screens = {
|
||||
require 'screens.at',
|
||||
require 'screens.cube',
|
||||
require 'screens.weather',
|
||||
require 'screens.time',
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
local node = {}
|
||||
|
||||
local lume = require('vendor.lume');
|
||||
|
||||
local bigFont = love.graphics.newFont('fonts/Lato-Light.ttf', 80)
|
||||
local textFont = love.graphics.newFont('fonts/Lato-Light.ttf', 50)
|
||||
local smallFont = love.graphics.newFont('fonts/Lato-Light.ttf', 30)
|
||||
|
||||
local updateInterval = 2 * 60
|
||||
local lastUpdate = 0
|
||||
local state = nil
|
||||
|
||||
function node.load() end
|
||||
function node.unload() end
|
||||
|
||||
function node.render()
|
||||
love.graphics.setColor( 0, 0, 0 )
|
||||
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
|
||||
|
||||
if state then
|
||||
love.graphics.setColor( 255, 255, 255, 100 )
|
||||
love.graphics.setFont(bigFont)
|
||||
love.graphics.printf('Currently at hackerspace:', 50, 100, love.graphics.getWidth() - 100, 'center')
|
||||
|
||||
usersList = (table.concat(lume.map(state.users, function(v) return v.login end), ', ') or 'nobody...') .. '\n'
|
||||
|
||||
if state.unknown > 0 then
|
||||
usersList = usersList .. '\n...and ' .. tostring(state.unknown) .. ' unknown creatures'
|
||||
end
|
||||
|
||||
if state.kektops > 0 then
|
||||
usersList = usersList .. '\n...and ' .. tostring(state.kektops) .. ' kektops'
|
||||
end
|
||||
|
||||
if state.esps > 0 then
|
||||
usersList = usersList .. '\n...and ' .. tostring(state.esps) .. ' ESPs'
|
||||
end
|
||||
|
||||
love.graphics.setColor( 255, 255, 255 )
|
||||
love.graphics.setFont(textFont)
|
||||
love.graphics.printf(usersList, 50, 220, love.graphics.getWidth() - 100, 'center')
|
||||
else
|
||||
love.graphics.setColor( 255, 255, 255, 80 )
|
||||
|
||||
love.graphics.setFont(smallFont)
|
||||
love.graphics.printf("Loading at...", 0, love.graphics.getHeight() - 200, love.graphics.getWidth(), 'center')
|
||||
end
|
||||
end
|
||||
|
||||
function node.update(dt)
|
||||
if lastUpdate < love.timer.getTime() - updateInterval or
|
||||
(not state and lastUpdate < love.timer.getTime() - 5) then
|
||||
lastUpdate = love.timer.getTime()
|
||||
print("Updating...")
|
||||
|
||||
local updateThread = love.thread.newThread('screens/at_thread.lua')
|
||||
updateThread:start()
|
||||
end
|
||||
|
||||
state = love.thread.getChannel('at'):pop() or state
|
||||
end
|
||||
|
||||
return node
|
|
@ -0,0 +1,14 @@
|
|||
local socket = require("socket")
|
||||
local http = require("socket.http")
|
||||
local json = require("vendor.json")
|
||||
local lume = require("vendor.lume")
|
||||
|
||||
local miseryURL = 'http://at.hackerspace.pl/api'
|
||||
|
||||
local r, c, h = http.request(miseryURL)
|
||||
if c == 200 then
|
||||
love.thread.getChannel('at'):push(json.decode(r))
|
||||
print("Update finished")
|
||||
else
|
||||
print("Update failed")
|
||||
end
|
Loading…
Reference in New Issue