main.lua 2.2 KB

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