Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CommandBind.cpp 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*!
  2. * \file src/commands/CommandBind.cpp
  3. * \brief Bind command
  4. *
  5. * \author xythobuz
  6. */
  7. #include "global.h"
  8. #include "Console.h"
  9. #include "OpenRaider.h"
  10. #include "commands/CommandBind.h"
  11. std::string CommandBind::name() {
  12. return "bind";
  13. }
  14. std::string CommandBind::brief() {
  15. return "bind a keyboard/mouse action";
  16. }
  17. void CommandBind::printHelp() {
  18. getConsole() << "bind-Command Usage:" << Console::endl;
  19. getConsole() << " bind ACTION KEY" << Console::endl;
  20. getConsole() << "Available Actions:" << Console::endl;
  21. getConsole() << " menu" << Console::endl;
  22. getConsole() << " console" << Console::endl;
  23. getConsole() << " forward" << Console::endl;
  24. getConsole() << " backward" << Console::endl;
  25. getConsole() << " left" << Console::endl;
  26. getConsole() << " right" << Console::endl;
  27. getConsole() << " jump" << Console::endl;
  28. getConsole() << " crouch" << Console::endl;
  29. getConsole() << " use" << Console::endl;
  30. getConsole() << " holster" << Console::endl;
  31. getConsole() << " walk" << Console::endl;
  32. getConsole() << "Key-Format:" << Console::endl;
  33. getConsole() << " 'a' or '1' for character/number keys" << Console::endl;
  34. getConsole() << " \"leftctrl\" for symbols and special keys" << Console::endl;
  35. }
  36. int CommandBind::execute(std::istream& args) {
  37. std::string a, b;
  38. if (!(args >> a >> b)) {
  39. getConsole() << "Invalid use of bind-command" << Console::endl;
  40. return -1;
  41. } else {
  42. ActionEvents e = stringToActionEvent(a.c_str());
  43. if (e == ActionEventCount) {
  44. getConsole() << "bind-Error: Unknown action (" << a << ")" << Console::endl;
  45. return -2;
  46. }
  47. KeyboardButton c = stringToKeyboardButton(b.c_str());
  48. if (c == unknownKey) {
  49. getConsole() << "bind-Error: Unknown key (" << b << ")" << Console::endl;
  50. return -3;
  51. }
  52. getOpenRaider().keyBindings[e] = c;
  53. return 0;
  54. }
  55. }