Add misery module, fix unknown weather icon
parent
c65f888bef
commit
1496814f1b
1
main.lua
1
main.lua
|
@ -7,6 +7,7 @@ environment = os.getenv('ENV')
|
|||
screens = {
|
||||
require 'screens.weather',
|
||||
require 'screens.time',
|
||||
require 'screens.misery',
|
||||
require 'screens.screen1',
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
local node = {}
|
||||
|
||||
local inspect = require('vendor.inspect')
|
||||
|
||||
local textFont = love.graphics.newFont('fonts/Lato-Light.ttf', 50)
|
||||
local smallFont = love.graphics.newFont('fonts/Lato-Light.ttf', 30)
|
||||
|
||||
local updateInterval = 2 * 60
|
||||
local lastUpdate = 0
|
||||
local state = nil
|
||||
|
||||
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())
|
||||
|
||||
if state then
|
||||
love.graphics.setColor( 255, 255, 255 )
|
||||
love.graphics.setFont(textFont)
|
||||
love.graphics.printf(state.text, 50, 180, love.graphics.getWidth() - 100, 'center')
|
||||
|
||||
love.graphics.setColor( 255, 255, 255, 200 )
|
||||
love.graphics.setFont(smallFont)
|
||||
love.graphics.printf(state.description, 200, love.graphics.getHeight() - 100, love.graphics.getWidth() - 400, 'center')
|
||||
else
|
||||
love.graphics.setColor( 255, 255, 255, 80 )
|
||||
|
||||
love.graphics.setFont(smallFont)
|
||||
love.graphics.printf("Loading misery...", 0, love.graphics.getHeight() - 200, love.graphics.getWidth(), 'center')
|
||||
end
|
||||
end
|
||||
|
||||
function node.update(dt)
|
||||
if lastUpdate < love.timer.getTime() - updateInterval then
|
||||
lastUpdate = love.timer.getTime()
|
||||
print("Updating...")
|
||||
|
||||
local updateThread = love.thread.newThread('screens/misery_thread.lua')
|
||||
updateThread:start()
|
||||
end
|
||||
|
||||
state = love.thread.getChannel('misery'):pop() or state
|
||||
end
|
||||
|
||||
return node
|
|
@ -0,0 +1,35 @@
|
|||
local socket = require("socket")
|
||||
local http = require("socket.http")
|
||||
local json = require("vendor.json")
|
||||
local lume = require("vendor.lume")
|
||||
|
||||
local miseryURL = 'http://oodviewer.q3k.me/term/_,'
|
||||
|
||||
math.randomseed( os.time() )
|
||||
|
||||
function unescape(str)
|
||||
str = string.gsub( str, '<', '<' )
|
||||
str = string.gsub( str, '>', '>' )
|
||||
str = string.gsub( str, '"', '"' )
|
||||
str = string.gsub( str, ''', "'" )
|
||||
str = string.gsub( str, '&#(%d+);', function(n) return string.char(n) end )
|
||||
str = string.gsub( str, '&#x(%d+);', function(n) return string.char(tonumber(n,16)) end )
|
||||
str = string.gsub( str, '&', '&' ) -- Be sure to do this after all others
|
||||
return str
|
||||
end
|
||||
|
||||
local r, c, h = http.request(miseryURL)
|
||||
if c == 200 then
|
||||
local data = {}
|
||||
for item, desc in string.gmatch(r, '<li>([^\n]*) <i>([^<]*)</i>') do
|
||||
data[#data + 1] = {
|
||||
text = unescape(item:gsub('<[^>]*>', '')),
|
||||
description = unescape(desc),
|
||||
}
|
||||
end
|
||||
|
||||
love.thread.getChannel('misery'):push(lume.randomchoice(data))
|
||||
print("Update finished")
|
||||
else
|
||||
print("Update failed")
|
||||
end
|
|
@ -9,9 +9,10 @@ local smallFont = love.graphics.newFont('fonts/Lato-Light.ttf', 30)
|
|||
local weatherGlyphs = {
|
||||
snow = "",
|
||||
mist = "",
|
||||
clear = "",
|
||||
}
|
||||
|
||||
local updateInterval = 60
|
||||
local updateInterval = 5 * 60
|
||||
local lastUpdate = 0
|
||||
local state = nil
|
||||
|
||||
|
@ -25,11 +26,13 @@ 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 )
|
||||
|
||||
if state then
|
||||
love.graphics.setFont(weatherFont)
|
||||
love.graphics.print(tostring(weatherGlyphs[state.weather]), 150, 0)
|
||||
love.graphics.setColor( 255, 255, 255 )
|
||||
|
||||
if weatherGlyphs[state.weather] then
|
||||
love.graphics.setFont(weatherFont)
|
||||
love.graphics.print(weatherGlyphs[state.weather], 150, 0)
|
||||
end
|
||||
|
||||
love.graphics.setFont(textFont)
|
||||
love.graphics.printf(tostring(state.temperature) .. "°", 600, 180, 650, 'center')
|
||||
|
@ -39,14 +42,19 @@ function node.render()
|
|||
if state.insideTemperature then
|
||||
love.graphics.printf("Room: " .. state.insideTemperature .. "° / " .. 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
|
||||
|
||||
function node.update(dt)
|
||||
if lastUpdate < love.timer.getTime() - updateInterval then
|
||||
lastUpdate = love.timer.getTime()
|
||||
print("update")
|
||||
print(inspect(state))
|
||||
print("Updating...")
|
||||
|
||||
local updateThread = love.thread.newThread('screens/weather_thread.lua')
|
||||
updateThread:start()
|
||||
end
|
||||
|
|
|
@ -24,6 +24,7 @@ if c == 200 then
|
|||
insideTemperature = insideData[1],
|
||||
insideHumidity = insideData[2],
|
||||
})
|
||||
print("Update finished")
|
||||
else
|
||||
print("failed")
|
||||
print("Update failed")
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue