autoCursor: automatic mouse-input handling Library

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
YoungNeer
Party member
Posts: 118
Joined: Wed May 15, 2019 7:49 am

autoCursor: automatic mouse-input handling Library

Post by YoungNeer »

autoCursor is a straight-forward artificial mouse-input-handling module for the beloved LÖVE framework which allows many cool features such as making the cursor follow a particular position rather than jumping from one position to another and of course that's not all.

Sometimes - when developing games with AI - you want the AI-agent to move the mouse on its own (maybe in board-games like chess,tic-tac-toe,etc where such actions adds to the illusion that another player is playing with the user so-to-speak). You can achieve that by using love.mouse:setPosition but the problem is that it would appear very fake because the cursor is not moving to a position rather jumping to a position. So would it not be nice if you had a framework whose sole purpose-in-life was to achieve that functionality in LÖVE2D allowing you to make the mouse follow to a particular position with other features such as changing the speed at which mouse follows a position or automatically clicking mouse when the cursor has reached the position, etc.
This post only looks at some basic usage of autoCursor
For full documentation and usage refer to
https://github.com/YoungNeer/lovelib/tr ... autocursor

Code: Select all

acursor = require 'autoCursor'
function love.load()
    acursor.setDestination(200,200)
    --so here the destination point is (200,200)
end

function love.update(dt)
    acursor.update()
end
Just this small piece of code and the result is awesome - the mouse cursor is moving on its own!!!

Note that the mouse cursor is moving from the source point [default (0,0)] to destination point [here (200,200)] and the speed is set by default - 1 pixel/frame. You can change the speed to custom value in love.load (or other function) function like this-

Code: Select all

    acursor.setSpeed(5,5)
And you can also make automatic clicks i.e. the mouse cursor will click when the destination point is reached using the function

Code: Select all

    acursor.clickOnReachingDest()
By default clicking is done right after destination is reached. However to make it look more natural you can add a pause in between. For example if you want a pause of 0.5 seconds then you can do-

Code: Select all

    acursor.setCODTime(0.5)
And you can also enable automatically dragging i.e. the mouse cursor will click on every frame at the current position of the cursor

Code: Select all

    acursor.enableDragging()
Finally the most powerful feature is loading data from table and executing it so that you don't have to do this clickOnReachingDest(), bla bla every single time.

All you have to do is make a table in a specific format (look at github link to know more) for ex-

Code: Select all

    points={
 	{toX=400,toY=200}
  	{toY=500,drag=true}
    }
 
and then use updateT instead of update:-

Code: Select all

    acursor.updateT(points,dt)
And if you want to change the speed for each operation by adding speedX and speedY to the table. And you can also add a pause after each operation (just to make it look more natural). All these are discussed in the github link

Finally lastly there's VIRTUAL MOUSE EVENTS which you can over-ride on your own for complicated cases. This is discussed in detail in the Example Section in the Github link.
There are some other features as well. Plus demos to get you started, Plus two Card Game examples to show you how you will can autoCursor in actual situations such as AI-MODE for Solitaire, etc games. So head on to the github link ( with Demos )
https://github.com/YoungNeer/lovelib/tr ... autocursor
Last edited by YoungNeer on Tue Jul 23, 2019 7:56 am, edited 3 times in total.
My Github- your contribution is highly appreciated
User avatar
4vZEROv
Party member
Posts: 126
Joined: Wed Jan 02, 2019 8:44 pm

Re: autoCursor: automatic mouse-input handling Library

Post by 4vZEROv »

clickOnDest is at the same time a function and a bool so the function override the value.

Also I don't think you understand the : notation in lua. It make an invisile "self" parameter in the function that represent the object that call the function.
Instead of :

Code: Select all

function fcursor:setPosition(x,y) fcursor.x,fcursor.y=x or 0,y or 0 end
You should write:

Code: Select all

function fcursor:setPosition(x,y) self.x,self.y=x or 0,y or 0 end

Even if writing a library is a good way to improve, I don't think you should share them for others to use if they are of bad quality. Free software doesn't mean no effort software.
User avatar
YoungNeer
Party member
Posts: 118
Joined: Wed May 15, 2019 7:49 am

Re: autoCursor: automatic mouse-input handling Library

Post by YoungNeer »

4vZEROv wrote: Wed Jul 17, 2019 7:47 pm
Also I don't think you understand the : notation in lua. It make an invisile "self" parameter in the function that represent the object that call the function.
Your point is correct but since there will only be once instance of autoCursor i think self and fcursor are synonymous - but yeah good find.

Thanks for pointing that out. I changed the name of function clickOnDest to clickPointOnDest (FYI i'm terrible when it comes to giving decent names to functions)
P.S. The new version has dragging option as well
My Github- your contribution is highly appreciated
User avatar
YoungNeer
Party member
Posts: 118
Joined: Wed May 15, 2019 7:49 am

autoCursor is now even more powerful!!!

Post by YoungNeer »

Okay I don't want to sound all great but autoCursor is now even more powerful! Now you can artificially control the cursor for as long as you want Now it can load data from table so you can even store it on file and later load it and do all sorts of stuff with it
My Github- your contribution is highly appreciated
User avatar
Pyuu
Prole
Posts: 22
Joined: Mon Jul 11, 2016 1:19 am

Re: autoCursor: automatic mouse-input handling Library

Post by Pyuu »

Just a general bit of feedback for code readability, just because a function Can be defined in 1 line of code, doesn't mean it should.
Especially line 3 of autocursor.lua. I need a horizontal scrollbar just to read the full line...

Also, just because you can

Code: Select all

fcursor.x,fcursor.y,fcursor.stage,fcursor.dragging,fcursor.destReached,fcursor.clickOnDest=0,0,0,false,false,false
Doesn't mean you should.

Something like

Code: Select all

fcursor.x = 0
fcursor.y = 0
fcursor.stage = 0
fcursor.dragging = false
fcursor.destReached = false
fcursor.clickOnDest = false
May take 6 lines of code, but my eyes are a lot less overwhelmed looking at it.
User avatar
YoungNeer
Party member
Posts: 118
Joined: Wed May 15, 2019 7:49 am

Re: autoCursor: automatic mouse-input handling Library

Post by YoungNeer »

Pyuu wrote: Fri Jul 19, 2019 7:42 pm Just a general bit of feedback for code readability, just because a function Can be defined in 1 line of code, doesn't mean it should.
Especially line 3 of autocursor.lua. I need a horizontal scrollbar just to read the full line...
Well I am sorry about your eyes but the code that you are referring to is trivial and I thought the reader may understand what it does just by reading the name of the function (which is reset) and even in case if some didn't there was also a prologue comment.
My Github- your contribution is highly appreciated
User avatar
YoungNeer
Party member
Posts: 118
Joined: Wed May 15, 2019 7:49 am

Re: autoCursor: automatic mouse-input handling Library

Post by YoungNeer »

autoCursor UPDATED!!! Please go to the github link to check new features!!
https://github.com/YoungNeer/lovelib/tr ... autocursor
My Github- your contribution is highly appreciated
Post Reply

Who is online

Users browsing this forum: SiENcE and 212 guests