summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Dobrowolski <admin@tastycode.pl>2017-01-08 22:24:13 +0100
committerPiotr Dobrowolski <admin@tastycode.pl>2017-01-08 22:24:56 +0100
commitcac836c793a917686ddfdbdc8b9ccac5c7622853 (patch)
tree87ed7013a8978926a015171cdddfc2acea1b814c
parent82f85333ab408a92bb3815eb778c39bdf0c9e4ea (diff)
downloadlove2d-signage-cac836c793a917686ddfdbdc8b9ccac5c7622853.tar.gz
love2d-signage-cac836c793a917686ddfdbdc8b9ccac5c7622853.tar.bz2
love2d-signage-cac836c793a917686ddfdbdc8b9ccac5c7622853.tar.xz
love2d-signage-cac836c793a917686ddfdbdc8b9ccac5c7622853.zip
Separate config from state, cleanup
-rw-r--r--config.lua11
-rw-r--r--main.lua42
-rw-r--r--screens/cube.lua65
-rw-r--r--screens/misery.lua12
-rw-r--r--screens/misery_thread.lua25
-rw-r--r--screens/time.lua6
-rw-r--r--screens/weather.lua13
7 files changed, 108 insertions, 66 deletions
diff --git a/config.lua b/config.lua
new file mode 100644
index 0000000..d17ed01
--- /dev/null
+++ b/config.lua
@@ -0,0 +1,11 @@
+return {
+ transitionTime = 1,
+ cycleTime = 5,
+ screens = {
+ require 'screens.cube',
+ require 'screens.weather',
+ require 'screens.time',
+ require 'screens.misery',
+ require 'screens.screen1',
+ },
+}
diff --git a/main.lua b/main.lua
index 65321bf..dce898d 100644
--- a/main.lua
+++ b/main.lua
@@ -3,23 +3,9 @@ local inspect = require 'vendor.inspect'
local push = require 'vendor.push'
local lurker = require 'vendor.lurker'
-environment = os.getenv('ENV')
+local config = require('config')
-screens = {
- require 'screens.weather',
- require 'screens.time',
- require 'screens.misery',
- require 'screens.screen1',
-}
-
-state = {
- currentScreen = 1,
- state = 'running',
- cycleTime = 3,
- transitionTime = 1,
- transitioning = false,
- stateCounter = 0,
-}
+environment = os.getenv('ENV')
local gameWidth, gameHeight = 1280, 720
local windowWidth, windowHeight = love.window.getDesktopDimensions()
@@ -37,6 +23,12 @@ function love.resize(w, h)
end
function love.load()
+ state = {
+ currentScreen = 1,
+ transitioning = false,
+ stateCounter = 0,
+ }
+
love.mouse.setVisible( false )
secondaryCanvas = love.graphics.newCanvas(push:getWidth(), push:getHeight())
@@ -44,7 +36,7 @@ function love.load()
fpsGraph = debugGraph:new('fps', 0, 0)
memGraph = debugGraph:new('mem', 0, 30)
- for key, node in ipairs(screens) do
+ for key, node in ipairs(config.screens) do
node.load()
end
@@ -52,8 +44,6 @@ function love.load()
end
function lurker.preswap(f)
- print(f)
-
if f:match('_thread.lua') then
print("Preventing _thread update!")
return false
@@ -70,11 +60,11 @@ function love.draw()
oldw, oldh = love.graphics.getWidth, love.graphics.getHeight
love.graphics.getWidth, love.graphics.getHeight = getw, geth
- screens[state.currentScreen].render()
+ cofnig.screens[state.currentScreen].render()
if state.transitioning then
-- Render next screen into canvas and fade accordingly
- secondaryCanvas:renderTo(screens[state.currentScreen % #screens + 1].render)
+ secondaryCanvas:renderTo(config.screens[state.currentScreen % #config.screens + 1].render)
love.graphics.setColor(255, 255, 255, 255 * (state.stateCounter / state.transitionTime)) -- red, green, blue, opacity (this would be white with 20% opacity)
love.graphics.draw(secondaryCanvas, 0, 0)
end
@@ -93,22 +83,22 @@ function love.draw()
end
function love.update(dt)
- screens[state.currentScreen].update(dt)
+ config.screens[state.currentScreen].update(dt)
if state.transitioning then
- screens[state.currentScreen % #screens + 1].update(dt)
+ config.screens[state.currentScreen % #config.screens + 1].update(dt)
end
state.stateCounter = state.stateCounter + dt
if state.transitioning then
- if state.stateCounter >= state.transitionTime then
+ if state.stateCounter >= config.transitionTime then
state.stateCounter = 0
state.transitioning = false
- state.currentScreen = (state.currentScreen % #screens) + 1
+ state.currentScreen = (state.currentScreen % #config.screens) + 1
end
else
- if state.stateCounter >= state.cycleTime then
+ if state.stateCounter >= config.cycleTime then
state.stateCounter = 0
state.transitioning = true
end
diff --git a/screens/cube.lua b/screens/cube.lua
new file mode 100644
index 0000000..fb40ed8
--- /dev/null
+++ b/screens/cube.lua
@@ -0,0 +1,65 @@
+local node = {}
+local papa = love.graphics.newImage("papa.png")
+local h = 25.0
+local v = {
+ {-h, -h, -h},
+ { h, -h, -h},
+ { h, h, -h},
+ {-h, h, -h},
+ {-h, -h, h},
+ { h, -h, h},
+ { h, h, h},
+ {-h, h, h}
+}
+
+local c = {
+ {0, 1, 31},
+ {1, 2, 31},
+ {2, 3, 31},
+ {3, 0, 31},
+ {0, 4, 34},
+ {1, 5, 34},
+ {2, 6, 34},
+ {3, 7, 34},
+ {4, 5, 32},
+ {5, 6,32},
+ {6, 7,32},
+ {7, 4,32}
+}
+
+local E = 100 * math.tan(2*math.pi/3)
+
+function to2d(p) return p[1] * E / (p[3]+E), p[2] * E / (p[3]+E) end
+
+function node.load() 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 )
+ local w = love.graphics.getWidth() / 2
+ local h = love.graphics.getHeight() / 2
+ local scl = 6
+ for _, p in ipairs(c) do
+ x1, y1 = to2d(v[p[1]+1])
+ x2, y2 = to2d(v[p[2]+1])
+ love.graphics.line(x1 * scl + w, y1 * scl + h, x2 * scl + w, y2 * scl + h)
+ end
+end
+
+function node.update(dt)
+ for _, vec in ipairs(v) do
+ angle = -dt/3
+ nv0 = math.cos(angle) * vec[1] + math.sin(angle) * vec[3]
+ nv2 = -math.sin(angle) * vec[1] + math.cos(angle) * vec[3]
+ vec[1] = nv0
+ vec[3] = nv2
+ angle = dt
+ nv1 = math.cos(angle) * vec[2] - math.sin(angle) * vec[3]
+ nv2 = math.sin(angle) * vec[2] + math.cos(angle) * vec[3]
+ vec[2] = nv1
+ vec[3] = nv2
+ end
+end
+
+return node
diff --git a/screens/misery.lua b/screens/misery.lua
index 28d1151..47221a1 100644
--- a/screens/misery.lua
+++ b/screens/misery.lua
@@ -9,11 +9,8 @@ local updateInterval = 2 * 60
local lastUpdate = 0
local state = nil
-function node.load()
-end
-
-function node.unload()
-end
+function node.load() end
+function node.unload() end
function node.render()
love.graphics.setColor( 0, 0, 0 )
@@ -22,11 +19,12 @@ function node.render()
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.printf(state.entry, 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')
+ local description = 'added by ' .. state.author .. ' on ' .. os.date('%Y/%m/%d %X', state.added)
+ love.graphics.printf(description, 200, love.graphics.getHeight() - 100, love.graphics.getWidth() - 400, 'center')
else
love.graphics.setColor( 255, 255, 255, 80 )
diff --git a/screens/misery_thread.lua b/screens/misery_thread.lua
index 8b0c6d9..416d209 100644
--- a/screens/misery_thread.lua
+++ b/screens/misery_thread.lua
@@ -3,32 +3,11 @@ 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, '&lt;', '<' )
- str = string.gsub( str, '&gt;', '>' )
- str = string.gsub( str, '&quot;', '"' )
- str = string.gsub( str, '&apos;', "'" )
- 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, '&amp;', '&' ) -- Be sure to do this after all others
- return str
-end
+local miseryURL = 'http://oodviewer.q3k.me/randomterm.json/_,'
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))
+ love.thread.getChannel('misery'):push(json.decode(r))
print("Update finished")
else
print("Update failed")
diff --git a/screens/time.lua b/screens/time.lua
index dac73da..7cb5b6e 100644
--- a/screens/time.lua
+++ b/screens/time.lua
@@ -1,11 +1,9 @@
local node = {}
-local socket = require("socket")
local textFont = love.graphics.newFont('fonts/Lato-Thin.ttf', 400)
local smallFont = love.graphics.newFont('fonts/Lato-Light.ttf', 60)
-function node.load()
-end
+function node.load() end
function node.render()
love.graphics.setColor( 0, 0, 0 )
@@ -14,7 +12,7 @@ function node.render()
love.graphics.setColor( 255, 255, 255 )
love.graphics.setFont(textFont);
- love.graphics.printf(os.date('%H:%M'), 0, 120, love.graphics.getWidth(), 'center');
+ love.graphics.printf(os.date('%H:%M'), 0, 100, love.graphics.getWidth(), 'center');
love.graphics.setFont(smallFont);
love.graphics.printf(os.date('%Y/%m/%d'), 0, 575, love.graphics.getWidth(), 'center');
diff --git a/screens/weather.lua b/screens/weather.lua
index 98b2416..c8abd48 100644
--- a/screens/weather.lua
+++ b/screens/weather.lua
@@ -10,17 +10,15 @@ local weatherGlyphs = {
snow = "",
mist = "",
clear = "",
+ clouds = "",
}
local updateInterval = 5 * 60
local lastUpdate = 0
local state = nil
-function node.load()
-end
-
-function node.unload()
-end
+function node.load() end
+function node.unload() end
function node.render()
love.graphics.setColor( 0, 0, 0 )
@@ -31,7 +29,10 @@ function node.render()
if weatherGlyphs[state.weather] then
love.graphics.setFont(weatherFont)
- love.graphics.print(weatherGlyphs[state.weather], 150, 35)
+ love.graphics.print(weatherGlyphs[state.weather], 120, 35)
+ else
+ love.graphics.setFont(smallFont)
+ love.graphics.print(state.weather, 150, love.graphics.getHeight()/2 - 60)
end
love.graphics.setFont(textFont)