Blamite Game Engine - blam!  00272.10.26.20.0001.blamite
The core library for the Blamite Game Engine.
script_doc.hpp
Go to the documentation of this file.
1 #include "../console.h"
2 
3 #include <Strings/components/utils/io/io.h>
4 
5 
6 namespace Blam::Console
7 {
14  {
15  public:
17  {
18  name = "script_doc";
19  description = "saves a file called hs_doc.txt with parameters for all script commands and globals.";
20  aliases = { "hs_doc" };
21 
23  }
24 
26  {
27  delete this;
28  }
29 
30  CommandStatus onCommand(std::vector<std::string> arguments)
31  {
32  std::string doc_contents = "";
33 
34  // built-in commands
35  {
36  doc_contents += "== Built-in Commands ==";
37  doc_contents += "\n\n\n\n";
38 
39  std::map<std::string, Blam::Console::ConsoleCommand*> commands = Blam::Console::GetCommandList();
40  std::map<std::string, Blam::Console::ConsoleCommand*>::iterator it;
41 
42  for (it = commands.begin(); it != commands.end(); it++)
43  {
44  Blam::Console::ConsoleCommand* command = it->second;
45 
46  // Syntax line
47  {
48  std::string syntax_line = "(";
49 
50  syntax_line += command->name;
51 
52  if (command->syntax != "")
53  {
54  syntax_line += " ";
55  syntax_line += command->syntax;
56  }
57 
58  syntax_line += ")";
59 
60  doc_contents += syntax_line;
61  }
62 
63  // Aliases line
64  if (command->aliases.size() > 0)
65  {
66  doc_contents += "\n\n";
67 
68  std::string aliases_line = "aliases: [";
69 
70  for (int i = 0; i < command->aliases.size(); i++)
71  {
72  std::string alias = command->aliases.at(i);
73 
74  aliases_line += alias;
75 
76  if (i != command->aliases.size() - 1)
77  {
78  aliases_line += ", ";
79  }
80  }
81 
82  aliases_line += "]";
83 
84  doc_contents += aliases_line;
85  }
86 
87  // Description line
88  if (command->description != "")
89  {
90  doc_contents += "\n\n";
91  doc_contents += command->description;
92  }
93 
94 
95  doc_contents += "\n\n\n\n";
96  }
97  }
98 
99  // script functions
100  {
101  doc_contents += "== Commands ==";
102  doc_contents += "\n\n\n\n";
103 
104  // none of these yet...
105  }
106 
107  // global variables
108  {
109  using namespace Blam::Globals;
110 
111  doc_contents += "== Script Globals ==";
112  doc_contents += "\n\n\n\n";
113 
114  std::map<std::string, EngineGlobal>* globals = GetGlobalsList();
115  std::map<std::string, EngineGlobal>::iterator it;
116 
117  for (it = globals->begin(); it != globals->end(); it++)
118  {
119  // name line
120  {
121  std::string global_line = "(" + it->second.name + " <" + GetGvarTypeLabel(it->second.type) + ">)";
122 
123  if (it->second.read_only)
124  {
125  global_line += " [protected]";
126  }
127 
128  doc_contents += global_line;
129  }
130 
131  if (it->second.info != "")
132  {
133  doc_contents += "\n";
134  doc_contents += it->second.info;
135  }
136 
137  doc_contents += "\n\n";
138  }
139  }
140 
141  std::string file_path = Blam::Config::GetConfig()->GetString("game_data_root") + "./hs_doc.txt";
142 
143  BlamStrings::Utils::IO::CreateNewFile(file_path, doc_contents);
144 
145  WinExec(std::string("notepad " + file_path).c_str(), SW_SHOWDEFAULT);
146 
147  return CMD_OK;
148  }
149  };
150 }
Blam::Console::ConsoleCommand::aliases
std::vector< std::string > aliases
A list of aliases for the command. Executing any of these instead of the command name will behave the...
Definition: console.h:75
Blam::Console::GetCommandList
BLAM std::map< std::string, ConsoleCommand * > GetCommandList()
Retrieves the list of all loaded console commands.
Definition: console.cpp:150
Blam::Console::ConsoleCommand::description
std::string description
An optional description of the command. Shown when using the classify command.
Definition: console.h:73
Blam::Console::ConsoleCommand::type
CommandType type
The type of command this is. See Blam::Console::CommandType for more information.
Definition: console.h:77
Blam::Console::CommandStatus
CommandStatus
Indicates the return state of a console command.
Definition: console.h:28
Blam::Config::GetConfig
BLAM ConfigFile * GetConfig(std::string filename)
Retrieves the specified configuration file.
Definition: config.cpp:232
Blam::Console::ScriptDocCommand::~ScriptDocCommand
~ScriptDocCommand()
Definition: script_doc.hpp:25
Blam::Globals
Namespace containing things relating to game engine globals.
Definition: globals.h:193
Blam::Console::ScriptDocCommand::onCommand
CommandStatus onCommand(std::vector< std::string > arguments)
Called upon command execution.
Definition: script_doc.hpp:30
Blam::Console::Builtin
@ Builtin
A command that is hard-coded into the engine.
Definition: console.h:41
Blam::Console::ConsoleCommand::name
std::string name
The name of the console command.
Definition: console.h:70
globals
std::map< std::string, EngineGlobal > globals
The list of loaded globals.
Definition: globals.cpp:20
Blam::Globals::GetGlobalsList
BLAM std::map< std::string, EngineGlobal > * GetGlobalsList()
Retrieves the list of loaded globals.
Definition: globals.cpp:22
Blam::Console
Namespace for things relating to the debug console.
Definition: abort.hpp:5
Blam::Console::ConsoleCommand
Class used to represent a console command.
Definition: console.h:50
CMD_OK
#define CMD_OK
Macro for OK command status. See Blam::Console::Ok for more details.
Definition: console.h:9
Blam::Console::ScriptDocCommand
Class for the script_doc command.
Definition: script_doc.hpp:13
Blam::Globals::GetGvarTypeLabel
BLAM std::string GetGvarTypeLabel(GvarType type)
Retrieves a string representation of a global's type, for use in UI.
Definition: globals.cpp:40
Blam::Console::ConsoleCommand::syntax
std::string syntax
The syntax information for the command. Shown to the user when using the help command with an argumen...
Definition: console.h:74
Blam::Console::ScriptDocCommand::ScriptDocCommand
ScriptDocCommand()
Definition: script_doc.hpp:16
Blam::Config::ConfigFile::GetString
std::string GetString(std::string option)
Retrieves the specified config option's value as a string.
Definition: config_accessors.cpp:10