Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.17 KB | None | 0 0
  1. local sandwich = {
  2.   _VERSION     = 'sandwich v1.0.0',
  3.   _DESCRIPTION = 'A LÖVE2D resource manager',
  4.   _URL         = 'http://github.com/superzazu/sandwich.lua',
  5.   _LICENSE     = [[
  6.     ... (license text)
  7.   ]]
  8.   _DOC         = [[
  9.         sandwich.addType(type, callback)
  10.             | type: string
  11.             | callback: function(string, ...)
  12.   ]]
  13. }
  14.  
  15. local resources = {}
  16.  
  17. local callbacks = {
  18.     image = function(resource_name, ...)
  19.         love.graphics.newImage(resource_name)
  20.     end,
  21.    
  22.     quad = function(resource_name, ...)
  23.         love.graphics.newQuad(...)
  24.     end,
  25.    
  26.     sound = function(resource_name, ...)
  27.         love.audio.newSource(resource_name, 'static'),
  28.     end,
  29.    
  30.     audio = function(resource_name, ...)
  31.         love.audio.newSource(resource_name, 'shared')
  32.     end
  33. }
  34.  
  35. sandwich.addType = function(type, callback)
  36.     callbacks[type] = callback
  37. end
  38.  
  39. sandwich.addResource = function(type, resource_name, ...)
  40.     if not resources[type] then
  41.         resources[type] = {}
  42.     end
  43.    
  44.     if not resources[type][resource_name] then
  45.         resources[type][resource_name] = callbacks[type](resource_name, ...)
  46.     end
  47. end
  48.  
  49. sandwich.get = function(type, resource_name)
  50.     return resources[type][resource_name]
  51. end
  52.  
  53. return sandwich
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement