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.

Command.cpp 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. /*!
  2. * \file src/Command.cpp
  3. * \brief OpenRaider command implementation
  4. *
  5. * \author xythobuz
  6. */
  7. #include <fstream>
  8. #include <sstream>
  9. #include "global.h"
  10. #include "Camera.h"
  11. #include "Console.h"
  12. #include "Entity.h"
  13. #include "Font.h"
  14. #include "Game.h"
  15. #include "math/math.h"
  16. #include "Menu.h"
  17. #include "Render.h"
  18. #include "Sound.h"
  19. #include "TombRaider.h"
  20. #include "Window.h"
  21. #include "World.h"
  22. #include "utils/strings.h"
  23. #include "utils/time.h"
  24. #include "OpenRaider.h"
  25. int OpenRaider::loadConfig(const char *config) {
  26. assert(config != NULL);
  27. assert(config[0] != '\0');
  28. char *configFile = fullPath(config, 0);
  29. getConsole().print("Loading config from \"%s\"...", configFile);
  30. std::ifstream file(configFile);
  31. if (!file) {
  32. getConsole().print("Could not open file!");
  33. return -1;
  34. }
  35. for (std::string line; std::getline(file, line);) {
  36. if (line.length() == 0)
  37. continue;
  38. int error = command(line);
  39. if (error != 0)
  40. getConsole().print("Error Code: %d", error);
  41. }
  42. file.close();
  43. return 0;
  44. }
  45. int OpenRaider::command(const char *command) {
  46. std::string tmp(command);
  47. return this->command(tmp);
  48. }
  49. int OpenRaider::command(std::string &c) {
  50. // Remove comment, if any
  51. size_t comment = c.find_first_of('#');
  52. if (comment != std::string::npos)
  53. c.erase(comment);
  54. // Execute command
  55. std::stringstream command(c);
  56. std::string cmd;
  57. command >> cmd;
  58. command >> std::boolalpha >> std::ws;
  59. if (cmd.length() == 0)
  60. return 0;
  61. if (cmd.compare("set") == 0) {
  62. return set(command);
  63. } else if (cmd.compare("bind") == 0) {
  64. std::string a, b;
  65. if (!(command >> a >> b)) {
  66. getConsole().print("Invalid use of bind-command");
  67. return -1;
  68. } else {
  69. return bind(a.c_str(), b.c_str());
  70. }
  71. } else if (cmd.compare("quit") == 0) {
  72. exit(0);
  73. } else if (cmd.compare("load") == 0) {
  74. if (!mRunning) {
  75. getConsole().print("Use load command interactively!");
  76. return -999;
  77. }
  78. std::string temp;
  79. command >> temp;
  80. int error = getGame().loadLevel(temp.c_str());
  81. return error;
  82. } else if (cmd.compare("help") == 0) {
  83. std::string tmp;
  84. if (!(command >> tmp)) {
  85. getConsole().print("Available commands:");
  86. getConsole().print(" load - load a level");
  87. getConsole().print(" set - set a parameter");
  88. getConsole().print(" bind - bind a keyboard/mouse action");
  89. getConsole().print(" animate - [BOOL|n|p] - Animate models");
  90. getConsole().print(" move - [walk|fly|noclip]");
  91. /*
  92. getConsole().print(" sshot - make a screenshot");
  93. getConsole().print(" sound - INT - Test play sound");
  94. getConsole().print(" mode - MODE - Render mode");
  95. getConsole().print(" light - BOOL - GL Lights");
  96. getConsole().print(" fog - BOOL - GL Fog");
  97. getConsole().print(" viewmodel - INT - Change Laras model");
  98. getConsole().print(" pos - Print position info");
  99. getConsole().print(" ralpha - BOOL - Room Alpha");
  100. getConsole().print(" upf - BOOL - Update Room List Per Frame");
  101. getConsole().print(" entmodel - BOOL");
  102. getConsole().print(" ponytail - BOOL");
  103. getConsole().print(" pigtail - BOOL");
  104. getConsole().print(" ponypos - FLOAT FLOAT FLOAT FLOAT - x y z angle");
  105. */
  106. getConsole().print(" help - print command help");
  107. getConsole().print(" quit - exit OpenRaider");
  108. getConsole().print("Use help COMMAND to get additional info");
  109. getConsole().print("Pass BOOLs as true or false");
  110. } else {
  111. return help(tmp);
  112. }
  113. } else if (cmd.compare("animate") == 0) {
  114. if ((!mRunning) || (!getGame().isLoaded())) {
  115. getConsole().print("Use animate command interactively!");
  116. return -999;
  117. }
  118. if (command.peek() == 'n') {
  119. // Step all skeletal models to their next animation
  120. if (getRender().getFlags() & Render::fAnimateAllModels) {
  121. for (unsigned int i = 0; i < getWorld().sizeEntity(); i++) {
  122. Entity &e = getWorld().getEntity(i);
  123. SkeletalModel &m = e.getModel();
  124. if (e.getAnimation() < (m.size() - 1))
  125. e.setAnimation(e.getAnimation() + 1);
  126. else
  127. e.setAnimation(0);
  128. }
  129. } else {
  130. getConsole().print("Animations need to be enabled!");
  131. }
  132. } else if (command.peek() == 'p') {
  133. // Step all skeletal models to their previous animation
  134. if (getRender().getFlags() & Render::fAnimateAllModels) {
  135. for (unsigned int i = 0; i < getWorld().sizeEntity(); i++) {
  136. Entity &e = getWorld().getEntity(i);
  137. SkeletalModel &m = e.getModel();
  138. if (e.getAnimation() > 0)
  139. e.setAnimation(e.getAnimation() - 1);
  140. else
  141. if (m.size() > 0)
  142. e.setAnimation(m.size() - 1);
  143. }
  144. } else {
  145. getConsole().print("Animations need to be enabled!");
  146. }
  147. } else {
  148. // Enable or disable animating all skeletal models
  149. bool b = false;
  150. if (!(command >> b)) {
  151. getConsole().print("Pass BOOL to animate command!");
  152. return -2;
  153. }
  154. if (b)
  155. getRender().setFlags(Render::fAnimateAllModels);
  156. else
  157. getRender().clearFlags(Render::fAnimateAllModels);
  158. getConsole().print(b ? "Animating all models" : "No longer animating all models");
  159. }
  160. } else if (cmd.compare("move") == 0) {
  161. if ((!mRunning) || (!getGame().isLoaded())) {
  162. getConsole().print("Use move command interactively!");
  163. return -999;
  164. }
  165. std::string temp;
  166. command >> temp;
  167. if (temp.compare("walk") == 0) {
  168. getGame().getLara().setMoveType(Entity::MoveTypeWalk);
  169. } else if (temp.compare("fly") == 0) {
  170. getGame().getLara().setMoveType(Entity::MoveTypeFly);
  171. } else if (temp.compare("noclip") == 0) {
  172. getGame().getLara().setMoveType(Entity::MoveTypeNoClipping);
  173. } else {
  174. getConsole().print("Invalid use of move command (%s)!", temp.c_str());
  175. return -9;
  176. }
  177. getConsole().print("%sing", temp.c_str());
  178. /*
  179. } else if (cmd.compare("mode") == 0) {
  180. std::string mode;
  181. command >> mode;
  182. if (!getGame().isLoaded()) {
  183. getConsole().print("Load a level to set the mode!");
  184. return -1;
  185. }
  186. if (mode.compare("wireframe") == 0) {
  187. getRender().setMode(Render::modeWireframe);
  188. getConsole().print("Wireframe mode");
  189. } else if (mode.compare("solid") == 0) {
  190. getRender().setMode(Render::modeSolid);
  191. getConsole().print("Solid mode");
  192. } else if (mode.compare("texture") == 0) {
  193. getRender().setMode(Render::modeTexture);
  194. getConsole().print("Texture mode");
  195. } else if (mode.compare("vertexlight") == 0) {
  196. getRender().setMode(Render::modeVertexLight);
  197. getConsole().print("Vertexlight mode");
  198. } else if (mode.compare("titlescreen") == 0) {
  199. getRender().setMode(Render::modeLoadScreen);
  200. getConsole().print("Titlescreen mode");
  201. } else {
  202. getConsole().print("Invalid use of mode command (%s)!", mode.c_str());
  203. return -1;
  204. }
  205. } else if (cmd.compare("light") == 0) {
  206. if (args->size() > 0) {
  207. bool b;
  208. if (readBool(args->at(0), &b) < 0) {
  209. getConsole().print("Pass BOOL to light command!");
  210. return -15;
  211. }
  212. if (b)
  213. getRender().setFlags(Render::fGL_Lights);
  214. else
  215. getRender().clearFlags(Render::fGL_Lights);
  216. getConsole().print("GL-Lights are now %s", b ? "on" : "off");
  217. } else {
  218. getConsole().print("Invalid use of light-command!");
  219. return -16;
  220. }
  221. } else if (cmd.compare("fog") == 0) {
  222. if (args->size() > 0) {
  223. bool b;
  224. if (readBool(args->at(0), &b) < 0) {
  225. getConsole().print("Pass BOOL to fog command!");
  226. return -17;
  227. }
  228. if (b)
  229. getRender().setFlags(Render::fFog);
  230. else
  231. getRender().clearFlags(Render::fFog);
  232. getConsole().print("Fog is now %s", b ? "on" : "off");
  233. } else {
  234. getConsole().print("Invalid use of fog-command!");
  235. return -18;
  236. }
  237. } else if (cmd.compare("ralpha") == 0) {
  238. if (args->size() > 0) {
  239. bool b;
  240. if (readBool(args->at(0), &b) < 0) {
  241. getConsole().print("Pass BOOL to ralpha command!");
  242. return -24;
  243. }
  244. if (b)
  245. getRender().setFlags(Render::fRoomAlpha);
  246. else
  247. getRender().clearFlags(Render::fRoomAlpha);
  248. getConsole().print("Room Alpha is now %s", b ? "on" : "off");
  249. } else {
  250. getConsole().print("Invalid use of ralpha-command!");
  251. return -25;
  252. }
  253. } else if (cmd.compare("upf") == 0) {
  254. if (args->size() > 0) {
  255. bool b;
  256. if (readBool(args->at(0), &b) < 0) {
  257. getConsole().print("Pass BOOL to upf command!");
  258. return -30;
  259. }
  260. if (b)
  261. getRender().setFlags(Render::fUpdateRoomListPerFrame);
  262. else
  263. getRender().clearFlags(Render::fUpdateRoomListPerFrame);
  264. getConsole().print("URLPF is now %s", b ? "on" : "off");
  265. } else {
  266. getConsole().print("Invalid use of upf-command!");
  267. return -31;
  268. }
  269. } else if (cmd.compare("entmodel") == 0) {
  270. if (args->size() > 0) {
  271. bool b;
  272. if (readBool(args->at(0), &b) < 0) {
  273. getConsole().print("Pass BOOL to entmodel command!");
  274. return -38;
  275. }
  276. if (b)
  277. getRender().setFlags(Render::fEntityModels);
  278. else
  279. getRender().clearFlags(Render::fEntityModels);
  280. getConsole().print("Entmodels are now %s", b ? "on" : "off");
  281. } else {
  282. getConsole().print("Invalid use of entmodel-command!");
  283. return -39;
  284. }
  285. } else if (cmd.compare("ponytail") == 0) {
  286. if (args->size() > 0) {
  287. bool b;
  288. if (readBool(args->at(0), &b) < 0) {
  289. getConsole().print("Pass BOOL to ponytail command!");
  290. return -44;
  291. }
  292. if (b)
  293. getRender().setFlags(Render::fRenderPonytail);
  294. else
  295. getRender().clearFlags(Render::fRenderPonytail);
  296. getConsole().print("Ponytail is now %s", b ? "on" : "off");
  297. } else {
  298. getConsole().print("Invalid use of ponytail-command!");
  299. return -45;
  300. }
  301. } else if (cmd.compare("sshot") == 0) {
  302. if (!mRunning) {
  303. getConsole().print("Use sshot command interactively!");
  304. return -999;
  305. }
  306. char *filename = bufferString("%s/sshots/%s", mBaseDir, VERSION);
  307. bool console = (args->size() > 0) && (strcmp(args->at(0), "console") == 0);
  308. bool menu = (args->size() > 0) && (strcmp(args->at(0), "menu") == 0);
  309. if (!console) {
  310. getConsole().setVisible(false);
  311. if (menu)
  312. getMenu().setVisible(true);
  313. frame();
  314. frame(); // Double buffered
  315. }
  316. getRender().screenShot(filename);
  317. if (!console) {
  318. getConsole().setVisible(true);
  319. if (menu)
  320. getMenu().setVisible(false);
  321. }
  322. getConsole().print("Screenshot stored...");
  323. delete filename;
  324. } else if (cmd.compare("sound") == 0) {
  325. if ((!mRunning) || (!getGame().isLoaded())) {
  326. getConsole().print("Use sound command interactively!");
  327. return -999;
  328. }
  329. if (args->size() > 0) {
  330. getSound().play(atoi(args->at(0)));
  331. } else {
  332. getConsole().print("Invalid use of sound command!");
  333. return -12;
  334. }
  335. } else if (cmd.compare("viewmodel") == 0) {
  336. if ((!mRunning) || (!getGame().isLoaded())) {
  337. getConsole().print("Use viewmodel command interactively!");
  338. return -999;
  339. }
  340. unsigned int n = atoi(args->at(0));
  341. if (n < getWorld().sizeSkeletalModel())
  342. getGame().getLara().setSkeletalModel(n);
  343. else {
  344. getConsole().print("Invalid SkeletalModel index!");
  345. return -66;
  346. }
  347. } else if (cmd.compare("pos") == 0) {
  348. if ((!mRunning) || (!getGame().isLoaded())) {
  349. getConsole().print("Use pos command interactively!");
  350. return -21;
  351. }
  352. getGame().getLara().print();
  353. } else if (cmd.compare("pigtail") == 0) {
  354. if ((!mRunning) || (!getGame().isLoaded())) {
  355. getConsole().print("Use pigtail command interactively!");
  356. return -999;
  357. }
  358. if (args->size() > 0) {
  359. bool b;
  360. if (readBool(args->at(0), &b) < 0) {
  361. getConsole().print("Pass BOOL to pigtail command!");
  362. return -46;
  363. }
  364. SkeletalModel &tmp = getGame().getLara().getModel();
  365. tmp.setPigTail(b);
  366. getConsole().print("Pigtail is now %s", b ? "on" : "off");
  367. } else {
  368. getConsole().print("Invalid use of pigtail-command!");
  369. return -47;
  370. }
  371. } else if (cmd.compare("ponypos") == 0) {
  372. if ((!mRunning) || (!getGame().isLoaded())) {
  373. getConsole().print("Use ponypos command interactively!");
  374. return -999;
  375. }
  376. if (args->size() > 3) {
  377. SkeletalModel &tmp = getGame().getLara().getModel();
  378. tmp.setPonyPos((float)atof(args->at(0)), (float)atof(args->at(1)),
  379. (float)atof(args->at(2)), (float)atof(args->at(3)));
  380. } else {
  381. getConsole().print("Invalid use of ponypos-command!");
  382. return -48;
  383. }
  384. */
  385. } else {
  386. getConsole().print("Unknown command: %s", cmd.c_str());
  387. return -50;
  388. }
  389. return 0;
  390. }
  391. int OpenRaider::help(std::string &cmd) {
  392. if (cmd.compare("set") == 0) {
  393. getConsole().print("set-Command Usage:");
  394. getConsole().print(" set VAR VAL");
  395. getConsole().print("Available Variables:");
  396. getConsole().print(" basedir STRING");
  397. getConsole().print(" pakdir STRING");
  398. getConsole().print(" audiodir STRING");
  399. getConsole().print(" datadir STRING");
  400. getConsole().print(" font STRING");
  401. getConsole().print(" size INT INT");
  402. getConsole().print(" fullscreen BOOL");
  403. getConsole().print(" audio BOOL");
  404. getConsole().print(" volume BOOL");
  405. getConsole().print(" mouse_x FLOAT");
  406. getConsole().print(" mouse_y FLOAT");
  407. getConsole().print(" fps BOOL");
  408. getConsole().print("Enclose STRINGs with \"\"!");
  409. } else if (cmd.compare("bind") == 0) {
  410. getConsole().print("bind-Command Usage:");
  411. getConsole().print(" bind ACTION KEY");
  412. getConsole().print("Available Actions:");
  413. getConsole().print(" menu");
  414. getConsole().print(" console");
  415. getConsole().print(" forward");
  416. getConsole().print(" backward");
  417. getConsole().print(" left");
  418. getConsole().print(" right");
  419. getConsole().print(" jump");
  420. getConsole().print(" crouch");
  421. getConsole().print(" use");
  422. getConsole().print(" holster");
  423. getConsole().print(" walk");
  424. getConsole().print("Key-Format:");
  425. getConsole().print(" 'a' or '1' for character/number keys");
  426. getConsole().print(" \"leftctrl\" for symbols and special keys");
  427. } else if (cmd.compare("load") == 0) {
  428. getConsole().print("load-Command Usage:");
  429. getConsole().print(" load /path/to/level");
  430. /*
  431. } else if (cmd.compare("sshot") == 0) {
  432. getConsole().print("sshot-Command Usage:");
  433. getConsole().print(" sshot [console|menu]");
  434. getConsole().print("Add console/menu to capture them too");
  435. } else if (cmd.compare("sound") == 0) {
  436. getConsole().print("sound-Command Usage:");
  437. getConsole().print(" sound INT");
  438. getConsole().print("Where INT is a valid sound ID integer");
  439. } else if (cmd.compare("move") == 0) {
  440. getConsole().print("move-Command Usage:");
  441. getConsole().print(" move COMMAND");
  442. getConsole().print("Where COMMAND is one of the following:");
  443. getConsole().print(" walk");
  444. getConsole().print(" fly");
  445. getConsole().print(" noclip");
  446. } else if (cmd.compare("mode") == 0) {
  447. getConsole().print("mode-Command Usage:");
  448. getConsole().print(" mode MODE");
  449. getConsole().print("Where MODE is one of the following:");
  450. getConsole().print(" wireframe");
  451. getConsole().print(" solid");
  452. getConsole().print(" texture");
  453. getConsole().print(" vertexlight");
  454. getConsole().print(" titlescreen");
  455. */
  456. } else if (cmd.compare("animate") == 0) {
  457. getConsole().print("animate-Command Usage:");
  458. getConsole().print(" animate [n|p|BOOL]");
  459. getConsole().print("Where the commands have the following meaning:");
  460. getConsole().print(" BOOL to (de)activate animating all models");
  461. getConsole().print(" n to step all models to their next animation");
  462. getConsole().print(" p to step all models to their previous animation");
  463. } else {
  464. getConsole().print("No help available for %s", cmd.c_str());
  465. return -1;
  466. }
  467. return 0;
  468. }
  469. char *OpenRaider::expandDirectoryNames(const char *s) {
  470. assert(s != NULL);
  471. assert(s[0] != '\0');
  472. char *result = bufferString("%s", s);
  473. if (mPakDir != NULL) {
  474. char *tmp = stringReplace(s, "$(pakdir)", mPakDir);
  475. delete [] result;
  476. result = tmp;
  477. }
  478. if (mAudioDir != NULL) {
  479. char *tmp = stringReplace(s, "$(audiodir)", mAudioDir);
  480. delete [] result;
  481. result = tmp;
  482. }
  483. if (mDataDir != NULL) {
  484. char *tmp = stringReplace(s, "$(datadir)", mDataDir);
  485. delete [] result;
  486. result = tmp;
  487. }
  488. if (mBaseDir != NULL) {
  489. char *tmp = stringReplace(result, "$(basedir)", mBaseDir);
  490. delete [] result;
  491. result = tmp;
  492. }
  493. return result;
  494. }
  495. #define CHANGE_DIR_WITH_EXPANSION(a) do { \
  496. std::string temp; \
  497. command >> temp; \
  498. const char *value = temp.c_str(); \
  499. char *quotes = stringRemoveQuotes(value); \
  500. char *tmp = expandDirectoryNames(quotes); \
  501. a = fullPath(tmp, 0); \
  502. delete [] tmp; \
  503. delete [] quotes; \
  504. } while(false)
  505. int OpenRaider::set(std::istream &command) {
  506. std::string var;
  507. command >> var;
  508. if (var.compare("size") == 0) {
  509. unsigned int w = DEFAULT_WIDTH, h = DEFAULT_HEIGHT;
  510. if (!(command >> w >> h)) {
  511. getConsole().print("set-size-Error: Invalid value(s)");
  512. return -2;
  513. }
  514. getWindow().setSize(w, h);
  515. } else if (var.compare("fullscreen") == 0) {
  516. bool fullscreen = false;
  517. if (!(command >> fullscreen)) {
  518. getConsole().print("set-fullscreen-Error: Invalid value");
  519. return -3;
  520. }
  521. getWindow().setFullscreen(fullscreen);
  522. } else if (var.compare("audio") == 0) {
  523. bool audio = false;
  524. if (!(command >> audio)) {
  525. getConsole().print("set-audio-Error: Invalid value");
  526. return -4;
  527. }
  528. getSound().setEnabled(audio);
  529. } else if (var.compare("volume") == 0) {
  530. float vol = 1.0f;
  531. if (!(command >> vol)) {
  532. getConsole().print("set-volume-Error: Invalid value");
  533. return -5;
  534. }
  535. getSound().setVolume(vol);
  536. } else if (var.compare("mouse_x") == 0) {
  537. float sense = 1.0f;
  538. if (!(command >> sense)) {
  539. getConsole().print("set-mouse_x-Error: Invalid value");
  540. return -6;
  541. }
  542. getCamera().setSensitivityX(OR_DEG_TO_RAD(sense));
  543. } else if (var.compare("mouse_y") == 0) {
  544. float sense = 1.0f;
  545. if (!(command >> sense)) {
  546. getConsole().print("set-mouse_y-Error: Invalid value");
  547. return -7;
  548. }
  549. getCamera().setSensitivityY(OR_DEG_TO_RAD(sense));
  550. } else if (var.compare("fps") == 0) {
  551. bool fps = false;
  552. if (!(command >> fps)) {
  553. getConsole().print("set-fps-Error: Invalid value");
  554. return -8;
  555. }
  556. mFPS = fps;
  557. } else if (var.compare("basedir") == 0) {
  558. CHANGE_DIR_WITH_EXPANSION(mBaseDir);
  559. } else if (var.compare("pakdir") == 0) {
  560. CHANGE_DIR_WITH_EXPANSION(mPakDir);
  561. } else if (var.compare("audiodir") == 0) {
  562. CHANGE_DIR_WITH_EXPANSION(mAudioDir);
  563. } else if (var.compare("datadir") == 0) {
  564. CHANGE_DIR_WITH_EXPANSION(mDataDir);
  565. } else if (var.compare("font") == 0) {
  566. std::string temp;
  567. command >> temp;
  568. const char *value = temp.c_str();
  569. char *quotes = stringReplace(value, "\"", "");
  570. char *tmp = expandDirectoryNames(quotes);
  571. getFont().setFont(tmp);
  572. delete [] tmp;
  573. delete [] quotes;
  574. } else {
  575. getConsole().print("set-Error: Unknown variable (%s)", var.c_str());
  576. return -1;
  577. }
  578. return 0;
  579. }
  580. int OpenRaider::bind(const char *action, const char *key) {
  581. assert(action != NULL);
  582. assert(action[0] != '\0');
  583. assert(key != NULL);
  584. assert(key[0] != '\0');
  585. ActionEvents e = stringToActionEvent(action);
  586. if (e == ActionEventCount) {
  587. getConsole().print("bind-Error: Unknown action (%s --> %s)", key, action);
  588. return -1;
  589. }
  590. KeyboardButton c = stringToKeyboardButton(key);
  591. if (c == unknownKey) {
  592. getConsole().print("bind-Error: Unknown key (%s)", key);
  593. return -2;
  594. }
  595. keyBindings[e] = c;
  596. return 0;
  597. }