get rid of unneccessary keycode package

This commit is contained in:
HF 2021-01-27 16:05:22 +01:00
parent 97737a16a1
commit e4a6171666
4 changed files with 25 additions and 25 deletions

5
package-lock.json generated
View File

@ -5472,11 +5472,6 @@
"object.assign": "^4.1.1" "object.assign": "^4.1.1"
} }
}, },
"keycode": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/keycode/-/keycode-2.2.0.tgz",
"integrity": "sha1-PQr1bce4uOXLqNCpfxByBO7CKwQ="
},
"kuler": { "kuler": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/kuler/-/kuler-2.0.0.tgz", "resolved": "https://registry.npmjs.org/kuler/-/kuler-2.0.0.tgz",

View File

@ -45,7 +45,6 @@
"ip-address": "^7.1.0", "ip-address": "^7.1.0",
"isomorphic-fetch": "^3.0.0", "isomorphic-fetch": "^3.0.0",
"js-file-download": "^0.4.12", "js-file-download": "^0.4.12",
"keycode": "^2.1.9",
"localforage": "^1.9.0", "localforage": "^1.9.0",
"morgan": "^1.10.0", "morgan": "^1.10.0",
"multer": "^1.4.1", "multer": "^1.4.1",

View File

@ -1,11 +1,12 @@
/* /*
* Creates Viewport for 2D Canvas * Controls for 2D canvases
*
* keycodes:
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values
* *
* @flow * @flow
*/ */
import keycode from 'keycode';
import { import {
setHover, setHover,
unsetHover, unsetHover,
@ -444,9 +445,9 @@ class PixelPlainterControls {
} }
onKeyUp(event: KeyboardEvent) { onKeyUp(event: KeyboardEvent) {
switch (keycode(event)) { switch (event.key) {
case 'shift': case 'Shift':
case 'caps lock': case 'CapsLock':
this.holdPainting = false; this.holdPainting = false;
break; break;
default: default:
@ -461,22 +462,21 @@ class PixelPlainterControls {
return; return;
} }
const { store } = this; const { store } = this;
const key = keycode(event);
switch (key) { switch (event.key) {
case 'up': case 'ArrowUp':
case 'w': case 'w':
store.dispatch(moveNorth()); store.dispatch(moveNorth());
break; break;
case 'left': case 'ArrowLeft':
case 'a': case 'a':
store.dispatch(moveWest()); store.dispatch(moveWest());
break; break;
case 'down': case 'ArrowDown':
case 's': case 's':
store.dispatch(moveSouth()); store.dispatch(moveSouth());
break; break;
case 'right': case 'ArrowRight':
case 'd': case 'd':
store.dispatch(moveEast()); store.dispatch(moveEast());
break; break;
@ -488,19 +488,27 @@ class PixelPlainterControls {
case 'q': case 'q':
store.dispatch(zoomOut()); store.dispatch(zoomOut());
break; break;
case 'ctrl': case 'Control':
case 'shift': { case 'Shift': {
const state = store.getState(); const state = store.getState();
const { hover } = state.gui; const { hover } = state.gui;
if (hover) { if (hover) {
if (key === 'ctrl') { if (event.key === 'Control') {
// ctrl
const clrIndex = this.renderer.getColorIndexOfPixel(...hover); const clrIndex = this.renderer.getColorIndexOfPixel(...hover);
if (clrIndex !== null) { if (clrIndex !== null) {
store.dispatch(selectColor(clrIndex)); store.dispatch(selectColor(clrIndex));
} }
} else { return;
}
if (event.location === KeyboardEvent.DOM_KEY_LOCATION_LEFT) {
// left shift
this.holdPainting = true; this.holdPainting = true;
PixelPlainterControls.placePixel(store, this.renderer, hover); PixelPlainterControls.placePixel(store, this.renderer, hover);
return;
}
if (event.location === KeyboardEvent.DOM_KEY_LOCATION_RIGHT) {
// right shift
} }
} }
break; break;

View File

@ -2,8 +2,6 @@
* keypress actions * keypress actions
* @flow * @flow
*/ */
import keycode from 'keycode';
import store from '../ui/store'; import store from '../ui/store';
import copy from '../utils/clipboard'; import copy from '../utils/clipboard';
import { import {
@ -24,7 +22,7 @@ function onKeyPress(event: KeyboardEvent) {
return; return;
} }
switch (keycode(event)) { switch (event.key) {
case 'g': case 'g':
store.dispatch(toggleGrid()); store.dispatch(toggleGrid());
break; break;