Skip to content
Snippets Groups Projects
Commit 38a2c56d authored by johnshaughnessy's avatar johnshaughnessy
Browse files

KBM: Add wasd and scaling grabbables.

parent cec48bed
No related branches found
No related tags found
No related merge requests found
import { paths } from "../systems/userinput/paths";
/**
* Manages ownership and haptics on an interatable
* @namespace network
......@@ -82,6 +83,13 @@ AFRAME.registerComponent("super-networked-interactable", {
}
},
tick: function() {
const userinput = AFRAME.scenes[0].systems.userinput;
const delta = userinput.readFrameValueAtPath(paths.actions.cursorScaleGrabbedGrabbable);
if (delta) {
this._changeScale(delta);
}
},
_stateAdded(evt) {
switch (evt.detail) {
case "scaleUp":
......
......@@ -2,8 +2,24 @@ import { paths } from "../paths";
import { sets } from "../sets";
import { xforms } from "./xforms";
const wasd_vec2 = "/var/mouse-and-keyboard/wasd_vec2";
export const KBMBindings = {
[sets.global]: [
{
src: {
w: paths.device.keyboard.key("w"),
a: paths.device.keyboard.key("a"),
s: paths.device.keyboard.key("s"),
d: paths.device.keyboard.key("d")
},
dest: { vec2: wasd_vec2 },
xform: xforms.wasd_to_vec2
},
{
src: { value: wasd_vec2 },
dest: { value: paths.actions.characterAcceleration },
xform: xforms.copy
},
{
src: { value: paths.device.keyboard.key("shift") },
dest: { value: paths.actions.boost },
......@@ -183,6 +199,16 @@ export const KBMBindings = {
},
dest: { value: paths.actions.cursorModDelta },
xform: xforms.copyIfFalse
},
{
src: {
bool: paths.device.keyboard.key("shift"),
value: paths.device.mouse.wheel
},
dest: { value: paths.actions.cursorScaleGrabbedGrabbable },
xform: xforms.copyIfTrue,
priority: 150,
root: "wheel"
}
],
......
......@@ -82,5 +82,14 @@ export const xforms = {
return function always(frame, _, dest) {
frame[dest.value] = constValue;
};
},
wasd_to_vec2: function(frame, { w, a, s, d }, { vec2 }) {
let x = 0;
let y = 0;
if (frame[a]) x -= 1;
if (frame[d]) x += 1;
if (frame[w]) y += 1;
if (frame[s]) y -= 1;
frame[vec2] = [x, y];
}
};
......@@ -22,6 +22,7 @@ paths.actions.cursorStopDrawing = "/actions/cursorStopDrawing";
paths.actions.cursorPenNextColor = "/actions/cursorPenNextColor";
paths.actions.cursorPenPrevColor = "/actions/cursorPenPrevColor";
paths.actions.cursorScalePenTip = "/actions/cursorScalePenTip";
paths.actions.cursorScaleGrabbedGrabbable = "/actions/cursorScaleGrabbedGrabbable";
paths.actions.startTeleport = "/actions/startTeleport";
paths.actions.stopTeleport = "/actions/stopTeleport";
paths.actions.rightHandPose = "/actions/rightHandPose";
......
......@@ -122,6 +122,17 @@ window.addEventListener(
);
AFRAME.registerSystem("userinput", {
readFrameValueAtPath(path) {
return frame[path];
},
activate(set, value) {
pendingSetChanges.push({ set, fn: value === false ? "deactivate" : "activate" });
},
deactivate(set) {
pendingSetChanges.push({ set, fn: "deactivate" });
},
init() {
// TODO: Handle device (dis/re)connection
activeDevices.add(new MouseDevice());
......@@ -137,7 +148,7 @@ AFRAME.registerSystem("userinput", {
registeredMappings.add(keyboardDebugBindings);
//registeredMappings.add(oculusgoBindings);
this.xformStates = new Map();
registeredMappings.add(oculustouchBindings);
//registeredMappings.add(oculustouchBindings);
},
tick() {
......@@ -184,20 +195,4 @@ AFRAME.registerSystem("userinput", {
// TODO: draw debug data to the screen
}
},
readFrameValueAtPath(path) {
return frame[path];
},
activate(set, value) {
pendingSetChanges.push({ set, fn: value === false ? "deactivate" : "activate" });
},
deactivate(set) {
pendingSetChanges.push({ set, fn: "deactivate" });
},
registerTickCallback(cb) {
callbacks.push(cb);
}
});
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