Elaztek Developer Hub
Blamite Game Engine - blam!  00406.12.10.23.1457.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  Blam::Modules::Keystone::OpenLocalURL("file://" + file_path);
158  }
159 
160  //WinExec(std::string("notepad " + file_path).c_str(), SW_SHOWDEFAULT);
161 
162  return BlamResult::Success_OK;
163  }
164  };
165 }
Blam::Modules::Keystone::OpenLocalURL
BLAM bool OpenLocalURL(std::string url)
Opens a local file with the user's default application.
Definition: keystone.cpp:84
BlamCommandType::Builtin
@ Builtin
A command that is hard-coded into the engine.
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:34
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:31
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:33
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:228
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:35
BlamConsoleCommand::type
BlamCommandType type
The type of command this is. See #Blam::Resources::Console::BlamCommandType for more information.
Definition: console.h:38
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:36
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