mirror of
https://github.com/RGBCube/Site
synced 2025-08-01 13:37:49 +00:00
cube: add keyboard controls
This commit is contained in:
parent
876ed64056
commit
89b9e6fbb8
1 changed files with 52 additions and 1 deletions
|
@ -76,6 +76,14 @@
|
||||||
this.z - that.z,
|
this.z - that.z,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
mul(that) {
|
||||||
|
return Vec(
|
||||||
|
this.x * that.x,
|
||||||
|
this.y * that.y,
|
||||||
|
this.z * that.z,
|
||||||
|
);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
Vec.ZERO = Vec(0, 0, 0);
|
Vec.ZERO = Vec(0, 0, 0);
|
||||||
|
@ -163,7 +171,7 @@
|
||||||
|
|
||||||
window.addEventListener("beforeunload", () => {
|
window.addEventListener("beforeunload", () => {
|
||||||
localStorage.setItem("mouseDown", JSON.stringify(mouse.down));
|
localStorage.setItem("mouseDown", JSON.stringify(mouse.down));
|
||||||
localStorage.setItem("mouseLastMove", JSON.stringify(-(window.performance.now() - mouse.lastMove)));
|
localStorage.setItem("mouseLastMove", JSON.stringify(-(globalThis.performance.now() - mouse.lastMove)));
|
||||||
localStorage.setItem("mousePrevious", JSON.stringify([
|
localStorage.setItem("mousePrevious", JSON.stringify([
|
||||||
mouse.previous.x,
|
mouse.previous.x,
|
||||||
mouse.previous.y,
|
mouse.previous.y,
|
||||||
|
@ -193,6 +201,49 @@
|
||||||
localStorage.setItem("lastSave", JSON.stringify(Date.now()));
|
localStorage.setItem("lastSave", JSON.stringify(Date.now()));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.addEventListener("keydown", (event) => {
|
||||||
|
const shift = event.shiftKey ? Vec(-1, -1, -1) : Vec(1, 1, 1);
|
||||||
|
|
||||||
|
let effect;
|
||||||
|
|
||||||
|
switch (event.key) {
|
||||||
|
case "Enter":
|
||||||
|
effect = Vec(0, 0, 4).mul(shift);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case " ":
|
||||||
|
effect = Vec(4, 0, 0).mul(shift);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "h":
|
||||||
|
case "ArrowLeft":
|
||||||
|
effect = Vec(0, -4, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "j":
|
||||||
|
case "ArrowDown":
|
||||||
|
effect = Vec(-4, 0, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "k":
|
||||||
|
case "ArrowUp":
|
||||||
|
effect = Vec(4, 0, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "l":
|
||||||
|
case "ArrowRight":
|
||||||
|
effect = Vec(0, 4, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
velocity = velocity.sum(effect);
|
||||||
|
|
||||||
|
mouse.lastMove = globalThis.performance.now();
|
||||||
|
});
|
||||||
|
|
||||||
const handleUp = () => {
|
const handleUp = () => {
|
||||||
mouse.down = false;
|
mouse.down = false;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue