From 304d64b5f932e181d6244028bd9bd07b160286ed Mon Sep 17 00:00:00 2001 From: machenmusik Date: Thu, 20 Apr 2017 22:05:24 -0400 Subject: [PATCH] per separate discussion, use controllers list from system not getGamepadsByPrefix --- src/components/vive-tracker.js | 4 ++-- tests/components/vive-tracker.test.js | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/components/vive-tracker.js b/src/components/vive-tracker.js index 0d82e86c49a..32be848e7df 100644 --- a/src/components/vive-tracker.js +++ b/src/components/vive-tracker.js @@ -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++; } diff --git a/tests/components/vive-tracker.test.js b/tests/components/vive-tracker.test.js index ff3facb3d2e..be437b2b231 100644 --- a/tests/components/vive-tracker.test.js +++ b/tests/components/vive-tracker.test.js @@ -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(); }); }); @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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