Skip to content

Commit

Permalink
per separate discussion, use controllers list from system not getGame…
Browse files Browse the repository at this point in the history
…padsByPrefix
  • Loading branch information
machenmusik committed Apr 24, 2017
1 parent 68bd87b commit 304d64b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/components/vive-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ module.exports.Component = registerComponent('vive-tracker', {

checkIfControllerPresent: function () {
var data = this.data;
var gamepads = this.getGamepadsByPrefix(GAMEPAD_ID_PREFIX);
var gamepads = this.el.sceneEl.systems['tracked-controls'].controllers;
var seenIndex = 0;
var controllerIndex = -1;
for (var i = 0; i < gamepads.length; i++) {
if (gamepads[i].hand) { continue; }
if (gamepads[i].id.indexOf(GAMEPAD_ID_PREFIX) < 0 || gamepads[i].hand) { continue; }
if (seenIndex === data.index) { controllerIndex = seenIndex; }
seenIndex++;
}
Expand Down
18 changes: 9 additions & 9 deletions tests/components/vive-tracker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ suite(controllerComponentName, function () {
el.setAttribute(controllerComponentName, '');
el.addEventListener('loaded', function () {
var controllerComponent = el.components[controllerComponentName];
controllerComponent.getGamepadsByPrefix = function () { return controllerComponent.isControllerPresentMockValue ? [{id: 'OpenVR Tracker', index: 0, hand: '', pose: {}}] : []; };
controllerComponent.controllersWhenPresent = [{id: 'OpenVR Tracker', index: 0, hand: '', pose: {}}];
done();
});
});
Expand All @@ -21,7 +21,7 @@ suite(controllerComponentName, function () {
var injectTrackedControlsSpy = this.sinon.spy(controllerComponent, 'injectTrackedControls');
var removeEventListenersSpy = this.sinon.spy(controllerComponent, 'removeEventListeners');
// mock isControllerPresent to return false
controllerComponent.isControllerPresentMockValue = false;
el.sceneEl.systems['tracked-controls'].controllers = [];
// reset so we don't think we've looked before
delete controllerComponent.controllerPresent;
// do the check
Expand All @@ -40,7 +40,7 @@ suite(controllerComponentName, function () {
var injectTrackedControlsSpy = this.sinon.spy(controllerComponent, 'injectTrackedControls');
var removeEventListenersSpy = this.sinon.spy(controllerComponent, 'removeEventListeners');
// mock isControllerPresent to return false
controllerComponent.isControllerPresentMockValue = false;
el.sceneEl.systems['tracked-controls'].controllers = [];
// pretend we've looked before
controllerComponent.controllerPresent = false;
// do the check
Expand All @@ -59,7 +59,7 @@ suite(controllerComponentName, function () {
var injectTrackedControlsSpy = this.sinon.spy(controllerComponent, 'injectTrackedControls');
var removeEventListenersSpy = this.sinon.spy(controllerComponent, 'removeEventListeners');
// mock isControllerPresent to return true
controllerComponent.isControllerPresentMockValue = true;
el.sceneEl.systems['tracked-controls'].controllers = controllerComponent.controllersWhenPresent;
// reset so we don't think we've looked before
delete controllerComponent.controllerPresent;
// do the check
Expand All @@ -78,7 +78,7 @@ suite(controllerComponentName, function () {
var injectTrackedControlsSpy = this.sinon.spy(controllerComponent, 'injectTrackedControls');
var removeEventListenersSpy = this.sinon.spy(controllerComponent, 'removeEventListeners');
// mock isControllerPresent to return true
controllerComponent.isControllerPresentMockValue = true;
el.sceneEl.systems['tracked-controls'].controllers = controllerComponent.controllersWhenPresent;
// pretend we've looked before
controllerComponent.controllerPresent = true;
// do the check
Expand Down Expand Up @@ -117,7 +117,7 @@ suite(controllerComponentName, function () {
var controllerComponent = el.components[controllerComponentName];
var evt;
// mock isControllerPresent to return true
controllerComponent.isControllerPresentMockValue = true;
el.sceneEl.systems['tracked-controls'].controllers = controllerComponent.controllersWhenPresent;
// do the check
controllerComponent.checkIfControllerPresent();
// install event handler listening for thumbstickmoved
Expand All @@ -137,7 +137,7 @@ suite(controllerComponentName, function () {
var controllerComponent = el.components[controllerComponentName];
var evt;
// mock isControllerPresent to return true
controllerComponent.isControllerPresentMockValue = true;
el.sceneEl.systems['tracked-controls'].controllers = controllerComponent.controllersWhenPresent;
// do the check
controllerComponent.checkIfControllerPresent();
// install event handler listening for thumbstickmoved
Expand All @@ -160,7 +160,7 @@ suite(controllerComponentName, function () {
var controllerComponent = el.components[controllerComponentName];
var evt;
// mock isControllerPresent to return true
controllerComponent.isControllerPresentMockValue = true;
el.sceneEl.systems['tracked-controls'].controllers = controllerComponent.controllersWhenPresent;
// do the check
controllerComponent.checkIfControllerPresent();
// install event handler listening for triggerchanged
Expand Down Expand Up @@ -188,7 +188,7 @@ suite(controllerComponentName, function () {
controllerComponent.pause();
controllerComponent.play();
// mock isControllerPresent to return false
controllerComponent.isControllerPresentMockValue = false;
el.sceneEl.systems['tracked-controls'].controllers = [];
// reset everGotGamepadEvent so we don't think we've looked before
delete controllerComponent.everGotGamepadEvent;
// fire emulated gamepaddisconnected event
Expand Down

0 comments on commit 304d64b

Please sign in to comment.