Added assets manager singleton.

This commit is contained in:
2025-10-05 17:47:17 -04:00
parent 03b5d1dafb
commit c3d52252c0
11 changed files with 330 additions and 30 deletions

53
src/ui/font.lua Normal file
View 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