Page 1 of 1

A Simple Resource Library

Posted: Tue Mar 30, 2021 7:38 pm
by monolifed
https://github.com/monolifed/lua-modules -> simple_cache.lua

example:

Code: Select all

local asrl = require("asrl")
local cache = asrl.newCache()
cache:addLoader("registerImage", love.graphics.newImage)

-- sometimes first entry is not a unique key so we need a key function
local function font_keyfunc(name, pt)
	if type(name) == "string" then return ("%s_%s"):format(name, pt) end
	if type(name) == "number" then return ("%s_%s"):format("default_font", name) end
end
cache:addLoader("registerFont",  love.graphics.newFont, font_keyfunc)

cache:addLoader("registerAudio", love.audio.newSource)
...
cache:invalidate()
...
local font = cache:registerFont("assets/somefont.ttf", 16)
...
cache:cleanup()

Re: A Simple Resource Library

Posted: Thu Jun 03, 2021 12:35 pm
by Gunroar:Cannon()
Looks nice!