Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add properties representing entities to controller objects #27

Closed
rwaldron opened this issue Apr 23, 2014 · 1 comment
Closed

Add properties representing entities to controller objects #27

rwaldron opened this issue Apr 23, 2014 · 1 comment

Comments

@rwaldron
Copy link
Contributor

For every non-trivial project that uses dualShock, that I'm currently working (3 on going) I find that I need to create state objects for the controller, eg:

var state = {
  r1: { 
    value: 0
  }
};

controller.on('r1:press', function() {
  state.r1.value = 1;
});

controller.on('r1:release', function() {
  state.r1.value = 0;
});

// ... elsewhere I might have something like this: 

controller.on('left:move', function() {
  // treat r1's value as some kind of modifier
  if (state.r1.value) {
    // when r1 was pressed do stuff
  } else {
    // otherwise do the other stuff
  }
});

It would be nice if this was part of the controller object itself, which would reduce the above example to:

// No other events are needed!

controller.on('left:move', function() {
  // treat r1's value as some kind of modifier
  if (controller.r1.value) {
    // when r1 was pressed do stuff
  } else {
    // otherwise do the other stuff
  }
});

Each "entity" (button, analog stick, etc) should have a corresponding property on the controller object. Each button entity property would be an object that contained at least the following properties: state, value. Each analog entity property would contain axis value properties.

controller { 
  _events: ..., 

  left: {
    x: 0-255,
    y: 0-255
  },
  right: {
    x: 0-255,
    y: 0-255
  },  
  l1: { 
    state: press|hold|release|analog, 
    value: 0|1 
  },
  r1: { 
    state: press|hold|release|analog, 
    value: 0|1 
  },
  l2: { 
    state: press|hold|release|analog, 
    value: 0-255 
  },
  r2: { 
    state: press|hold|release|analog, 
    value: 0-255
  },
  triangle: { 
    state: press|hold|release|analog, 
    value: 0|1 
  },
  circle: { 
    state: press|hold|release|analog, 
    value: 0|1 
  },
  x: { 
    state: press|hold|release|analog, 
    value: 0|1 
  },
  square: { 
    state: press|hold|release|analog, 
    value: 0|1 
  },
  select: { 
    state: press|hold|release|analog, 
    value: 0|1
  },
  start: { 
    state: press|hold|release|analog, 
    value: 0|1
  },  
  leftAnalogBump: { 
    state: press|hold|release|analog, 
    value: 0|1 
  },
  rightAnalogBump: { 
    state: press|hold|release|analog, 
    value: 0|1 
  },
  dpadUp: { 
    state: press|hold|release|analog, 
    value: 0|1 
  },
  dpadRight: { 
    state: press|hold|release|analog, 
    value: 0|1 
  },
  dpadDown: { 
    state: press|hold|release|analog, 
    value: 0|1 
  },
  dpadLeft: { 
    state: press|hold|release|analog, 
    value: 0|1 
  },
  psxButton: { 
    state: press|hold|release|analog, 
    value: 0|1 
  } 
}

If this feature is desirable, I can provide a patch

@rdepena
Copy link
Owner

rdepena commented Apr 23, 2014

if you have to maintain these state objects then its a legitimate use case, note that I would not add the "analog" state to the buttons as it would conflict with the new hold state.

rwaldron added a commit to rwaldron/node-dualshock-controller that referenced this issue Apr 23, 2014
…epenagh-27

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
rwaldron added a commit to rwaldron/node-dualshock-controller that referenced this issue Apr 23, 2014
…epenagh-27

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
rwaldron added a commit to rwaldron/node-dualshock-controller that referenced this issue Apr 23, 2014
…epenagh-27

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
rwaldron added a commit to rwaldron/node-dualshock-controller that referenced this issue Apr 23, 2014
…epenagh-27

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
rwaldron added a commit to rwaldron/node-dualshock-controller that referenced this issue Apr 23, 2014
…epenagh-27

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
rwaldron added a commit to rwaldron/node-dualshock-controller that referenced this issue Apr 23, 2014
…epenagh-27

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
rwaldron added a commit to rwaldron/node-dualshock-controller that referenced this issue Apr 23, 2014
…epenagh-27

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
rdepena pushed a commit that referenced this issue Apr 24, 2014
Add properties representing entities to controller objects. Closes gh-27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants