Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sandwich = {
- _VERSION = 'sandwich v1.0.0',
- _DESCRIPTION = 'A LÖVE2D resource manager',
- _URL = 'http://github.com/superzazu/sandwich.lua',
- _LICENSE = [[
- ... (license text)
- ]]
- _DOC = [[
- sandwich.addType(type, callback)
- | type: string
- | callback: function(string, ...)
- ]]
- }
- local resources = {}
- local callbacks = {
- image = function(resource_name, ...)
- love.graphics.newImage(resource_name)
- end,
- quad = function(resource_name, ...)
- love.graphics.newQuad(...)
- end,
- sound = function(resource_name, ...)
- love.audio.newSource(resource_name, 'static'),
- end,
- audio = function(resource_name, ...)
- love.audio.newSource(resource_name, 'shared')
- end
- }
- sandwich.addType = function(type, callback)
- callbacks[type] = callback
- end
- sandwich.addResource = function(type, resource_name, ...)
- if not resources[type] then
- resources[type] = {}
- end
- if not resources[type][resource_name] then
- resources[type][resource_name] = callbacks[type](resource_name, ...)
- end
- end
- sandwich.get = function(type, resource_name)
- return resources[type][resource_name]
- end
- return sandwich
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement