Serge Bazanski | 18c1a26 | 2022-07-07 14:24:53 +0200 | [diff] [blame] | 1 | local 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 | |
| 12 | local inspect = require('vendor.inspect') |
| 13 | |
| 14 | local textFont = love.graphics.newFont('fonts/Lato-Light.ttf', 90) |
| 15 | local headFont = love.graphics.newFont('fonts/Lato-Regular.ttf', 90) |
| 16 | local smallFont = love.graphics.newFont('fonts/Lato-Light.ttf', 30) |
| 17 | |
| 18 | function 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 |
| 48 | end |
| 49 | |
| 50 | function 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 |
| 62 | end |
| 63 | |
| 64 | return node |