Skip to content
Snippets Groups Projects
Commit f1f41ff0 authored by netpro2k's avatar netpro2k
Browse files

Simplify userinput in super-networked-interactable

parent 47acc01d
No related branches found
No related tags found
No related merge requests found
import { paths } from "../systems/userinput/paths"; import { paths } from "../systems/userinput/paths";
const pathsMap = {
"player-right-controller": {
scaleGrabbedGrabbable: paths.actions.rightHand.scaleGrabbedGrabbable
},
"player-left-controller": {
scaleGrabbedGrabbable: paths.actions.leftHand.scaleGrabbedGrabbable
},
cursor: {
scaleGrabbedGrabbable: paths.actions.cursor.scaleGrabbedGrabbable
}
};
/** /**
* Manages ownership and haptics on an interatable * Manages ownership and haptics on an interatable
* @namespace network * @namespace network
...@@ -30,14 +42,12 @@ AFRAME.registerComponent("super-networked-interactable", { ...@@ -30,14 +42,12 @@ AFRAME.registerComponent("super-networked-interactable", {
} }
}); });
this._stateAdded = this._stateAdded.bind(this);
this._onGrabStart = this._onGrabStart.bind(this); this._onGrabStart = this._onGrabStart.bind(this);
this._onGrabEnd = this._onGrabEnd.bind(this); this._onGrabEnd = this._onGrabEnd.bind(this);
this._onOwnershipLost = this._onOwnershipLost.bind(this); this._onOwnershipLost = this._onOwnershipLost.bind(this);
this.el.addEventListener("grab-start", this._onGrabStart); this.el.addEventListener("grab-start", this._onGrabStart);
this.el.addEventListener("grab-end", this._onGrabEnd); this.el.addEventListener("grab-end", this._onGrabEnd);
this.el.addEventListener("ownership-lost", this._onOwnershipLost); this.el.addEventListener("ownership-lost", this._onOwnershipLost);
this.el.addEventListener("stateadded", this._stateAdded);
this.system.addComponent(this); this.system.addComponent(this);
}, },
...@@ -46,7 +56,6 @@ AFRAME.registerComponent("super-networked-interactable", { ...@@ -46,7 +56,6 @@ AFRAME.registerComponent("super-networked-interactable", {
this.el.removeEventListener("grab-start", this._onGrabStart); this.el.removeEventListener("grab-start", this._onGrabStart);
this.el.removeEventListener("grab-end", this._onGrabEnd); this.el.removeEventListener("grab-end", this._onGrabEnd);
this.el.removeEventListener("ownership-lost", this._onOwnershipLost); this.el.removeEventListener("ownership-lost", this._onOwnershipLost);
this.el.removeEventListener("stateadded", this._stateAdded);
this.system.removeComponent(this); this.system.removeComponent(this);
}, },
...@@ -77,7 +86,7 @@ AFRAME.registerComponent("super-networked-interactable", { ...@@ -77,7 +86,7 @@ AFRAME.registerComponent("super-networked-interactable", {
}, },
_changeScale: function(delta) { _changeScale: function(delta) {
if (this.el.is("grabbed") && this.el.components.hasOwnProperty("stretchable")) { if (delta && this.el.is("grabbed") && this.el.components.hasOwnProperty("stretchable")) {
this.currentScale.addScalar(delta).clampScalar(this.data.minScale, this.data.maxScale); this.currentScale.addScalar(delta).clampScalar(this.data.minScale, this.data.maxScale);
this.el.setAttribute("scale", this.currentScale); this.el.setAttribute("scale", this.currentScale);
this.el.components["stretchable"].stretchBody(this.el, this.currentScale); this.el.components["stretchable"].stretchBody(this.el, this.currentScale);
...@@ -85,38 +94,10 @@ AFRAME.registerComponent("super-networked-interactable", { ...@@ -85,38 +94,10 @@ AFRAME.registerComponent("super-networked-interactable", {
}, },
tick: function() { tick: function() {
const userinput = AFRAME.scenes[0].systems.userinput; const grabber = this.el.components.grabbable.grabbers[0];
const grabbable = this.el.components.grabbable; if (!(grabber && pathsMap[grabber.id])) return;
let delta = 0;
if (this.el.is("grabbed") && this.el.components.hasOwnProperty("stretchable")) {
const isLeftHand = grabbable.grabbers[0] === document.querySelector("[super-hands], #player-left-controller");
if (isLeftHand) {
delta = userinput.readFrameValueAtPath(paths.actions.leftHand.scaleGrabbedGrabbable);
}
const isRightHand = grabbable.grabbers[0] === document.querySelector("[super-hands], #player-right-controller");
if (isRightHand) {
delta = userinput.readFrameValueAtPath(paths.actions.rightHand.scaleGrabbedGrabbable);
}
const isCursor = document.querySelector("[cursor-controller]").components["cursor-controller"].data.cursor;
if (isCursor) {
delta = userinput.readFrameValueAtPath(paths.actions.cursor.scaleGrabbedGrabbable);
}
}
if (delta) {
this._changeScale(delta);
}
},
_stateAdded(evt) { const userinput = AFRAME.scenes[0].systems.userinput;
switch (evt.detail) { this._changeScale(userinput.readFrameValueAtPath(pathsMap[grabber.id].scaleGrabbedGrabbable));
case "scaleUp":
this._changeScale(-this.data.scrollScaleDelta);
break;
case "scaleDown":
this._changeScale(this.data.scrollScaleDelta);
break;
default:
break;
}
} }
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment