summaryrefslogtreecommitdiffstats
path: root/screens/weather.lua
blob: df7a4000a4b5d0fbb83334ec03286fe57db4e516 (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 = {}

local inspect = require('vendor.inspect')

local weatherFont = love.graphics.newFont('fonts/weathericons-regular-webfont.ttf', 400)
local textFont = love.graphics.newFont('fonts/Lato-Thin.ttf', 300)
local smallFont = love.graphics.newFont('fonts/Lato-Light.ttf', 20)

local weatherGlyphs = {
  snow = "",
  mist = "",
}

local updateInterval = 60
local lastUpdate = 0
local state = {
  weather = "snow",
  temperature = 0,
}

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())

  love.graphics.setColor( 255, 255, 255 )

  love.graphics.setFont(textFont);
  love.graphics.printf(tostring(state.temperature) .. "°", 600, 180, 650, 'center');

  love.graphics.setFont(weatherFont);
  love.graphics.print(tostring(weatherGlyphs[state.weather]), 150, 0);

  love.graphics.setFont(smallFont)
  love.graphics.printf("piździ x---DD", 0, love.graphics.getHeight() - 40, love.graphics.getWidth(), 'center')
end

function node.update(dt)
  if lastUpdate < love.timer.getTime() - updateInterval then
    lastUpdate = love.timer.getTime()
    print("update")
    print(inspect(state))
    local updateThread = love.thread.newThread('screens/weather_thread.lua')
    updateThread:start()
  end

  state = love.thread.getChannel('weather'):pop() or state
end

return node