Download react-tetris/src/control/index.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 855 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-tetris/src/control/index.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-tetris/src/control/index.js
-
curl -L -o index.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-tetris/src/control/index.js
855 Bytes
| import store from '../store'; | |
| import todo from './todo'; | |
| const keyboard = { | |
| 37: 'left', | |
| 38: 'rotate', | |
| 39: 'right', | |
| 40: 'down', | |
| 32: 'space', | |
| 83: 's', | |
| 82: 'r', | |
| 80: 'p', | |
| }; | |
| let keydownActive; | |
| const boardKeys = Object.keys(keyboard).map(e => parseInt(e, 10)); | |
| const keyDown = (e) => { | |
| if (e.metaKey === true || boardKeys.indexOf(e.keyCode) === -1) { | |
| return; | |
| } | |
| const type = keyboard[e.keyCode]; | |
| if (type === keydownActive) { | |
| return; | |
| } | |
| keydownActive = type; | |
| todo[type].down(store); | |
| }; | |
| const keyUp = (e) => { | |
| if (e.metaKey === true || boardKeys.indexOf(e.keyCode) === -1) { | |
| return; | |
| } | |
| const type = keyboard[e.keyCode]; | |
| if (type === keydownActive) { | |
| keydownActive = ''; | |
| } | |
| todo[type].up(store); | |
| }; | |
| document.addEventListener('keydown', keyDown, true); | |
| document.addEventListener('keyup', keyUp, true); | |