------------------------------------------------------------------------------
-- Imports
------------------------------------------------------------------------------

local love       = require 'love'
local make_class = require 'src.utils.classes'
local Asset      = require 'src.utils.asset'

------------------------------------------------------------------------------
-- Class definitions
------------------------------------------------------------------------------

-- Font is a simple wrapper around Löve's own Font class to allow for
-- easy loading/unloading and automatically checking if it's is valid
-- before using it.
local Font = make_class(Asset)


------------------------------------------------------------------------------
-- Class methods
------------------------------------------------------------------------------

function Font:_init(file_name, size)
    self.file_name = string.format('assets/%s', file_name)
    self.size = (size ~= nil and size) or 20
end


function Font:load()
    if not self:is_loaded() then
        self.f = love.graphics.newFont(self.file_name, self.size)
    end
end


function Font:unload()
    self.f = nil
end


function Font:is_loaded()
    return self.f ~= nil
end


function Font:set()
    if self.f ~= nil then love.graphics.setFont(self.f) end
end


function Font:unset()
    love.graphics.setFont()
end


function Font:get_width(text)
    if self.f ~= nil then return self.f:getWidth(text) else return nil end
end


function Font:get_height(text)
    if self.f ~= nil then return self.f:getHeight(text) else return nil end
end


------------------------------------------------------------------------------
-- Module return
------------------------------------------------------------------------------

return Font
