Cargo is a simple library I made that automatically loads and caches assets in a LÖVE project. It maps a directory in your project to a Lua table and takes care of loading those assets the first time they are accessed. So if you have an "images" folder with several .png files in it, you can do the following:
local assets = require('cargo').init('/')
function love.draw()
love.graphics.draw(assets.images.monster)
love.graphics.draw(assets.images.player)
-- etc.
end
Notice that you don't have to call love.graphics.newImage on each image to get up and running. It supports nested folders and most common resource types, but you can also define custom resources if needed. The code and documentation are available here:
I often coded such a setup whenever i worked on a project. It greatly improves workflow.
One thing I allways worked towards was dependencies support for files.
a File may have a .ini or other means of declaring dependency on another elsewhere in the mapping. The module would pause loading any dependency seeking files (adding to a queue) and then loop over the queue constantly until all files that can be loaded are loaded. A last loop over checks if a file cannot load because of missing dependency and then informs user. Was perfect for mod/addon implementation where each can depend on an external mod file.
I have a similar project, love2d-assets-loader. It was hell of a fun working on it. I also remember Kikito's awesome love-loader, which is threaded.
Your implementation is short and really neat, as far as I can see. Very nice!
Currently it will keep assets loaded. Cargo could use weak references but then you'd have to manually keep references to anything you want to keep loaded, which is kind of a pain. You may be able to get away with doing something like:
bjornbytes wrote:Currently it will keep assets loaded. Cargo could use weak references but then you'd have to manually keep references to anything you want to keep loaded, which is kind of a pain. You may be able to get away with doing something like: