blob: a0444d53bc2f14bc04211f418f382aa4ac1920a3 [file] [log] [blame]
Serge Bazanski18c1a262022-07-07 14:24:53 +02001local node = ThreadNode:extend('node.currency', {
2 threadFile = 'nodes/currency_thread.lua',
3 threadChannel = 'currency',
4
5 updateInterval = 10,
6 state = {
7 values = {},
8 changes = {},
9 },
10})
11
12local inspect = require('vendor.inspect')
13
14local textFont = love.graphics.newFont('fonts/Lato-Light.ttf', 90)
15local headFont = love.graphics.newFont('fonts/Lato-Regular.ttf', 90)
16local smallFont = love.graphics.newFont('fonts/Lato-Light.ttf', 30)
17
18function node:render()
19 love.graphics.setColor( 0, 0, 0 )
20 love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
21
22 if self.state.values and self.state.values[2] then
23 local pad = 20
24 love.graphics.setColor( 1.0, 1.0, 1.0 )
25 love.graphics.setFont(headFont)
26 love.graphics.printf("BTCPLN", 0, 180, love.graphics.getWidth()/2, 'right')
27 love.graphics.printf("TRYIDR", 0, 350, love.graphics.getWidth()/2, 'right')
28 love.graphics.setFont(textFont)
29 if self.state.changes[1] then
30 love.graphics.setColor( 0, 1.0, 0 )
31 else
32 love.graphics.setColor( 1.0, 0, 0 )
33 end
34 love.graphics.printf(self.state.values[1], love.graphics.getWidth()/2 + 2*pad, 180, love.graphics.getWidth()/2 - 2*pad, 'left')
35
36 if self.state.changes[2] then
37 love.graphics.setColor( 0, 1.0, 0 )
38 else
39 love.graphics.setColor( 1.0, 0, 0 )
40 end
41 love.graphics.printf(self.state.values[2], love.graphics.getWidth()/2 + 2*pad, 350, love.graphics.getWidth()/2 - 2*pad, 'left')
42 else
43 love.graphics.setColor( 1.0, 1.0, 1.0, 0.4 )
44
45 love.graphics.setFont(smallFont)
46 love.graphics.printf("Loading currency...", 0, love.graphics.getHeight() - 200, love.graphics.getWidth(), 'center')
47 end
48end
49
50function node:onUpdate(v)
51 for n in ipairs(v.values) do
52 if self.state.values[n] then
53 if self.state.values[n] ~= v.values[n] then
54 self.state.changes[n] = self.state.values[n] > v.values[n]
55 end
56 else
57 self.state.changes[n] = true
58 end
59 end
60
61 self.state.values = v.values
62end
63
64return node