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