Added assets manager singleton.
This commit is contained in:
53
src/ui/font.lua
Normal file
53
src/ui/font.lua
Normal file
@@ -0,0 +1,53 @@
|
||||
------------------------------------------------------------------------------
|
||||
-- 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()
|
||||
self.f = love.graphics.newFont(self.file_name, self.size)
|
||||
end
|
||||
|
||||
|
||||
function Font:unload()
|
||||
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
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- Module return
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
return Font
|
||||
Reference in New Issue
Block a user