summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Dobrowolski <admin@tastycode.pl>2017-01-12 20:38:04 +0100
committerPiotr Dobrowolski <admin@tastycode.pl>2017-01-12 20:38:04 +0100
commit805a4273aa7bb4019f3db1e906430a3913b43885 (patch)
treec2e25d0cf028e87e67bbf81e2eec728b305812b9
parent6d74bedd83082edcbb13423981f3db99b2de4bdb (diff)
downloadlove2d-signage-805a4273aa7bb4019f3db1e906430a3913b43885.tar.gz
love2d-signage-805a4273aa7bb4019f3db1e906430a3913b43885.tar.bz2
love2d-signage-805a4273aa7bb4019f3db1e906430a3913b43885.tar.xz
love2d-signage-805a4273aa7bb4019f3db1e906430a3913b43885.zip
Add at screen
-rw-r--r--config.lua1
-rw-r--r--screens/at.lua63
-rw-r--r--screens/at_thread.lua14
3 files changed, 78 insertions, 0 deletions
diff --git a/config.lua b/config.lua
index d17ed01..af4c087 100644
--- a/config.lua
+++ b/config.lua
@@ -2,6 +2,7 @@ return {
transitionTime = 1,
cycleTime = 5,
screens = {
+ require 'screens.at',
require 'screens.cube',
require 'screens.weather',
require 'screens.time',
diff --git a/screens/at.lua b/screens/at.lua
new file mode 100644
index 0000000..b58ee81
--- /dev/null
+++ b/screens/at.lua
@@ -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
diff --git a/screens/at_thread.lua b/screens/at_thread.lua
new file mode 100644
index 0000000..1bc782d
--- /dev/null
+++ b/screens/at_thread.lua
@@ -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