diff options
author | Piotr Dobrowolski <admin@tastycode.pl> | 2017-02-08 00:53:11 +0100 |
---|---|---|
committer | Piotr Dobrowolski <admin@tastycode.pl> | 2017-02-08 00:53:11 +0100 |
commit | 9c8d2432e799760a8b59881f27f4e72db96a95a0 (patch) | |
tree | 88a472fea7e27735bb8a26cdb53e2c2f77d8266e | |
parent | 62b8e8cad06d6aad0d8e8fec0e57eacaec113fb8 (diff) | |
parent | e86f411dfcef958cf75103ad1eb0e133ba546dc3 (diff) | |
download | love2d-signage-9c8d2432e799760a8b59881f27f4e72db96a95a0.tar.gz love2d-signage-9c8d2432e799760a8b59881f27f4e72db96a95a0.tar.bz2 love2d-signage-9c8d2432e799760a8b59881f27f4e72db96a95a0.tar.xz love2d-signage-9c8d2432e799760a8b59881f27f4e72db96a95a0.zip |
Merge branch 'master' of hackerspace.pl:informatic/love2d-signage
-rw-r--r-- | config.lua | 1 | ||||
-rw-r--r-- | nodes/time.lua | 10 | ||||
-rw-r--r-- | nodes/weather.lua | 52 | ||||
-rw-r--r-- | nodes/weather_thread.lua | 2 |
4 files changed, 55 insertions, 10 deletions
@@ -3,6 +3,7 @@ return { transitionTime = 0.5, showProgress = true, nodes = { + {'nodes.weather'}, {'nodes.newdash', displayTime=10}, {'nodes.misery', displayTime = 7}, {'nodes.slideshow', files={'images/pig.png'}, displayTime=5}, diff --git a/nodes/time.lua b/nodes/time.lua index 7f8befc..1e0968b 100644 --- a/nodes/time.lua +++ b/nodes/time.lua @@ -3,6 +3,12 @@ local node = Node:extend('nodes.time', {}) local textFont = love.graphics.newFont('fonts/Lato-Thin.ttf', 400) local smallFont = love.graphics.newFont('fonts/Lato-Light.ttf', 60) +function node:init(config) + node.super.init(self, config) + self.timeFormat = self.timeFormat or '%H:%M' + self.dateFormat = self.dateFormat or '%Y/%m/%d' +end + function node:render() love.graphics.setColor( 0, 0, 0 ) love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight()) @@ -10,10 +16,10 @@ function node:render() love.graphics.setColor( 255, 255, 255 ) love.graphics.setFont(textFont); - love.graphics.printf(os.date('%H:%M'), 0, 0.14*love.graphics.getHeight(), love.graphics.getWidth(), 'center'); + love.graphics.printf(os.date(self.timeFormat), 0, 0.14*love.graphics.getHeight(), love.graphics.getWidth(), 'center'); love.graphics.setFont(smallFont); - love.graphics.printf(os.date('%Y/%m/%d'), 0, 0.8*love.graphics.getHeight(), love.graphics.getWidth(), 'center'); + love.graphics.printf(os.date(self.dateFormat), 0, 0.8*love.graphics.getHeight(), love.graphics.getWidth(), 'center'); end return node diff --git a/nodes/weather.lua b/nodes/weather.lua index fa3bf98..f5bf82c 100644 --- a/nodes/weather.lua +++ b/nodes/weather.lua @@ -9,15 +9,51 @@ local weatherFont = love.graphics.newFont('fonts/weathericons-regular-webfont.tt 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 = "", +local weatherGlyphs = {} + +local weatherGlyphsSet = { + day = { + snow = "", + mist = "", + clear = "", + -- clouds = "", + clouds = "", -- x---DDD + drizzle = "", + }, + night = { + snow = "", + mist = "", + clear = "", + clouds = "", + drizzle = "", + + } } +function node:timeOfDay() + local sunRise = tonumber(os.date("%H%M", self.state.sunRise)) + local sunSet = tonumber(os.date("%H%M", self.state.sunSet)) + local now = tonumber(os.date("%H%M")) + if sunRise == nil or sunSet == nil then + return weatherGlyphsSet["day"] -- smth gone wrong. assume daylight + end + if now < sunSet and now > sunRise then + print('day') + return weatherGlyphsSet["day"] + else + print('night') + return weatherGlyphsSet["night"] + end +end + +function node:beforeEnter() + if self.state then + weatherGlyphs = self:timeOfDay() + else + weatherGlyphs = weatherGlyphsSet["day"] -- do not know sunraise and sunset yet. assume daylight + end +end + function node:render() love.graphics.setColor( 0, 0, 0 ) love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight()) @@ -34,7 +70,7 @@ function node:render() end love.graphics.setFont(textFont) - love.graphics.printf(tostring(self.state.temperature) .. "°", 600, 150, 650, 'center') + love.graphics.printf(tostring(math.floor(self.state.temperature + 0.5)) .. "°", 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') diff --git a/nodes/weather_thread.lua b/nodes/weather_thread.lua index 4a627be..ebf0400 100644 --- a/nodes/weather_thread.lua +++ b/nodes/weather_thread.lua @@ -21,6 +21,8 @@ if c == 200 then weather = data.weather[1].main:lower(), temperature = data.main.temp, lastUpdate = data.dt, + sunRise = data.sys.sunrise, + sunSet = data.sys.sunset, insideTemperature = insideData[1], insideHumidity = insideData[2], }) |