jcmoyer / hug

A utility library for LÖVE with a focus on simplicity
Apache License 2.0
2 stars 1 forks source link

Implement a resource model #23

Open jcmoyer opened 8 years ago

jcmoyer commented 8 years ago

Problems this would solve:

resource 'block' {
  type = 'image', filename = 'assets/block.png'
}

-- maybe this would be better? it adds to the overall implementation complexity though
image 'block' {
  filename = 'assets/block.png'
}

...

-- perhaps something like this to load resource scripts
local resources = resource.dofile('resource_list.lua')
-- though as with animation DSL this could be done without loading a file:
local resources = resource.dsl(function()
  resource 'block' {
    type = 'image', filename = 'assets/block.png'
  }
end)

-- indexing this theoretical table would automatically load the image and return it, probably via
-- the lazy module
local x = resources['block']

-- Without DSL:
local rcm = rcmanager.new()
local block = rcm:addresource('block')
block:attribute('type', 'image')
block:attribute('filename', 'assets/block.png')
local x = rcm['block'] ?
-- there probably needs to be an additional layer between creation and access to facilitate
-- resource chains

Concepts