Parametric date&time format i time.node

master
Bartłomiej Wąs 2017-01-25 21:31:51 +01:00
parent 46f60205a5
commit e86f411dfc
1 changed files with 8 additions and 2 deletions

View File

@ -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