editor.lua 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. local Editor = class()
  2. function Editor:load(options)
  3. self.options = options
  4. self.grid = app.ui.editor.grid()
  5. self.event = app.util.event()
  6. self.view = app.ui.editor.view()
  7. self.effects = app.media.effects()
  8. self.effects:remove('deathDesaturate')
  9. self.collision = app.logic.collision()
  10. self.map = app.logic.map()
  11. self.dragger = app.ui.editor.dragger()
  12. self.scaler = app.ui.editor.scaler()
  13. self.selector = app.ui.editor.selector()
  14. self.deletor = app.ui.editor.deletor()
  15. self.saver = app.ui.editor.saver()
  16. self.debug = app.ui.editor.debug()
  17. self.widgets = {self.grid}
  18. self.components = {
  19. self.view,
  20. self.effects,
  21. self.dragger,
  22. self.scaler,
  23. self.deletor,
  24. self.selector,
  25. self.saver,
  26. self.map,
  27. self.debug
  28. }
  29. table.each(self.widgets, function(widget)
  30. if widget.draw and widget.depth then self.view:register(widget) end
  31. end)
  32. end
  33. function Editor:update()
  34. table.each(self.components, f.egoexe('update'))
  35. table.each(self.widgets, f.egoexe('update'))
  36. end
  37. function Editor:draw()
  38. self.view:draw()
  39. end
  40. function Editor:keypressed(key)
  41. table.each(self.components, f.egoexe('keypressed', key))
  42. table.each(self.widgets, f.egoexe('keypressed', key))
  43. end
  44. function Editor:keyreleased(key)
  45. if key == 'escape' then
  46. app.util.context:remove(ctx)
  47. app.util.context:add(app.context.menu)
  48. end
  49. end
  50. function Editor:textinput(key)
  51. table.each(self.components, f.egoexe('textinput', key))
  52. table.each(self.widgets, f.egoexe('textinput', key))
  53. end
  54. function Editor:mousepressed(x, y, button)
  55. table.each(self.components, f.egoexe('mousepressed', x, y, button))
  56. table.each(self.widgets, f.egoexe('mousepressed', x, y, button))
  57. end
  58. function Editor:mousereleased(x, y, button)
  59. table.each(self.components, f.egoexe('mousereleased', x, y, button))
  60. table.each(self.widgets, f.egoexe('mousereleased', x, y, button))
  61. end
  62. function Editor:resize()
  63. self.view:resize()
  64. end
  65. return Editor