summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Dobrowolski <admin@tastycode.pl>2017-01-17 17:52:32 +0100
committerPiotr Dobrowolski <admin@tastycode.pl>2017-01-17 17:52:32 +0100
commit61b38314e61881e6eef1d2ffa39792b18d7a4772 (patch)
tree2841301555715c94ff9eb88415a22761d2a7117e
parentffccb380f7c12e20251c8c291c93c86e7f4999ad (diff)
downloadlove2d-signage-61b38314e61881e6eef1d2ffa39792b18d7a4772.tar.gz
love2d-signage-61b38314e61881e6eef1d2ffa39792b18d7a4772.tar.bz2
love2d-signage-61b38314e61881e6eef1d2ffa39792b18d7a4772.tar.xz
love2d-signage-61b38314e61881e6eef1d2ffa39792b18d7a4772.zip
slideshow: Multiple files support
-rw-r--r--nodes/slideshow.lua50
1 files changed, 44 insertions, 6 deletions
diff --git a/nodes/slideshow.lua b/nodes/slideshow.lua
index f6c778b..08e7200 100644
--- a/nodes/slideshow.lua
+++ b/nodes/slideshow.lua
@@ -1,23 +1,61 @@
local node = Node:extend('nodes.slideshow', {})
-local smallFont = love.graphics.newFont('fonts/Lato-Light.ttf', 60)
+local smallFont = love.graphics.newFont('fonts/Lato-Light.ttf', 50)
function node:init(config)
self.super:init(config)
- if (self.fileName ~= Nil) and (love.filesystem.exists( self.fileName )) then
+ self:loadImage()
+end
+
+function node:loadImage()
+ local files = self:processFiles(self.files)
+ if files ~= nil then
+ if self.fileName then
+ self.fileName = files[(lume.find(self.files, self.fileName) or 1) % #self.files + 1]
+ else
+ self.fileName = files[1]
+ end
+ end
+
+ if self.fileName ~= nil and love.filesystem.exists( self.fileName ) then
self.image = love.graphics.newImage( self.fileName )
else
- self.image = Nil
+ self.image = nil
end
end
+function node:processFiles(files)
+ local nFiles = {}
+
+ for _, f in ipairs(files) do
+ if love.filesystem.isDirectory(f) then
+ print(f, "is directory")
+ for _, nf in ipairs(love.filesystem.getDirectoryItems(f)) do
+ print(nf, "hey")
+ if love.filesystem.isFile(f .. "/" .. nf) then
+ nFiles[#nFiles + 1] = f .. "/" .. nf
+ end
+ end
+ else
+ print(f, "is file")
+ nFiles[#nFiles + 1] = f
+ end
+ end
+ print("expanded to: ", inspect(nFiles))
+ return nFiles
+end
+
+function node:beforeEnter()
+ self:loadImage()
+end
+
function node:render()
love.graphics.setColor( 0, 0, 0 )
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
- if self.image == Nil then
+ if self.image == nil then
love.graphics.setFont(smallFont);
- love.graphics.setColor( 255, 255, 255 )
- love.graphics.printf('File not found.', 0, love.graphics.getHeight()/2 , love.graphics.getWidth(), 'center');
+ love.graphics.setColor( 255, 255, 255, 120 )
+ love.graphics.printf('File not found:\n' .. tostring(self.fileName), 0, love.graphics.getHeight()*0.7 , love.graphics.getWidth(), 'center');
else
love.graphics.setColor( 255, 255, 255 )
love.graphics.draw( self.image, love.graphics.getWidth()/2, love.graphics.getHeight()/2, 0, 1, 1, self.image:getWidth()/2, self.image:getHeight()/2 )