Refactor shortcuts into a central file and fix issue with caps lock

This commit is contained in:
Mitchell McCaffrey
2021-03-25 16:31:06 +11:00
parent c77db06bce
commit ad68aa7226
9 changed files with 190 additions and 85 deletions

View File

@@ -11,6 +11,8 @@ import { useKeyboard } from "../../contexts/KeyboardContext";
import Vector2 from "../../helpers/Vector2";
import shortcuts from "../../shortcuts";
function MapGridEditor({ map, onGridChange }) {
const stageScale = useDebouncedStageScale();
const mapWidth = useMapWidth();
@@ -166,20 +168,19 @@ function MapGridEditor({ map, onGridChange }) {
}
function handleKeyDown(event) {
const { key, shiftKey } = event;
const nudgeAmount = shiftKey ? 2 : 0.5;
if (key === "ArrowUp") {
const nudgeAmount = event.shiftKey ? 2 : 0.5;
if (shortcuts.gridNudgeUp(event)) {
// Stop arrow up/down scrolling if overflowing
event.preventDefault();
nudgeGrid({ x: 0, y: -1 }, nudgeAmount);
}
if (key === "ArrowLeft") {
if (shortcuts.gridNudgeLeft(event)) {
nudgeGrid({ x: -1, y: 0 }, nudgeAmount);
}
if (key === "ArrowRight") {
if (shortcuts.gridNudgeRight(event)) {
nudgeGrid({ x: 1, y: 0 }, nudgeAmount);
}
if (key === "ArrowDown") {
if (shortcuts.gridNudgeDown(event)) {
event.preventDefault();
nudgeGrid({ x: 0, y: 1 }, nudgeAmount);
}