OpenTTD
script_info.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #ifndef SCRIPT_INFO_HPP
11 #define SCRIPT_INFO_HPP
12 
13 #include <squirrel.h>
14 #include "../misc/countedptr.hpp"
15 
16 #include "script_config.hpp"
17 
19 static const int MAX_SL_OPS = 100000;
21 static const int MAX_CONSTRUCTOR_OPS = 100000;
23 static const int MAX_CREATEINSTANCE_OPS = 100000;
25 static const int MAX_GET_OPS = 1000;
27 static const int MAX_GET_SETTING_OPS = 100000;
28 
31 public:
32  ScriptInfo() :
33  engine(nullptr),
34  SQ_instance(nullptr),
35  main_script(nullptr),
36  tar_file(nullptr),
37  author(nullptr),
38  name(nullptr),
39  short_name(nullptr),
40  description(nullptr),
41  date(nullptr),
42  instance_name(nullptr),
43  version(0),
44  url(nullptr),
45  scanner(nullptr)
46  {}
47  ~ScriptInfo();
48 
52  const char *GetAuthor() const { return this->author; }
53 
57  const char *GetName() const { return this->name; }
58 
62  const char *GetShortName() const { return this->short_name; }
63 
67  const char *GetDescription() const { return this->description; }
68 
72  int GetVersion() const { return this->version; }
73 
77  const char *GetDate() const { return this->date; }
78 
82  const char *GetInstanceName() const { return this->instance_name; }
83 
87  const char *GetURL() const { return this->url; }
88 
92  const char *GetMainScript() const { return this->main_script; }
93 
97  const char *GetTarFile() const { return this->tar_file; }
98 
102  bool CheckMethod(const char *name) const;
103 
107  static SQInteger Constructor(HSQUIRRELVM vm, ScriptInfo *info);
108 
112  virtual class ScriptScanner *GetScanner() { return this->scanner; }
113 
117  bool GetSettings();
118 
122  const ScriptConfigItemList *GetConfigList() const;
123 
127  const ScriptConfigItem *GetConfigItem(const char *name) const;
128 
132  SQInteger AddSetting(HSQUIRRELVM vm);
133 
137  SQInteger AddLabels(HSQUIRRELVM vm);
138 
142  int GetSettingDefaultValue(const char *name) const;
143 
147  virtual bool IsDeveloperOnly() const { return false; }
148 
149 protected:
150  class Squirrel *engine;
151  HSQOBJECT *SQ_instance;
153 
154 private:
155  char *main_script;
156  char *tar_file;
157  const char *author;
158  const char *name;
159  const char *short_name;
160  const char *description;
161  const char *date;
162  const char *instance_name;
163  int version;
164  const char *url;
165 
167 };
168 
169 #endif /* SCRIPT_INFO_HPP */
int GetVersion() const
Get the version of the script.
Definition: script_info.hpp:72
int version
Version of the script.
class ScriptScanner * scanner
ScriptScanner object that was used to scan this script info.
HSQOBJECT * SQ_instance
The Squirrel instance created for this info.
bool CheckMethod(const char *name) const
Check if a given method exists.
Definition: script_info.cpp:47
const ScriptConfigItemList * GetConfigList() const
Get the config list for this Script.
const char * GetName() const
Get the Name of the script.
Definition: script_info.hpp:57
const char * date
The date the script was written at.
std::list< ScriptConfigItem > ScriptConfigItemList
List of ScriptConfig items.
const char * url
URL of the script.
const char * GetShortName() const
Get the 4 character long short name of the script.
Definition: script_info.hpp:62
ScriptConfigItemList config_list
List of settings from this Script.
const char * instance_name
Name of the main class in the script.
int GetSettingDefaultValue(const char *name) const
Get the default value for a setting.
Scanner to help finding scripts.
const char * GetMainScript() const
Get the filename of the main.nut script.
Definition: script_info.hpp:92
const char * GetDate() const
Get the last-modified date of the script.
Definition: script_info.hpp:77
const char * short_name
Short name (4 chars) which uniquely identifies the script.
SQInteger AddLabels(HSQUIRRELVM vm)
Add labels for a setting.
All static information from an Script like name, version, etc.
Definition: script_info.hpp:30
const char * author
Author of the script.
bool GetSettings()
Get the settings of the Script.
const char * GetURL() const
Get the website for this script.
Definition: script_info.hpp:87
Simple counted object.
Definition: countedptr.hpp:204
const ScriptConfigItem * GetConfigItem(const char *name) const
Get the description of a certain Script config option.
virtual class ScriptScanner * GetScanner()
Get the scanner which has found this ScriptInfo.
const char * GetDescription() const
Get the description of the script.
Definition: script_info.hpp:67
const char * name
Full name of the script.
SQInteger AddSetting(HSQUIRRELVM vm)
Set a setting.
ScriptConfig stores the configuration settings of every Script.
Info about a single Script setting.
static const int MAX_SL_OPS
The maximum number of operations for saving or loading the data of a script.
Definition: script_info.hpp:19
static const int MAX_GET_OPS
Number of operations to get the author and similar information.
Definition: script_info.hpp:25
char * main_script
The full path of the script.
static const int MAX_CREATEINSTANCE_OPS
Number of operations to create an instance of a script.
Definition: script_info.hpp:23
const char * GetAuthor() const
Get the Author of the script.
Definition: script_info.hpp:52
class Squirrel * engine
Engine used to register for Squirrel.
static const int MAX_CONSTRUCTOR_OPS
The maximum number of operations for initial start of a script.
Definition: script_info.hpp:21
static SQInteger Constructor(HSQUIRRELVM vm, ScriptInfo *info)
Process the creation of a FileInfo object.
Definition: script_info.cpp:58
const char * description
Small description of the script.
char * tar_file
If, which tar file the script was in.
static const int MAX_GET_SETTING_OPS
Maximum number of operations allowed for getting a particular setting.
Definition: script_info.hpp:27
const char * GetInstanceName() const
Get the name of the instance of the script to create.
Definition: script_info.hpp:82
const char * GetTarFile() const
Get the filename of the tar the script is in.
Definition: script_info.hpp:97
virtual bool IsDeveloperOnly() const
Can this script be selected by developers only?