Codechange: use std::string for script API versions
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
* Check if the API version provided by the Game is supported.
|
||||
* @param api_version The API version as provided by the Game.
|
||||
*/
|
||||
static bool CheckAPIVersion(const char *api_version)
|
||||
static bool CheckAPIVersion(const std::string &api_version)
|
||||
{
|
||||
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" };
|
||||
return versions.find(api_version) != versions.end();
|
||||
@@ -73,7 +73,7 @@ template <> const char *GetClassName<GameInfo, ScriptType::GS>() { return "GSInf
|
||||
}
|
||||
/* Try to get the API version the AI is written for. */
|
||||
if (!info->CheckMethod("GetAPIVersion")) return SQ_ERROR;
|
||||
if (!info->engine->CallStringMethodStrdup(*info->SQ_instance, "GetAPIVersion", &info->api_version, MAX_GET_OPS)) return SQ_ERROR;
|
||||
if (!info->engine->CallStringMethod(*info->SQ_instance, "GetAPIVersion", &info->api_version, MAX_GET_OPS)) return SQ_ERROR;
|
||||
if (!CheckAPIVersion(info->api_version)) {
|
||||
Debug(script, 1, "Loading info.nut from ({}.{}): GetAPIVersion returned invalid version", info->GetName(), info->GetVersion());
|
||||
return SQ_ERROR;
|
||||
@@ -88,16 +88,10 @@ template <> const char *GetClassName<GameInfo, ScriptType::GS>() { return "GSInf
|
||||
|
||||
GameInfo::GameInfo() :
|
||||
min_loadable_version(0),
|
||||
is_developer_only(false),
|
||||
api_version(nullptr)
|
||||
is_developer_only(false)
|
||||
{
|
||||
}
|
||||
|
||||
GameInfo::~GameInfo()
|
||||
{
|
||||
free(this->api_version);
|
||||
}
|
||||
|
||||
bool GameInfo::CanLoadFromVersion(int version) const
|
||||
{
|
||||
if (version == -1) return true;
|
||||
|
@@ -16,7 +16,6 @@
|
||||
class GameInfo : public ScriptInfo {
|
||||
public:
|
||||
GameInfo();
|
||||
~GameInfo();
|
||||
|
||||
/**
|
||||
* Register the functions of this class.
|
||||
@@ -36,14 +35,14 @@ public:
|
||||
/**
|
||||
* Get the API version this Game is written for.
|
||||
*/
|
||||
const char *GetAPIVersion() const { return this->api_version; }
|
||||
const std::string &GetAPIVersion() const { return this->api_version; }
|
||||
|
||||
bool IsDeveloperOnly() const override { return this->is_developer_only; }
|
||||
|
||||
private:
|
||||
int min_loadable_version; ///< The Game can load savegame data if the version is equal or greater than this.
|
||||
bool is_developer_only; ///< Is the script selectable by non-developers?
|
||||
const char *api_version; ///< API version used by this Game.
|
||||
std::string api_version; ///< API version used by this Game.
|
||||
};
|
||||
|
||||
/** All static information from an Game library like name, version, etc. */
|
||||
|
Reference in New Issue
Block a user