diff --git a/source/ps/Mod.cpp b/source/ps/Mod.cpp index ab42607038..ff07af440f 100644 --- a/source/ps/Mod.cpp +++ b/source/ps/Mod.cpp @@ -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; +} diff --git a/source/ps/Mod.h b/source/ps/Mod.h index 0ce3d35eb1..3c36175166 100644 --- a/source/ps/Mod.h +++ b/source/ps/Mod.h @@ -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 diff --git a/source/ps/SavedGame.cpp b/source/ps/SavedGame.cpp index 60d24bfa55..8891471951 100644 --- a/source/ps/SavedGame.cpp +++ b/source/ps/SavedGame.cpp @@ -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; -} diff --git a/source/ps/SavedGame.h b/source/ps/SavedGame.h index fcca8c2347..67cdb13b7d 100644 --- a/source/ps/SavedGame.h +++ b/source/ps/SavedGame.h @@ -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& 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& 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& 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& 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 diff --git a/source/ps/scripting/JSInterface_Mod.cpp b/source/ps/scripting/JSInterface_Mod.cpp index 21e4ecab0e..7ba2c8a96f 100644 --- a/source/ps/scripting/JSInterface_Mod.cpp +++ b/source/ps/scripting/JSInterface_Mod.cpp @@ -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("GetEngineInfo"); scriptInterface.RegisterFunction("GetAvailableMods"); scriptInterface.RegisterFunction("RestartEngine"); scriptInterface.RegisterFunction, &JSI_Mod::SetMods>("SetMods"); diff --git a/source/ps/scripting/JSInterface_Mod.h b/source/ps/scripting/JSInterface_Mod.h index 96bf8bf2ef..ccfdb42250 100644 --- a/source/ps/scripting/JSInterface_Mod.h +++ b/source/ps/scripting/JSInterface_Mod.h @@ -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& mods); diff --git a/source/ps/scripting/JSInterface_SavedGame.cpp b/source/ps/scripting/JSInterface_SavedGame.cpp index 5928eae3f8..c49cb46b63 100644 --- a/source/ps/scripting/JSInterface_SavedGame.cpp +++ b/source/ps/scripting/JSInterface_SavedGame.cpp @@ -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("GetEngineInfo"); scriptInterface.RegisterFunction("GetSavedGames"); scriptInterface.RegisterFunction("DeleteSavedGame"); scriptInterface.RegisterFunction("SaveGame"); diff --git a/source/ps/scripting/JSInterface_SavedGame.h b/source/ps/scripting/JSInterface_SavedGame.h index 1e00984da1..dcd94934d5 100644 --- a/source/ps/scripting/JSInterface_SavedGame.h +++ b/source/ps/scripting/JSInterface_SavedGame.h @@ -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);