mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-22 06:23:04 +01:00
Allow plugins to target a specific API version
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
# include "../OpenRCT2.h"
|
||||
# include "../core/File.h"
|
||||
# include "Duktape.hpp"
|
||||
# include "ScriptEngine.h"
|
||||
|
||||
# include <algorithm>
|
||||
# include <fstream>
|
||||
@@ -120,6 +121,7 @@ PluginMetadata Plugin::GetMetadata(const DukValue& dukMetadata)
|
||||
metadata.Name = TryGetString(dukMetadata["name"], "Plugin name not specified.");
|
||||
metadata.Version = TryGetString(dukMetadata["version"], "Plugin version not specified.");
|
||||
metadata.Type = ParsePluginType(TryGetString(dukMetadata["type"], "Plugin type not specified."));
|
||||
|
||||
CheckForLicence(dukMetadata["licence"], metadata.Name);
|
||||
|
||||
auto dukMinApiVersion = dukMetadata["minApiVersion"];
|
||||
@@ -128,6 +130,12 @@ PluginMetadata Plugin::GetMetadata(const DukValue& dukMetadata)
|
||||
metadata.MinApiVersion = dukMinApiVersion.as_int();
|
||||
}
|
||||
|
||||
auto dukTargetApiVersion = dukMetadata["targetApiVersion"];
|
||||
if (dukTargetApiVersion.type() == DukValue::Type::NUMBER)
|
||||
{
|
||||
metadata.TargetApiVersion = dukTargetApiVersion.as_int();
|
||||
}
|
||||
|
||||
auto dukAuthors = dukMetadata["authors"];
|
||||
dukAuthors.push();
|
||||
if (dukAuthors.is_array())
|
||||
@@ -161,4 +169,13 @@ void Plugin::CheckForLicence(const DukValue& dukLicence, std::string_view plugin
|
||||
log_error("Plugin %s does not specify a licence", std::string(pluginName).c_str());
|
||||
}
|
||||
|
||||
int32_t Plugin::GetTargetAPIVersion() const
|
||||
{
|
||||
if (_metadata.TargetApiVersion)
|
||||
return *_metadata.TargetApiVersion;
|
||||
|
||||
// If not specified, default to 33 since that is the API version from before 'targetAPIVersion' was introduced.
|
||||
return 33;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user