Elaztek Developer Hub
Blamite Game Engine - blam!  00398.09.22.23.2015.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 
28  {
29  delete this;
30  }
31 
32  BlamCommandResult onCommand(std::vector<std::string> arguments)
33  {
34  bool quiet = false;
35 
36  if (arguments.size() > 0)
37  {
38  if (arguments[0] == "quiet")
39  {
40  quiet = true;
41  }
42  }
43 
44  std::string doc_contents = "";
45 
46  // built-in commands
47  {
48  doc_contents += "== Built-in Commands ==";
49  doc_contents += "\n\n\n\n";
50 
51  std::map<std::string, BlamConsoleCommand*> commands = Blam::Resources::Console::GetCommandList();
52  std::map<std::string, BlamConsoleCommand*>::iterator it;
53 
54  for (it = commands.begin(); it != commands.end(); it++)
55  {
56  BlamConsoleCommand* command = it->second;
57 
58  // Syntax line
59  {
60  std::string syntax_line = "(";
61 
62  syntax_line += command->name;
63 
64  if (command->syntax != "")
65  {
66  syntax_line += " ";
67  syntax_line += command->syntax;
68  }
69 
70  syntax_line += ")";
71 
72  doc_contents += syntax_line;
73  }
74 
75  // Aliases line
76  if (command->aliases.size() > 0)
77  {
78  doc_contents += "\n\n";
79 
80  std::string aliases_line = "aliases: [";
81 
82  for (int i = 0; i < command->aliases.size(); i++)
83  {
84  std::string alias = command->aliases.at(i);
85 
86  aliases_line += alias;
87 
88  if (i != command->aliases.size() - 1)
89  {
90  aliases_line += ", ";
91  }
92  }
93 
94  aliases_line += "]";
95 
96  doc_contents += aliases_line;
97  }
98 
99  // Description line
100  if (command->description != "")
101  {
102  doc_contents += "\n\n";
103  doc_contents += command->description;
104  }
105 
106  // Network-safety line
107  {
108  doc_contents += "\n\n";
109  doc_contents += "NETWORK SAFE: Unspecified (networking is not available yet)";
110  }
111 
112  doc_contents += "\n\n\n\n";
113  }
114  }
115 
116  // script functions
117  {
118  doc_contents += "== Commands ==";
119  doc_contents += "\n\n\n\n";
120 
121  // none of these yet...
122  }
123 
124  // global variables
125  {
126  using namespace Blam::Globals;
127 
128  doc_contents += "== Script Globals ==";
129  doc_contents += "\n\n\n\n";
130 
131  std::map<std::string, EngineGlobal>* globals = GetGlobalsList();
132  std::map<std::string, EngineGlobal>::iterator it;
133 
134  for (it = globals->begin(); it != globals->end(); it++)
135  {
136  // name line
137  {
138  std::string global_line = "(" + it->second.name + " <" + GetGvarTypeLabel(it->second.type) + ">)";
139 
140  if (it->second.read_only)
141  {
142  global_line += " [protected]";
143  }
144 
145  doc_contents += global_line;
146  }
147 
148  if (it->second.info != "")
149  {
150  doc_contents += "\n";
151  doc_contents += it->second.info;
152  }
153 
154  doc_contents += "\n\n";
155  }
156  }
157 
158  std::string file_path = Blam::Config::GetConfig()->GetString("game_data_root") + "/hs_doc.txt";
159 
160  BlamStrings::Utils::IO::CreateNewFile(file_path, doc_contents);
161 
162  if (!quiet)
163  {
164  Blam::Modules::Keystone::OpenLocalURL("file://" + file_path);
165  }
166 
167  //WinExec(std::string("notepad " + file_path).c_str(), SW_SHOWDEFAULT);
168 
169  return CMD_OK;
170  }
171  };
172 }
Blam::Modules::Keystone::OpenLocalURL
BLAM bool OpenLocalURL(std::string url)
Definition: keystone.cpp:86
BlamCommandType::Builtin
@ Builtin
A command that is hard-coded into the engine.
Blam::Resources::Console::ScriptDocCommand::~ScriptDocCommand
~ScriptDocCommand()
Definition: script_doc.hpp:27
globals
Definition: globals.h:26
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:59
Blam::Resources::Console::ScriptDocCommand::onCommand
BlamCommandResult onCommand(std::vector< std::string > arguments)
Called upon command execution.
Definition: script_doc.hpp:32
keystone.h
Blam::Globals
Namespace containing things relating to game engine globals.
Definition: globals.h:23
BlamConsoleCommand
Class used to represent a console command.
Definition: console.h:56
Blam::Config::GetConfig
BLAM ConfigFile * GetConfig()
Retrieves the engine configuration file.
Definition: compat.cpp:5
BlamCommandResult
BlamCommandResult
Indicates the return state of a console command.
Definition: console.h:22
CMD_OK
#define CMD_OK
Macro for OK command status. See #Blam::Resources::Console::Ok for more details.
Definition: console.h:8
BlamConsoleCommand::name
std::string name
The name of the console command.
Definition: console.h:58
it
ARPHIC PUBLIC LICENSE Ltd Yung Chi Taiwan All rights reserved except as specified below Everyone is permitted to copy and distribute verbatim copies of this license but changing it is forbidden Preamble The licenses for most software are designed to take away your freedom to share and change it By the ARPHIC PUBLIC LICENSE specifically permits and encourages you to use this provided that you give the recipients all the rights that we gave you and make sure they can get the modifications of this software Legal Terms Font means the TrueType fonts AR PL Mingti2L AR PL KaitiM AR PL KaitiM and the derivatives of those fonts created through any modification including modifying reordering converting changing font or adding deleting some characters in from glyph table PL means Public License Copyright Holder means whoever is named in the copyright or copyrights for the Font You means the or person redistributing or modifying the Font Freely Available means that you have the freedom to copy or modify the Font as well as redistribute copies of the Font under the same conditions you not price If you you can charge for this service Copying &Distribution You may copy and distribute verbatim copies of this Font in any without provided that you retain this license including modifying reordering converting changing font or adding deleting some characters in from glyph and copy and distribute such modifications under the terms of Section provided that the following conditions are such as by offering access to copy the modifications from a designated or distributing the modifications on a medium customarily used for software interchange c If the modified fonts normally reads commands interactively when you must cause it
Definition: ARPHICPL.TXT:36
Blam::Resources::Console::GetCommandList
BLAM std::map< std::string, BlamConsoleCommand * > GetCommandList()
Retrieves the list of all loaded console commands.
Definition: console.cpp:237
Blam::Resources::Console::ScriptDocCommand
Class for the script_doc command.
Definition: script_doc.hpp:14
Blam::Globals::GetGlobalsList
BLAM std::map< std::string, EngineGlobal > * GetGlobalsList()
Retrieves the list of loaded globals.
Definition: globals.cpp:22
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:60
BlamConsoleCommand::type
BlamCommandType type
The type of command this is. See #Blam::Resources::Console::BlamCommandType for more information.
Definition: console.h:63
Blam::Config::ConfigFile::GetString
std::string GetString(std::string option)
Retrieves a string option from a configuration file.
Definition: compat.cpp:58
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:61
Blam::Resources::Console
Namespace for things relating to the debug console.
Definition: abort.hpp:5
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