ChatCommand.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include "ChatCommand.h"
  2. ChatCommand::ChatCommand(
  3. Framework::Text name, Framework::Text description, int securityLevel)
  4. : Framework::ReferenceCounter(),
  5. name(name),
  6. description(description),
  7. securityLevel(securityLevel)
  8. {}
  9. void ChatCommand::addParam(ChatCommandParameter* param)
  10. {
  11. params.add(param);
  12. }
  13. const Framework::RCArray<ChatCommandParameter>& ChatCommand::getParams() const
  14. {
  15. return params;
  16. }
  17. Framework::Text ChatCommand::getName() const
  18. {
  19. return name;
  20. }
  21. Framework::Text ChatCommand::getHelp() const
  22. {
  23. Framework::Text result = "/";
  24. result += name;
  25. for (ChatCommandParameter* param : params)
  26. {
  27. result += " ";
  28. if (param->isOptional()) result += "[";
  29. result += param->getName();
  30. if (param->isOptional()) result += "]";
  31. }
  32. if (description.getLength() > 0)
  33. {
  34. result += "\n ";
  35. result += description;
  36. }
  37. for (ChatCommandParameter* param : params)
  38. {
  39. if (param->getDescription().getLength() > 0)
  40. {
  41. result += "\n ";
  42. if (param->isOptional()) result += "[";
  43. result += param->getName();
  44. if (param->isOptional()) result += "]";
  45. result += " - ";
  46. result += param->getDescription();
  47. }
  48. }
  49. return result;
  50. }
  51. int ChatCommand::getSecurityLevel() const
  52. {
  53. return securityLevel;
  54. }
  55. ChatCommandParameter::ChatCommandParameter(
  56. Framework::Text name, Framework::Text description, bool optional)
  57. : ReferenceCounter(),
  58. name(name),
  59. description(description),
  60. optional(optional)
  61. {}
  62. bool ChatCommandParameter::isLegalValue(Framework::Text value) const
  63. {
  64. return 1;
  65. }
  66. Framework::Text ChatCommandParameter::getDefaultValue(Entity* zActor) const
  67. {
  68. return "";
  69. }
  70. Framework::Text ChatCommandParameter::getName() const
  71. {
  72. return name;
  73. }
  74. Framework::Text ChatCommandParameter::getDescription() const
  75. {
  76. return description;
  77. }
  78. bool ChatCommandParameter::isOptional() const
  79. {
  80. return optional;
  81. }