Ticket #4020: 4020_altf4_v1.patch

File 4020_altf4_v1.patch, 5.5 KB (added by Imarok, 8 years ago)

fixed with the help of elexis

  • binaries/data/mods/public/gui/session/session.js

     
    511511        resumeGame(true);
    512512}
    513513
     514function 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
    514524/**
    515525 * Leave the game
    516526 * @param willRejoin If player is going to be rejoining a networked game.
     
    518528function leaveGame(willRejoin)
    519529{
    520530    let extendedSimState = Engine.GuiInterfaceCall("GetExtendedSimulationState");
    521     let simData = {
    522         "timeElapsed" : extendedSimState.timeElapsed,
    523         "playerStates": extendedSimState.players,
    524         "mapSettings": g_GameAttributes.settings
    525     };
    526531
    527     if (!g_IsReplay)
    528         Engine.SaveReplayMetadata(JSON.stringify(simData));
    529 
    530532    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")
    533535        resignGame(true);
    534536
    535537    // Before ending the game
     
    541543        Engine.SendUnregisterGame();
    542544
    543545    Engine.SwitchGuiPage("page_summary.xml", {
    544         "sim": simData,
     546        "sim": {
     547            "timeElapsed" : extendedSimState.timeElapsed,
     548            "playerStates": extendedSimState.players,
     549            "mapSettings": g_GameAttributes.settings
     550        },
    545551        "gui": {
    546552            "assignedPlayer": Engine.GetPlayerID(),
    547553            "disconnected": g_Disconnected,
  • source/ps/Game.cpp

     
    110110    delete m_ReplayStream;
    111111}
    112112
     113void CGame::SaveReplayMetadata(ScriptInterface *scriptInterface, jsval globalObject){
     114    m_ReplayLogger->SaveReplayMetadata(scriptInterface, globalObject);
     115}
     116
    113117void CGame::SetTurnManager(CNetTurnManager* turnManager)
    114118{
    115119    if (m_TurnManager)
  • source/ps/Game.h

     
    181181    inline std::string GetReplayPath() const
    182182    {   return m_ReplayPath; }
    183183
     184    void SaveReplayMetadata(ScriptInterface *scriptInterface, jsval globalObject);
     185
    184186    /**
    185187     * Replace the current turn manager.
    186188     * This class will take ownership of the pointer.
  • source/ps/GameSetup/GameSetup.cpp

     
    701701
    702702void EndGame()
    703703{
     704    if (g_Game != NULL)
     705        g_Game->SaveReplayMetadata(g_GUI->GetActiveGUI()->GetScriptInterface().get(), g_GUI->GetActiveGUI()->GetGlobalObject());
     706
    704707    SAFE_DELETE(g_NetClient);
    705708    SAFE_DELETE(g_NetServer);
    706709    SAFE_DELETE(g_Game);
  • source/ps/Replay.cpp

     
    2020#include "Replay.h"
    2121
    2222#include "graphics/TerrainTextureManager.h"
     23#include "gui/GUIManager.h"
    2324#include "lib/timer.h"
    2425#include "lib/file/file_system.h"
    2526#include "lib/res/h_mgr.h"
    2627#include "lib/tex/tex.h"
     28#include "ps/CLogger.h"
    2729#include "ps/Game.h"
    2830#include "ps/Loader.h"
    2931#include "ps/Mod.h"
     
    6163    delete m_Stream;
    6264}
    6365
     66void 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
    6478void CReplayLogger::StartGame(JS::MutableHandleValue attribs)
    6579{
    6680    // Add timestamp, since the file-modification-date can change
  • source/ps/Replay.h

     
    1 /* Copyright (C) 2015 Wildfire Games.
     1/* Copyright (C) 2016 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    5252     * Remember the directory containing the commands.txt file, so that we can save additional files to it.
    5353     */
    5454    virtual OsPath GetDirectory() const = 0;
     55
     56    virtual void SaveReplayMetadata(ScriptInterface *scriptInterface, jsval globalObject) = 0;
    5557};
    5658
    5759/**
     
    6466    virtual void Turn(u32 UNUSED(n), u32 UNUSED(turnLength), std::vector<SimulationCommand>& UNUSED(commands)) { }
    6567    virtual void Hash(const std::string& UNUSED(hash), bool UNUSED(quick)) { }
    6668    virtual OsPath GetDirectory() const { return OsPath(); }
     69    virtual void SaveReplayMetadata(ScriptInterface *scriptInterface, jsval globalObject){}
    6770};
    6871
    6972/**
     
    8083    virtual void Turn(u32 n, u32 turnLength, std::vector<SimulationCommand>& commands);
    8184    virtual void Hash(const std::string& hash, bool quick);
    8285    virtual OsPath GetDirectory() const;
     86    virtual void SaveReplayMetadata(ScriptInterface *scriptInterface, jsval globalObject);
    8387
    8488private:
    8589    ScriptInterface& m_ScriptInterface;