OpenTTD Source
20240919-master-gdf0233f4c2
|
Go to the documentation of this file.
10 #include "../stdafx.h"
12 #include "../script/squirrel_class.hpp"
17 #include "../safeguards.h"
25 static const std::set<std::string> versions = {
"1.2",
"1.3",
"1.4",
"1.5",
"1.6",
"1.7",
"1.8",
"1.9",
"1.10",
"1.11",
"12",
"13",
"14",
"15" };
26 return versions.find(api_version) != versions.end();
32 template <>
const char *GetClassName<GameInfo, ScriptType::GS>() {
return "GSInfo"; }
38 SQGSInfo.PreRegister(
engine);
48 SQGSInfo.PostRegister(
engine);
55 SQUserPointer instance =
nullptr;
56 if (SQ_FAILED(sq_getinstanceup(vm, 2, &instance,
nullptr)) || instance ==
nullptr)
return sq_throwerror(vm,
"Pass an instance of a child class of GameInfo to RegisterGame");
60 if (res != 0)
return res;
74 if (!info->
CheckMethod(
"GetAPIVersion"))
return SQ_ERROR;
77 Debug(script, 1,
"Loading info.nut from ({}.{}): GetAPIVersion returned invalid version", info->
GetName(), info->
GetVersion());
82 sq_setinstanceup(vm, 2,
nullptr);
88 GameInfo::GameInfo() :
89 min_loadable_version(0),
90 is_developer_only(false)
SQInteger AddSetting(HSQUIRRELVM vm)
Set a setting.
std::string api_version
API version used by this Game.
class Squirrel * engine
Engine used to register for Squirrel.
static SQInteger Constructor(HSQUIRRELVM vm, ScriptInfo *info)
Process the creation of a FileInfo object.
static bool CheckAPIVersion(const std::string &api_version)
Check if the API version provided by the Game is supported.
std::string category
The category this library is in.
void AddClassBegin(const char *class_name)
Adds a class to the global scope.
@ SCRIPTCONFIG_BOOLEAN
This value is a boolean (either 0 (false) or 1 (true) ).
static SQInteger Constructor(HSQUIRRELVM vm)
Create an GSLibrary, using this GSInfo as start-template.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
int version
Version of the script.
void AddClassEnd()
Finishes adding a class to the global scope.
bool CanLoadFromVersion(int version) const
Check if we can start this Game.
static const int MAX_GET_OPS
Number of operations to get the author and similar information.
void DefSQAdvancedMethod(Squirrel *engine, Func function_proc, const char *function_name)
This defines a method inside a class for Squirrel, which has access to the 'engine' (experts only!...
@ SCRIPTCONFIG_NONE
No flags set.
static SQInteger Constructor(HSQUIRRELVM vm)
Create an Game, using this GameInfo as start-template.
bool CheckMethod(const char *name) const
Check if a given method exists.
@ SCRIPTCONFIG_INGAME
This setting can be changed while the Script is running.
@ SCRIPTCONFIG_DEVELOPER
This setting will only be visible when the Script development tools are active.
const std::string & GetName() const
Get the Name of the script.
static void RegisterAPI(Squirrel *engine)
Register the functions of this class.
static void RegisterAPI(Squirrel *engine)
Register the functions of this class.
bool is_developer_only
Is the script selectable by non-developers?
void RegisterScript(class ScriptInfo *info)
Register a ScriptInfo to the scanner.
int GetVersion() const
Get the version of the script.
bool MethodExists(HSQOBJECT instance, const char *method_name)
Check if a method exists in an instance.
SQInteger AddLabels(HSQUIRRELVM vm)
Add labels for a setting.
void AddMethod(const char *method_name, SQFUNCTION proc, uint nparam=0, const char *params=nullptr, void *userdata=nullptr, int size=0)
Adds a function to the stack.
All static information from an Game like name, version, etc.
All static information from an Game library like name, version, etc.
The template to define classes in Squirrel.
int min_loadable_version
The Game can load savegame data if the version is equal or greater than this.
HSQOBJECT SQ_instance
The Squirrel instance created for this info.
virtual class ScriptScanner * GetScanner()
Get the scanner which has found this ScriptInfo.