| 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( 1.0, 1.0, 1.0 ) |
| |
| 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 |