goo.lua 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. goo = {}
  2. goo.instances = {}
  3. goo.fathers = {}
  4. GOO_PATH = 'goo/'
  5. function goo.newobject( name, base )
  6. local object = {}
  7. local base = base or 'base'
  8. object.name = name
  9. object.base = goo[base]
  10. object.state = nil
  11. object.meta = { __index = object }
  12. setmetatable( object, { __index = goo[base] } )
  13. goo[name] = object
  14. return object
  15. end
  16. function goo.newinstance( instance, parent )
  17. table.insert( goo.instances, instance )
  18. if not parent then table.insert( goo.fathers, instance ) end
  19. end
  20. function goo.newstate( name )
  21. return {}
  22. end
  23. function goo.load()
  24. -- Load the base object
  25. goo.base = require( GOO_PATH .. 'base' )
  26. -- Load all objects
  27. local object_list = love.filesystem.enumerate( 'goo/objects' )
  28. for k,v in pairs( object_list ) do
  29. local name = v:gsub( '.lua', '' )
  30. require( GOO_PATH .. 'objects/'..v )
  31. end
  32. -- Set skin
  33. goo.setskin( 'default' )
  34. end
  35. function goo.setskin( skinname )
  36. GOO_SKINPATH = string.format( '%s/skins/%s/', GOO_PATH, skinname )
  37. goo.skin, goo.fonts = require( GOO_SKINPATH .. 'style.lua' )
  38. end
  39. function goo.update(dt)
  40. for k, instance in ipairs( goo.instances ) do instance:update(dt) end
  41. end
  42. function goo.draw()
  43. for k, father in ipairs( goo.fathers ) do
  44. love.graphics.push()
  45. love.graphics.translate( father.x, father.y )
  46. father:drawall()
  47. love.graphics.pop()
  48. end
  49. end
  50. function goo.mousepressed(x,y,button)
  51. for i = #goo.instances, 1, -1 do
  52. local instance = goo.instances[i]
  53. if instance.hoverstate == 'over' then instance:mousepressed(x,y,button) end
  54. end
  55. end
  56. function goo.mousereleased(x,y,button)
  57. for i = #goo.instances, 1, -1 do
  58. local instance = goo.instances[i]
  59. instance:mousereleased(x,y,button)
  60. end
  61. end
  62. function goo.keypressed(key,unicode)
  63. for k, instance in ipairs( goo.instances ) do instance:keypressed(key,unicode) end
  64. end
  65. function goo.keyreleased(key,unicode)
  66. for k, instance in ipairs( goo.instances ) do instance:keyreleased(key,unicode) end
  67. end