forked from hswaw/hscloud
Serge Bazanski
18c1a263cf
This is b28e6f07aa48f1e2f01eb37bffa180f97a7b03bd from https://code.hackerspace.pl/q3k/love2d-signage/. We only keep code commited by inf and q3k, and we're both now licensing this code under the ISC license, as per COPYING in the root of hscloud. Change-Id: Ibeee2e6923605e4b1a17a1d295867c056863ef59 Reviewed-on: https://gerrit.hackerspace.pl/c/hscloud/+/1335 Reviewed-by: informatic <informatic@hackerspace.pl> Reviewed-by: q3k <q3k@hackerspace.pl>
64 lines
2 KiB
Lua
64 lines
2 KiB
Lua
local node = ThreadNode:extend('node.currency', {
|
|
threadFile = 'nodes/currency_thread.lua',
|
|
threadChannel = 'currency',
|
|
|
|
updateInterval = 10,
|
|
state = {
|
|
values = {},
|
|
changes = {},
|
|
},
|
|
})
|
|
|
|
local inspect = require('vendor.inspect')
|
|
|
|
local textFont = love.graphics.newFont('fonts/Lato-Light.ttf', 90)
|
|
local headFont = love.graphics.newFont('fonts/Lato-Regular.ttf', 90)
|
|
local smallFont = love.graphics.newFont('fonts/Lato-Light.ttf', 30)
|
|
|
|
function node:render()
|
|
love.graphics.setColor( 0, 0, 0 )
|
|
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
|
|
|
|
if self.state.values and self.state.values[2] then
|
|
local pad = 20
|
|
love.graphics.setColor( 1.0, 1.0, 1.0 )
|
|
love.graphics.setFont(headFont)
|
|
love.graphics.printf("BTCPLN", 0, 180, love.graphics.getWidth()/2, 'right')
|
|
love.graphics.printf("TRYIDR", 0, 350, love.graphics.getWidth()/2, 'right')
|
|
love.graphics.setFont(textFont)
|
|
if self.state.changes[1] then
|
|
love.graphics.setColor( 0, 1.0, 0 )
|
|
else
|
|
love.graphics.setColor( 1.0, 0, 0 )
|
|
end
|
|
love.graphics.printf(self.state.values[1], love.graphics.getWidth()/2 + 2*pad, 180, love.graphics.getWidth()/2 - 2*pad, 'left')
|
|
|
|
if self.state.changes[2] then
|
|
love.graphics.setColor( 0, 1.0, 0 )
|
|
else
|
|
love.graphics.setColor( 1.0, 0, 0 )
|
|
end
|
|
love.graphics.printf(self.state.values[2], love.graphics.getWidth()/2 + 2*pad, 350, love.graphics.getWidth()/2 - 2*pad, 'left')
|
|
else
|
|
love.graphics.setColor( 1.0, 1.0, 1.0, 0.4 )
|
|
|
|
love.graphics.setFont(smallFont)
|
|
love.graphics.printf("Loading currency...", 0, love.graphics.getHeight() - 200, love.graphics.getWidth(), 'center')
|
|
end
|
|
end
|
|
|
|
function node:onUpdate(v)
|
|
for n in ipairs(v.values) do
|
|
if self.state.values[n] then
|
|
if self.state.values[n] ~= v.values[n] then
|
|
self.state.changes[n] = self.state.values[n] > v.values[n]
|
|
end
|
|
else
|
|
self.state.changes[n] = true
|
|
end
|
|
end
|
|
|
|
self.state.values = v.values
|
|
end
|
|
|
|
return node
|