Index: binaries/data/mods/public/gui/common/functions_global_object.js =================================================================== --- binaries/data/mods/public/gui/common/functions_global_object.js +++ binaries/data/mods/public/gui/common/functions_global_object.js @@ -82,17 +82,3 @@ Engine.ResetCursor(); } - -/** - * Also called from the C++ side when ending the game. - * The current page can be the summary screen or a message box, so it can't be moved to session/. - */ -function getReplayMetadata() -{ - let extendedSimState = Engine.GuiInterfaceCall("GetExtendedSimulationState"); - return { - "timeElapsed": extendedSimState.timeElapsed, - "playerStates": extendedSimState.players, - "mapSettings": Engine.GetInitAttributes().settings - }; -} Index: binaries/data/mods/public/gui/credits/texts/programming.json =================================================================== --- binaries/data/mods/public/gui/credits/texts/programming.json +++ binaries/data/mods/public/gui/credits/texts/programming.json @@ -109,6 +109,7 @@ {"nick": "idanwin"}, {"nick": "Imarok", "name": "J. S."}, {"nick": "infyquest", "name": "Vijay Kiran Kamuju"}, + {"nick": "irishninja", "name": "Brian Broll"}, {"nick": "IronNerd", "name": "Matthew McMullan"}, {"nick": "Itms", "name": "Nicolas Auvray"}, {"nick": "Jaison", "name": "Marco tom Suden"}, Index: binaries/data/mods/public/gui/session/session.js =================================================================== --- binaries/data/mods/public/gui/session/session.js +++ binaries/data/mods/public/gui/session/session.js @@ -732,7 +732,7 @@ // Before ending the game let replayDirectory = Engine.GetCurrentReplayDirectory(); - let simData = getReplayMetadata(); + let simData = Engine.GuiInterfaceCall("GetReplayMetadata"); let playerID = Engine.GetPlayerID(); Engine.EndGame(); Index: binaries/data/mods/public/simulation/components/GuiInterface.js =================================================================== --- binaries/data/mods/public/simulation/components/GuiInterface.js +++ binaries/data/mods/public/simulation/components/GuiInterface.js @@ -191,6 +191,16 @@ return ret; }; +GuiInterface.prototype.GetReplayMetadata = function () +{ + let extendedSimState = this.GetExtendedSimulationState(); + return { + "timeElapsed": extendedSimState.timeElapsed, + "playerStates": extendedSimState.players, + "mapSettings": Engine.GetInitAttributes().settings + }; +}; + GuiInterface.prototype.GetRenamedEntities = function(player) { if (this.miragedEntities[player]) @@ -1913,6 +1923,7 @@ "GetSimulationState": 1, "GetExtendedSimulationState": 1, + "GetReplayMetadata": 1, "GetRenamedEntities": 1, "ClearRenamedEntities": 1, "GetEntityState": 1, Index: source/ps/Game.h =================================================================== --- source/ps/Game.h +++ source/ps/Game.h @@ -151,6 +151,14 @@ return !m_GameView; } + /** + * Get m_IsSavingReplay. + * + * @return bool the value of m_IsSavingReplay. + **/ + inline bool IsSavingReplay() const + { return m_IsSavingReplay; } + /** * Get m_IsVisualReplay. * @@ -224,6 +232,7 @@ int LoadVisualReplayData(); OsPath m_ReplayPath; + bool m_IsSavingReplay; bool m_IsVisualReplay; std::istream* m_ReplayStream; u32 m_FinalReplayTurn; Index: source/ps/Game.cpp =================================================================== --- source/ps/Game.cpp +++ source/ps/Game.cpp @@ -74,7 +74,8 @@ m_ViewedPlayerID(-1), m_IsSavedGame(false), m_IsVisualReplay(false), - m_ReplayStream(NULL) + m_ReplayStream(nullptr), + m_IsSavingReplay(replayLog) { // TODO: should use CDummyReplayLogger unless activated by cmd-line arg, perhaps? if (replayLog) Index: source/ps/GameSetup/GameSetup.cpp =================================================================== --- source/ps/GameSetup/GameSetup.cpp +++ source/ps/GameSetup/GameSetup.cpp @@ -700,8 +700,8 @@ const bool nonVisual = g_Game && g_Game->IsGraphicsDisabled(); if (g_Game && g_Game->IsGameStarted() && !g_Game->IsVisualReplay() && - g_AtlasGameLoop && !g_AtlasGameLoop->running && !nonVisual) - VisualReplay::SaveReplayMetadata(g_GUI->GetActiveGUI()->GetScriptInterface().get()); + g_AtlasGameLoop && !g_AtlasGameLoop->running && g_Game->IsSavingReplay()) + VisualReplay::SaveReplayMetadata(g_Game->GetSimulation2()); SAFE_DELETE(g_NetClient); SAFE_DELETE(g_NetServer); Index: source/ps/VisualReplay.h =================================================================== --- source/ps/VisualReplay.h +++ source/ps/VisualReplay.h @@ -117,7 +117,7 @@ /** * Saves the metadata from the session to metadata.json. */ -void SaveReplayMetadata(ScriptInterface* scriptInterface); +void SaveReplayMetadata(const CSimulation2* simulation); /** * Adds a replay to the replayCache. Index: source/ps/VisualReplay.cpp =================================================================== --- source/ps/VisualReplay.cpp +++ source/ps/VisualReplay.cpp @@ -34,6 +34,9 @@ #include "ps/Replay.h" #include "ps/Util.h" #include "scriptinterface/ScriptInterface.h" +#include "simulation2/components/ICmpGuiInterface.h" +#include "simulation2/Simulation2.h" +#include "simulation2/system/CmpPtr.h" /** * Filter too short replays (value in seconds). @@ -472,26 +475,28 @@ StoreCacheFile(scriptInterface, cachedReplaysObject); } -void VisualReplay::SaveReplayMetadata(ScriptInterface* scriptInterface) +void VisualReplay::SaveReplayMetadata(const CSimulation2* simulation) { - JSContext* cx = scriptInterface->GetContext(); - JSAutoRequest rq(cx); - - JS::RootedValue metadata(cx); - JS::RootedValue global(cx, scriptInterface->GetGlobalObject()); - - if (!scriptInterface->CallFunction(global, "getReplayMetadata", &metadata)) + CmpPtr cmpGuiInterface(*simulation, SYSTEM_ENTITY); + if (!cmpGuiInterface) { LOGERROR("Could not save replay metadata!"); return; } + ScriptInterface& scriptInterface = simulation->GetScriptInterface(); + JSContext* cxSim = scriptInterface.GetContext(); + JSAutoRequest rqSim(cxSim); + JS::RootedValue arg(cxSim, JS::UndefinedValue()); + JS::RootedValue metadata(cxSim); + cmpGuiInterface->ScriptCall(INVALID_PLAYER, L"GetReplayMetadata", arg, &metadata); + // Get the directory of the currently active replay const OsPath fileName = g_Game->GetReplayLogger().GetDirectory() / L"metadata.json"; CreateDirectories(fileName.Parent(), 0700); std::ofstream stream (OsString(fileName).c_str(), std::ofstream::out | std::ofstream::trunc); - stream << scriptInterface->StringifyJSON(&metadata, false); + stream << scriptInterface.StringifyJSON(&metadata, false); stream.close(); debug_printf("Saved replay metadata to %s\n", fileName.string8().c_str()); } Index: source/simulation2/system/ComponentManager.cpp =================================================================== --- source/simulation2/system/ComponentManager.cpp +++ source/simulation2/system/ComponentManager.cpp @@ -31,6 +31,7 @@ #include "ps/CLogger.h" #include "ps/Filesystem.h" #include "ps/scripting/JSInterface_VFS.h" +#include "simulation2/scripting/JSInterface_Simulation.h" /** * Used for script-only message types. @@ -84,6 +85,7 @@ m_ScriptInterface.RegisterFunction ("AddLocalEntity"); m_ScriptInterface.RegisterFunction ("DestroyEntity"); m_ScriptInterface.RegisterFunction ("FlushDestroyedEntities"); + m_ScriptInterface.RegisterFunction("GetInitAttributes"); } // Globalscripts may use VFS script functions