A Simple Resource Library

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
monolifed
Party member
Posts: 188
Joined: Sat Feb 06, 2016 9:42 pm

A Simple Resource Library

Post 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()
Last edited by monolifed on Fri Jun 11, 2021 3:30 am, edited 1 time in total.
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: A Simple Resource Library

Post by Gunroar:Cannon() »

Looks nice!
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 14 guests