summaryrefslogtreecommitdiffstats
path: root/nodes/weather.lua
blob: fa3bf982df23d00f564a12b2dec8ced119ed0c63 (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
local node = ThreadNode:extend('nodes.weather', {
  threadFile = 'nodes/weather_thread.lua',
  threadChannel = 'weather',

  updateInterval = 5 * 60,
})

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', 30)

local weatherGlyphs = {
  snow = "",
  mist = "",
  clear = "",
  -- clouds = "",
  clouds = "", -- x---DDD
  drizzle = "",
}

function node:render()
  love.graphics.setColor( 0, 0, 0 )
  love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())

  if self.state then
    love.graphics.setColor( 255, 255, 255 )

    if weatherGlyphs[self.state.weather] then
      love.graphics.setFont(weatherFont)
      love.graphics.print(weatherGlyphs[self.state.weather], 120, 35)
    else
      love.graphics.setFont(smallFont)
      love.graphics.print(self.state.weather, 150, love.graphics.getHeight()/2 - 60)
    end

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

    love.graphics.setFont(smallFont)
    love.graphics.printf(os.date("Last update: %Y/%m/%d %H:%M", self.state.lastUpdate), 0, love.graphics.getHeight() - 60, love.graphics.getWidth(), 'center')
    if self.state.insideTemperature then
      love.graphics.printf("Room: " .. tostring(self.state.insideTemperature) .. "° / " .. tostring(self.state.insideHumidity) .. "%RH", 0, love.graphics.getHeight() - 100, love.graphics.getWidth(), 'center')
    end
  else
    love.graphics.setColor( 255, 255, 255, 80 )

    love.graphics.setFont(smallFont)
    love.graphics.printf("Loading weather...", 0, love.graphics.getHeight() - 200, love.graphics.getWidth(), 'center')
  end
end

return node