main.lua 2.2 KB

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