diff --git a/src/systems/cameras.js b/src/systems/cameras.js new file mode 100644 index 0000000000000000000000000000000000000000..2aa2e40819e231b91355e6d46a63b6785e4eb04c --- /dev/null +++ b/src/systems/cameras.js @@ -0,0 +1,28 @@ +// Used for tracking and managing camera tools in the scene +AFRAME.registerSystem("cameras", { + init() { + this.cameraEls = []; + }, + + register(el) { + this.cameraEls.push(el); + el.addEventListener("ownership-changed", this._onOwnershipChange); + this.currentCamera = null; + }, + + deregister(el) { + this.cameraEls = this.cameraEls.filter(c => c !== el); + el.removeEventListener("ownership-changed", this._onOwnershipChange); + this.currentCamera = null; + }, + + getCurrent() { + if (this.currentCamera) return this.currentCamera; + this.currentCamera = this.cameraEls.find(NAF.utils.isMine); + return this.currentCamera; + }, + + _onOwnershipChange() { + this.currentCamera = null; + } +});