Ticket #3883: persist_match_settings_v9.1.patch

File persist_match_settings_v9.1.patch, 3.3 KB (added by Imarok, 8 years ago)

removed some unneeded code and renamed cleanUpSettings

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

     
    846846    mapSelectionBox.selected = Math.max(0, mapListFiles.indexOf(g_GameAttributes.map || ""));
    847847}
    848848
     849/**
     850 * Removes every setting the user cannot change
     851 */
     852function removeInvalidSettings(attrs)
     853{
     854    // Find which settings can be changed by the user
     855    let allowedSettings = ["PlayerData"];
     856
     857    if (attrs.mapType == "skirmish" || attrs.mapType == "random")
     858        allowedSettings = allowedSettings.concat(
     859        [
     860            "GameType",
     861            "WonderDuration",
     862            "PopulationCap",
     863            "Ceasefire",
     864            "StartingResources",
     865            "RevealMap",
     866            "LockTeams",
     867            "ExploreMap",
     868            "DisableTreasures"
     869        ]);
     870
     871    if (attrs.mapType == "random")
     872        allowedSettings.push("Size");
     873
     874    if (g_IsNetworked)
     875        allowedSettings.push("CheatsEnabled");
     876
     877    if (Engine.HasXmppClient())
     878        allowedSettings.push("RatingEnabled");
     879
     880    // Only load settings which can be changed by the user
     881    for (let prop in attrs.settings)
     882        if (allowedSettings.indexOf(prop) == -1)
     883            delete attrs.settings[prop];
     884
     885    if (attrs.settings.RatingEnabled)
     886        attrs.settings.CheatsEnabled = false;
     887}
     888
    849889function loadMapData(name)
    850890{
    851891    if (!name || !g_MapPath[g_GameAttributes.mapType])
     
    868908    if (Engine.ConfigDB_GetValue("user", "persistmatchsettings") != "true")
    869909        return;
    870910
     911    // Load file
    871912    let settingsFile = g_IsNetworked ? g_MatchSettings_MP : g_MatchSettings_SP;
    872913    if (!Engine.FileExists(settingsFile))
    873914        return;
     
    878919
    879920    g_IsInGuiUpdate = true;
    880921
     922    removeInvalidSettings(attrs);
     923
     924    // Restore valid matchsettings
    881925    let mapName = attrs.map || "";
    882926    let mapSettings = attrs.settings;
    883927
     
    913957    // Reload, as the maptype or mapfilter might have changed
    914958    initMapNameList();
    915959
    916     g_GameAttributes.settings.RatingEnabled = Engine.HasXmppClient();
    917     Engine.SetRankedGame(g_GameAttributes.settings.RatingEnabled);
     960    Engine.SetRankedGame(!!g_GameAttributes.settings.RatingEnabled);
    918961
    919962    updateGUIObjects();
    920963}
     
    11251168    if (g_IsInGuiUpdate || !g_IsController || !name)
    11261169        return;
    11271170
    1128     // Reset some map specific properties which are not necessarily redefined on each map
    1129     for (let prop of ["TriggerScripts", "CircularMap", "Garrison"])
    1130         g_GameAttributes.settings[prop] = undefined;
     1171    removeInvalidSettings(g_GameAttributes);
    11311172
    11321173    let mapData = loadMapData(name);
    11331174    let mapSettings = mapData && mapData.settings ? deepcopy(mapData.settings) : {};
    11341175
    1135     // Reset victory conditions
    1136     if (g_GameAttributes.mapType != "random")
    1137     {
    1138         let victoryIdx = g_VictoryConditions.Name.indexOf(mapSettings.GameType || "") != -1 ? g_VictoryConditions.Name.indexOf(mapSettings.GameType) : g_VictoryConditions.Default;
    1139         g_GameAttributes.settings.GameType = g_VictoryConditions.Name[victoryIdx];
    1140         g_GameAttributes.settings.VictoryScripts = g_VictoryConditions.Scripts[victoryIdx];
    1141     }
    1142 
    1143     if (g_GameAttributes.mapType == "scenario")
    1144         delete g_GameAttributes.settings.WonderDuration;
    1145 
    11461176    if (mapSettings.PlayerData)
    11471177        sanitizePlayerData(mapSettings.PlayerData);
    11481178
     
    11761206                Engine.AssignNetworkPlayer(player, "");
    11771207        }
    11781208    }
    1179 
    11801209    updateGameAttributes();
    11811210}
    11821211