Changeset View
Changeset View
Standalone View
Standalone View
source/ps/scripting/JSInterface_Mod.cpp
/* Copyright (C) 2018 Wildfire Games. | /* Copyright (C) 2018 Wildfire Games. | ||||
Stan: year. | |||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 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 | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
* GNU General Public License for more details. | * GNU General Public License for more details. | ||||
* | * | ||||
* You should have received a copy of the GNU General Public License | * 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/>. | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include "JSInterface_Mod.h" | #include "JSInterface_Mod.h" | ||||
#include "ps/Mod.h" | #include "ps/Mod.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include "scriptinterface/FunctionWrapper.h" | |||||
extern void RestartEngine(); | extern void RestartEngine(); | ||||
JS::Value JSI_Mod::GetEngineInfo(ScriptInterface::CxPrivate* pCxPrivate) | JS::Value JSI_Mod::GetEngineInfo(ScriptInterface::CxPrivate* pCxPrivate) | ||||
{ | { | ||||
Not Done Inline ActionsDon't we indent inside the namespace? Imarok: Don't we indent inside the namespace? | |||||
Done Inline ActionsIt's actually pretty inconsistent, and not mentioned in the coding conventions. I feel like a good rule would be something like this:
Which would kind of make them look like classes in header files, but not add un-necessary indent in .cpp files. In this particular case adding an indent doesn't really improve things much imo. wraitii: It's actually pretty inconsistent, and not mentioned in the coding conventions.
I feel like a… | |||||
Not Done Inline ActionsI guess a good rule would be something we can format with clang format or astyle :) Stan: I guess a good rule would be something we can format with clang format or astyle :) | |||||
return Mod::GetEngineInfo(*(pCxPrivate->pScriptInterface)); | return Mod::GetEngineInfo(*(pCxPrivate->pScriptInterface)); | ||||
} | } | ||||
/** | /** | ||||
* Returns a JS object containing a listing of available mods that | * Returns a JS object containing a listing of available mods that | ||||
* have a modname.json file in their modname folder. The returned | * have a modname.json file in their modname folder. The returned | ||||
* object looks like { modname1: json1, modname2: json2, ... } where | * object looks like { modname1: json1, modname2: json2, ... } where | ||||
* jsonN is the content of the modnameN/modnameN.json file as a JS | * jsonN is the content of the modnameN/modnameN.json file as a JS | ||||
* object. | * object. | ||||
* | * | ||||
* @return JS object with available mods as the keys of the modname.json | * @return JS object with available mods as the keys of the modname.json | ||||
* properties. | * properties. | ||||
*/ | */ | ||||
JS::Value JSI_Mod::GetAvailableMods(ScriptInterface::CxPrivate* pCxPrivate) | JS::Value JSI_Mod::GetAvailableMods(ScriptInterface::CxPrivate* pCxPrivate) | ||||
{ | { | ||||
return Mod::GetAvailableMods(*(pCxPrivate->pScriptInterface)); | return Mod::GetAvailableMods(*(pCxPrivate->pScriptInterface)); | ||||
} | } | ||||
void JSI_Mod::RestartEngine(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | void JSI_Mod::RestartEngine() | ||||
{ | { | ||||
::RestartEngine(); | ::RestartEngine(); | ||||
} | } | ||||
void JSI_Mod::SetMods(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::vector<CStr>& mods) | void JSI_Mod::SetMods(const std::vector<CStr>& mods) | ||||
{ | { | ||||
g_modsLoaded = mods; | g_modsLoaded = mods; | ||||
} | } | ||||
void JSI_Mod::RegisterScriptFunctions(const ScriptInterface& scriptInterface) | void JSI_Mod::RegisterScriptFunctions(const ScriptInterface& scriptInterface) | ||||
{ | { | ||||
scriptInterface.RegisterFunction<JS::Value, &GetEngineInfo>("GetEngineInfo"); | ScriptWrapper::WrapAndRegister<decltype(&GetEngineInfo), &GetEngineInfo>(scriptInterface, "GetEngineInfo"); | ||||
scriptInterface.RegisterFunction<JS::Value, &JSI_Mod::GetAvailableMods>("GetAvailableMods"); | ScriptWrapper::WrapAndRegister<decltype(&JSI_Mod::GetAvailableMods), &JSI_Mod::GetAvailableMods>(scriptInterface, "GetAvailableMods"); | ||||
scriptInterface.RegisterFunction<void, &JSI_Mod::RestartEngine>("RestartEngine"); | ScriptWrapper::WrapAndRegister<decltype(&JSI_Mod::RestartEngine), &JSI_Mod::RestartEngine>(scriptInterface, "RestartEngine"); | ||||
scriptInterface.RegisterFunction<void, std::vector<CStr>, &JSI_Mod::SetMods>("SetMods"); | ScriptWrapper::WrapAndRegister<decltype(&JSI_Mod::SetMods), &JSI_Mod::SetMods>(scriptInterface, "SetMods"); | ||||
} | } |
Wildfire Games · Phabricator
year.