mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 01:04:06 +00:00
Rework Mod into a class.
`Mod` currently modifies 4 global arrays, including some that are 'public'. The logic flow is easier to understand if this becomes a real class with const-correctness and public/private methods. Differential Revision: https://code.wildfiregames.com/D3981 This was SVN commit r25469.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2020 Wildfire Games.
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -23,11 +23,14 @@
|
||||
#ifndef OSX_ATLAS_H
|
||||
#define OSX_ATLAS_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
class CStr8;
|
||||
|
||||
/**
|
||||
* Runs a new pyrogenesis process with the -editor argument.
|
||||
* Necessary because SDL and WxWidgets conflict.
|
||||
*/
|
||||
void startNewAtlasProcess();
|
||||
void startNewAtlasProcess(const std::vector<CStr8>& mods);
|
||||
|
||||
#endif // OSX_ATLAS_H
|
||||
|
||||
@@ -28,14 +28,7 @@
|
||||
#include "lib/types.h"
|
||||
#include "ps/CStr.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace Mod
|
||||
{
|
||||
extern std::vector<CStr> g_ModsLoaded;
|
||||
}
|
||||
|
||||
void startNewAtlasProcess()
|
||||
void startNewAtlasProcess(const std::vector<CStr8>& mods)
|
||||
{
|
||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
@@ -43,7 +36,7 @@ void startNewAtlasProcess()
|
||||
[args addObject:@"--editor"];
|
||||
|
||||
// Pass mods on the command line.
|
||||
for (const CStr& mod : Mod::g_ModsLoaded)
|
||||
for (const CStr8& mod : mods)
|
||||
{
|
||||
std::string arg = std::string("-mod=") + mod;
|
||||
[args addObject:[[NSString alloc] initWithUTF8String:arg.c_str()]];
|
||||
|
||||
+3
-3
@@ -598,7 +598,7 @@ static void RunGameOrAtlas(int argc, const char* argv[])
|
||||
g_VFS = CreateVfs();
|
||||
// Mount with highest priority, we don't want mods overwriting this.
|
||||
g_VFS->Mount(L"cache/", paths.Cache(), VFS_MOUNT_ARCHIVABLE, VFS_MAX_PRIORITY);
|
||||
MountMods(paths, Mod::GetModsFromArguments(args, INIT_MODS));
|
||||
MountMods(paths, g_Mods.GetModsFromArguments(args, INIT_MODS));
|
||||
|
||||
{
|
||||
CReplayPlayer replay;
|
||||
@@ -698,7 +698,7 @@ static void RunGameOrAtlas(int argc, const char* argv[])
|
||||
|
||||
// Do not install mods again in case of restart (typically from the mod selector)
|
||||
modsToInstall.clear();
|
||||
Mod::ClearIncompatibleMods();
|
||||
g_Mods.ClearIncompatibleMods();
|
||||
|
||||
Shutdown(0);
|
||||
MainControllerShutdown();
|
||||
@@ -708,7 +708,7 @@ static void RunGameOrAtlas(int argc, const char* argv[])
|
||||
|
||||
#if OS_MACOSX
|
||||
if (g_Shutdown == ShutdownType::RestartAsAtlas)
|
||||
startNewAtlasProcess();
|
||||
startNewAtlasProcess(g_Mods.GetEnabledMods());
|
||||
#else
|
||||
if (g_Shutdown == ShutdownType::RestartAsAtlas)
|
||||
ATLAS_RunIfOnCmdLine(args, true);
|
||||
|
||||
@@ -441,7 +441,7 @@ static void InitVfs(const CmdLineArgs& args, int flags)
|
||||
// Engine localization files (regular priority, these can be overwritten).
|
||||
g_VFS->Mount(L"l10n/", paths.RData()/"l10n"/"");
|
||||
|
||||
MountMods(paths, Mod::GetModsFromArguments(args, flags));
|
||||
MountMods(paths, g_Mods.GetModsFromArguments(args, flags));
|
||||
|
||||
// note: don't bother with g_VFS->TextRepresentation - directories
|
||||
// haven't yet been populated and are empty.
|
||||
@@ -851,18 +851,18 @@ bool AutostartVisualReplay(const std::string& replayFile);
|
||||
bool EnableModsOrSetDefault(const CmdLineArgs& args, const std::vector<CStr>& mods, bool fromConfig)
|
||||
{
|
||||
ScriptInterface scriptInterface("Engine", "CheckAndEnableMods", g_ScriptContext);
|
||||
if (Mod::CheckAndEnableMods(scriptInterface, mods))
|
||||
if (g_Mods.CheckAndEnableMods(scriptInterface, mods))
|
||||
return true;
|
||||
// Here we refuse to start as there is no gui anyway
|
||||
if (args.Has("autostart-nonvisual"))
|
||||
{
|
||||
if (fromConfig)
|
||||
LOGERROR("Trying to start with incompatible mods from configuration file: %s.", boost::algorithm::join(Mod::GetIncompatibleMods(), ", "));
|
||||
LOGERROR("Trying to start with incompatible mods from configuration file: %s.", boost::algorithm::join(g_Mods.GetIncompatibleMods(), ", "));
|
||||
else
|
||||
LOGERROR("Trying to start with incompatible mods: %s.", boost::algorithm::join(Mod::GetIncompatibleMods(), ", "));
|
||||
LOGERROR("Trying to start with incompatible mods: %s.", boost::algorithm::join(g_Mods.GetIncompatibleMods(), ", "));
|
||||
return false;
|
||||
}
|
||||
Mod::SetDefaultMods();
|
||||
g_Mods.SetDefaultMods();
|
||||
RestartEngine();
|
||||
return false;
|
||||
}
|
||||
@@ -901,7 +901,7 @@ bool Init(const CmdLineArgs& args, int flags)
|
||||
const int heapGrowthBytesGCTrigger = 20 * 1024 * 1024;
|
||||
g_ScriptContext = ScriptContext::CreateContext(contextSize, heapGrowthBytesGCTrigger);
|
||||
|
||||
Mod::CacheEnabledModVersions(g_ScriptContext);
|
||||
g_Mods.CacheEnabledModVersions(g_ScriptContext);
|
||||
|
||||
// Special command-line mode to dump the entity schemas instead of running the game.
|
||||
// (This must be done after loading VFS etc, but should be done before wasting time
|
||||
@@ -945,7 +945,7 @@ bool Init(const CmdLineArgs& args, int flags)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!EnableModsOrSetDefault(args, Mod::g_ModsLoaded, false))
|
||||
else if (!EnableModsOrSetDefault(args, g_Mods.GetEnabledMods(), false))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
+48
-43
@@ -24,6 +24,7 @@
|
||||
#include "lib/file/vfs/vfs.h"
|
||||
#include "lib/utf8.h"
|
||||
#include "ps/Filesystem.h"
|
||||
#include "ps/GameSetup/CmdLineArgs.h"
|
||||
#include "ps/GameSetup/GameSetup.h"
|
||||
#include "ps/GameSetup/Paths.h"
|
||||
#include "ps/Profiler2.h"
|
||||
@@ -39,13 +40,12 @@
|
||||
#include <sstream>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Mod
|
||||
namespace
|
||||
{
|
||||
std::vector<CStr> g_ModsLoaded;
|
||||
std::vector<CStr> g_IncompatibleMods;
|
||||
std::vector<CStr> g_FailedMods;
|
||||
|
||||
std::vector<std::vector<CStr>> g_LoadedModVersions;
|
||||
/**
|
||||
* Global instance of Mod, always exists.
|
||||
*/
|
||||
Mod g_ModInstance;
|
||||
|
||||
bool ParseModJSON(const ScriptRequest& rq, const PIVFS& vfs, OsPath modsPath, OsPath mod, JS::MutableHandleValue json)
|
||||
{
|
||||
@@ -94,8 +94,14 @@ bool ParseModJSON(const ScriptRequest& rq, const PIVFS& vfs, OsPath modsPath, Os
|
||||
return Script::ParseJSON(rq, buffer.str(), json);
|
||||
}
|
||||
}
|
||||
} // anonymous namespace
|
||||
|
||||
JS::Value GetAvailableMods(const ScriptInterface& scriptInterface)
|
||||
Mod& Mod::Instance()
|
||||
{
|
||||
return g_ModInstance;
|
||||
}
|
||||
|
||||
JS::Value Mod::GetAvailableMods(const ScriptInterface& scriptInterface) const
|
||||
{
|
||||
PROFILE2("GetAvailableMods");
|
||||
|
||||
@@ -144,66 +150,66 @@ JS::Value GetAvailableMods(const ScriptInterface& scriptInterface)
|
||||
return value.get();
|
||||
}
|
||||
|
||||
const std::vector<CStr>& GetEnabledMods()
|
||||
const std::vector<CStr>& Mod::GetEnabledMods() const
|
||||
{
|
||||
return g_ModsLoaded;
|
||||
return m_ModsLoaded;
|
||||
}
|
||||
|
||||
const std::vector<CStr>& GetIncompatibleMods()
|
||||
const std::vector<CStr>& Mod::GetIncompatibleMods() const
|
||||
{
|
||||
return g_IncompatibleMods;
|
||||
return m_IncompatibleMods;
|
||||
}
|
||||
|
||||
const std::vector<CStr>& GetFailedMods()
|
||||
const std::vector<CStr>& Mod::GetFailedMods() const
|
||||
{
|
||||
return g_FailedMods;
|
||||
return m_FailedMods;
|
||||
}
|
||||
|
||||
const std::vector<CStr>& GetModsFromArguments(const CmdLineArgs& args, int flags)
|
||||
const std::vector<CStr>& Mod::GetModsFromArguments(const CmdLineArgs& args, int flags)
|
||||
{
|
||||
const bool initMods = (flags & INIT_MODS) == INIT_MODS;
|
||||
const bool addPublic = (flags & INIT_MODS_PUBLIC) == INIT_MODS_PUBLIC;
|
||||
|
||||
if (!initMods)
|
||||
return g_ModsLoaded;
|
||||
return m_ModsLoaded;
|
||||
|
||||
g_ModsLoaded = args.GetMultiple("mod");
|
||||
m_ModsLoaded = args.GetMultiple("mod");
|
||||
|
||||
if (addPublic)
|
||||
g_ModsLoaded.insert(g_ModsLoaded.begin(), "public");
|
||||
m_ModsLoaded.insert(m_ModsLoaded.begin(), "public");
|
||||
|
||||
g_ModsLoaded.insert(g_ModsLoaded.begin(), "mod");
|
||||
m_ModsLoaded.insert(m_ModsLoaded.begin(), "mod");
|
||||
|
||||
return g_ModsLoaded;
|
||||
return m_ModsLoaded;
|
||||
}
|
||||
|
||||
void SetDefaultMods()
|
||||
void Mod::SetDefaultMods()
|
||||
{
|
||||
g_ModsLoaded.clear();
|
||||
g_ModsLoaded.insert(g_ModsLoaded.begin(), "mod");
|
||||
m_ModsLoaded.clear();
|
||||
m_ModsLoaded.insert(m_ModsLoaded.begin(), "mod");
|
||||
}
|
||||
|
||||
void ClearIncompatibleMods()
|
||||
void Mod::ClearIncompatibleMods()
|
||||
{
|
||||
g_IncompatibleMods.clear();
|
||||
g_FailedMods.clear();
|
||||
m_IncompatibleMods.clear();
|
||||
m_FailedMods.clear();
|
||||
}
|
||||
|
||||
bool CheckAndEnableMods(const ScriptInterface& scriptInterface, const std::vector<CStr>& mods)
|
||||
bool Mod::CheckAndEnableMods(const ScriptInterface& scriptInterface, const std::vector<CStr>& mods)
|
||||
{
|
||||
ScriptRequest rq(scriptInterface);
|
||||
|
||||
JS::RootedValue availableMods(rq.cx, GetAvailableMods(scriptInterface));
|
||||
if (!AreModsCompatible(scriptInterface, mods, availableMods))
|
||||
{
|
||||
g_FailedMods = mods;
|
||||
m_FailedMods = mods;
|
||||
return false;
|
||||
}
|
||||
g_ModsLoaded = mods;
|
||||
m_ModsLoaded = mods;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AreModsCompatible(const ScriptInterface& scriptInterface, const std::vector<CStr>& mods, const JS::RootedValue& availableMods)
|
||||
bool Mod::AreModsCompatible(const ScriptInterface& scriptInterface, const std::vector<CStr>& mods, const JS::RootedValue& availableMods)
|
||||
{
|
||||
ScriptRequest rq(scriptInterface);
|
||||
std::unordered_map<CStr, std::vector<CStr>> modDependencies;
|
||||
@@ -218,12 +224,12 @@ bool AreModsCompatible(const ScriptInterface& scriptInterface, const std::vector
|
||||
// Requested mod is not available, fail
|
||||
if (!Script::HasProperty(rq, availableMods, mod.c_str()))
|
||||
{
|
||||
g_IncompatibleMods.push_back(mod);
|
||||
m_IncompatibleMods.push_back(mod);
|
||||
continue;
|
||||
}
|
||||
if (!Script::GetProperty(rq, availableMods, mod.c_str(), &modData))
|
||||
{
|
||||
g_IncompatibleMods.push_back(mod);
|
||||
m_IncompatibleMods.push_back(mod);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -268,13 +274,13 @@ bool AreModsCompatible(const ScriptInterface& scriptInterface, const std::vector
|
||||
const std::unordered_map<CStr, CStr>::iterator it = modNameVersions.find(modToCheck);
|
||||
if (it == modNameVersions.end())
|
||||
{
|
||||
g_IncompatibleMods.push_back(mod);
|
||||
m_IncompatibleMods.push_back(mod);
|
||||
continue;
|
||||
}
|
||||
// 0.0.25(0ad) , <=, 0.0.24(required version)
|
||||
if (!CompareVersionStrings(it->second, op, versionToCheck))
|
||||
{
|
||||
g_IncompatibleMods.push_back(mod);
|
||||
m_IncompatibleMods.push_back(mod);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
@@ -283,10 +289,10 @@ bool AreModsCompatible(const ScriptInterface& scriptInterface, const std::vector
|
||||
|
||||
}
|
||||
|
||||
return g_IncompatibleMods.empty();
|
||||
return m_IncompatibleMods.empty();
|
||||
}
|
||||
|
||||
bool CompareVersionStrings(const CStr& version, const CStr& op, const CStr& required)
|
||||
bool Mod::CompareVersionStrings(const CStr& version, const CStr& op, const CStr& required) const
|
||||
{
|
||||
std::vector<CStr> versionSplit;
|
||||
std::vector<CStr> requiredSplit;
|
||||
@@ -320,16 +326,16 @@ bool CompareVersionStrings(const CStr& version, const CStr& op, const CStr& requ
|
||||
}
|
||||
|
||||
|
||||
void CacheEnabledModVersions(const shared_ptr<ScriptContext>& scriptContext)
|
||||
void Mod::CacheEnabledModVersions(const shared_ptr<ScriptContext>& scriptContext)
|
||||
{
|
||||
ScriptInterface scriptInterface("Engine", "CacheEnabledModVersions", scriptContext);
|
||||
ScriptRequest rq(scriptInterface);
|
||||
|
||||
JS::RootedValue availableMods(rq.cx, GetAvailableMods(scriptInterface));
|
||||
|
||||
g_LoadedModVersions.clear();
|
||||
m_LoadedModVersions.clear();
|
||||
|
||||
for (const CStr& mod : g_ModsLoaded)
|
||||
for (const CStr& mod : m_ModsLoaded)
|
||||
{
|
||||
// Ignore mod mod as it is irrelevant for compatibility checks
|
||||
if (mod == "mod")
|
||||
@@ -340,19 +346,19 @@ void CacheEnabledModVersions(const shared_ptr<ScriptContext>& scriptContext)
|
||||
if (Script::GetProperty(rq, availableMods, mod.c_str(), &modData))
|
||||
Script::GetProperty(rq, modData, "version", version);
|
||||
|
||||
g_LoadedModVersions.push_back({mod, version});
|
||||
m_LoadedModVersions.push_back({mod, version});
|
||||
}
|
||||
}
|
||||
|
||||
JS::Value GetLoadedModsWithVersions(const ScriptInterface& scriptInterface)
|
||||
JS::Value Mod::GetLoadedModsWithVersions(const ScriptInterface& scriptInterface) const
|
||||
{
|
||||
ScriptRequest rq(scriptInterface);
|
||||
JS::RootedValue returnValue(rq.cx);
|
||||
Script::ToJSVal(rq, &returnValue, g_LoadedModVersions);
|
||||
Script::ToJSVal(rq, &returnValue, m_LoadedModVersions);
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
JS::Value GetEngineInfo(const ScriptInterface& scriptInterface)
|
||||
JS::Value Mod::GetEngineInfo(const ScriptInterface& scriptInterface) const
|
||||
{
|
||||
ScriptRequest rq(scriptInterface);
|
||||
|
||||
@@ -369,4 +375,3 @@ JS::Value GetEngineInfo(const ScriptInterface& scriptInterface)
|
||||
|
||||
return metainfo;
|
||||
}
|
||||
}
|
||||
|
||||
+26
-12
@@ -19,21 +19,27 @@
|
||||
#define INCLUDED_MOD
|
||||
|
||||
#include "ps/CStr.h"
|
||||
#include "ps/GameSetup/CmdLineArgs.h"
|
||||
#include "scriptinterface/ScriptForward.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class CmdLineArgs;
|
||||
|
||||
extern CmdLineArgs g_CmdLineArgs;
|
||||
|
||||
namespace Mod
|
||||
{
|
||||
extern std::vector<CStr> g_ModsLoaded;
|
||||
#define g_Mods (Mod::Instance())
|
||||
|
||||
class Mod
|
||||
{
|
||||
public:
|
||||
// Singleton-like interface.
|
||||
static Mod& Instance();
|
||||
|
||||
JS::Value GetAvailableMods(const ScriptInterface& scriptInterface) const;
|
||||
const std::vector<CStr>& GetEnabledMods() const;
|
||||
const std::vector<CStr>& GetIncompatibleMods() const;
|
||||
const std::vector<CStr>& GetFailedMods() const;
|
||||
|
||||
JS::Value GetAvailableMods(const ScriptInterface& scriptInterface);
|
||||
const std::vector<CStr>& GetEnabledMods();
|
||||
const std::vector<CStr>& GetIncompatibleMods();
|
||||
const std::vector<CStr>& GetFailedMods();
|
||||
/**
|
||||
* This reads the version numbers from the launched mods.
|
||||
* It caches the result, since the reading of zip files is slow and
|
||||
@@ -45,7 +51,7 @@ namespace Mod
|
||||
const std::vector<CStr>& GetModsFromArguments(const CmdLineArgs& args, int flags);
|
||||
bool AreModsCompatible(const ScriptInterface& scriptInterface, const std::vector<CStr>& mods, const JS::RootedValue& availableMods);
|
||||
bool CheckAndEnableMods(const ScriptInterface& scriptInterface, const std::vector<CStr>& mods);
|
||||
bool CompareVersionStrings(const CStr& required, const CStr& op, const CStr& version);
|
||||
bool CompareVersionStrings(const CStr& required, const CStr& op, const CStr& version) const;
|
||||
void SetDefaultMods();
|
||||
void ClearIncompatibleMods();
|
||||
|
||||
@@ -56,7 +62,7 @@ namespace Mod
|
||||
* @param scriptInterface the ScriptInterface in which to create the return data.
|
||||
* @return list of loaded mods with the format [[modA, versionA], [modB, versionB], ...]
|
||||
*/
|
||||
JS::Value GetLoadedModsWithVersions(const ScriptInterface& scriptInterface);
|
||||
JS::Value GetLoadedModsWithVersions(const ScriptInterface& scriptInterface) const;
|
||||
|
||||
/**
|
||||
* Gets info (version and mods loaded) on the running engine
|
||||
@@ -64,6 +70,14 @@ namespace Mod
|
||||
* @param scriptInterface the ScriptInterface in which to create the return data.
|
||||
* @return list of objects containing data
|
||||
*/
|
||||
JS::Value GetEngineInfo(const ScriptInterface& scriptInterface);
|
||||
}
|
||||
JS::Value GetEngineInfo(const ScriptInterface& scriptInterface) const;
|
||||
|
||||
private:
|
||||
std::vector<CStr> m_ModsLoaded;
|
||||
std::vector<CStr> m_IncompatibleMods;
|
||||
std::vector<CStr> m_FailedMods;
|
||||
|
||||
std::vector<std::vector<CStr>> m_LoadedModVersions;
|
||||
};
|
||||
|
||||
#endif // INCLUDED_MOD
|
||||
|
||||
@@ -73,7 +73,7 @@ void CReplayLogger::StartGame(JS::MutableHandleValue attribs)
|
||||
|
||||
// Add engine version and currently loaded mods for sanity checks when replaying
|
||||
Script::SetProperty(rq, attribs, "engine_version", engine_version);
|
||||
JS::RootedValue mods(rq.cx, Mod::GetLoadedModsWithVersions(m_ScriptInterface));
|
||||
JS::RootedValue mods(rq.cx, g_Mods.GetLoadedModsWithVersions(m_ScriptInterface));
|
||||
Script::SetProperty(rq, attribs, "mods", mods);
|
||||
|
||||
m_Directory = createDateIndexSubdirectory(VisualReplay::GetDirectoryPath());
|
||||
@@ -170,7 +170,7 @@ void CReplayPlayer::CheckReplayMods(const ScriptInterface& scriptInterface, JS::
|
||||
Script::GetProperty(rq, attribs, "mods", replayMods);
|
||||
|
||||
std::vector<std::vector<CStr>> enabledMods;
|
||||
JS::RootedValue enabledModsJS(rq.cx, Mod::GetLoadedModsWithVersions(scriptInterface));
|
||||
JS::RootedValue enabledModsJS(rq.cx, g_Mods.GetLoadedModsWithVersions(scriptInterface));
|
||||
Script::FromJSVal(rq, enabledModsJS, enabledMods);
|
||||
|
||||
CStr warn;
|
||||
@@ -208,7 +208,7 @@ void CReplayPlayer::Replay(const bool serializationtest, const int rejointesttur
|
||||
const int heapGrowthBytesGCTrigger = 20 * 1024 * 1024;
|
||||
g_ScriptContext = ScriptContext::CreateContext(contextSize, heapGrowthBytesGCTrigger);
|
||||
|
||||
Mod::CacheEnabledModVersions(g_ScriptContext);
|
||||
g_Mods.CacheEnabledModVersions(g_ScriptContext);
|
||||
|
||||
g_Game = new CGame(false);
|
||||
if (serializationtest)
|
||||
|
||||
@@ -81,7 +81,7 @@ Status SavedGames::Save(const CStrW& name, const CStrW& description, CSimulation
|
||||
WARN_RETURN(ERR::FAIL);
|
||||
|
||||
JS::RootedValue initAttributes(rq.cx, simulation.GetInitAttributes());
|
||||
JS::RootedValue mods(rq.cx, Mod::GetLoadedModsWithVersions(simulation.GetScriptInterface()));
|
||||
JS::RootedValue mods(rq.cx, g_Mods.GetLoadedModsWithVersions(simulation.GetScriptInterface()));
|
||||
|
||||
JS::RootedValue metadata(rq.cx);
|
||||
|
||||
|
||||
@@ -26,10 +26,15 @@ extern void RestartEngine();
|
||||
|
||||
namespace JSI_Mod
|
||||
{
|
||||
Mod* ModGetter(const ScriptRequest&, JS::CallArgs&)
|
||||
{
|
||||
return &g_Mods;
|
||||
}
|
||||
|
||||
bool SetModsAndRestartEngine(const ScriptInterface& scriptInterface, const std::vector<CStr>& mods)
|
||||
{
|
||||
Mod::ClearIncompatibleMods();
|
||||
if (!Mod::CheckAndEnableMods(scriptInterface, mods))
|
||||
g_Mods.ClearIncompatibleMods();
|
||||
if (!g_Mods.CheckAndEnableMods(scriptInterface, mods))
|
||||
return false;
|
||||
|
||||
RestartEngine();
|
||||
@@ -38,16 +43,16 @@ bool SetModsAndRestartEngine(const ScriptInterface& scriptInterface, const std::
|
||||
|
||||
bool HasFailedMods()
|
||||
{
|
||||
return Mod::GetFailedMods().size() > 0;
|
||||
return g_Mods.GetFailedMods().size() > 0;
|
||||
}
|
||||
|
||||
void RegisterScriptFunctions(const ScriptRequest& rq)
|
||||
{
|
||||
ScriptFunction::Register<&Mod::GetEngineInfo>(rq, "GetEngineInfo");
|
||||
ScriptFunction::Register<&Mod::GetAvailableMods>(rq, "GetAvailableMods");
|
||||
ScriptFunction::Register<&Mod::GetEnabledMods>(rq, "GetEnabledMods");
|
||||
ScriptFunction::Register<&Mod::GetEngineInfo, ModGetter>(rq, "GetEngineInfo");
|
||||
ScriptFunction::Register<&Mod::GetAvailableMods, ModGetter>(rq, "GetAvailableMods");
|
||||
ScriptFunction::Register<&Mod::GetEnabledMods, ModGetter>(rq, "GetEnabledMods");
|
||||
ScriptFunction::Register<HasFailedMods> (rq, "HasFailedMods");
|
||||
ScriptFunction::Register<&Mod::GetFailedMods>(rq, "GetFailedMods");
|
||||
ScriptFunction::Register<&Mod::GetFailedMods, ModGetter>(rq, "GetFailedMods");
|
||||
ScriptFunction::Register<&SetModsAndRestartEngine>(rq, "SetModsAndRestartEngine");
|
||||
}
|
||||
}
|
||||
|
||||
+37
-37
@@ -42,45 +42,45 @@ public:
|
||||
CStr version = "0.0.24";// 0ad version
|
||||
|
||||
// 0.0.24 = 0.0.24
|
||||
TS_ASSERT(Mod::CompareVersionStrings(version, eq, required));
|
||||
TS_ASSERT(!Mod::CompareVersionStrings(version, lt, required));
|
||||
TS_ASSERT(!Mod::CompareVersionStrings(version, gt, required));
|
||||
TS_ASSERT(Mod::CompareVersionStrings(version, leq, required));
|
||||
TS_ASSERT(Mod::CompareVersionStrings(version, geq, required));
|
||||
TS_ASSERT(g_Mods.CompareVersionStrings(version, eq, required));
|
||||
TS_ASSERT(!g_Mods.CompareVersionStrings(version, lt, required));
|
||||
TS_ASSERT(!g_Mods.CompareVersionStrings(version, gt, required));
|
||||
TS_ASSERT(g_Mods.CompareVersionStrings(version, leq, required));
|
||||
TS_ASSERT(g_Mods.CompareVersionStrings(version, geq, required));
|
||||
|
||||
// 0.0.23 <= 0.0.24
|
||||
version = "0.0.23";
|
||||
TS_ASSERT(!Mod::CompareVersionStrings(version, eq, required));
|
||||
TS_ASSERT(Mod::CompareVersionStrings(version, lt, required));
|
||||
TS_ASSERT(!Mod::CompareVersionStrings(version, gt, required));
|
||||
TS_ASSERT(Mod::CompareVersionStrings(version, leq, required));
|
||||
TS_ASSERT(!Mod::CompareVersionStrings(version, geq, required));
|
||||
TS_ASSERT(!g_Mods.CompareVersionStrings(version, eq, required));
|
||||
TS_ASSERT(g_Mods.CompareVersionStrings(version, lt, required));
|
||||
TS_ASSERT(!g_Mods.CompareVersionStrings(version, gt, required));
|
||||
TS_ASSERT(g_Mods.CompareVersionStrings(version, leq, required));
|
||||
TS_ASSERT(!g_Mods.CompareVersionStrings(version, geq, required));
|
||||
|
||||
// 0.0.25 >= 0.0.24
|
||||
version = "0.0.25";
|
||||
TS_ASSERT(!Mod::CompareVersionStrings(version, eq, required));
|
||||
TS_ASSERT(!Mod::CompareVersionStrings(version, lt, required));
|
||||
TS_ASSERT(Mod::CompareVersionStrings(version, gt, required));
|
||||
TS_ASSERT(!Mod::CompareVersionStrings(version, leq, required));
|
||||
TS_ASSERT(Mod::CompareVersionStrings(version, geq, required));
|
||||
TS_ASSERT(!g_Mods.CompareVersionStrings(version, eq, required));
|
||||
TS_ASSERT(!g_Mods.CompareVersionStrings(version, lt, required));
|
||||
TS_ASSERT(g_Mods.CompareVersionStrings(version, gt, required));
|
||||
TS_ASSERT(!g_Mods.CompareVersionStrings(version, leq, required));
|
||||
TS_ASSERT(g_Mods.CompareVersionStrings(version, geq, required));
|
||||
|
||||
// 0.0.9 <= 0.1.0
|
||||
version = "0.0.9";
|
||||
required = "0.1.0";
|
||||
TS_ASSERT(!Mod::CompareVersionStrings(version, eq, required));
|
||||
TS_ASSERT(Mod::CompareVersionStrings(version, lt, required));
|
||||
TS_ASSERT(!Mod::CompareVersionStrings(version, gt, required));
|
||||
TS_ASSERT(Mod::CompareVersionStrings(version, leq, required));
|
||||
TS_ASSERT(!Mod::CompareVersionStrings(version, geq, required));
|
||||
TS_ASSERT(!g_Mods.CompareVersionStrings(version, eq, required));
|
||||
TS_ASSERT(g_Mods.CompareVersionStrings(version, lt, required));
|
||||
TS_ASSERT(!g_Mods.CompareVersionStrings(version, gt, required));
|
||||
TS_ASSERT(g_Mods.CompareVersionStrings(version, leq, required));
|
||||
TS_ASSERT(!g_Mods.CompareVersionStrings(version, geq, required));
|
||||
|
||||
// 5.3 <= 5.3.0
|
||||
version = "5.3";
|
||||
required = "5.3.0";
|
||||
TS_ASSERT(!Mod::CompareVersionStrings(version, eq, required));
|
||||
TS_ASSERT(Mod::CompareVersionStrings(version, lt, required));
|
||||
TS_ASSERT(!Mod::CompareVersionStrings(version, gt, required));
|
||||
TS_ASSERT(Mod::CompareVersionStrings(version, leq, required));
|
||||
TS_ASSERT(!Mod::CompareVersionStrings(version, geq, required));
|
||||
TS_ASSERT(!g_Mods.CompareVersionStrings(version, eq, required));
|
||||
TS_ASSERT(g_Mods.CompareVersionStrings(version, lt, required));
|
||||
TS_ASSERT(!g_Mods.CompareVersionStrings(version, gt, required));
|
||||
TS_ASSERT(g_Mods.CompareVersionStrings(version, leq, required));
|
||||
TS_ASSERT(!g_Mods.CompareVersionStrings(version, geq, required));
|
||||
}
|
||||
|
||||
void test_compatible()
|
||||
@@ -148,38 +148,38 @@ public:
|
||||
|
||||
mods.clear();
|
||||
mods.push_back("public");
|
||||
Mod::ClearIncompatibleMods();
|
||||
TS_ASSERT(Mod::AreModsCompatible(script, mods, availableMods));
|
||||
g_Mods.ClearIncompatibleMods();
|
||||
TS_ASSERT(g_Mods.AreModsCompatible(script, mods, availableMods));
|
||||
|
||||
mods.clear();
|
||||
mods.push_back("mod");
|
||||
mods.push_back("public");
|
||||
Mod::ClearIncompatibleMods();
|
||||
TS_ASSERT(Mod::AreModsCompatible(script, mods, availableMods));
|
||||
g_Mods.ClearIncompatibleMods();
|
||||
TS_ASSERT(g_Mods.AreModsCompatible(script, mods, availableMods));
|
||||
|
||||
mods.clear();
|
||||
mods.push_back("public");
|
||||
mods.push_back("good");
|
||||
Mod::ClearIncompatibleMods();
|
||||
TS_ASSERT(Mod::AreModsCompatible(script, mods, availableMods));
|
||||
g_Mods.ClearIncompatibleMods();
|
||||
TS_ASSERT(g_Mods.AreModsCompatible(script, mods, availableMods));
|
||||
|
||||
mods.clear();
|
||||
mods.push_back("public");
|
||||
mods.push_back("good2");
|
||||
Mod::ClearIncompatibleMods();
|
||||
TS_ASSERT(Mod::AreModsCompatible(script, mods, availableMods));
|
||||
g_Mods.ClearIncompatibleMods();
|
||||
TS_ASSERT(g_Mods.AreModsCompatible(script, mods, availableMods));
|
||||
|
||||
mods.clear();
|
||||
mods.push_back("public");
|
||||
mods.push_back("wrong");
|
||||
Mod::ClearIncompatibleMods();
|
||||
TS_ASSERT(!Mod::AreModsCompatible(script, mods, availableMods));
|
||||
g_Mods.ClearIncompatibleMods();
|
||||
TS_ASSERT(!g_Mods.AreModsCompatible(script, mods, availableMods));
|
||||
|
||||
mods.clear();
|
||||
mods.push_back("public");
|
||||
mods.push_back("does_not_exist");
|
||||
Mod::ClearIncompatibleMods();
|
||||
TS_ASSERT(!Mod::AreModsCompatible(script, mods, availableMods));
|
||||
g_Mods.ClearIncompatibleMods();
|
||||
TS_ASSERT(!g_Mods.AreModsCompatible(script, mods, availableMods));
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user