2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2009-03-15 22:41:57 +00:00
|
|
|
/** @file script_info.hpp ScriptInfo keeps track of all information of a script, like Author, Description, ... */
|
|
|
|
|
2010-12-22 11:46:41 +00:00
|
|
|
#ifndef SCRIPT_INFO_HPP
|
|
|
|
#define SCRIPT_INFO_HPP
|
2009-03-15 22:41:57 +00:00
|
|
|
|
2010-01-15 16:41:15 +00:00
|
|
|
#include <squirrel.h>
|
2009-03-15 22:41:57 +00:00
|
|
|
#include "../misc/countedptr.hpp"
|
|
|
|
|
2011-11-29 23:26:35 +00:00
|
|
|
#include "script_config.hpp"
|
|
|
|
|
2011-11-29 23:26:44 +00:00
|
|
|
/** The maximum number of operations for saving or loading the data of a script. */
|
|
|
|
static const int MAX_SL_OPS = 100000;
|
|
|
|
/** The maximum number of operations for initial start of a script. */
|
|
|
|
static const int MAX_CONSTRUCTOR_OPS = 100000;
|
|
|
|
/** Number of operations to create an instance of a script. */
|
|
|
|
static const int MAX_CREATEINSTANCE_OPS = 100000;
|
|
|
|
/** Number of operations to get the author and similar information. */
|
|
|
|
static const int MAX_GET_OPS = 1000;
|
|
|
|
/** Maximum number of operations allowed for getting a particular setting. */
|
|
|
|
static const int MAX_GET_SETTING_OPS = 100000;
|
|
|
|
|
|
|
|
/** All static information from an Script like name, version, etc. */
|
2011-11-29 23:21:52 +00:00
|
|
|
class ScriptInfo : public SimpleCountedObject {
|
2009-03-15 22:41:57 +00:00
|
|
|
public:
|
2011-11-29 23:21:52 +00:00
|
|
|
ScriptInfo() :
|
2019-04-10 21:07:06 +00:00
|
|
|
engine(nullptr),
|
|
|
|
SQ_instance(nullptr),
|
|
|
|
author(nullptr),
|
|
|
|
name(nullptr),
|
|
|
|
short_name(nullptr),
|
|
|
|
description(nullptr),
|
|
|
|
date(nullptr),
|
|
|
|
instance_name(nullptr),
|
2009-12-06 20:22:21 +00:00
|
|
|
version(0),
|
2019-04-10 21:07:06 +00:00
|
|
|
url(nullptr),
|
|
|
|
scanner(nullptr)
|
2009-03-15 22:41:57 +00:00
|
|
|
{}
|
2011-11-29 23:21:52 +00:00
|
|
|
~ScriptInfo();
|
2009-03-15 22:41:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Author of the script.
|
|
|
|
*/
|
|
|
|
const char *GetAuthor() const { return this->author; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Name of the script.
|
|
|
|
*/
|
|
|
|
const char *GetName() const { return this->name; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the 4 character long short name of the script.
|
|
|
|
*/
|
|
|
|
const char *GetShortName() const { return this->short_name; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the description of the script.
|
|
|
|
*/
|
|
|
|
const char *GetDescription() const { return this->description; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the version of the script.
|
|
|
|
*/
|
|
|
|
int GetVersion() const { return this->version; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the last-modified date of the script.
|
|
|
|
*/
|
|
|
|
const char *GetDate() const { return this->date; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the name of the instance of the script to create.
|
|
|
|
*/
|
|
|
|
const char *GetInstanceName() const { return this->instance_name; }
|
|
|
|
|
2009-04-19 15:14:23 +00:00
|
|
|
/**
|
|
|
|
* Get the website for this script.
|
|
|
|
*/
|
|
|
|
const char *GetURL() const { return this->url; }
|
|
|
|
|
2009-03-15 22:41:57 +00:00
|
|
|
/**
|
|
|
|
* Get the filename of the main.nut script.
|
|
|
|
*/
|
2020-12-06 20:11:50 +00:00
|
|
|
const char *GetMainScript() const { return this->main_script.c_str(); }
|
2009-03-15 22:41:57 +00:00
|
|
|
|
2011-09-08 09:55:04 +00:00
|
|
|
/**
|
|
|
|
* Get the filename of the tar the script is in.
|
|
|
|
*/
|
2020-12-06 20:11:50 +00:00
|
|
|
std::string GetTarFile() const { return this->tar_file; }
|
2011-09-08 09:55:04 +00:00
|
|
|
|
2009-03-15 22:41:57 +00:00
|
|
|
/**
|
|
|
|
* Check if a given method exists.
|
|
|
|
*/
|
|
|
|
bool CheckMethod(const char *name) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the creation of a FileInfo object.
|
|
|
|
*/
|
2011-11-29 23:21:52 +00:00
|
|
|
static SQInteger Constructor(HSQUIRRELVM vm, ScriptInfo *info);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the scanner which has found this ScriptInfo.
|
|
|
|
*/
|
|
|
|
virtual class ScriptScanner *GetScanner() { return this->scanner; }
|
2009-03-15 22:41:57 +00:00
|
|
|
|
2011-11-29 23:26:35 +00:00
|
|
|
/**
|
|
|
|
* Get the settings of the Script.
|
|
|
|
*/
|
|
|
|
bool GetSettings();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the config list for this Script.
|
|
|
|
*/
|
|
|
|
const ScriptConfigItemList *GetConfigList() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the description of a certain Script config option.
|
|
|
|
*/
|
|
|
|
const ScriptConfigItem *GetConfigItem(const char *name) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a setting.
|
|
|
|
*/
|
|
|
|
SQInteger AddSetting(HSQUIRRELVM vm);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add labels for a setting.
|
|
|
|
*/
|
|
|
|
SQInteger AddLabels(HSQUIRRELVM vm);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the default value for a setting.
|
|
|
|
*/
|
|
|
|
int GetSettingDefaultValue(const char *name) const;
|
|
|
|
|
2011-12-19 20:57:08 +00:00
|
|
|
/**
|
|
|
|
* Can this script be selected by developers only?
|
|
|
|
*/
|
|
|
|
virtual bool IsDeveloperOnly() const { return false; }
|
2011-11-29 23:26:35 +00:00
|
|
|
|
2009-03-15 22:41:57 +00:00
|
|
|
protected:
|
2011-11-29 23:26:35 +00:00
|
|
|
class Squirrel *engine; ///< Engine used to register for Squirrel.
|
|
|
|
HSQOBJECT *SQ_instance; ///< The Squirrel instance created for this info.
|
|
|
|
ScriptConfigItemList config_list; ///< List of settings from this Script.
|
2011-11-29 23:21:52 +00:00
|
|
|
|
2009-03-15 22:41:57 +00:00
|
|
|
private:
|
2020-12-06 20:11:50 +00:00
|
|
|
std::string main_script; ///< The full path of the script.
|
|
|
|
std::string tar_file; ///< If, which tar file the script was in.
|
2011-11-29 23:21:52 +00:00
|
|
|
const char *author; ///< Author of the script.
|
|
|
|
const char *name; ///< Full name of the script.
|
|
|
|
const char *short_name; ///< Short name (4 chars) which uniquely identifies the script.
|
|
|
|
const char *description; ///< Small description of the script.
|
|
|
|
const char *date; ///< The date the script was written at.
|
2011-11-29 23:21:59 +00:00
|
|
|
const char *instance_name; ///< Name of the main class in the script.
|
2011-11-29 23:21:52 +00:00
|
|
|
int version; ///< Version of the script.
|
|
|
|
const char *url; ///< URL of the script.
|
|
|
|
|
|
|
|
class ScriptScanner *scanner; ///< ScriptScanner object that was used to scan this script info.
|
2009-03-15 22:41:57 +00:00
|
|
|
};
|
|
|
|
|
2010-12-22 11:46:41 +00:00
|
|
|
#endif /* SCRIPT_INFO_HPP */
|