2021-03-01 21:52:24 +01:00
|
|
|
/* Copyright (C) 2021 Wildfire Games.
|
2014-08-25 18:02:54 +02: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 20:14:45 +02:00
|
|
|
#include "JSInterface_Mod.h"
|
2014-08-25 18:02:54 +02:00
|
|
|
|
2017-12-05 18:17:21 +01:00
|
|
|
#include "ps/Mod.h"
|
2021-03-01 21:52:24 +01:00
|
|
|
#include "scriptinterface/FunctionWrapper.h"
|
2018-04-27 18:48:44 +02:00
|
|
|
#include "scriptinterface/ScriptInterface.h"
|
2014-08-25 18:02:54 +02:00
|
|
|
|
2018-05-08 11:45:54 +02:00
|
|
|
extern void RestartEngine();
|
2014-08-25 18:02:54 +02:00
|
|
|
|
2021-03-01 21:52:24 +01:00
|
|
|
namespace
|
|
|
|
{
|
2021-05-09 15:53:25 +02:00
|
|
|
bool SetModsAndRestartEngine(ScriptInterface::CmptPrivate* pCmptPrivate, const std::vector<CStr>& mods)
|
2018-02-17 18:36:43 +01:00
|
|
|
{
|
2021-05-09 15:53:25 +02:00
|
|
|
Mod::ClearIncompatibleMods();
|
|
|
|
if (!Mod::CheckAndEnableMods(*(pCmptPrivate->pScriptInterface), mods))
|
|
|
|
return false;
|
2018-02-17 18:36:43 +01:00
|
|
|
|
2021-05-09 15:53:25 +02:00
|
|
|
RestartEngine();
|
|
|
|
return true;
|
|
|
|
}
|
2014-08-25 18:02:54 +02:00
|
|
|
}
|
|
|
|
|
2021-05-09 15:53:25 +02:00
|
|
|
bool HasFailedMods(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate))
|
2014-08-25 18:02:54 +02:00
|
|
|
{
|
2021-05-09 15:53:25 +02:00
|
|
|
return Mod::GetFailedMods().size() > 0;
|
2021-03-01 21:52:24 +01:00
|
|
|
}
|
2014-08-25 18:02:54 +02:00
|
|
|
|
2021-03-01 21:52:24 +01:00
|
|
|
void JSI_Mod::RegisterScriptFunctions(const ScriptRequest& rq)
|
2014-08-25 18:02:54 +02:00
|
|
|
{
|
2021-05-09 15:53:25 +02:00
|
|
|
ScriptFunction::Register<&Mod::GetEngineInfo>(rq, "GetEngineInfo");
|
|
|
|
ScriptFunction::Register<&Mod::GetAvailableMods>(rq, "GetAvailableMods");
|
|
|
|
ScriptFunction::Register<&Mod::GetEnabledMods>(rq, "GetEnabledMods");
|
|
|
|
ScriptFunction::Register<HasFailedMods> (rq, "HasFailedMods");
|
|
|
|
ScriptFunction::Register<&Mod::GetFailedMods>(rq, "GetFailedMods");
|
|
|
|
ScriptFunction::Register<&SetModsAndRestartEngine>(rq, "SetModsAndRestartEngine");
|
2014-08-25 18:02:54 +02:00
|
|
|
}
|