blob: c5f9530593d75e378b78f179b0c5a59615164768 [file] [log] [blame]
Serge Bazanski18c1a262022-07-07 14:24:53 +02001local node = Node:extend('nodes.countdown', {
2 target = 1498780800,
3 description = 'to get the fuck out of here',
4 precision = 3,
5})
6
7local textFont = love.graphics.newFont('fonts/Lato-Thin.ttf', 100)
8local smallFont = love.graphics.newFont('fonts/Lato-Light.ttf', 60)
9
10function node:init(config)
11 node.super.init(self, config)
12end
13
14function timefmt(time, precision)
15 precision = precision or 3
16
17 local p = {
18 {60, "seconds"},
19 {60, "minutes"},
20 {24, "hours"},
21 {7, "days"},
22 {nil, "weeks"},
23 }
24 local parts = {}
25 local v
26 for i, e in ipairs(p) do
27 if e[1] == nil then
28 v = time
29 else
30 v = time % e[1]
31 time = math.floor(time / e[1])
32 end
33
34 if v ~= 0 then
35 table.insert(parts, 1, tostring(v) .. " " .. e[2])
36 end
37 end
38
39 return table.concat(lume.slice(parts, 1, precision), " ")
40end
41
42function node:render()
43 love.graphics.setColor( 0, 0, 0 )
44 love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
45
46 love.graphics.setColor( 1.0, 1.0, 1.0 )
47
48 love.graphics.setFont(textFont);
49 love.graphics.printf(timefmt(math.abs(self.target - os.time()), self.precision), 0, 0.3*love.graphics.getHeight(), love.graphics.getWidth(), 'center');
50
51 love.graphics.setFont(smallFont);
52 love.graphics.printf(self.description, 0, 0.7*love.graphics.getHeight(), love.graphics.getWidth(), 'center');
53end
54
55return node