Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions src/components/daydream-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ module.exports.Component = registerComponent('daydream-controls', {
this.checkIfControllerPresent = bind(this.checkIfControllerPresent, this);
this.removeControllersUpdateListener = bind(this.removeControllersUpdateListener, this);
this.onAxisMoved = bind(this.onAxisMoved, this);
this.onGamepadConnectionEvent = bind(this.onGamepadConnectionEvent, this);
},

init: function () {
Expand All @@ -58,7 +57,6 @@ module.exports.Component = registerComponent('daydream-controls', {
this.onButtonTouchEnd = function (evt) { onButtonEvent(evt.detail.id, 'touchend', self); };
this.onAxisMoved = bind(this.onAxisMoved, this);
this.controllerPresent = false;
this.everGotGamepadEvent = false;
this.lastControllerCheck = 0;
this.bindMethods();
this.checkControllerPresentAndSetup = checkControllerPresentAndSetup; // To allow mock.
Expand Down Expand Up @@ -93,27 +91,14 @@ module.exports.Component = registerComponent('daydream-controls', {
this.checkControllerPresentAndSetup(this, GAMEPAD_ID_PREFIX, {hand: this.data.hand});
},

onGamepadConnectionEvent: function (evt) {
this.everGotGamepadEvent = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, per @vincentfretin's comment, there are a few more:

src/components/gearvr-controls.js
59:    this.everGotGamepadEvent = false;

tests/components/daydream-controls.test.js
198:      // Reset everGotGamepadEvent so we don't think we've looked before.
199:      delete component.everGotGamepadEvent;

tests/components/gearvr-controls.test.js
211:      // Reset everGotGamepadEvent so we don't think we've looked before.
212:      delete component.everGotGamepadEvent;

tests/components/oculus-touch-controls.test.js
166:      // Reset everGotGamepadEvent so we don't think we've looked before.
167:      delete component.everGotGamepadEvent;

tests/components/vive-controls.test.js
194:      // Reset everGotGamepadEvent to mock not looked before.
195:      delete component.everGotGamepadEvent;

tests/components/windows-motion-controls.test.js
533:      // Reset everGotGamepadEvent so we don't think we've looked before.
534:      delete component.everGotGamepadEvent;

// Due to an apparent bug in FF Nightly
// where only one gamepadconnected / disconnected event is fired,
// which makes it difficult to handle in individual controller entities,
// we no longer remove the controllersupdate listener as a result.
this.checkIfControllerPresent();
},

play: function () {
this.checkIfControllerPresent();
this.addControllersUpdateListener();
window.addEventListener('gamepadconnected', this.onGamepadConnectionEvent, false);
window.addEventListener('gamepaddisconnected', this.onGamepadConnectionEvent, false);
},

pause: function () {
this.removeEventListeners();
this.removeControllersUpdateListener();
window.removeEventListener('gamepadconnected', this.onGamepadConnectionEvent, false);
window.removeEventListener('gamepaddisconnected', this.onGamepadConnectionEvent, false);
},

injectTrackedControls: function () {
Expand Down Expand Up @@ -141,7 +126,7 @@ module.exports.Component = registerComponent('daydream-controls', {
},

onControllersUpdate: function () {
if (!this.everGotGamepadEvent) { this.checkIfControllerPresent(); }
this.checkIfControllerPresent();
},

onModelLoaded: function (evt) {
Expand Down
1 change: 0 additions & 1 deletion src/components/gearvr-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ module.exports.Component = registerComponent('gearvr-controls', {
this.onButtonTouchEnd = function (evt) { onButtonEvent(evt.detail.id, 'touchend', self); };
this.onAxisMoved = bind(this.onAxisMoved, this);
this.controllerPresent = false;
this.everGotGamepadEvent = false;
this.lastControllerCheck = 0;
this.bindMethods();
this.checkControllerPresentAndSetup = checkControllerPresentAndSetup; // To allow mock.
Expand Down
30 changes: 1 addition & 29 deletions tests/components/daydream-controls.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global assert, process, setup, suite, test, Event */
/* global assert, process, setup, suite, test */
var entityFactory = require('../helpers').entityFactory;

suite('daydream-controls', function () {
Expand Down Expand Up @@ -177,34 +177,6 @@ suite('daydream-controls', function () {
});
});

suite('gamepaddisconnected', function () {
/**
* Due to an apparent bug in FF Nightly
* where only one gamepadconnected / disconnected event is fired,
* which makes it difficult to handle in individual controller entities,
* we no longer remove the controllersupdate listener as a result.
*/
test('checks present on gamepaddisconnected', function () {
var el = this.el;
var component = el.components['daydream-controls'];
var checkIfControllerPresentSpy = this.sinon.spy(component, 'checkIfControllerPresent');
// Because checkIfControllerPresent may be used in bound form, bind and reinstall.
component.checkIfControllerPresent = component.checkIfControllerPresent.bind(component);
component.pause();
component.play();

el.sceneEl.systems['tracked-controls'].controllers = [];

// Reset everGotGamepadEvent so we don't think we've looked before.
delete component.everGotGamepadEvent;

// Fire emulated gamepaddisconnected event.
window.dispatchEvent(new Event('gamepaddisconnected'));

assert.ok(checkIfControllerPresentSpy.called);
});
});

suite('armModel', function () {
function makePresent (el) {
var component = el.components['daydream-controls'];
Expand Down
27 changes: 1 addition & 26 deletions tests/components/gearvr-controls.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global assert, process, setup, suite, test, Event */
/* global assert, process, setup, suite, test */
var entityFactory = require('../helpers').entityFactory;

suite('gearvr-controls', function () {
Expand Down Expand Up @@ -191,31 +191,6 @@ suite('gearvr-controls', function () {
});
});

suite('gamepaddisconnected', function () {
/**
* Due to an apparent bug in FF Nightly
* where only one gamepadconnected / disconnected event is fired,
* which makes it difficult to handle in individual controller entities,
* we no longer remove the controllersupdate listener as a result.
*/
test('check present on gamepaddisconnected', function () {
var el = this.el;
var component = el.components['gearvr-controls'];
var checkIfControllerPresentSpy = this.sinon.spy(component, 'checkIfControllerPresent');
// Because checkIfControllerPresent may be used in bound form, bind and reinstall.
component.checkIfControllerPresent = component.checkIfControllerPresent.bind(component);
component.pause();
component.play();

el.sceneEl.systems['tracked-controls'].controllers = [];
// Reset everGotGamepadEvent so we don't think we've looked before.
delete component.everGotGamepadEvent;
// Fire emulated gamepaddisconnected event.
window.dispatchEvent(new Event('gamepaddisconnected'));
assert.ok(checkIfControllerPresentSpy.called);
});
});

suite('armModel', function () {
function makePresent (el) {
var component = el.components['gearvr-controls'];
Expand Down
24 changes: 1 addition & 23 deletions tests/components/oculus-touch-controls.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global assert, process, setup, suite, test, Event */
/* global assert, process, setup, suite, test */
var entityFactory = require('../helpers').entityFactory;

suite('oculus-touch-controls', function () {
Expand Down Expand Up @@ -149,26 +149,4 @@ suite('oculus-touch-controls', function () {
el.emit('buttonchanged', {id: 1, state: {value: 0.5, pressed: true, touched: true}});
});
});

suite('gamepaddisconnected', function () {
/**
* In FF Nightly, only one gamepadconnected/disconnected event is fired,
* which makes it difficult to handle in individual controller entities.
* We no longer remove the controllersupdate listener as a result.
*/
test('checks if present on gamepaddisconnected event', function () {
var checkIfControllerPresentSpy = this.sinon.spy(component, 'checkIfControllerPresent');
// Because checkIfControllerPresent may be used in bound form, bind and reinstall.
component.checkIfControllerPresent = component.checkIfControllerPresent.bind(component);
component.pause();
component.play();
// Mock isControllerPresent to return false.
// Reset everGotGamepadEvent so we don't think we've looked before.
delete component.everGotGamepadEvent;
// Fire emulated gamepaddisconnected event.
window.dispatchEvent(new Event('gamepaddisconnected'));

assert.ok(checkIfControllerPresentSpy.called);
});
});
});
24 changes: 1 addition & 23 deletions tests/components/vive-controls.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global assert, Event, process, setup, suite, test, THREE */
/* global assert, process, setup, suite, test, THREE */
var entityFactory = require('../helpers').entityFactory;

suite('vive-controls', function () {
Expand Down Expand Up @@ -177,28 +177,6 @@ suite('vive-controls', function () {
});
});

suite('gamepaddisconnected', function () {
/*
Apparent bug in FF Nightly where only one gamepadconnected/disconnected event is
fired which makes it difficult to handle in individual controller entities. We no
longer remove the controllersupdate listener as a result.
*/
test('checks if controller present on gamepaddisconnected', function () {
var checkIfControllerPresentSpy = this.sinon.spy(component, 'checkIfControllerPresent');
// Because checkIfControllerPresent may be used in bound form, bind and reinstall.
component.checkIfControllerPresent = component.checkIfControllerPresent.bind(component);
component.pause();
component.play();

controlsSystem.controllers = [];
// Reset everGotGamepadEvent to mock not looked before.
delete component.everGotGamepadEvent;
// Fire emulated gamepaddisconnected event.
window.dispatchEvent(new Event('gamepaddisconnected'));
assert.ok(checkIfControllerPresentSpy.called);
});
});

suite('model', function () {
test.skip('loads', function (done) {
component.addEventListeners();
Expand Down
22 changes: 1 addition & 21 deletions tests/components/windows-motion-controls.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global assert, process, setup, suite, test, THREE, Event */
/* global assert, process, setup, suite, test, THREE */
var entityFactory = require('../helpers').entityFactory;

suite('windows-motion-controls', function () {
Expand Down Expand Up @@ -521,26 +521,6 @@ suite('windows-motion-controls', function () {
}
});

suite('gamepaddisconnected', function () {
test('checks if present on gamepaddisconnected event', function (done) {
var checkIfControllerPresentSpy = this.sinon.spy(component, 'checkIfControllerPresent');
// Because checkIfControllerPresent may be used in bound form, using this.bind,
// we need to re-create the binding and re-attach the event listeners for our spy to work
component.checkIfControllerPresent = component.checkIfControllerPresent.bind(component);
// Pause and resume to remove and re-attach the event listeners, with our spy.
component.pause();
component.play();
// Reset everGotGamepadEvent so we don't think we've looked before.
delete component.everGotGamepadEvent;
// Fire emulated gamepaddisconnected event.
window.dispatchEvent(new Event('gamepaddisconnected'));

assert.ok(checkIfControllerPresentSpy.called, 'checkIfControllerPresent not called in response to gamepaddisconnected');

setTimeout(() => { done(); });
});
});

suite('setModelVisibility', function () {
test('shows model', function () {
var component = el.components['windows-motion-controls'];
Expand Down