init.lua 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. local class, object = require("class"), require("class.object")
  2. local Console = require("debug_overlay.console")
  3. local Graphs = require("debug_overlay.graphs")
  4. local Watch = require("debug_overlay.watch")
  5. local ECSDebug = require("debug_overlay.ecs")
  6. require("imgui")
  7. local Debug = class(object)
  8. function Debug:init()
  9. self.debug_menus = {
  10. Debug = {
  11. Console = Console:new(),
  12. Watch = Watch:new(),
  13. Graphs = Graphs:new(),
  14. },
  15. ECS = {
  16. ECS = ECSDebug:new()
  17. }
  18. }
  19. self.console = self.debug_menus.Debug.Console
  20. self.watch = self.debug_menus.Debug.Watch
  21. end
  22. function Debug:render()
  23. self.debug_menus.Debug.Graphs:update()
  24. if imgui.BeginMainMenuBar() then
  25. for menu,windows in pairs(self.debug_menus) do
  26. -- Menu
  27. if imgui.BeginMenu(menu) then
  28. for k,v in pairs(windows) do
  29. if imgui.MenuItem(k, v.shortcut, v.visible) then
  30. v:toggle()
  31. end
  32. end
  33. imgui.EndMenu()
  34. end
  35. end
  36. imgui.EndMainMenuBar()
  37. for menu,windows in pairs(self.debug_menus) do
  38. for k, window in pairs(windows) do
  39. if window.visible then
  40. window:render()
  41. end
  42. end
  43. end
  44. end
  45. end
  46. function Debug:keypressed(key)
  47. for _, windows in pairs(self.debug_menus) do
  48. for __, window in pairs(windows) do
  49. if window.shortcut and key == window.shortcut then
  50. window:toggle()
  51. end
  52. end
  53. end
  54. end
  55. return Debug