Ticket #4020: 4020_altf4_v1.patch
File 4020_altf4_v1.patch, 5.5 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/gui/session/session.js
511 511 resumeGame(true); 512 512 } 513 513 514 function saveReplayMetadata() 515 { 516 let extendedSimState = Engine.GuiInterfaceCall("GetExtendedSimulationState"); 517 Engine.SaveReplayMetadata(JSON.stringify({ 518 "timeElapsed" : extendedSimState.timeElapsed, 519 "playerStates": extendedSimState.players, 520 "mapSettings": g_GameAttributes.settings 521 })); 522 } 523 514 524 /** 515 525 * Leave the game 516 526 * @param willRejoin If player is going to be rejoining a networked game. … … 518 528 function leaveGame(willRejoin) 519 529 { 520 530 let extendedSimState = Engine.GuiInterfaceCall("GetExtendedSimulationState"); 521 let simData = {522 "timeElapsed" : extendedSimState.timeElapsed,523 "playerStates": extendedSimState.players,524 "mapSettings": g_GameAttributes.settings525 };526 531 527 if (!g_IsReplay)528 Engine.SaveReplayMetadata(JSON.stringify(simData));529 530 532 if (!willRejoin && 531 simData.playerStates[Engine.GetPlayerID()] &&532 simData.playerStates[Engine.GetPlayerID()].state == "active")533 extendedSimState.players[Engine.GetPlayerID()] && 534 extendedSimState.players[Engine.GetPlayerID()].state == "active") 533 535 resignGame(true); 534 536 535 537 // Before ending the game … … 541 543 Engine.SendUnregisterGame(); 542 544 543 545 Engine.SwitchGuiPage("page_summary.xml", { 544 "sim": simData, 546 "sim": { 547 "timeElapsed" : extendedSimState.timeElapsed, 548 "playerStates": extendedSimState.players, 549 "mapSettings": g_GameAttributes.settings 550 }, 545 551 "gui": { 546 552 "assignedPlayer": Engine.GetPlayerID(), 547 553 "disconnected": g_Disconnected, -
source/ps/Game.cpp
110 110 delete m_ReplayStream; 111 111 } 112 112 113 void CGame::SaveReplayMetadata(ScriptInterface *scriptInterface, jsval globalObject){ 114 m_ReplayLogger->SaveReplayMetadata(scriptInterface, globalObject); 115 } 116 113 117 void CGame::SetTurnManager(CNetTurnManager* turnManager) 114 118 { 115 119 if (m_TurnManager) -
source/ps/Game.h
181 181 inline std::string GetReplayPath() const 182 182 { return m_ReplayPath; } 183 183 184 void SaveReplayMetadata(ScriptInterface *scriptInterface, jsval globalObject); 185 184 186 /** 185 187 * Replace the current turn manager. 186 188 * This class will take ownership of the pointer. -
source/ps/GameSetup/GameSetup.cpp
701 701 702 702 void EndGame() 703 703 { 704 if (g_Game != NULL) 705 g_Game->SaveReplayMetadata(g_GUI->GetActiveGUI()->GetScriptInterface().get(), g_GUI->GetActiveGUI()->GetGlobalObject()); 706 704 707 SAFE_DELETE(g_NetClient); 705 708 SAFE_DELETE(g_NetServer); 706 709 SAFE_DELETE(g_Game); -
source/ps/Replay.cpp
20 20 #include "Replay.h" 21 21 22 22 #include "graphics/TerrainTextureManager.h" 23 #include "gui/GUIManager.h" 23 24 #include "lib/timer.h" 24 25 #include "lib/file/file_system.h" 25 26 #include "lib/res/h_mgr.h" 26 27 #include "lib/tex/tex.h" 28 #include "ps/CLogger.h" 27 29 #include "ps/Game.h" 28 30 #include "ps/Loader.h" 29 31 #include "ps/Mod.h" … … 61 63 delete m_Stream; 62 64 } 63 65 66 void CReplayLogger::SaveReplayMetadata(ScriptInterface *scriptInterface, jsval globalObject) 67 { 68 JSContext* cx = scriptInterface->GetContext(); 69 JSAutoRequest rq(cx); 70 71 JS::RootedValue data(cx); 72 JS::RootedValue global(cx, globalObject); 73 bool ok = scriptInterface->CallFunction(global, "saveReplayMetadata", &data); 74 if (!ok) 75 LOGERROR("Could not save replay metadata"); 76 } 77 64 78 void CReplayLogger::StartGame(JS::MutableHandleValue attribs) 65 79 { 66 80 // Add timestamp, since the file-modification-date can change -
source/ps/Replay.h
1 /* Copyright (C) 201 5Wildfire Games.1 /* Copyright (C) 2016 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 52 52 * Remember the directory containing the commands.txt file, so that we can save additional files to it. 53 53 */ 54 54 virtual OsPath GetDirectory() const = 0; 55 56 virtual void SaveReplayMetadata(ScriptInterface *scriptInterface, jsval globalObject) = 0; 55 57 }; 56 58 57 59 /** … … 64 66 virtual void Turn(u32 UNUSED(n), u32 UNUSED(turnLength), std::vector<SimulationCommand>& UNUSED(commands)) { } 65 67 virtual void Hash(const std::string& UNUSED(hash), bool UNUSED(quick)) { } 66 68 virtual OsPath GetDirectory() const { return OsPath(); } 69 virtual void SaveReplayMetadata(ScriptInterface *scriptInterface, jsval globalObject){} 67 70 }; 68 71 69 72 /** … … 80 83 virtual void Turn(u32 n, u32 turnLength, std::vector<SimulationCommand>& commands); 81 84 virtual void Hash(const std::string& hash, bool quick); 82 85 virtual OsPath GetDirectory() const; 86 virtual void SaveReplayMetadata(ScriptInterface *scriptInterface, jsval globalObject); 83 87 84 88 private: 85 89 ScriptInterface& m_ScriptInterface;