<commit_before>import backpack from './backpack';
import combatSetKey from './combatSetKey';
import createGroup from './createGroup';
import doRepair from './doRepair';
import {doSendGold} from '../../world/newMap/sendGold';
import fastWearMgr from './fastWearMgr';
import gotoGuild from './gotoGuild';
import joinAllGroup from './joinAllGroup';
import logPage from './logPage';
import movePage from './movePage';
import partial from '../../common/partial';
import profile from './profile';
import toWorld from './toWorld';

var keyLookup = [
  [33, combatSetKey, 0], // Shift+1
  [64, combatSetKey, 1], // Shift+2
  [34, combatSetKey, 1], // Shift+2 -- for UK keyboards, I think
  [35, combatSetKey, 2], // Shift+3
  [36, combatSetKey, 3], // Shift+4
  [37, combatSetKey, 4], // Shift+5
  [94, combatSetKey, 5], // Shift+6
  [38, combatSetKey, 6], // Shift+7
  [42, combatSetKey, 7], // Shift+8
  [40, combatSetKey, 8], // Shift+9
  [48, toWorld], // go to world [0]
  [60, movePage, '<'], // move to prev page [<]
  [62, movePage, '>'], // move to next page [>]
  [71, createGroup], // create group [G]
  [76, logPage], // Log Page [L]
  [98, backpack], // backpack [b]
  [103, gotoGuild], // go to guild [g]
  [106, joinAllGroup], // join all group [j]
  [108, logPage], // Log Page [l]
  [112, profile], // profile [p]
  [114, doRepair], // repair [r]
  [118, fastWearMgr], // fast wear manager [v]
  [121, doSendGold], // fast send gold [y]
  [163, combatSetKey, 2] // Shift+3 -- for UK keyboards
];

function thisCharCode(charCode, arr) {return charCode === arr[0];}

function handleKey(charCode) {
  var mapping = keyLookup.find(partial(thisCharCode, charCode));
  if (mapping) {
    mapping[1](mapping[2]);
  }
}

function notTagName(evt, tag) {return evt.target.tagName !== tag;}

var bailOut = [
  function(evt) {
    return ['HTML', 'BODY'].every(partial(notTagName, evt));
  },
  /* ignore control, alt and meta keys
  (I think meta is the command key in Macintoshes) */
  function(evt) {return evt.ctrlKey;},
  function(evt) {return evt.metaKey;},
  function(evt) {return evt.altKey;}
];

function reason(evt, fn) {return fn(evt);}

function doNotHandle(evt) {
  return bailOut.some(partial(reason, evt));
}

function keyPress(evt) {
  if (doNotHandle(evt)) {return;}
  handleKey(evt.charCode);
}

export default function replaceKeyHandler() {
  document.onkeypress = keyPress;
}<commit_msg>updated key handler (Crappaud)<commit_after>import backpack from './backpack';
import combatSetKey from './combatSetKey';
import createGroup from './createGroup';
import doRepair from './doRepair';
import {doSendGold} from '../../world/newMap/sendGold';
import fastWearMgr from './fastWearMgr';
import gotoGuild from './gotoGuild';
import joinAllGroup from './joinAllGroup';
import logPage from './logPage';
import movePage from './movePage';
import on from '../../common/on';
import partial from '../../common/partial';
import profile from './profile';
import toWorld from './toWorld';

var keyLookup = [
  ['!', combatSetKey, 0], // Shift+1
  ['@', combatSetKey, 1], // Shift+2
  ['"', combatSetKey, 1], // Shift+2 -- for UK keyboards
  ['#', combatSetKey, 2], // Shift+3
  ['£', combatSetKey, 2], // Shift+3 -- for UK keyboards
  ['$', combatSetKey, 3], // Shift+4
  ['%', combatSetKey, 4], // Shift+5
  ['^', combatSetKey, 5], // Shift+6
  ['&', combatSetKey, 6], // Shift+7
  ['*', combatSetKey, 7], // Shift+8
  ['(', combatSetKey, 8], // Shift+9
  ['0', toWorld], // go to world [0]
  ['<', movePage, '<'], // move to prev page [<]
  ['>', movePage, '>'], // move to next page [>]
  ['G', createGroup], // create group [G]
  ['L', logPage], // Log Page [L]
  ['b', backpack], // backpack [b]
  ['g', gotoGuild], // go to guild [g]
  ['j', joinAllGroup], // join all group [j]
  ['l', logPage], // Log Page [l]
  ['p', profile], // profile [p]
  ['r', doRepair], // repair [r]
  ['v', fastWearMgr], // fast wear manager [v]
  ['y', doSendGold] // fast send gold [y]
];

function thisKey(key, arr) {return key === arr[0];}

function handleKey(key) {
  var mapping = keyLookup.find(partial(thisKey, key));
  if (mapping) {mapping[1](mapping[2]);}
}

function notTagName(evt, tag) {return evt.target.tagName !== tag;}

var bailOut = [
  function(evt) {
    return ['HTML', 'BODY'].every(partial(notTagName, evt));
  },
  /* ignore control, alt and meta keys
  (I think meta is the command key in Macintoshes) */
  function(evt) {return evt.ctrlKey;},
  function(evt) {return evt.metaKey;},
  function(evt) {return evt.altKey;}
];

function reason(evt, fn) {return fn(evt);}

function doNotHandle(evt) {
  return bailOut.some(partial(reason, evt));
}

function handleKeyUp(e) {
  if (doNotHandle(e)) {return;}
  handleKey(e.key);
}

export default function replaceKeyHandler() {
  on(document, 'keyup', handleKeyUp);
}
{'fraction_non_alphanumeric': 0.1927860696517413, 'fraction_numerical': 0.022595356550580432, 'mean_word_length': 3.8443775100401605, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7649267', 'n_tokens_mistral': 1740, 'n_tokens_neox': 1692, 'n_words': 492}