1
0
forked from 0ad/0ad

Move GetEngineInfo to Mod.[h|cpp]

Suggested by: elexis
refs d5807cd59f

This was SVN commit r21242.
This commit is contained in:
Imarok 2018-02-17 17:36:43 +00:00
parent 7c8c4ac2f7
commit 01f581e813
8 changed files with 75 additions and 78 deletions

View File

@ -124,3 +124,18 @@ JS::Value Mod::GetLoadedModsWithVersions(const ScriptInterface& scriptInterface)
}
return ret;
}
JS::Value Mod::GetEngineInfo(const ScriptInterface& scriptInterface)
{
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
JS::RootedValue metainfo(cx);
scriptInterface.Eval("({})", &metainfo);
scriptInterface.SetProperty(metainfo, "engine_version", std::string(engine_version));
scriptInterface.SetProperty(metainfo, "mods", JS::RootedValue(cx, Mod::GetLoadedModsWithVersions(scriptInterface)));
scriptInterface.FreezeObject(metainfo, true);
return metainfo;
}

View File

@ -29,5 +29,12 @@ namespace Mod
{
JS::Value GetAvailableMods(const ScriptInterface& scriptInterface);
JS::Value GetLoadedModsWithVersions(const ScriptInterface& scriptInterface);
/**
* Gets info (version and mods loaded) on the running engine
*
* @param scriptInterface the ScriptInterface in which to create the return data.
* @return list of objects containing saved game data
*/
JS::Value GetEngineInfo(const ScriptInterface& scriptInterface);
}
#endif // INCLUDED_MOD

View File

@ -287,18 +287,3 @@ bool SavedGames::DeleteSavedGame(const std::wstring& name)
// Successfully deleted file
return true;
}
JS::Value SavedGames::GetEngineInfo(const ScriptInterface& scriptInterface)
{
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
JS::RootedValue metainfo(cx);
scriptInterface.Eval("({})", &metainfo);
scriptInterface.SetProperty(metainfo, "engine_version", std::string(engine_version));
scriptInterface.SetProperty(metainfo, "mods", JS::RootedValue(cx, Mod::GetLoadedModsWithVersions(scriptInterface)));
scriptInterface.FreezeObject(metainfo, true);
return metainfo;
}

View File

@ -36,66 +36,56 @@ class CGUIManager;
namespace SavedGames
{
/**
* Create new saved game archive with given name and simulation data
*
* @param name Name to save the game with
* @param description A user-given description of the save
* @param simulation
* @param guiMetadataClone if not NULL, store some UI-related data with the saved game
* @return INFO::OK if successfully saved, else an error Status
*/
Status Save(const CStrW& name, const CStrW& description, CSimulation2& simulation, const shared_ptr<ScriptInterface::StructuredClone>& guiMetadataClone);
/**
* Create new saved game archive with given name and simulation data
*
* @param name Name to save the game with
* @param description A user-given description of the save
* @param simulation
* @param guiMetadataClone if not NULL, store some UI-related data with the saved game
* @return INFO::OK if successfully saved, else an error Status
*/
Status Save(const CStrW& name, const CStrW& description, CSimulation2& simulation, const shared_ptr<ScriptInterface::StructuredClone>& guiMetadataClone);
/**
* Create new saved game archive with given prefix and simulation data
*
* @param prefix Create new numbered file starting with this prefix
* @param description A user-given description of the save
* @param simulation
* @param guiMetadataClone if not NULL, store some UI-related data with the saved game
* @return INFO::OK if successfully saved, else an error Status
*/
Status SavePrefix(const CStrW& prefix, const CStrW& description, CSimulation2& simulation, const shared_ptr<ScriptInterface::StructuredClone>& guiMetadataClone);
/**
* Create new saved game archive with given prefix and simulation data
*
* @param prefix Create new numbered file starting with this prefix
* @param description A user-given description of the save
* @param simulation
* @param guiMetadataClone if not NULL, store some UI-related data with the saved game
* @return INFO::OK if successfully saved, else an error Status
*/
Status SavePrefix(const CStrW& prefix, const CStrW& description, CSimulation2& simulation, const shared_ptr<ScriptInterface::StructuredClone>& guiMetadataClone);
/**
* Load saved game archive with the given name
*
* @param name filename of saved game (without path or extension)
* @param scriptInterface
* @param[out] metadata object containing metadata associated with saved game,
* parsed from metadata.json inside the archive.
* @param[out] savedState serialized simulation state stored as string of bytes,
* loaded from simulation.dat inside the archive.
* @return INFO::OK if successfully loaded, else an error Status
*/
Status Load(const std::wstring& name, const ScriptInterface& scriptInterface, JS::MutableHandleValue metadata, std::string& savedState);
/**
* Load saved game archive with the given name
*
* @param name filename of saved game (without path or extension)
* @param scriptInterface
* @param[out] metadata object containing metadata associated with saved game,
* parsed from metadata.json inside the archive.
* @param[out] savedState serialized simulation state stored as string of bytes,
* loaded from simulation.dat inside the archive.
* @return INFO::OK if successfully loaded, else an error Status
*/
Status Load(const std::wstring& name, const ScriptInterface& scriptInterface, JS::MutableHandleValue metadata, std::string& savedState);
/**
* Get list of saved games for GUI script usage
*
* @param scriptInterface the ScriptInterface in which to create the return data.
* @return array of objects containing saved game data
*/
JS::Value GetSavedGames(const ScriptInterface& scriptInterface);
/**
* Permanently deletes the saved game archive with the given name
*
* @param name filename of saved game (without path or extension)
* @return true if deletion was successful, or false on error
*/
bool DeleteSavedGame(const std::wstring& name);
/**
* Gets info (version and mods loaded) on the running engine
*
* @param scriptInterface the ScriptInterface in which to create the return data.
* @return list of objects containing saved game data
*/
JS::Value GetEngineInfo(const ScriptInterface& scriptInterface);
/**
* Get list of saved games for GUI script usage
*
* @param scriptInterface the ScriptInterface in which to create the return data.
* @return array of objects containing saved game data
*/
JS::Value GetSavedGames(const ScriptInterface& scriptInterface);
/**
* Permanently deletes the saved game archive with the given name
*
* @param name filename of saved game (without path or extension)
* @return true if deletion was successful, or false on error
*/
bool DeleteSavedGame(const std::wstring& name);
}
#endif // INCLUDED_SAVEDGAME

