Ticket #3355: t3355_move_population_capacities_v1.patch
File t3355_move_population_capacities_v1.patch, 5.6 KB (added by , 9 years ago) |
---|
-
binaries/data/mods/public/gui/common/settings.js
29 29 */ 30 30 function loadSettingsValues() 31 31 { 32 32 var settings = { 33 33 "Ceasefire": loadCeasefire(), 34 "PopulationCapacities": loadPopulationCapacities(), 34 35 "StartingResources": loadSettingValuesFile("starting_resources.json") 35 36 }; 36 37 37 38 if (Object.keys(settings).some(key => settings[key] === undefined)) 38 39 return undefined; … … 85 86 sprintf(translatePluralWithContext("ceasefire", "%(minutes)s minute", "%(minutes)s minutes", timeout), { "minutes": timeout }) 86 87 })); 87 88 } 88 89 89 90 /** 91 * Loads available population capacities. 92 * 93 * @returns {Array|undefined} 94 */ 95 function 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 /** 90 113 * Creates an object with all values of that property of the given setting and 91 114 * finds the index of the default value. 92 115 * 93 116 * This allows easy copying of setting values to dropdown lists. 94 117 * -
binaries/data/mods/public/gui/gamesetup/gamesetup.js
3 3 const DEFAULT_NETWORKED_MAP = "Acropolis 01"; 4 4 const DEFAULT_OFFLINE_MAP = "Acropolis 01"; 5 5 6 6 const VICTORY_DEFAULTIDX = 1; 7 7 8 // TODO: Move these somewhere like simulation\data\game_types.json, Atlas needs them too9 // 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);15 8 const g_Ceasefire = prepareForDropdown(g_Settings ? g_Settings.Ceasefire : undefined); 9 const g_PopulationCapacities = prepareForDropdown(g_Settings ? g_Settings.PopulationCapacities : undefined); 10 const g_StartingResources = prepareForDropdown(g_Settings ? g_Settings.StartingResources : undefined); 16 11 17 12 //////////////////////////////////////////////////////////////////////////////////////////////// 18 13 19 14 // Is this is a networked game, or offline 20 15 var g_IsNetworked; … … 197 192 updateGameAttributes(); 198 193 } 199 194 gameSpeed.selected = g_GameSpeeds["default"]; 200 195 201 196 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; 205 200 populationCaps.onSelectionChange = function() { 206 201 if (this.selected != -1) 207 g_GameAttributes.settings.PopulationCap = POPULATION_CAP_DATA[this.selected];202 g_GameAttributes.settings.PopulationCap = g_PopulationCapacities.Population[this.selected]; 208 203 209 204 updateGameAttributes(); 210 205 } 211 206 212 207 var startingResourcesL = Engine.GetGUIObjectByName("startingResources"); … … 1248 1243 observerLateJoin.checked = g_GameAttributes.settings.ObserverLateJoin; 1249 1244 observerLateJoinText.caption = observerLateJoin.checked ? translate("Yes") : translate("No"); 1250 1245 1251 1246 gameSpeedText.caption = g_GameSpeeds.names[speedIdx]; 1252 1247 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]; 1255 1250 startingResources.selected = mapSettings.StartingResources !== undefined && g_StartingResources.Resources.indexOf(mapSettings.StartingResources) != -1 ? g_StartingResources.Resources.indexOf(mapSettings.StartingResources) : g_StartingResources.Default; 1256 1251 startingResourcesText.caption = g_StartingResources.Title[startingResources.selected]; 1257 1252 ceasefire.selected = mapSettings.Ceasefire !== undefined && g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) != -1 ? g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) : g_Ceasefire.Default; 1258 1253 ceasefireText.caption = g_Ceasefire.Title[ceasefire.selected]; 1259 1254 -
binaries/data/mods/public/simulation/data/settings/population_capacities.json
1 { 2 "PopulationCapacities": [50, 100, 150, 200, 250, 300, 10000], 3 "Default": 300 4 }