Ticket #3143: 3143_lobby_data_gameattribs.patch

File 3143_lobby_data_gameattribs.patch, 3.9 KB (added by Imarok, 8 years ago)

preparation patch defining g_GameAttributes for session.js

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

     
    622622        "timeElapsed" : extendedSimState.timeElapsed,
    623623        "playerStates": extendedSimState.players,
    624624        "players": g_Players,
    625         "mapSettings": Engine.GetMapSettings(),
     625        "mapSettings": g_GameAttributes.settings,
    626626        "isInGame": true,
    627627        "gameResult": translate("Current Scores"),
    628628        "callback": "resumeGame"
  • binaries/data/mods/public/gui/session/session.js

     
    6464var g_FollowPlayer = false;
    6565
    6666/**
    67  * Unique ID for lobby reports.
    68  */
    69 var g_MatchID;
    70 
    71 /**
    7267 * Cache the basic player data (name, civ, color).
    7368 */
    7469var g_Players = [];
     
    9691    }
    9792};
    9893
     94var g_GameAttributes;
     95
    9996/**
    10097 * Cache dev-mode settings that are frequently or widely used.
    10198 */
     
    230227        g_IsNetworked = initData.isNetworked;
    231228        g_IsController = initData.isController;
    232229        g_PlayerAssignments = initData.playerAssignments;
    233         g_MatchID = initData.attribs.matchID;
     230        g_GameAttributes = initData.attribs;
    234231        g_ReplaySelectionData = initData.replaySelectionData;
    235232        g_HasRejoined = initData.isRejoining;
    236233
     
    485482
    486483function reportPerformance(time)
    487484{
    488     let settings = Engine.GetMapSettings();
     485    let settings = g_GameAttributes.settings;
    489486    Engine.SubmitUserReport("profile", 3, JSON.stringify({
    490487        "time": time,
    491488        "map": settings.Name,
     
    526523    let simData = {
    527524        "timeElapsed" : extendedSimState.timeElapsed,
    528525        "playerStates": extendedSimState.players,
    529         "mapSettings": Engine.GetMapSettings()
     526        "mapSettings": g_GameAttributes.settings
    530527    };
    531528
    532529    if (!g_IsReplay)
     
    12221219    playerStatistics.feminisation = "";
    12231220    playerStatistics.percentMapExplored = "";
    12241221
    1225     let mapName = Engine.GetMapSettings().Name;
     1222    let mapName = g_GameAttributes.settings.Name;
    12261223    let playerStates = "";
    12271224    let playerCivs = "";
    12281225    let teams = "";
     
    12721269    reportObject.timeElapsed = extendedSimState.timeElapsed;
    12731270    reportObject.playerStates = playerStates;
    12741271    reportObject.playerID = Engine.GetPlayerID();
    1275     reportObject.matchID = g_MatchID;
     1272    reportObject.matchID = g_GameAttributes.matchID;
    12761273    reportObject.civs = playerCivs;
    12771274    reportObject.teams = teams;
    12781275    reportObject.teamsLocked = String(teamsLocked);
  • source/gui/scripting/ScriptFunctions.cpp

     
    510510    return settings;
    511511}
    512512
    513 JS::Value GetMapSettings(ScriptInterface::CxPrivate* pCxPrivate)
    514 {
    515     if (!g_Game)
    516         return JS::UndefinedValue();
    517 
    518     JSContext* cx = g_Game->GetSimulation2()->GetScriptInterface().GetContext();
    519     JSAutoRequest rq(cx);
    520 
    521     JS::RootedValue mapSettings(cx);
    522     g_Game->GetSimulation2()->GetMapSettings(&mapSettings);
    523     return pCxPrivate->pScriptInterface->CloneValueFromOtherContext(
    524         g_Game->GetSimulation2()->GetScriptInterface(),
    525         mapSettings);
    526 }
    527 
    528513/**
    529514 * Get the current X coordinate of the camera.
    530515 */
     
    10701055    scriptInterface.RegisterFunction<bool, &AtlasIsAvailable>("AtlasIsAvailable");
    10711056    scriptInterface.RegisterFunction<bool, &IsAtlasRunning>("IsAtlasRunning");
    10721057    scriptInterface.RegisterFunction<JS::Value, VfsPath, &LoadMapSettings>("LoadMapSettings");
    1073     scriptInterface.RegisterFunction<JS::Value, &GetMapSettings>("GetMapSettings");
    10741058    scriptInterface.RegisterFunction<float, &CameraGetX>("CameraGetX");
    10751059    scriptInterface.RegisterFunction<float, &CameraGetZ>("CameraGetZ");
    10761060    scriptInterface.RegisterFunction<void, entity_id_t, &CameraFollow>("CameraFollow");