main.lua 2.1 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. debug_overlay.console:debug("Have fun!")
  20. p = Position:new()
  21. p.x = 2
  22. p.y = 5
  23. debug_overlay.watch:add(p, "x")
  24. debug_overlay.watch:add(p, "y")
  25. end
  26. function love.update(dt)
  27. imgui.NewFrame()
  28. end
  29. function love.draw()
  30. debug_overlay:render()
  31. imgui.Render();
  32. end
  33. function love.quit()
  34. imgui.ShutDown();
  35. end
  36. --
  37. -- User inputs
  38. --
  39. function love.textinput(t)
  40. imgui.TextInput(t)
  41. if not imgui.GetWantCaptureKeyboard() then
  42. -- Pass event to the game
  43. end
  44. end
  45. function love.resize(width, height)
  46. pixel = shine.pixelate()
  47. crt = shine.crt()
  48. glow = shine.glowsimple()
  49. blur = shine.boxblur()
  50. scan = shine.scanlines()
  51. pe = scan:chain(glow):chain(crt)
  52. end
  53. function love.keypressed(key)
  54. imgui.KeyPressed(key)
  55. debug_overlay:keypressed(key)
  56. if not imgui.GetWantCaptureKeyboard() then
  57. -- Pass event to the game
  58. end
  59. end
  60. function love.keyreleased(key)
  61. imgui.KeyReleased(key)
  62. if not imgui.GetWantCaptureKeyboard() then
  63. -- Pass event to the game
  64. end
  65. a = nil
  66. end
  67. function love.mousemoved(x, y)
  68. imgui.MouseMoved(x, y)
  69. if not imgui.GetWantCaptureMouse() then
  70. -- Pass event to the game
  71. end
  72. end
  73. function love.mousepressed(x, y, button)
  74. imgui.MousePressed(button)
  75. if not imgui.GetWantCaptureMouse() then
  76. -- Pass event to the game
  77. end
  78. end
  79. function love.mousereleased(x, y, button)
  80. imgui.MouseReleased(button)
  81. if not imgui.GetWantCaptureMouse() then
  82. -- Pass event to the game
  83. end
  84. end
  85. function love.wheelmoved(x, y)
  86. imgui.WheelMoved(y)
  87. if not imgui.GetWantCaptureMouse() then
  88. -- Pass event to the game
  89. end
  90. end