npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-pad

v0.0.15

Published

Game controllers for node

Downloads

24

Readme

node-stick

Is a library for using game controllers with nodejs. Currently only the dualshock 3 is supported, but support for xbox360 controller is planned for a future release.

##Installation Easy install using npm

npm install node-pad

Beware it uses a third party node module with c++ bindings to communicate with hid devices and is not guaranteed to work on your system.

Preview

First, some taster code. Just to blow your mind.

var dualshock3 = require('node-pad').dualshock3

dualshock3.on('connect', function(controller) {

  var player = game.createPlayer()
  
  controller.on('join', function(){
    
    player.joinGame()

    controller.lthumb.on('move', function(event){
      player.moveInDirection({
        x: event.x,
        y: event.y
      })
    })

    controller.lthumb.on('release', function(){
      player.stopMoving()
    })

    controller.rthumb.on('move', function(event){
      player.updateCameraDirection({
        x: event.x,
        y: event.y
      })
    })
    
    controller.rthumb.on('release', function(){
      player.stopCamera()
    })
    
    controller.r2.on('press', function(){
      player.fireWeapon()
    })
    
    controller.l2.on('press', function(pressure){
      player.throwGrenade(pressure)
    })
    
    controller.cross.on('press', function(pressure){
      player.jump(pressure)
    })
    
    controller.l3.on('press', function(){
      player.enterCrouchingPosition()
    })
    
    controller.l3.on('release', function(){
      player.leaveCrouchingPosition()
    })

  })

  controller.on('disconnect', function(){
    player.exitGame()
  })
})

Connecting controllers

The nodepad module fires a connect event on the coresponding controller type when a new controller is plugged in.

nodepad.dualshock3.on('connect', function(controller){
  // controller object is available
})

In the case of the dualshock3 there is an additional event join that is fired when a controlle is connected and has started to send data. Sometimes it starts right away and sometimes it waits for the ps button to get pressed. This has to be figured out in a future release.

nodepad.dualshock3.on('connect', function(controller){
  controller.on('join', function(){
    // Bind events
  })
})

controller object

The controller object has buttons, dpads and thumbs(sticks) that you can bind events to. What kind of elements it has depend on the controller layout and naming.

dualshock3

The dualshock3 controller object has this layout:

cross, square, circle, triangle

These buttons are pressure sensitive and emits the followin events:

controller.button.emit('press', pressure)
controller.button.emit('release')
controller.button.emit('pressurechange', newpressure)

r1, r2, l1, l2

These buttons are pressure sensitive and emits the followin events:

controller.button.emit('press', pressure)
controller.button.emit('release')
controller.button.emit('pressurechange', newpressure)

r3, l3

These are buttons and emits the followin events:

controller.button.emit('press', pressure)
controller.button.emit('release')

dpad.up, dpad.down, dpap.right, dpad.left

These buttons are pressure sensitive and emits the followin events:

controller.dpad.direction.emit('press', pressure)
controller.dpad.direction.emit('release')
controller.dpad.direction.emit('pressurechange', newpressure)

lthumb, rthumb

These are thumbs(sticks) and emits the folowing events

controller.thumb.emit('move', event)
controller.thumb.emit('release')      //This is emited when the stick returns from and off to a centered position
controller.thumb.emit('move:x', x)
controller.thumb.emit('move:y', y)

start, select

These are buttons and emits the followin events:

controller.button.emit('press', pressure)
controller.button.emit('release')