Update: Translations from eints
[openttd-github.git] / src / script / script_info.hpp
blob90a04d13d83c1faf369b3b4bbdbe3609d8ae53d0
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 */
8 /** @file script_info.hpp ScriptInfo keeps track of all information of a script, like Author, Description, ... */
10 #ifndef SCRIPT_INFO_HPP
11 #define SCRIPT_INFO_HPP
13 #include <squirrel.h>
14 #include "../misc/countedptr.hpp"
16 #include "script_config.hpp"
18 /** The maximum number of operations for saving or loading the data of a script. */
19 static const int MAX_SL_OPS = 100000;
20 /** The maximum number of operations for initial start of a script. */
21 static const int MAX_CONSTRUCTOR_OPS = 100000;
22 /** Number of operations to create an instance of a script. */
23 static const int MAX_CREATEINSTANCE_OPS = 100000;
24 /** Number of operations to get the author and similar information. */
25 static const int MAX_GET_OPS = 1000;
26 /** Maximum number of operations allowed for getting a particular setting. */
27 static const int MAX_GET_SETTING_OPS = 100000;
29 /** All static information from an Script like name, version, etc. */
30 class ScriptInfo : public SimpleCountedObject {
31 public:
32 ScriptInfo() :
33 engine(nullptr),
34 version(0),
35 scanner(nullptr)
38 /**
39 * Get the Author of the script.
41 const std::string &GetAuthor() const { return this->author; }
43 /**
44 * Get the Name of the script.
46 const std::string &GetName() const { return this->name; }
48 /**
49 * Get the 4 character long short name of the script.
51 const std::string &GetShortName() const { return this->short_name; }
53 /**
54 * Get the description of the script.
56 const std::string &GetDescription() const { return this->description; }
58 /**
59 * Get the version of the script.
61 int GetVersion() const { return this->version; }
63 /**
64 * Get the last-modified date of the script.
66 const std::string &GetDate() const { return this->date; }
68 /**
69 * Get the name of the instance of the script to create.
71 const std::string &GetInstanceName() const { return this->instance_name; }
73 /**
74 * Get the website for this script.
76 const std::string &GetURL() const { return this->url; }
78 /**
79 * Get the filename of the main.nut script.
81 const std::string &GetMainScript() const { return this->main_script; }
83 /**
84 * Get the filename of the tar the script is in.
86 const std::string &GetTarFile() const { return this->tar_file; }
88 /**
89 * Check if a given method exists.
91 bool CheckMethod(const char *name) const;
93 /**
94 * Process the creation of a FileInfo object.
96 static SQInteger Constructor(HSQUIRRELVM vm, ScriptInfo *info);
98 /**
99 * Get the scanner which has found this ScriptInfo.
101 virtual class ScriptScanner *GetScanner() { return this->scanner; }
104 * Get the settings of the Script.
106 bool GetSettings();
109 * Get the config list for this Script.
111 const ScriptConfigItemList *GetConfigList() const;
114 * Get the description of a certain Script config option.
116 const ScriptConfigItem *GetConfigItem(const std::string_view name) const;
119 * Set a setting.
121 SQInteger AddSetting(HSQUIRRELVM vm);
124 * Add labels for a setting.
126 SQInteger AddLabels(HSQUIRRELVM vm);
129 * Get the default value for a setting.
131 int GetSettingDefaultValue(const std::string &name) const;
134 * Can this script be selected by developers only?
136 virtual bool IsDeveloperOnly() const { return false; }
138 protected:
139 class Squirrel *engine; ///< Engine used to register for Squirrel.
140 HSQOBJECT SQ_instance; ///< The Squirrel instance created for this info.
141 ScriptConfigItemList config_list; ///< List of settings from this Script.
143 private:
144 std::string main_script; ///< The full path of the script.
145 std::string tar_file; ///< If, which tar file the script was in.
146 std::string author; ///< Author of the script.
147 std::string name; ///< Full name of the script.
148 std::string short_name; ///< Short name (4 chars) which uniquely identifies the script.
149 std::string description; ///< Small description of the script.
150 std::string date; ///< The date the script was written at.
151 std::string instance_name; ///< Name of the main class in the script.
152 int version; ///< Version of the script.
153 std::string url; ///< URL of the script.
155 class ScriptScanner *scanner; ///< ScriptScanner object that was used to scan this script info.
158 void Script_CreateDummyInfo(HSQUIRRELVM vm, const char *type, const char *dir);
159 void Script_CreateDummy(HSQUIRRELVM vm, StringID string, const char *type);
161 #endif /* SCRIPT_INFO_HPP */