2021-03-01 12:52:24 -08:00
|
|
|
/* Copyright (C) 2021 Wildfire Games.
|
2014-08-25 09:02:54 -07:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
|
*
|
|
|
|
|
* 0 A.D. 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, either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* 0 A.D. 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 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
2018-04-22 11:14:45 -07:00
|
|
|
#include "JSInterface_Mod.h"
|
2014-08-25 09:02:54 -07:00
|
|
|
|
2017-12-05 09:17:21 -08:00
|
|
|
#include "ps/Mod.h"
|
2021-03-01 12:52:24 -08:00
|
|
|
#include "scriptinterface/FunctionWrapper.h"
|
2014-08-25 09:02:54 -07:00
|
|
|
|
2018-05-08 02:45:54 -07:00
|
|
|
extern void RestartEngine();
|
2014-08-25 09:02:54 -07:00
|
|
|
|
2021-05-15 06:54:58 -07:00
|
|
|
namespace JSI_Mod
|
2021-03-01 12:52:24 -08:00
|
|
|
{
|
2021-05-20 01:32:11 -07:00
|
|
|
Mod* ModGetter(const ScriptRequest&, JS::CallArgs&)
|
|
|
|
|
{
|
|
|
|
|
return &g_Mods;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-15 06:54:58 -07:00
|
|
|
bool SetModsAndRestartEngine(const ScriptInterface& scriptInterface, const std::vector<CStr>& mods)
|
2018-02-17 09:36:43 -08:00
|
|
|
{
|
2021-05-20 01:32:11 -07:00
|
|
|
g_Mods.ClearIncompatibleMods();
|
|
|
|
|
if (!g_Mods.CheckAndEnableMods(scriptInterface, mods))
|
2021-05-09 06:53:25 -07:00
|
|
|
return false;
|
2018-02-17 09:36:43 -08:00
|
|
|
|
2021-05-09 06:53:25 -07:00
|
|
|
RestartEngine();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-08-25 09:02:54 -07:00
|
|
|
|
2021-05-15 06:54:58 -07:00
|
|
|
bool HasFailedMods()
|
2014-08-25 09:02:54 -07:00
|
|
|
{
|
2021-05-20 01:32:11 -07:00
|
|
|
return g_Mods.GetFailedMods().size() > 0;
|
2021-03-01 12:52:24 -08:00
|
|
|
}
|
2014-08-25 09:02:54 -07:00
|
|
|
|
2021-05-15 06:54:58 -07:00
|
|
|
void RegisterScriptFunctions(const ScriptRequest& rq)
|
2014-08-25 09:02:54 -07:00
|
|
|
{
|
2021-05-20 01:32:11 -07:00
|
|
|
ScriptFunction::Register<&Mod::GetEngineInfo, ModGetter>(rq, "GetEngineInfo");
|
|
|
|
|
ScriptFunction::Register<&Mod::GetAvailableMods, ModGetter>(rq, "GetAvailableMods");
|
|
|
|
|
ScriptFunction::Register<&Mod::GetEnabledMods, ModGetter>(rq, "GetEnabledMods");
|
2021-05-09 06:53:25 -07:00
|
|
|
ScriptFunction::Register<HasFailedMods> (rq, "HasFailedMods");
|
2021-05-20 01:32:11 -07:00
|
|
|
ScriptFunction::Register<&Mod::GetFailedMods, ModGetter>(rq, "GetFailedMods");
|
2021-05-09 06:53:25 -07:00
|
|
|
ScriptFunction::Register<&SetModsAndRestartEngine>(rq, "SetModsAndRestartEngine");
|
2014-08-25 09:02:54 -07:00
|
|
|
}
|
2021-05-15 06:54:58 -07:00
|
|
|
}
|