summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Dobrowolski <admin@tastycode.pl>2017-04-23 12:48:10 +0200
committerPiotr Dobrowolski <admin@tastycode.pl>2017-04-23 12:48:10 +0200
commit303e342807e967f9a0dc21a08e4d58cf0656437d (patch)
tree3fdad8c6aa953d7115fa7eeade486424f7341610
parentaac427a19c67bf2bca06d4f0e0d9942c47f4d6af (diff)
downloadlove2d-signage-303e342807e967f9a0dc21a08e4d58cf0656437d.tar.gz
love2d-signage-303e342807e967f9a0dc21a08e4d58cf0656437d.tar.bz2
love2d-signage-303e342807e967f9a0dc21a08e4d58cf0656437d.zip
countdown: Very important node
-rw-r--r--nodes/countdown.lua55
1 files changed, 55 insertions, 0 deletions
diff --git a/nodes/countdown.lua b/nodes/countdown.lua
new file mode 100644
index 0000000..19cc965
--- /dev/null
+++ b/nodes/countdown.lua
@@ -0,0 +1,55 @@
+local node = Node:extend('nodes.countdown', {
+ target = 1498780800,
+ description = 'to get the fuck out of here',
+ precision = 3,
+})
+
+local textFont = love.graphics.newFont('fonts/Lato-Thin.ttf', 100)
+local smallFont = love.graphics.newFont('fonts/Lato-Light.ttf', 60)
+
+function node:init(config)
+ node.super.init(self, config)
+end
+
+function timefmt(time, precision)
+ precision = precision or 3
+
+ local p = {
+ {60, "seconds"},
+ {60, "minutes"},
+ {24, "hours"},
+ {7, "days"},
+ {nil, "weeks"},
+ }
+ local parts = {}
+ local v
+ for i, e in ipairs(p) do
+ if e[1] == nil then
+ v = time
+ else
+ v = time % e[1]
+ time = math.floor(time / e[1])
+ end
+
+ if v ~= 0 then
+ table.insert(parts, 1, tostring(v) .. " " .. e[2])
+ end
+ end
+
+ return table.concat(lume.slice(parts, 1, precision), " ")
+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 )
+
+ love.graphics.setFont(textFont);
+ love.graphics.printf(timefmt(math.abs(self.target - os.time()), self.precision), 0, 0.3*love.graphics.getHeight(), love.graphics.getWidth(), 'center');
+
+ love.graphics.setFont(smallFont);
+ love.graphics.printf(self.description, 0, 0.7*love.graphics.getHeight(), love.graphics.getWidth(), 'center');
+end
+
+return node