Elaztek Developer Hub
Blamite Game Engine - blam!  00453.06.08.26.0624.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 
6 {
13  {
14  public:
16  {
17  name = "script_doc";
18  description = "saves a file called hs_doc.txt with parameters for all script commands and globals.";
19  aliases = { "hs_doc" };
20  syntax = "script_doc [quiet]";
21 
23  }
24 
25  BlamResult Execute(std::vector<std::string> arguments)
26  {
27  bool quiet = false;
28 
29  if (arguments.size() > 0)
30  {
31  if (arguments[0] == "quiet")
32  {
33  quiet = true;
34  }
35  }
36 
37  std::string doc_contents = "";
38 
39  // built-in commands
40  {
41  doc_contents += "== Built-in Commands ==";
42  doc_contents += "\n\n\n\n";
43 
44  std::map<std::string, BlamConsoleCommand*> commands = Blam::Resources::Console::GetCommandList();
45  std::map<std::string, BlamConsoleCommand*>::iterator it;
46 
47  for (it = commands.begin(); it != commands.end(); it++)
48  {
49  BlamConsoleCommand* command = it->second;
50 
51  // Syntax line
52  {
53  std::string syntax_line = "(";
54 
55  syntax_line += command->name;
56 
57  if (command->syntax != "")
58  {
59  syntax_line += " ";
60  syntax_line += command->syntax;
61  }
62 
63  syntax_line += ")";
64 
65  doc_contents += syntax_line;
66  }
67 
68  // Aliases line
69  if (command->aliases.size() > 0)
70  {
71  doc_contents += "\n\n";
72 
73  std::string aliases_line = "aliases: [";
74 
75  for (int i = 0; i < command->aliases.size(); i++)
76  {
77  std::string alias = command->aliases.at(i);
78 
79  aliases_line += alias;
80 
81  if (i != command->aliases.size() - 1)
82  {
83  aliases_line += ", ";
84  }
85  }
86 
87  aliases_line += "]";
88 
89  doc_contents += aliases_line;
90  }
91 
92  // Description line
93  if (command->description != "")
94  {
95  doc_contents += "\n\n";
96  doc_contents += command->description;
97  }
98 
99  // Network-safety line
100  {
101  doc_contents += "\n\n";
102  doc_contents += "NETWORK SAFE: Unspecified (networking is not available yet)";
103  }
104 
105  doc_contents += "\n\n\n\n";
106  }
107  }
108 
109  // script functions
110  {
111  doc_contents += "== Commands ==";
112  doc_contents += "\n\n\n\n";
113 
114  // none of these yet...
115  }
116 
117  // global variables
118  {
119  doc_contents += "== Script Globals ==";
120  doc_contents += "\n\n\n\n";
121 
122  std::map<std::string, BlamEngineGlobal>* globals = Blam::Globals::GetGlobalsList();
123  std::map<std::string, BlamEngineGlobal>::iterator it;
124 
125  for (it = globals->begin(); it != globals->end(); it++)
126  {
127  // name line
128  {
129  std::string global_line = "(" + it->second.name + " <" + Blam::Globals::GetGlobalTypeLabel(it->second.type) + ">)";
130 
131  if (it->second.read_only)
132  {
133  global_line += " [protected]";
134  }
135 
136  doc_contents += global_line;
137  }
138 
139  if (it->second.info != "")
140  {
141  doc_contents += "\n";
142  doc_contents += it->second.info;
143  }
144 
145  doc_contents += "\n\n";
146  }
147  }
148 
149  std::string file_path = USER_DATA_PATH(BlamUserDataFolder::DataRoot) + "/hs_doc.txt";
150 
151  BlamStrings::Utils::IO::CreateNewFile(file_path, doc_contents);
152 
153  if (!quiet)
154  {
155  BlamStrings::Utils::IO::OpenFile(file_path);
156  }
157 
158  //WinExec(std::string("notepad " + file_path).c_str(), SW_SHOWDEFAULT);
159 
160  return BlamResult::Success_OK;
161  }
162  };
163 }
globals
Definition: globals.h:27
Blam::Resources::Console::ScriptDocCommand::ScriptDocCommand
ScriptDocCommand()
Definition: script_doc.hpp:15
BlamConsoleCommand::description
std::string description
An optional description of the command. Shown when using the classify command.
Definition: console.h:36
Blam::Resources::Console::ScriptDocCommand::Execute
BlamResult Execute(std::vector< std::string > arguments)
Called upon command execution.
Definition: script_doc.hpp:25
BlamConsoleCommand
Class used to represent a console command.
Definition: console.h:33
USER_DATA_PATH
#define USER_DATA_PATH(path)
Macro to quickly access a user data folder.
Definition: config.h:41
BlamConsoleCommand::name
std::string name
The name of the console command.
Definition: console.h:35
Blam::Resources::Console::GetCommandList
BLAM std::map< std::string, BlamConsoleCommand * > GetCommandList()
Retrieves the list of all loaded console commands.
Definition: console.cpp:239
Blam::Globals::GetGlobalTypeLabel
BLAM std::string GetGlobalTypeLabel(BlamGlobalType type)
Retrieves a string representation of a global's type, for use in UI.
Definition: globals.cpp:40
Blam::Resources::Console::ScriptDocCommand
Class for the script_doc command.
Definition: script_doc.hpp:12
BlamConsoleCommand::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:37
BlamConsoleCommand::type
BlamCommandType type
The type of command this is. See #Blam::Resources::Console::BlamCommandType for more information.
Definition: console.h:40
BlamUserDataFolder::DataRoot
@ DataRoot
The root of all user data. Defaults to BlamStrings::Utils::IO::GetEngineDataRoot().
BlamConsoleCommand::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:38
Blam::Resources::Console
Namespace for things relating to the debug console.
Definition: abort.hpp:5
Blam::Globals::GetGlobalsList
BLAM std::map< std::string, BlamEngineGlobal > * GetGlobalsList()
Retrieves the list of loaded globals.
Definition: globals.cpp:22
BlamCommandType::Builtin
@ Builtin
A command that is hard-coded into the engine.