View File

@ -23,6 +23,11 @@
extern void restart_engine();
JS::Value JSI_Mod::GetEngineInfo(ScriptInterface::CxPrivate* pCxPrivate)
{
return Mod::GetEngineInfo(*(pCxPrivate->pScriptInterface));
}
/**
* Returns a JS object containing a listing of available mods that
* have a modname.json file in their modname folder. The returned
@ -50,6 +55,7 @@ void JSI_Mod::SetMods(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std:
void JSI_Mod::RegisterScriptFunctions(const ScriptInterface& scriptInterface)
{
scriptInterface.RegisterFunction<JS::Value, &GetEngineInfo>("GetEngineInfo");
scriptInterface.RegisterFunction<JS::Value, &JSI_Mod::GetAvailableMods>("GetAvailableMods");
scriptInterface.RegisterFunction<void, &JSI_Mod::RestartEngine>("RestartEngine");
scriptInterface.RegisterFunction<void, std::vector<CStr>, &JSI_Mod::SetMods>("SetMods");

View File

@ -26,6 +26,7 @@ class ScriptInterface;
namespace JSI_Mod
{
void RegisterScriptFunctions(const ScriptInterface& scriptInterface);
JS::Value GetEngineInfo(ScriptInterface::CxPrivate* pCxPrivate);
JS::Value GetAvailableMods(ScriptInterface::CxPrivate* pCxPrivate);
void RestartEngine(ScriptInterface::CxPrivate* pCxPrivate);
void SetMods(ScriptInterface::CxPrivate* pCxPrivate, const std::vector<CStr>& mods);

View File

@ -27,11 +27,6 @@
#include "simulation2/Simulation2.h"
#include "simulation2/system/TurnManager.h"
JS::Value JSI_SavedGame::GetEngineInfo(ScriptInterface::CxPrivate* pCxPrivate)
{
return SavedGames::GetEngineInfo(*(pCxPrivate->pScriptInterface));
}
JS::Value JSI_SavedGame::GetSavedGames(ScriptInterface::CxPrivate* pCxPrivate)
{
return SavedGames::GetSavedGames(*(pCxPrivate->pScriptInterface));
@ -111,7 +106,6 @@ JS::Value JSI_SavedGame::StartSavedGame(ScriptInterface::CxPrivate* pCxPrivate,
void JSI_SavedGame::RegisterScriptFunctions(const ScriptInterface& scriptInterface)
{
scriptInterface.RegisterFunction<JS::Value, &GetEngineInfo>("GetEngineInfo");
scriptInterface.RegisterFunction<JS::Value, &GetSavedGames>("GetSavedGames");
scriptInterface.RegisterFunction<bool, std::wstring, &DeleteSavedGame>("DeleteSavedGame");
scriptInterface.RegisterFunction<void, std::wstring, std::wstring, JS::HandleValue, &SaveGame>("SaveGame");

View File

@ -22,7 +22,6 @@
namespace JSI_SavedGame
{
JS::Value GetEngineInfo(ScriptInterface::CxPrivate* pCxPrivate);
JS::Value GetSavedGames(ScriptInterface::CxPrivate* pCxPrivate);
bool DeleteSavedGame(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& name);
void SaveGame(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename, const std::wstring& description, JS::HandleValue GUIMetadata);