Skip to content

Instantly share code, notes, and snippets.

@caseyyee
Created April 19, 2017 20:20
Show Gist options
  • Save caseyyee/5f88b4b54b777d500b7ed552696d3ad5 to your computer and use it in GitHub Desktop.
Save caseyyee/5f88b4b54b777d500b7ed552696d3ad5 to your computer and use it in GitHub Desktop.
A-Frame component - which-controller-present
// by: @machenmusik
AFRAME.registerComponent('which-controller-present', {
init: function () {
this.el.addEventListener('componentinitialized', (function (evt) {
if (evt.detail.name !== 'tracked-controls') { return; }
// Determine which, if any, higher level controller component says controllerPresent.
// WARNING! If a dummy tracked-controls instance is already present,
// then componentinitialized may not fire for true injection!
Object.keys(this.el.components).forEach((name) => {
const component = this.el.components[name];
if (component.controllerPresent) {
// Log name, component data, and tracked-controls data.
console.log(name + ' ' + JSON.stringify(component.data) + ' => ' + JSON.stringify(event.detail.data));
// Emit controllerpresent event.
this.el.emit('controllerpresent', {name: name, component: component});
}
});
}).bind(this));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment