Ticket #3355: t3355_move_population_capacities_v1.patch

File t3355_move_population_capacities_v1.patch, 5.6 KB (added by elexis, 9 years ago)
  • binaries/data/mods/public/gui/common/settings.js

     
    2929 */
    3030function loadSettingsValues()
    3131{
    3232    var settings = {
    3333        "Ceasefire": loadCeasefire(),
     34        "PopulationCapacities": loadPopulationCapacities(),
    3435        "StartingResources": loadSettingValuesFile("starting_resources.json")
    3536    };
    3637
    3738    if (Object.keys(settings).some(key => settings[key] === undefined))
    3839        return undefined;
     
    8586            sprintf(translatePluralWithContext("ceasefire", "%(minutes)s minute", "%(minutes)s minutes", timeout), { "minutes": timeout })
    8687    }));
    8788}
    8889
    8990/**
     91 * Loads available population capacities.
     92 *
     93 * @returns {Array|undefined}
     94 */
     95function loadPopulationCapacities()
     96{
     97    var json = Engine.ReadJSONFile(g_SettingsDirectory + "population_capacities.json");
     98
     99    if (!json || json.Default === undefined || !json.PopulationCapacities || !Array.isArray(json.PopulationCapacities))
     100    {
     101        error("Could not load population_capacities.json");
     102        return undefined;
     103    }
     104
     105    return json.PopulationCapacities.map(population => ({
     106        "Population": population,
     107        "Default": population == json.Default,
     108        "Title": population < 10000 ? population : translate("Unlimited")
     109    }));
     110}
     111
     112/**
    90113 * Creates an object with all values of that property of the given setting and
    91114 * finds the index of the default value.
    92115 *
    93116 * This allows easy copying of setting values to dropdown lists.
    94117 *
  • binaries/data/mods/public/gui/gamesetup/gamesetup.js

     
    33const DEFAULT_NETWORKED_MAP = "Acropolis 01";
    44const DEFAULT_OFFLINE_MAP = "Acropolis 01";
    55
    66const VICTORY_DEFAULTIDX = 1;
    77
    8 // TODO: Move these somewhere like simulation\data\game_types.json, Atlas needs them too
    9 // Translation: Type of victory condition.
    10 const POPULATION_CAP = ["50", "100", "150", "200", "250", "300", translate("Unlimited")];
    11 const POPULATION_CAP_DATA = [50, 100, 150, 200, 250, 300, 10000];
    12 const POPULATION_CAP_DEFAULTIDX = 5;
    13 
    14 const g_StartingResources = prepareForDropdown(g_Settings ? g_Settings.StartingResources : undefined);
    158const g_Ceasefire = prepareForDropdown(g_Settings ? g_Settings.Ceasefire : undefined);
     9const g_PopulationCapacities = prepareForDropdown(g_Settings ? g_Settings.PopulationCapacities : undefined);
     10const g_StartingResources = prepareForDropdown(g_Settings ? g_Settings.StartingResources : undefined);
    1611
    1712////////////////////////////////////////////////////////////////////////////////////////////////
    1813
    1914// Is this is a networked game, or offline
    2015var g_IsNetworked;
     
    197192            updateGameAttributes();
    198193        }
    199194        gameSpeed.selected = g_GameSpeeds["default"];
    200195
    201196        var populationCaps = Engine.GetGUIObjectByName("populationCap");
    202         populationCaps.list = POPULATION_CAP;
    203         populationCaps.list_data = POPULATION_CAP_DATA;
    204         populationCaps.selected = POPULATION_CAP_DEFAULTIDX;
     197        populationCaps.list = g_PopulationCapacities.Title;
     198        populationCaps.list_data = g_PopulationCapacities.Population;
     199        populationCaps.selected = g_PopulationCapacities.Default;
    205200        populationCaps.onSelectionChange = function() {
    206201            if (this.selected != -1)
    207                 g_GameAttributes.settings.PopulationCap = POPULATION_CAP_DATA[this.selected];
     202                g_GameAttributes.settings.PopulationCap = g_PopulationCapacities.Population[this.selected];
    208203
    209204            updateGameAttributes();
    210205        }
    211206
    212207        var startingResourcesL = Engine.GetGUIObjectByName("startingResources");
     
    12481243    observerLateJoin.checked = g_GameAttributes.settings.ObserverLateJoin;
    12491244    observerLateJoinText.caption = observerLateJoin.checked ? translate("Yes") : translate("No");
    12501245
    12511246    gameSpeedText.caption = g_GameSpeeds.names[speedIdx];
    12521247    gameSpeedBox.selected = speedIdx;
    1253     populationCap.selected = (mapSettings.PopulationCap !== undefined && POPULATION_CAP_DATA.indexOf(mapSettings.PopulationCap) != -1 ? POPULATION_CAP_DATA.indexOf(mapSettings.PopulationCap) : POPULATION_CAP_DEFAULTIDX);
    1254     populationCapText.caption = POPULATION_CAP[populationCap.selected];
     1248    populationCap.selected = mapSettings.PopulationCap !== undefined && g_PopulationCapacities.Population.indexOf(mapSettings.PopulationCap) != -1 ? g_PopulationCapacities.Population.indexOf(mapSettings.PopulationCap) : g_PopulationCapacities.Default;
     1249    populationCapText.caption = g_PopulationCapacities.Title[populationCap.selected];
    12551250    startingResources.selected = mapSettings.StartingResources !== undefined && g_StartingResources.Resources.indexOf(mapSettings.StartingResources) != -1 ? g_StartingResources.Resources.indexOf(mapSettings.StartingResources) : g_StartingResources.Default;
    12561251    startingResourcesText.caption = g_StartingResources.Title[startingResources.selected];
    12571252    ceasefire.selected = mapSettings.Ceasefire !== undefined && g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) != -1 ? g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) : g_Ceasefire.Default;
    12581253    ceasefireText.caption = g_Ceasefire.Title[ceasefire.selected];
    12591254
  • binaries/data/mods/public/simulation/data/settings/population_capacities.json

     
     1{
     2    "PopulationCapacities": [50, 100, 150, 200, 250, 300, 10000],
     3    "Default": 300
     4}