yoannmoinet / nipplejs

:video_game: A virtual joystick for touch capable interfaces.
https://yoannmoinet.github.io/nipplejs
MIT License
1.78k stars 185 forks source link

catchDistance for static nipple[FEAT] #191

Closed Txori closed 2 years ago

Txori commented 2 years ago

It would be nice if the catchDistance property would also work with a static nipple. This way, clicking the other side of the screen wouldn't activate the nipple.

Txori commented 2 years ago

Something like adding:

if (opts.mode === 'static' && dist > opts.catchDistance) return;

just before:

    // If distance is bigger than nipple's size
    // we clamp the position.
    if (dist > size) {
        dist = size;
        pos = u.findCoord(nipple.position, dist, angle);
    }

is working nicely.

I also replaced:

    if (opts.mode !== 'semi') {
        process(nipple);
    } else {
        // In semi we check the distance of the touch
        // to decide if we have to reset the nipple
        var distance = u.distance(position, nipple.position);
        if (distance <= opts.catchDistance) {
            process(nipple);
        } else {
            nipple.destroy();
            self.processOnStart(evt);
            return;
        }
    }

by:

    switch(opts.mode)
    {
        default:
        process(nipple);
        break;

        case 'semi':
        // In semi we check the distance of the touch
        // to decide if we have to reset the nipple
        var distance = u.distance(position, nipple.position);
        if (distance <= opts.catchDistance) {
            process(nipple);
        } else {
            nipple.destroy();
            self.processOnStart(evt);
            return;
        }
        break;

        case 'static':
        var distance = u.distance(position, nipple.position);
        if (distance <= opts.catchDistance) process(nipple);
        break;
    }

So the nipple won't light up if we click farther than catchDistance.

yoannmoinet commented 2 years ago

Can you follow the template please? Feel free to re-open once the description has been updated following the template.

Txori commented 8 months ago

Bonjour Yoan. Aujourd'hui, j'avais un peu de temps libre et je me suis dit que j'allais mettre à jour nipplejs et enfin pouvoir m'occuper de ma FEAT correctement. Seulement, je n'arrive pas à compiler nipplejs. Quoi que je fasse avec les versions des dépendances, j'obtiens :

glob-parent  <5.1.2
Severity: high
glob-parent vulnerable to Regular Expression Denial of Service in enclosure regex - https://github.com/advisories/GHSA-ww39-953v-wcq6
No fix available
node_modules/watchpack-chokidar2/node_modules/glob-parent
  chokidar  1.0.0-rc1 - 2.1.8
  Depends on vulnerable versions of glob-parent
  node_modules/watchpack-chokidar2/node_modules/chokidar
    watchpack-chokidar2  *
    Depends on vulnerable versions of chokidar
    node_modules/watchpack-chokidar2
      watchpack  1.7.2 - 1.7.5
      Depends on vulnerable versions of watchpack-chokidar2
      node_modules/watchpack

4 high severity vulnerabilities

Est-ce qu'il y a quelque chose de particulier à faire ? Merci