main.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. -- Make sure the shared library can be found through package.cpath before loading the module.
  2. -- For example, if you put it in the LÖVE save directory, you could do something like this:
  3. -- local lib_path = love.filesystem.getSaveDirectory() .. "/libraries"
  4. local lib_path = "./libraries"
  5. local extension = jit.os == "Windows" and "dll" or jit.os == "Linux" and "so" or jit.os == "OSX" and "dylib"
  6. package.cpath = string.format("%s;%s/?.%s", package.cpath, lib_path, extension)
  7. local imgui = require "cimgui"
  8. local sti = require "sti"
  9. local lurker = require "lurker"
  10. lurker.postswap = function(file)
  11. -- reinit game here
  12. map = sti("assets/maps/world.lua")
  13. end
  14. love.load = function()
  15. love.window.setTitle("Cool Video Game")
  16. imgui.love.Init()
  17. local imio = imgui.GetIO()
  18. imio.ConfigFlags = imgui.love.ConfigFlags("NavEnableKeyboard", "DockingEnable")
  19. map = sti("assets/maps/world.lua")
  20. end
  21. love.draw = function()
  22. -- draw game here
  23. local game_canvas = love.graphics.newCanvas()
  24. love.graphics.setCanvas(game_canvas)
  25. map:draw(-60, -20, 8, 8)
  26. love.graphics.setCanvas()
  27. local size = imgui.ImVec2_Float(game_canvas:getDimensions())
  28. local viewport = imgui.GetMainViewport()
  29. imgui.DockSpaceOverViewport(viewport)
  30. -- draw windows here
  31. if imgui.Begin("Game") then
  32. imgui.Image(game_canvas, size)
  33. end
  34. imgui.End()
  35. imgui.ShowDemoWindow()
  36. -- code to render imgui
  37. imgui.Render()
  38. imgui.love.RenderDrawLists()
  39. end
  40. love.update = function(dt)
  41. lurker.update()
  42. imgui.love.Update(dt)
  43. imgui.NewFrame()
  44. map:update(dt)
  45. end
  46. love.mousemoved = function(x, y, ...)
  47. imgui.love.MouseMoved(x, y)
  48. if not imgui.love.GetWantCaptureMouse() then
  49. -- your code here
  50. end
  51. end
  52. love.mousepressed = function(x, y, button, ...)
  53. imgui.love.MousePressed(button)
  54. if not imgui.love.GetWantCaptureMouse() then
  55. -- your code here
  56. end
  57. end
  58. love.mousereleased = function(x, y, button, ...)
  59. imgui.love.MouseReleased(button)
  60. if not imgui.love.GetWantCaptureMouse() then
  61. -- your code here
  62. end
  63. end
  64. love.wheelmoved = function(x, y)
  65. imgui.love.WheelMoved(x, y)
  66. if not imgui.love.GetWantCaptureMouse() then
  67. -- your code here
  68. end
  69. end
  70. love.keypressed = function(key, ...)
  71. imgui.love.KeyPressed(key)
  72. if not imgui.love.GetWantCaptureKeyboard() then
  73. -- your code here
  74. end
  75. end
  76. love.keyreleased = function(key, ...)
  77. imgui.love.KeyReleased(key)
  78. if not imgui.love.GetWantCaptureKeyboard() then
  79. -- your code here
  80. end
  81. end
  82. love.textinput = function(t)
  83. -- only use imgui.love.TextInput when characters are expected
  84. if imgui.love.GetWantCaptureKeyboard() then
  85. imgui.love.TextInput(t)
  86. else
  87. -- your code here
  88. end
  89. end
  90. love.quit = function()
  91. return imgui.love.Shutdown()
  92. end
  93. -- for gamepad support also add the following:
  94. love.joystickadded = function(joystick)
  95. imgui.love.JoystickAdded(joystick)
  96. -- your code here
  97. end
  98. love.joystickremoved = function(joystick)
  99. imgui.love.JoystickRemoved()
  100. -- your code here
  101. end
  102. love.gamepadpressed = function(joystick, button)
  103. imgui.love.GamepadPressed(button)
  104. -- your code here
  105. end
  106. love.gamepadreleased = function(joystick, button)
  107. imgui.love.GamepadReleased(button)
  108. -- your code here
  109. end
  110. -- choose threshold for considering analog controllers active, defaults to 0 if unspecified
  111. local threshold = 0.2
  112. love.gamepadaxis = function(joystick, axis, value)
  113. imgui.love.GamepadAxis(axis, value, threshold)
  114. -- your code here
  115. end