Git Product home page Git Product logo

binocles's Introduction

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

binocles's People

Contributors

tourahi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.