ScriptManagerCommands.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include "ConfigCmdManager.h"
  16. #include "Console.h"
  17. /**
  18. * Runs a script string.
  19. *
  20. * @param params[in] Script parameters. Exactly three are required. The first
  21. * one is the command name and it's not evaluated here. The second one must be
  22. * the line to execute. If less than three parameter are passed, a usage string
  23. * will be printed instead, and nothing will be done.
  24. */
  25. void CmdScriptRunString(const Ogre::StringVector& params){
  26. if(params.size() < 2){
  27. Console::getSingleton().AddTextToOutput(
  28. "Usage: /script_run_string <string>"
  29. );
  30. return;
  31. }
  32. ScriptManager::getSingleton().RunString(params[1]);
  33. }
  34. /**
  35. * Runs a script string.
  36. *
  37. * @param params[in] Script parameters. Exactly three are required. The first
  38. * one is the command name and it's not evaluated here. The second one must be
  39. * the path to the file to execute. If less than three parameter are passed, a
  40. * usage string will be printed instead, and nothing will be done.
  41. */
  42. void CmdScriptRunFile(const Ogre::StringVector& params){
  43. if(params.size() < 2){
  44. Console::getSingleton().AddTextToOutput(
  45. "Usage: /script_run_file <file name>"
  46. );
  47. return;
  48. }
  49. ScriptManager::getSingleton().RunFile(params[1]);
  50. }
  51. void ScriptManager::InitCmd(){
  52. ConfigCmdManager::getSingleton().AddCommand(
  53. "script_run_string", "Run script string", "", CmdScriptRunString, NULL
  54. );
  55. ConfigCmdManager::getSingleton().AddCommand(
  56. "script_run_file", "Run script file", "", CmdScriptRunFile, NULL
  57. );
  58. }