Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
allow trackpad touch events, but not color change for vive-controls
  • Loading branch information
ngokevin committed Jun 14, 2017
commit c35fe26ff5793e68d4960bf5e9e719b06aedeb72
9 changes: 9 additions & 0 deletions src/components/vive-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ module.exports.Component = registerComponent('vive-controls', {
this.onButtonChanged = bind(this.onButtonChanged, this);
this.onButtonDown = function (evt) { self.onButtonEvent(evt.detail.id, 'down'); };
this.onButtonUp = function (evt) { self.onButtonEvent(evt.detail.id, 'up'); };
this.onButtonTouchEnd = function (evt) { self.onButtonEvent(evt.detail.id, 'touchend'); };
this.onButtonTouchStart = function (evt) { self.onButtonEvent(evt.detail.id, 'touchstart'); };
this.onAxisMoved = bind(this.onAxisMoved, this);
this.previousButtonValues = {};

Expand Down Expand Up @@ -202,6 +204,10 @@ module.exports.Component = registerComponent('vive-controls', {
var buttonName = this.mapping.buttons[id];
var color;
var i;
var isTouch = evtName.indexOf('touch') !== -1;

// Only trackpad has touch. Ignore for the rest, even if Gamepad API says touched.
if (isTouch && buttonName !== 'trackpad') { return; }

// Emit events.
if (Array.isArray(buttonName)) {
Expand All @@ -214,6 +220,9 @@ module.exports.Component = registerComponent('vive-controls', {

if (!this.data.model) { return; }

// Don't change color for trackpad touch.
if (isTouch) { return; }

// Update colors.
color = evtName === 'up' ? this.data.buttonColor : this.data.buttonHighlightColor;
if (Array.isArray(buttonName)) {
Expand Down
26 changes: 26 additions & 0 deletions tests/components/vive-controls.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,5 +282,31 @@ suite('vive-controls', function () {
});
component.injectTrackedControls();
});

test('does not change color for trigger touch', function (done) {
component.addEventListeners();
el.addEventListener('model-loaded', function (evt) {
el.emit('touchstart', {id: 1, state: {}});
setTimeout(() => {
var color = component.buttonMeshes.trigger.material.color;
assert.equal(new THREE.Color(color).getHexString(), 'fafafa');
done();
});
});
component.injectTrackedControls();
});

test('does not change color for trackpad touch', function (done) {
component.addEventListeners();
el.addEventListener('model-loaded', function (evt) {
el.emit('touchstart', {id: 0, state: {}});
setTimeout(() => {
var color = component.buttonMeshes.trackpad.material.color;
assert.equal(new THREE.Color(color).getHexString(), 'fafafa');
done();
});
});
component.injectTrackedControls();
});
});
});