summaryrefslogtreecommitdiffstats
path: root/nodes/currency.lua
blob: 081f7a336bbe80e617b11b31777fe271e5928da4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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( 255, 255, 255 )
    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)

    love.graphics.setColor( 0, 255, 0 )
    love.graphics.printf(self.state.values[1], love.graphics.getWidth()/2 + 2*pad, 180, love.graphics.getWidth()/2 - 2*pad, 'left')
    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( 255, 255, 255, 80 )

    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