Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.
/ Binocles Public archive

Debug your Love2D based game in a simple way.

License

Notifications You must be signed in to change notification settings

Tourahi/Binocles

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Binocles

Debugging Love2D in a simple way.

Binocles is a module based on Monocle https://github.com/kjarvi/monocle. this module gives the ability to easily :

  1. watch variables and complex expressions
  2. watch files and reload them when they change
  3. Reloads the game after any watched files have been changed.
  4. Custom colors
  5. Add Global variables to the listener from the console.
  6. Since the latest updates now you can watch nested tables recursively.

The setup of a basic main.lua file is as follows:

Note : Make sure to run the game from the console or use --console so you can see the listener output.

Binocles = require("Binocles");

local test = 0;
local player = {
  healt = 100,
  x = 10,
  y = 23.3,
  skills_lvl = {
    magic = 2,
    conjuring = 4,
    tinkering = 5,
    sub_skills = {
      magical_tinkering = 4
    }
  }
}

function love.load(arg)
  Binocles();
  -- Watch the FPS
  Binocles:watch("FPS", function() return math.floor(1/love.timer.getDelta()) end);
  Binocles:watch("test",function() return test end);
  Binocles:watch("player",function() return player end);

  Binocles:setPosition(10 ,1);
  Binocles:watchFiles( { 'main.lua' } ); -- Add files so the game reloads if they changed.
  Binocles:addColors( { {0.9,0.5,0.2,1.0} } ) -- Add colors to the pallete.

  --------------------------------------------------------------------------
  -- You can use Binocles.dump to print an object to the console directly.--
  --------------------------------------------------------------------------
end


function love.update(dt)
  Binocles:update();
end

function love.draw()
  Binocles:draw();
end

function love.keypressed(key)
  test = test + 1; -- inc test every time a key is pressed
  Binocles:keypressed(key);
end
  • Result :
    • Screenshot from 2021-03-04 22-47-06

For Moonscript:

 export Binocles = assert require "Binocles"
 with love
   .load = () ->
     Binocles!
     Binocles\watch "FPS",-> love.timer.getFPS!

Options :

  • You can send an options array in the constructor : Binocles(options);
options.active -- if bonocles is active (drawing)
options.customPrinter -- activate printing to console
options.draw_x -- x pos of the Bonocles instance (Used in :draw())
options.draw_y  -- y pos of the Bonocles instance (Used in :draw())
options.printColor -- text color (will be sent to love.graphics.setColor())
options.debugToggle -- Toggle (change the satate of self.active)
options.consoleToggle -- Start the interaction with the listener from the console
options.colorToggle -- toggle to change the printing color
options.watchedFiles  -- files to watch

options.restart --[[
* if true :  Restarts the game without relaunching the executable. This cleanly shuts down the main Lua state instance and creates a brand new one.
* if false : will reload only the watched file if it got modified (ctrl-s).
]]--

Console Example :

Screenshot from 2021-03-04 22-47-06

  • Click "f3" Use "," as a delimiter:

Screenshot from 2021-03-04 22-48-39

Screenshot from 2021-03-04 22-48-52

  • Or you can just give the table name :

Screenshot from 2021-03-09 09-52-33