main.lua 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. require "imgui"
  2. local ECS = require("ecs.ECS")
  3. local Debug = require("debug_overlay")
  4. local inspect = require 'inspect'
  5. debug_overlay = Debug:new()
  6. local ecs = ECS:new()
  7. local a = {b = 42}
  8. local Position = ecs:create_component("Position", [[
  9. int32_t x;
  10. int32_t y;
  11. ]])
  12. local p = ecs:get_component("Position", 42)
  13. _G.debug_overlay = debug_overlay
  14. _G.ecs = ecs
  15. --
  16. -- LOVE callbacks
  17. --
  18. function love.load(arg)
  19. p = Position:new()
  20. p.x = 2
  21. p.y = 5
  22. debug_overlay.watch:add(p, "x")
  23. debug_overlay.watch:add(p, "y")
  24. end
  25. function love.update(dt)
  26. imgui.NewFrame()
  27. end
  28. function love.draw()
  29. debug_overlay:render()
  30. imgui.Render();
  31. end
  32. function love.quit()
  33. imgui.ShutDown();
  34. end
  35. --
  36. -- User inputs
  37. --
  38. function love.textinput(t)
  39. imgui.TextInput(t)
  40. if not imgui.GetWantCaptureKeyboard() then
  41. -- Pass event to the game
  42. end
  43. end
  44. function love.resize(width, height)
  45. pixel = shine.pixelate()
  46. crt = shine.crt()
  47. glow = shine.glowsimple()
  48. blur = shine.boxblur()
  49. scan = shine.scanlines()
  50. pe = scan:chain(glow):chain(crt)
  51. end
  52. function love.keypressed(key)
  53. imgui.KeyPressed(key)
  54. debug_overlay:keypressed(key)
  55. if not imgui.GetWantCaptureKeyboard() then
  56. -- Pass event to the game
  57. end
  58. end
  59. function love.keyreleased(key)
  60. imgui.KeyReleased(key)
  61. if not imgui.GetWantCaptureKeyboard() then
  62. -- Pass event to the game
  63. end
  64. a = nil
  65. end
  66. function love.mousemoved(x, y)
  67. imgui.MouseMoved(x, y)
  68. if not imgui.GetWantCaptureMouse() then
  69. -- Pass event to the game
  70. end
  71. end
  72. function love.mousepressed(x, y, button)
  73. imgui.MousePressed(button)
  74. if not imgui.GetWantCaptureMouse() then
  75. -- Pass event to the game
  76. end
  77. end
  78. function love.mousereleased(x, y, button)
  79. imgui.MouseReleased(button)
  80. if not imgui.GetWantCaptureMouse() then
  81. -- Pass event to the game
  82. end
  83. end
  84. function love.wheelmoved(x, y)
  85. imgui.WheelMoved(y)
  86. if not imgui.GetWantCaptureMouse() then
  87. -- Pass event to the game
  88. end
  89. end