Ticket #3355: t3355_move_gamesetup_strings_v2.patch
File t3355_move_gamesetup_strings_v2.patch, 88.6 KB (added by , 9 years ago) |
---|
-
binaries/data/mods/public/gui/aiconfig/aiconfig.js
3 3 4 4 function init(settings) 5 5 { 6 6 g_PlayerSlot = settings.playerSlot; 7 7 8 translateObjectKeys(settings.ais, ["name", "description"]);9 8 g_AIs = [ 10 {id: "", data: {name: translateWithContext("ai", "None"), description: translate("AI will be disabled for this player.")}} 9 { "id": "", 10 "data": { 11 "name": translateWithContext("ai", "None"), 12 "description": translate("AI will be disabled for this player.") 13 } 14 } 11 15 ].concat(settings.ais); 12 16 13 17 var aiSelection = Engine.GetGUIObjectByName("aiSelection"); 14 aiSelection.list = [ translate(ai.data.name) for each (ai in g_AIs) ]; 15 16 var selected = 0; 17 for (var i = 0; i < g_AIs.length; ++i) 18 { 19 if (g_AIs[i].id == settings.id) 20 { 21 selected = i; 22 break; 23 } 24 } 25 aiSelection.selected = selected; 18 aiSelection.list = g_AIs.map(ai => translate(ai.data.name)); 19 aiSelection.selected = g_AIs.findIndex(ai => ai.id == settings.id); 26 20 27 21 var aiDiff = Engine.GetGUIObjectByName("aiDifficulty"); 28 // Translation: AI difficulty level. 29 aiDiff.list = [translateWithContext("aiDiff", "Sandbox"), translateWithContext("aiDiff", "Very Easy"), translateWithContext("aiDiff", "Easy"), translateWithContext("aiDiff", "Medium"), translateWithContext("aiDiff", "Hard"), translateWithContext("aiDiff", "Very Hard")]; 22 aiDiff.list = settings.difficulties.Title; 30 23 aiDiff.selected = settings.difficulty; 31 24 } 32 25 33 26 function selectAI(idx) 34 27 { 35 var id = g_AIs[idx].id; 36 var name = g_AIs[idx].data.name; 37 var description = g_AIs[idx].data.description; 38 39 Engine.GetGUIObjectByName("aiDescription").caption = description; 28 Engine.GetGUIObjectByName("aiDescription").caption = g_AIs[idx].data.description; 40 29 } 41 30 42 31 function returnAI() 43 32 { 44 var aiSelection = Engine.GetGUIObjectByName("aiSelection"); 45 var idx = aiSelection.selected; 46 var id = g_AIs[idx].id; 47 var name = g_AIs[idx].data.name; 48 33 var idx = Engine.GetGUIObjectByName("aiSelection").selected; 49 34 var difficulty = Engine.GetGUIObjectByName("aiDifficulty").selected; 50 35 51 36 // Pop the page before calling the callback, so the callback runs 52 37 // in the parent GUI page's context 53 Engine.PopGuiPageCB({"id": id, "name": name, "difficulty" : difficulty, "playerSlot" : g_PlayerSlot }); 38 Engine.PopGuiPageCB({ 39 "id": g_AIs[idx].id, 40 "name": g_sAIs[idx].data.name, 41 "difficulty": difficulty, 42 "playerSlot": g_PlayerSlot 43 }); 54 44 } -
binaries/data/mods/public/gui/common/functions_utility.js
83 83 return text.substr(0, 255).replace(/\\/g, "\\\\").replace(/\[/g, "\\["); 84 84 } 85 85 86 86 // ==================================================================== 87 87 88 // Load default player data, for when it's not otherwise specified89 function initPlayerDefaults()90 {91 var data = Engine.ReadJSONFile("simulation/data/player_defaults.json");92 if (!data || !data.PlayerData)93 {94 error("Failed to parse player defaults in player_defaults.json (check for valid JSON data)");95 return [];96 }97 98 return data.PlayerData;99 }100 101 // ====================================================================102 88 103 // Load map size data104 function initMapSizes()89 // Loads the translated description and filename of the preview image of the map (or a placeholder for random map). 90 function getMapDescriptionAndPreview(mapType, mapName) 105 91 { 106 var sizes = { 107 "shortNames":[], 108 "names":[], 109 "tiles": [], 110 "default": 0 111 }; 112 113 var data = Engine.ReadJSONFile("simulation/data/map_sizes.json"); 114 if (!data || !data.Sizes) 115 { 116 error("Failed to parse map sizes in map_sizes.json (check for valid JSON data)"); 117 return sizes; 118 } 119 120 translateObjectKeys(data, ["Name", "LongName"]); 121 for (var i = 0; i < data.Sizes.length; ++i) 122 { 123 sizes.shortNames.push(data.Sizes[i].Name); 124 sizes.names.push(data.Sizes[i].LongName); 125 sizes.tiles.push(data.Sizes[i].Tiles); 126 127 if (data.Sizes[i].Default) 128 sizes["default"] = i; 129 } 130 131 return sizes; 132 } 133 134 // ==================================================================== 92 let mapData; 93 if (mapType == "random" && mapName == "random") 94 mapData = { "settings": { "Description": translate("A randomly selected map.") } }; 95 else if (mapType == "random" && Engine.FileExists(mapName + ".json")) 96 mapData = Engine.ReadJSONFile(mapName + ".json"); 97 else if (Engine.FileExists(mapName + ".xml")) 98 mapData = Engine.LoadMapSettings(mapName + ".xml"); 99 else 100 warn(sprintf("Map '%(mapName)s' not found locally.", { "mapName": mapName })); 135 101 136 // Load game speed data 137 function initGameSpeeds() 138 { 139 var gameSpeeds = { 140 "names": [], 141 "speeds": [], 142 "default": 0 102 return { 103 "description": mapData && mapData.settings.Description ? 104 translate(mapData.settings.Description) : 105 translate("Sorry, no description available."), 106 107 "preview": mapData && mapData.settings.Preview ? 108 mapData.settings.Preview : 109 "nopreview.png" 143 110 }; 144 145 var data = Engine.ReadJSONFile("simulation/data/game_speeds.json");146 if (!data || !data.Speeds)147 {148 error("Failed to parse game speeds in game_speeds.json (check for valid JSON data)");149 return gameSpeeds;150 }151 152 translateObjectKeys(data, ["Name"]);153 for (var i = 0; i < data.Speeds.length; ++i)154 {155 gameSpeeds.names.push(data.Speeds[i].Name);156 gameSpeeds.speeds.push(data.Speeds[i].Speed);157 158 if (data.Speeds[i].Default)159 gameSpeeds["default"] = i;160 }161 162 return gameSpeeds;163 111 } 164 112 165 166 113 // ==================================================================== 167 114 168 115 // Convert integer color values to string (for use in GUI objects) 169 116 function rgbToGuiColor(color, alpha) 170 117 { … … 258 205 259 206 for (var word of autoCompleteList) 260 207 { 261 208 if (word.toLowerCase().indexOf(lastWord.toLowerCase()) != 0) 262 209 continue; 263 210 264 211 text = wordSplit.join(" ") 265 212 if (text.length > 0) 266 213 text += " "; 267 214 268 215 text += word; -
binaries/data/mods/public/gui/common/settings.js
1 // Used by lobby, gamesetup, session, and replay GUI 2 const g_Settings = loadAvailableSettings(); 3 4 function loadAvailableSettings() 5 { 6 const rootDir = "simulation/data/settings/"; 7 const gameTypeDir = rootDir + "GameTypes/"; 8 9 // Load Player Limits 10 let settings = Engine.ReadJSONFile(rootDir + "PlayerLimit.json"); 11 if (!settings) 12 return false; 13 14 // Load Game Types 15 settings.GameTypes = []; 16 for (let file of Engine.BuildDirEntList(gameTypeDir, "*.json", false)) 17 { 18 let gameType = file.substr(gameTypeDir.length).replace(".json", ""); 19 gameType = loadAvailableSettingsFile(gameType, file) 20 21 if (!gameType) 22 return false; 23 24 settings.GameTypes.push(gameType); 25 } 26 27 // Load even more settings 28 const settingNames = ["AIDifficulties", "Ceasefire", "GameSpeeds", "MapTypes", "MapSizes", 29 "PlayerDefaults", "PopulationCapacity", "StartingResources"]; 30 for (let settingName of settingNames) 31 { 32 settings[settingName] = loadAvailableSettingsFile(settingName, rootDir + settingName + ".json"); 33 if (!settings[settingName]) 34 return false; 35 } 36 37 return settings; 38 } 39 40 function loadAvailableSettingsFile(settingName, filename) 41 { 42 let json = Engine.ReadJSONFile(filename); 43 44 if (!json || !json[settingName]) 45 { 46 error("Couldn't load " + settingName + " settings!"); 47 return false; 48 } 49 50 if (json.TranslatedKeys) 51 translateObjectKeys(json, json.TranslatedKeys); 52 53 return json[settingName]; 54 } 55 56 function initAIDescription() 57 { 58 let ais = Engine.GetAIs(); 59 translateObjectKeys(ais, ["name", "description"]); 60 // Sort ais by displayed name 61 ais.sort((a, b) => a.data.name < b.data.name ? -1 : b.data.name < a.data.name ? +1 : 0); 62 return ais; 63 } 64 65 // Shows a message box and calls a function if the setting files couldn't be 66 // parsed 67 function validSettings(callback) 68 { 69 if (!g_Settings) 70 messageBox(400, 200, translate("Can't load game settings!"), translate("ERROR!"), 0, [translate("OK")], [callback]); 71 72 return g_Settings; 73 } 74 75 /* 76 * Switches propertyname and value index and extracts default value to easily 77 * copy settings to dropdownlists. Requires g_Settings. 78 */ 79 function prepareForDropdown(settingsName) 80 { 81 let settings = {}; 82 let settingValues = g_Settings[settingsName]; 83 for (let index in settingValues) 84 { 85 for (let property in settingValues[index]) 86 { 87 if (property == "Default") 88 continue; 89 90 if (index == 0) 91 settings[property] = []; 92 93 // Switch property and index 94 settings[property][index] = settingValues[index][property]; 95 } 96 97 // Copy default value 98 if (settingValues[index].Default) 99 settings.default = +index; 100 } 101 return settings; 102 } 103 104 //Returns the translation of the given AI name (like "petra"). Requires g_AIs. 105 function translateAIName(aiName) 106 { 107 let description = g_AIs.find(ai => ai.id == aiName); 108 return description ? translate(description.data.name) : translateWithContext("AI name", "Unknown"); 109 } 110 111 // Returns the translation of the given AI difficulty. Requires g_Settings. 112 function translateAIDifficulty(index) 113 { 114 let difficulty = g_Settings.AIDifficulties[index]; 115 return difficulty ? difficulty.Title : translateWithContext("AI difficulty", "Unknown"); 116 } 117 118 // Returns the translation of the given map type. Requires g_Settings. 119 function translateCeasefire(duration) 120 { 121 let ceasefire = g_Settings.Ceasefire.find(c => c.Duration == duration); 122 return ceasefire ? ceasefire.Title : translateWithContext("ceasefire duration", "Unknown"); 123 } 124 125 // Returns the translation of the given map type. Requires g_Settings. 126 function translateGameType(gameType) 127 { 128 let type = g_Settings.GameTypes.find(t => t.Name == gameType); 129 return type ? type.Title : translateWithContext("game type", "Unknown"); 130 } 131 132 // Returns the translation of the given map type. Requires g_Settings. 133 function translateMapType(mapType) 134 { 135 let type = g_Settings.MapTypes.find(t => t.Name == mapType); 136 return type ? type.Title : translateWithContext("map type", "Unknown"); 137 } 138 139 // Returns translated map size for a given a numeric size. Requires g_Settings. 140 function translateMapSize(tiles) 141 { 142 let size = g_Settings.MapSizes.find(s => s.Tiles == tiles); 143 return size ? size.Name : translateWithContext("map size", "Default"); 144 } 145 146 // Returns the translation for a given numeric value. Requires g_Settings. 147 function translatePopulationCapacity(population) 148 { 149 let popCap = g_Settings.PopulationCapacity.find(p => p.Population == population); 150 return popCap ? popCap.Title : translateWithContext("population capacity", "Unknown"); 151 } -
binaries/data/mods/public/gui/gamesetup/gamesetup.js
1 ////////////////////////////////////////////////////////////////////////////////////////////////2 1 // Constants 3 2 const DEFAULT_NETWORKED_MAP = "Acropolis 01"; 4 3 const DEFAULT_OFFLINE_MAP = "Acropolis 01"; 5 4 6 const VICTORY_DEFAULTIDX = 1; 7 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 // Translation: Amount of starting resources. 14 const STARTING_RESOURCES = [translateWithContext("startingResources", "Very Low"), translateWithContext("startingResources", "Low"), translateWithContext("startingResources", "Medium"), translateWithContext("startingResources", "High"), translateWithContext("startingResources", "Very High"), translateWithContext("startingResources", "Deathmatch")]; 15 const STARTING_RESOURCES_DATA = [100, 300, 500, 1000, 3000, 50000]; 16 const STARTING_RESOURCES_DEFAULTIDX = 1; 17 // Translation: Ceasefire. 18 const CEASEFIRE = [translateWithContext("ceasefire", "No ceasefire"), translateWithContext("ceasefire", "5 minutes"), translateWithContext("ceasefire", "10 minutes"), translateWithContext("ceasefire", "15 minutes"), translateWithContext("ceasefire", "20 minutes"), translateWithContext("ceasefire", "30 minutes"), translateWithContext("ceasefire", "45 minutes"), translateWithContext("ceasefire", "60 minutes")]; 19 const CEASEFIRE_DATA = [0, 5, 10, 15, 20, 30, 45, 60]; 20 const CEASEFIRE_DEFAULTIDX = 0; 21 // Max number of players for any map 22 const MAX_PLAYERS = 8; 23 24 //////////////////////////////////////////////////////////////////////////////////////////////// 5 // Contains settings transformed for the dropdown lists 6 var g_AIDiffs = {}; 7 var g_Ceasefire = {}; 8 var g_GameSpeeds = {}; 9 var g_GameTypes = {}; 10 var g_MapSizes = {}; 11 var g_MapTypes = {}; 12 var g_PlayerDefaults = []; 13 var g_PopulationCapacity = {}; 14 var g_StartingResources = {}; 25 15 26 16 // Is this is a networked game, or offline 27 17 var g_IsNetworked; 28 18 29 19 // Is this user in control of game settings (i.e. is a network server, or offline player) … … 50 40 var g_GameStarted = false; 51 41 52 42 var g_PlayerAssignments = {}; 53 43 54 44 // Default game setup attributes 55 var g_DefaultPlayerData = [];56 45 var g_GameAttributes = { 57 46 settings: {} 58 47 }; 59 48 60 var g_GameSpeeds = {};61 var g_MapSizes = {};62 63 var g_AIs = [];64 65 49 var g_ChatMessages = []; 66 50 67 51 // Data caches 68 52 var g_MapData = {}; 69 53 var g_CivData = {}; … … 76 60 // To prevent the display locking up while we load the map metadata, 77 61 // we'll start with a 'loading' message and switch to the main screen in the 78 62 // tick handler 79 63 var g_LoadingState = 0; // 0 = not started, 1 = loading, 2 = loaded 80 64 81 // Filled by scripts in victory_conditions/82 var g_VictoryConditions = {};83 84 65 //////////////////////////////////////////////////////////////////////////////////////////////// 85 66 86 67 function init(attribs) 87 68 { 88 69 switch (attribs.type) … … 115 96 } 116 97 117 98 // Called after the map data is loaded and cached 118 99 function initMain() 119 100 { 120 // Load AI list 121 g_AIs = Engine.GetAIs(); 122 123 // Sort AIs by displayed name 124 g_AIs.sort(function (a, b) { 125 return a.data.name < b.data.name ? -1 : b.data.name < a.data.name ? +1 : 0; 126 }); 127 128 // Get default player data - remove gaia 129 g_DefaultPlayerData = initPlayerDefaults(); 130 g_DefaultPlayerData.shift(); 131 for (var i = 0; i < g_DefaultPlayerData.length; ++i) 132 g_DefaultPlayerData[i].Civ = "random"; 101 if (!validSettings(cancelAndReturn)) 102 return; 133 103 134 g_GameSpeeds = initGameSpeeds(); 135 g_MapSizes = initMapSizes(); 104 // Transform setting arrays for usage in dropdown lists 105 g_AIDiffs = prepareForDropdown("AIDifficulties"); 106 g_Ceasefire = prepareForDropdown("Ceasefire"); 107 g_GameSpeeds = prepareForDropdown("GameSpeeds"); 108 g_GameTypes = prepareForDropdown("GameTypes"); 109 g_MapSizes = prepareForDropdown("MapSizes"); 110 g_MapTypes = prepareForDropdown("MapTypes"); 111 g_PopulationCapacity = prepareForDropdown("PopulationCapacity"); 112 g_StartingResources = prepareForDropdown("StartingResources"); 113 114 // Modify player defaults for later usage 115 g_PlayerDefaults = g_Settings.PlayerDefaults.map(player => { player.Civ = "random"; return player; }); 116 g_PlayerDefaults.shift() 136 117 137 118 // Init civs 138 119 initCivNameList(); 139 120 140 121 // Init map types 141 122 var mapTypes = Engine.GetGUIObjectByName("mapTypeSelection"); 142 mapTypes.list = [translateWithContext("map", "Skirmish"), translateWithContext("map", "Random"), translate("Scenario")];143 mapTypes.list_data = ["skirmish","random","scenario"];123 mapTypes.list = g_MapTypes.Title; 124 mapTypes.list_data = g_MapTypes.Name; 144 125 145 126 // Setup map filters - will appear in order they are added 146 127 addFilter("default", translate("Default"), function(settings) { return settings && (settings.Keywords === undefined || !keywordTestOR(settings.Keywords, ["naval", "demo", "hidden"])); }); 147 128 addFilter("naval", translate("Naval Maps"), function(settings) { return settings && settings.Keywords !== undefined && keywordTestAND(settings.Keywords, ["naval"]); }); 148 129 addFilter("demo", translate("Demo Maps"), function(settings) { return settings && settings.Keywords !== undefined && keywordTestAND(settings.Keywords, ["demo"]); }); … … 165 146 g_GameAttributes.matchID = Engine.GetMatchID(); 166 147 167 148 initMapNameList(); 168 149 169 150 var numPlayersSelection = Engine.GetGUIObjectByName("numPlayersSelection"); 170 var players = []; 171 for (var i = 1; i <= MAX_PLAYERS; ++i) 172 players.push(i); 173 numPlayersSelection.list = players; 174 numPlayersSelection.list_data = players; 175 numPlayersSelection.selected = MAX_PLAYERS - 1; 151 let playersArray = Array(g_Settings.MaxPlayers).fill(0).map((value, index) => index + 1); 152 numPlayersSelection.list = playersArray; 153 numPlayersSelection.list_data = playersArray; 154 numPlayersSelection.selected = g_Settings.MaxPlayers - 1; 176 155 177 156 var gameSpeed = Engine.GetGUIObjectByName("gameSpeed"); 178 157 gameSpeed.hidden = false; 179 158 Engine.GetGUIObjectByName("gameSpeedText").hidden = true; 180 gameSpeed.list = g_GameSpeeds. names;181 gameSpeed.list_data = g_GameSpeeds. speeds;159 gameSpeed.list = g_GameSpeeds.Title; 160 gameSpeed.list_data = g_GameSpeeds.Speed; 182 161 gameSpeed.onSelectionChange = function() { 183 162 if (this.selected != -1) 184 g_GameAttributes.gameSpeed = g_GameSpeeds. speeds[this.selected];163 g_GameAttributes.gameSpeed = g_GameSpeeds.Speed[this.selected]; 185 164 186 165 updateGameAttributes(); 187 166 } 188 gameSpeed.selected = g_GameSpeeds ["default"];167 gameSpeed.selected = g_GameSpeeds.default; 189 168 190 169 var populationCaps = Engine.GetGUIObjectByName("populationCap"); 191 populationCaps.list = POPULATION_CAP;192 populationCaps.list_data = POPULATION_CAP_DATA;193 populationCaps.selected = POPULATION_CAP_DEFAULTIDX;170 populationCaps.list = g_PopulationCapacity.Title; 171 populationCaps.list_data = g_PopulationCapacity.Population; 172 populationCaps.selected = g_PopulationCapacity.default; 194 173 populationCaps.onSelectionChange = function() { 195 174 if (this.selected != -1) 196 g_GameAttributes.settings.PopulationCap = POPULATION_CAP_DATA[this.selected];175 g_GameAttributes.settings.PopulationCap = g_PopulationCapacity.Population[this.selected]; 197 176 198 177 updateGameAttributes(); 199 178 } 200 179 201 180 var startingResourcesL = Engine.GetGUIObjectByName("startingResources"); 202 startingResourcesL.list = STARTING_RESOURCES;203 startingResourcesL.list_data = STARTING_RESOURCES_DATA;204 startingResourcesL.selected = STARTING_RESOURCES_DEFAULTIDX;181 startingResourcesL.list = g_StartingResources.Title; 182 startingResourcesL.list_data = g_StartingResources.Resources; 183 startingResourcesL.selected = g_StartingResources.default; 205 184 startingResourcesL.onSelectionChange = function() { 206 185 if (this.selected != -1) 207 g_GameAttributes.settings.StartingResources = STARTING_RESOURCES_DATA[this.selected];186 g_GameAttributes.settings.StartingResources = g_StartingResources.Resources[this.selected]; 208 187 209 188 updateGameAttributes(); 210 189 } 211 190 212 191 var ceasefireL = Engine.GetGUIObjectByName("ceasefire"); 213 ceasefireL.list = CEASEFIRE;214 ceasefireL.list_data = CEASEFIRE_DATA;215 ceasefireL.selected = CEASEFIRE_DEFAULTIDX;192 ceasefireL.list = g_Ceasefire.Title; 193 ceasefireL.list_data = g_Ceasefire.Duration; 194 ceasefireL.selected = g_Ceasefire.default; 216 195 ceasefireL.onSelectionChange = function() { 217 196 if (this.selected != -1) 218 g_GameAttributes.settings.Ceasefire = CEASEFIRE_DATA[this.selected];197 g_GameAttributes.settings.Ceasefire = g_Ceasefire.Duration[this.selected]; 219 198 220 199 updateGameAttributes(); 221 200 } 222 201 223 202 var victoryConditions = Engine.GetGUIObjectByName("victoryCondition"); 224 var victories = getVictoryConditions(); 225 victoryConditions.list = victories.text; 226 victoryConditions.list_data = victories.data; 203 victoryConditions.list = g_GameTypes.Title; 204 victoryConditions.list_data = g_GameTypes.Name; 227 205 victoryConditions.onSelectionChange = function() { 228 206 if (this.selected != -1) 229 207 { 230 g_GameAttributes.settings.GameType = victories.data[this.selected];231 g_GameAttributes.settings.VictoryScripts = victories.scripts[this.selected];208 g_GameAttributes.settings.GameType = g_GameTypes.Name[this.selected]; 209 g_GameAttributes.settings.VictoryScripts = g_GameTypes.Scripts[this.selected]; 232 210 } 233 211 234 212 updateGameAttributes(); 235 213 }; 236 victoryConditions.selected = VICTORY_DEFAULTIDX;214 victoryConditions.selected = g_GameTypes.default; 237 215 238 216 var mapSize = Engine.GetGUIObjectByName("mapSize"); 239 mapSize.list = g_MapSizes. names;240 mapSize.list_data = g_MapSizes. tiles;217 mapSize.list = g_MapSizes.LongName; 218 mapSize.list_data = g_MapSizes.Tiles; 241 219 mapSize.onSelectionChange = function() { 242 220 if (this.selected != -1) 243 g_GameAttributes.settings.Size = g_MapSizes. tiles[this.selected];221 g_GameAttributes.settings.Size = g_MapSizes.Tiles[this.selected]; 244 222 updateGameAttributes(); 245 223 }; 246 224 mapSize.selected = 0; 247 225 248 226 Engine.GetGUIObjectByName("revealMap").onPress = function() { … … 292 270 Engine.GetGUIObjectByName("gameSpeedText").hidden = false; 293 271 Engine.GetGUIObjectByName("gameSpeed").hidden = true; 294 272 295 273 // Disable player and game options controls 296 274 // TODO: Shouldn't players be able to choose their own assignment? 297 for ( var i = 0; i < MAX_PLAYERS; ++i)275 for (let i = 0; i < g_Settings.MaxPlayers; ++i) 298 276 { 299 277 Engine.GetGUIObjectByName("playerAssignment["+i+"]").hidden = true; 300 278 Engine.GetGUIObjectByName("playerCiv["+i+"]").hidden = true; 301 279 Engine.GetGUIObjectByName("playerTeam["+i+"]").hidden = true; 302 280 } … … 339 317 } 340 318 } 341 319 342 320 // Settings for all possible player slots 343 321 var boxSpacing = 32; 344 for ( var i = 0; i < MAX_PLAYERS; ++i)322 for (let i = 0; i < g_Settings.MaxPlayers; ++i) 345 323 { 346 324 // Space player boxes 347 325 var box = Engine.GetGUIObjectByName("playerBox["+i+"]"); 348 326 var boxSize = box.size; 349 327 var h = boxSize.bottom - boxSize.top; 350 328 boxSize.top = i * boxSpacing; 351 329 boxSize.bottom = i * boxSpacing + h; 352 330 box.size = boxSize; 353 331 354 332 // Populate team dropdowns 355 var team = Engine.GetGUIObjectByName("playerTeam["+i+"]"); 356 team.list = [translateWithContext("team", "None"), "1", "2", "3", "4"]; 357 team.list_data = [-1, 0, 1, 2, 3]; 333 let team = Engine.GetGUIObjectByName("playerTeam["+i+"]"); 334 let teamsArray = Array(g_Settings.MaxTeams).fill(0).map((v, i) => i + 1); // 1, 2, ... MaxTeams 335 team.list = [translateWithContext("team", "None")].concat(teamsArray); // "None", 1, 2, ..., maxTeams 336 team.list_data = [-1].concat(teamsArray.map(player => player - 1)); // -1, 0, ..., (maxTeams-1) 358 337 team.selected = 0; 359 338 360 339 let playerSlot = i; // declare for inner function use 361 340 team.onSelectionChange = function() { 362 341 if (this.selected != -1) … … 398 377 } 399 378 } 400 379 401 380 function handleNetMessage(message) 402 381 { 382 if (!g_Settings) 383 return; 384 403 385 log("Net message: "+uneval(message)); 404 386 405 387 switch (message.type) 406 388 { 407 389 case "netstatus": … … 571 553 // Add random civ to beginning of list 572 554 civListNames.unshift('[color="orange"]' + translateWithContext("civilization", "Random") + '[/color]'); 573 555 civListCodes.unshift("random"); 574 556 575 557 // Update the dropdowns 576 for ( var i = 0; i < MAX_PLAYERS; ++i)558 for (let i = 0; i < g_Settings.MaxPlayers; ++i) 577 559 { 578 560 var civ = Engine.GetGUIObjectByName("playerCiv["+i+"]"); 579 561 civ.list = civListNames; 580 562 civ.list_data = civListCodes; 581 563 civ.selected = 0; … … 703 685 704 686 // Ensure that cheats are enabled in singleplayer 705 687 if (!g_IsNetworked) 706 688 mapSettings.CheatsEnabled = true; 707 689 708 var aiCodes = [ ai.id for each (ai in g_AIs) ];709 690 var civListCodes = [ civ.Code for each (civ in g_CivData) if (civ.SelectableInGameSetup !== false) ]; 710 691 civListCodes.push("random"); 711 692 712 693 var playerData = mapSettings.PlayerData; 713 694 … … 762 743 } 763 744 764 745 if (attrs.gameSpeed) 765 746 { 766 747 var gameSpeedBox = Engine.GetGUIObjectByName("gameSpeed"); 767 gameSpeedBox.selected = g_GameSpeeds. speeds.indexOf(attrs.gameSpeed);748 gameSpeedBox.selected = g_GameSpeeds.Speed.indexOf(attrs.gameSpeed); 768 749 } 769 750 770 751 if (!Engine.HasXmppClient()) 771 752 { 772 753 g_GameAttributes.settings.RatingEnabled = false; … … 787 768 Engine.WriteJSONFile(g_IsNetworked ? FILEPATH_MATCHSETTINGS_MP : FILEPATH_MATCHSETTINGS_SP, attributes); 788 769 } 789 770 //////////////////////////////////////////////////////////////////////////////////////////////// 790 771 // GUI event handlers 791 772 773 function cancelAndReturn() 774 { 775 cancelSetup(); 776 Engine.SwitchGuiPage(Engine.HasXmppClient() ? "page_lobby.xml" : "page_pregame.xml"); 777 } 778 792 779 function cancelSetup() 793 780 { 794 781 if (g_IsController) 795 782 saveGameAttributes(); 796 783 … … 858 845 } 859 846 else 860 847 { 861 848 // Add player data from defaults 862 849 for (var i = pData.length; i < num; ++i) 863 g_GameAttributes.settings.PlayerData.push(g_ DefaultPlayerData[i]);850 g_GameAttributes.settings.PlayerData.push(g_PlayerDefaults[i]); 864 851 } 865 852 866 853 // Some players may have lost their assigned slot 867 854 for (var guid in g_PlayerAssignments) 868 855 { … … 908 895 break; 909 896 910 897 case "skirmish": 911 898 g_GameAttributes.mapPath = "maps/skirmishes/"; 912 899 g_GameAttributes.settings = { 913 PlayerData: g_ DefaultPlayerData.slice(0, 4),900 PlayerData: g_PlayerDefaults.slice(0, 4), 914 901 Seed: Math.floor(Math.random() * 65536), 915 902 AISeed: Math.floor(Math.random() * 65536), 916 903 CheatsEnabled: g_GameAttributes.settings.CheatsEnabled 917 904 }; 918 905 break; 919 906 920 907 case "random": 921 908 g_GameAttributes.mapPath = "maps/random/"; 922 909 g_GameAttributes.settings = { 923 PlayerData: g_ DefaultPlayerData.slice(0, 4),910 PlayerData: g_PlayerDefaults.slice(0, 4), 924 911 Seed: Math.floor(Math.random() * 65536), 925 912 AISeed: Math.floor(Math.random() * 65536), 926 913 CheatsEnabled: g_GameAttributes.settings.CheatsEnabled 927 914 }; 928 915 break; … … 975 962 g_GameAttributes.settings[prop] = undefined; 976 963 977 964 var mapData = loadMapData(name); 978 965 var mapSettings = (mapData && mapData.settings ? deepcopy(mapData.settings) : {}); 979 966 967 // Reset victory conditions 968 if (g_GameAttributes.mapType != "random") 969 { 970 let victoryIdx = mapSettings.GameType && g_GameTypes.Name.indexOf(mapSettings.GameType) != -1 ? g_GameTypes.Name.indexOf(mapSettings.GameType) : g_GameTypes.default; 971 g_GameAttributes.settings.GameType = g_GameTypes.Name[victoryIdx]; 972 g_GameAttributes.settings.VictoryScripts = g_GameTypes.Scripts[victoryIdx]; 973 } 974 980 975 // Copy any new settings 981 976 g_GameAttributes.map = name; 982 977 g_GameAttributes.script = mapSettings.Script; 983 978 if (g_GameAttributes.map !== "random") 984 979 for (var prop in mapSettings) … … 990 985 991 986 // Use default AI if the map doesn't specify any explicitly 992 987 for (var i = 0; i < g_GameAttributes.settings.PlayerData.length; ++i) 993 988 { 994 989 if (!('AI' in g_GameAttributes.settings.PlayerData[i])) 995 g_GameAttributes.settings.PlayerData[i].AI = g_ DefaultPlayerData[i].AI;990 g_GameAttributes.settings.PlayerData[i].AI = g_PlayerDefaults[i].AI; 996 991 if (!('AIDiff' in g_GameAttributes.settings.PlayerData[i])) 997 g_GameAttributes.settings.PlayerData[i].AIDiff = g_ DefaultPlayerData[i].AIDiff;992 g_GameAttributes.settings.PlayerData[i].AIDiff = g_PlayerDefaults[i].AIDiff; 998 993 } 999 994 1000 995 // Reset player assignments on map change 1001 996 if (!g_IsNetworked) 1002 997 { // Slot 1 … … 1008 1003 1009 1004 for (var guid in g_PlayerAssignments) 1010 1005 { // Unassign extra players 1011 1006 var player = g_PlayerAssignments[guid].player; 1012 1007 1013 if (player <= MAX_PLAYERS&& player > numPlayers)1008 if (player <= g_Settings.MaxPlayers && player > numPlayers) 1014 1009 Engine.AssignNetworkPlayer(player, ""); 1015 1010 } 1016 1011 } 1017 1012 1018 1013 updateGameAttributes(); … … 1133 1128 1134 1129 //////////////////////////////////////////////////////////////////////////////////////////////// 1135 1130 1136 1131 function onGameAttributesChange() 1137 1132 { 1133 if (!g_Settings) 1134 return; 1135 1138 1136 g_IsInGuiUpdate = true; 1139 1137 1140 1138 // Don't set any attributes here, just show the changes in GUI 1141 1139 1142 1140 var mapName = g_GameAttributes.map || ""; 1143 1141 var mapSettings = g_GameAttributes.settings; 1144 var numPlayers = (mapSettings.PlayerData ? mapSettings.PlayerData.length : MAX_PLAYERS);1142 var numPlayers = mapSettings.PlayerData ? mapSettings.PlayerData.length : g_Settings.MaxPlayers; 1145 1143 1146 1144 // Update some controls for clients 1147 1145 if (!g_IsController) 1148 1146 { 1149 1147 var mapFilterSelection = Engine.GetGUIObjectByName("mapFilterSelection"); … … 1157 1155 Engine.GetGUIObjectByName("mapSelectionText").caption = translate(getMapDisplayName(mapName)); 1158 1156 if (mapSettings.PopulationCap) 1159 1157 { 1160 1158 var populationCapBox = Engine.GetGUIObjectByName("populationCap"); 1161 1159 populationCapBox.selected = populationCapBox.list_data.indexOf(mapSettings.PopulationCap); 1162 } 1160 } 1163 1161 if (mapSettings.StartingResources) 1164 1162 { 1165 1163 var startingResourcesBox = Engine.GetGUIObjectByName("startingResources"); 1166 1164 startingResourcesBox.selected = startingResourcesBox.list_data.indexOf(mapSettings.StartingResources); 1167 1165 } … … 1204 1202 var ceasefireText = Engine.GetGUIObjectByName("ceasefireText"); 1205 1203 var gameSpeedText = Engine.GetGUIObjectByName("gameSpeedText"); 1206 1204 var gameSpeedBox = Engine.GetGUIObjectByName("gameSpeed"); 1207 1205 1208 1206 // We have to check for undefined on these properties as not all maps define them. 1209 var sizeIdx = (mapSettings.Size !== undefined && g_MapSizes.tiles.indexOf(mapSettings.Size) != -1 ? g_MapSizes.tiles.indexOf(mapSettings.Size) : g_MapSizes["default"]); 1210 var speedIdx = (g_GameAttributes.gameSpeed !== undefined && g_GameSpeeds.speeds.indexOf(g_GameAttributes.gameSpeed) != -1) ? g_GameSpeeds.speeds.indexOf(g_GameAttributes.gameSpeed) : g_GameSpeeds["default"]; 1211 var victories = getVictoryConditions(); 1212 var victoryIdx = (mapSettings.GameType !== undefined && victories.data.indexOf(mapSettings.GameType) != -1 ? victories.data.indexOf(mapSettings.GameType) : VICTORY_DEFAULTIDX); 1213 enableCheats.checked = (mapSettings.CheatsEnabled === undefined || !mapSettings.CheatsEnabled ? false : true) 1207 var sizeIdx = mapSettings.Size && g_MapSizes.Tiles.indexOf(mapSettings.Size) != -1 ? g_MapSizes.Tiles.indexOf(mapSettings.Size) : g_MapSizes.default; 1208 var speedIdx = g_GameAttributes.gameSpeed && g_GameSpeeds.Speed.indexOf(g_GameAttributes.gameSpeed) != -1 ? g_GameSpeeds.Speed.indexOf(g_GameAttributes.gameSpeed) : g_GameSpeeds.default; 1209 var victoryIdx = mapSettings.GameType && g_GameTypes.Name.indexOf(mapSettings.GameType) != -1 ? g_GameTypes.Name.indexOf(mapSettings.GameType) : g_GameTypes.default; 1210 enableCheats.checked = mapSettings.CheatsEnabled ? true : false; 1214 1211 enableCheatsText.caption = (enableCheats.checked ? translate("Yes") : translate("No")); 1215 1212 if (mapSettings.RatingEnabled !== undefined) 1216 1213 { 1217 1214 enableRating.checked = mapSettings.RatingEnabled; 1218 1215 Engine.SetRankedGame(enableRating.checked); … … 1220 1217 enableCheats.enabled = !enableRating.checked; 1221 1218 lockTeams.enabled = !enableRating.checked; 1222 1219 } 1223 1220 else 1224 1221 enableRatingText.caption = "Unknown"; 1225 gameSpeedText.caption = g_GameSpeeds. names[speedIdx];1222 gameSpeedText.caption = g_GameSpeeds.Title[speedIdx]; 1226 1223 gameSpeedBox.selected = speedIdx; 1227 populationCap.selected = (mapSettings.PopulationCap !== undefined && POPULATION_CAP_DATA.indexOf(mapSettings.PopulationCap) != -1 ? POPULATION_CAP_DATA.indexOf(mapSettings.PopulationCap) : POPULATION_CAP_DEFAULTIDX);1228 populationCapText.caption = POPULATION_CAP[populationCap.selected];1229 startingResources.selected = (mapSettings.StartingResources !== undefined && STARTING_RESOURCES_DATA.indexOf(mapSettings.StartingResources) != -1 ? STARTING_RESOURCES_DATA.indexOf(mapSettings.StartingResources) : STARTING_RESOURCES_DEFAULTIDX);1230 startingResourcesText.caption = STARTING_RESOURCES[startingResources.selected];1231 ceasefire.selected = (mapSettings.Ceasefire !== undefined && CEASEFIRE_DATA.indexOf(mapSettings.Ceasefire) != -1 ? CEASEFIRE_DATA.indexOf(mapSettings.Ceasefire) : CEASEFIRE_DEFAULTIDX);1232 ceasefireText.caption = CEASEFIRE[ceasefire.selected];1224 populationCap.selected = mapSettings.PopulationCap && g_PopulationCapacity.Population.indexOf(mapSettings.PopulationCap) != -1 ? g_PopulationCapacity.Population.indexOf(mapSettings.PopulationCap) : g_PopulationCapacity.default; 1225 populationCapText.caption = g_PopulationCapacity.Title[populationCap.selected]; 1226 startingResources.selected = mapSettings.StartingResources && g_StartingResources.Resources.indexOf(mapSettings.StartingResources) != -1 ? g_StartingResources.Resources.indexOf(mapSettings.StartingResources) : g_StartingResources.default; 1227 startingResourcesText.caption = g_StartingResources.Title[startingResources.selected]; 1228 ceasefire.selected = mapSettings.Ceasefire !== undefined && g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) != -1 ? g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) : g_Ceasefire.default; 1229 ceasefireText.caption = g_Ceasefire.Title[ceasefire.selected]; 1233 1230 1234 1231 // Update map preview 1235 1232 Engine.GetGUIObjectByName("mapPreview").sprite = "cropped:(0.78125,0.5859375)session/icons/mappreview/" + getMapPreview(mapName); 1236 1233 1237 1234 // Hide/show settings depending on whether we can change them or not … … 1270 1267 } 1271 1268 else 1272 1269 { 1273 1270 // Client 1274 1271 numPlayersText.caption = numPlayers; 1275 mapSizeText.caption = g_MapSizes. names[sizeIdx];1272 mapSizeText.caption = g_MapSizes.LongName[sizeIdx]; 1276 1273 revealMapText.caption = (mapSettings.RevealMap ? translate("Yes") : translate("No")); 1277 1274 exploreMapText.caption = (mapSettings.ExporeMap ? translate("Yes") : translate("No")); 1278 1275 disableTreasuresText.caption = (mapSettings.DisableTreasures ? translate("Yes") : translate("No")); 1279 victoryConditionText.caption = victories.text[victoryIdx];1276 victoryConditionText.caption = g_GameTypes.Title[victoryIdx]; 1280 1277 lockTeamsText.caption = (mapSettings.LockTeams ? translate("Yes") : translate("No")); 1281 1278 } 1282 1279 1283 1280 break; 1284 1281 … … 1313 1310 { 1314 1311 // Client 1315 1312 revealMapText.caption = (mapSettings.RevealMap ? translate("Yes") : translate("No")); 1316 1313 exploreMapText.caption = (mapSettings.ExploreMap ? translate("Yes") : translate("No")); 1317 1314 disableTreasuresText.caption = (mapSettings.DisableTreasures ? translate("Yes") : translate("No")); 1318 victoryConditionText.caption = victories.text[victoryIdx];1315 victoryConditionText.caption = g_GameTypes.Title[victoryIdx]; 1319 1316 lockTeamsText.caption = (mapSettings.LockTeams ? translate("Yes") : translate("No")); 1320 1317 } 1321 1318 1322 1319 break; 1323 1320 … … 1343 1340 startingResourcesText.hidden = false; 1344 1341 populationCap.hidden = true; 1345 1342 populationCapText.hidden = false; 1346 1343 ceasefire.hidden = true; 1347 1344 ceasefireText.hidden = false; 1348 1345 1349 1346 numPlayersText.caption = numPlayers; 1350 1347 mapSizeText.caption = translate("Default"); 1351 1348 revealMapText.caption = (mapSettings.RevealMap ? translate("Yes") : translate("No")); 1352 1349 exploreMapText.caption = (mapSettings.ExploreMap ? translate("Yes") : translate("No")); 1353 1350 disableTreasuresText.caption = translate("No"); 1354 victoryConditionText.caption = victories.text[victoryIdx];1351 victoryConditionText.caption = g_GameTypes.Title[victoryIdx]; 1355 1352 lockTeamsText.caption = (mapSettings.LockTeams ? translate("Yes") : translate("No")); 1356 1353 1357 1354 startingResourcesText.caption = translate("Determined by scenario"); 1358 1355 populationCapText.caption = translate("Determined by scenario"); 1359 1356 ceasefireText.caption = translate("Determined by scenario"); … … 1377 1374 // Load the description from the map file, if there is one 1378 1375 var description = mapSettings.Description ? translate(mapSettings.Description) : translate("Sorry, no description available."); 1379 1376 1380 1377 // Describe the number of players and the victory conditions 1381 1378 var playerString = sprintf(translatePlural("%(number)s player. ", "%(number)s players. ", numPlayers), { number: numPlayers }); 1382 let victory = translate( victories.text[victoryIdx]);1383 if (victoryIdx != VICTORY_DEFAULTIDX)1379 let victory = translate(g_GameTypes.Title[victoryIdx]); 1380 if (victoryIdx != g_GameTypes.default) 1384 1381 victory = "[color=\"orange\"]" + victory + "[/color]"; 1385 1382 playerString += translate("Victory Condition:") + " " + victory + ".\n\n" + description; 1386 1383 1387 for ( var i = 0; i < MAX_PLAYERS; ++i)1384 for (let i = 0; i < g_Settings.MaxPlayers; ++i) 1388 1385 { 1389 1386 // Show only needed player slots 1390 1387 Engine.GetGUIObjectByName("playerBox["+i+"]").hidden = (i >= numPlayers); 1391 1388 1392 1389 // Show player data or defaults as necessary … … 1402 1399 var pTeamText = Engine.GetGUIObjectByName("playerTeamText["+i+"]"); 1403 1400 var pColor = Engine.GetGUIObjectByName("playerColor["+i+"]"); 1404 1401 1405 1402 // Player data / defaults 1406 1403 var pData = mapSettings.PlayerData ? mapSettings.PlayerData[i] : {}; 1407 var pDefs = g_ DefaultPlayerData ? g_DefaultPlayerData[i] : {};1404 var pDefs = g_PlayerDefaults[i];; 1408 1405 1409 1406 // Common to all game types 1410 1407 var color = rgbToGuiColor(getSetting(pData, pDefs, "Color")); 1411 1408 pColor.sprite = "color:" + color + " 100"; 1412 1409 pName.caption = translate(getSetting(pData, pDefs, "Name")); … … 1513 1510 1514 1511 // Only enable start button if we have enough assigned players 1515 1512 if (g_IsController) 1516 1513 Engine.GetGUIObjectByName("startGame").enabled = (g_AssignedCount > 0); 1517 1514 1518 for each (var ai in g_AIs) 1515 var ais = initAIDescription(); 1516 for (let ai of ais) 1519 1517 { 1520 1518 if (ai.data.hidden) 1521 1519 { 1522 1520 // If the map uses a hidden AI then don't hide it 1523 1521 var usedByMap = false; 1524 for ( var i = 0; i < MAX_PLAYERS; ++i)1522 for (let i = 0; i < g_Settings.MaxPlayers; ++i) 1525 1523 if (i < g_GameAttributes.settings.PlayerData.length && 1526 1524 g_GameAttributes.settings.PlayerData[i].AI == ai.id) 1527 1525 { 1528 1526 usedByMap = true; 1529 1527 break; … … 1540 1538 1541 1539 noAssignment = hostNameList.length; 1542 1540 hostNameList.push("[color=\"140 140 140 255\"]" + translate("Unassigned")); 1543 1541 hostGuidList.push(""); 1544 1542 1545 for ( var i = 0; i < MAX_PLAYERS; ++i)1543 for (let i = 0; i < g_Settings.MaxPlayers; ++i) 1546 1544 { 1547 1545 let playerSlot = i; 1548 1546 let playerID = i+1; // we don't show Gaia, so first slot is ID 1 1549 1547 1550 1548 var selection = assignments[playerID]; … … 1579 1577 if (g_IsController) 1580 1578 { 1581 1579 configButton.hidden = false; 1582 1580 configButton.onpress = function() { 1583 1581 Engine.PushGuiPage("page_aiconfig.xml", { 1584 ais: g_AIs, 1585 id: g_GameAttributes.settings.PlayerData[playerSlot].AI, 1586 difficulty: g_GameAttributes.settings.PlayerData[playerSlot].AIDiff, 1587 callback: "AIConfigCallback", 1588 playerSlot: playerSlot // required by the callback function 1582 "ais": ais, 1583 "id": g_GameAttributes.settings.PlayerData[playerSlot].AI, 1584 "difficulty": g_GameAttributes.settings.PlayerData[playerSlot].AIDiff, 1585 "difficulties" : g_AIDiffs, 1586 "callback": "AIConfigCallback", 1587 "playerSlot": playerSlot // required by the callback function 1589 1588 }); 1590 1589 }; 1591 1590 } 1592 1591 } 1593 1592 // There was a human, so make sure we don't have any AI left … … 1711 1710 var player = g_PlayerAssignments[msg.guid].player - 1; 1712 1711 var mapName = g_GameAttributes.map; 1713 1712 var mapData = loadMapData(mapName); 1714 1713 var mapSettings = (mapData && mapData.settings ? mapData.settings : {}); 1715 1714 var pData = mapSettings.PlayerData ? mapSettings.PlayerData[player] : {}; 1716 var pDefs = g_ DefaultPlayerData ? g_DefaultPlayerData[player] : {};1715 var pDefs = g_PlayerDefaults[player]; 1717 1716 1718 1717 color = rgbToGuiColor(getSetting(pData, pDefs, "Color")); 1719 1718 } 1720 1719 1721 1720 var formatted; … … 1784 1783 1785 1784 function updateReadyUI() 1786 1785 { 1787 1786 if (!g_IsNetworked) 1788 1787 return; // Disabled for single-player games. 1789 var isAI = new Array( MAX_PLAYERS+ 1);1788 var isAI = new Array(g_Settings.MaxPlayers + 1); 1790 1789 for (var i = 0; i < isAI.length; ++i) 1791 1790 isAI[i] = true; 1792 1791 var allReady = true; 1793 1792 for (var guid in g_PlayerAssignments) 1794 1793 { 1795 1794 // We don't really care whether observers are ready. 1796 1795 if (g_PlayerAssignments[guid].player == -1 || !g_GameAttributes.settings.PlayerData[g_PlayerAssignments[guid].player - 1]) 1797 1796 continue; 1798 1797 var pData = g_GameAttributes.settings.PlayerData ? g_GameAttributes.settings.PlayerData[g_PlayerAssignments[guid].player - 1] : {}; 1799 var pDefs = g_ DefaultPlayerData ? g_DefaultPlayerData[g_PlayerAssignments[guid].player - 1] : {};1798 var pDefs = g_PlayerDefaults[g_PlayerAssignments[guid].player - 1]; 1800 1799 isAI[g_PlayerAssignments[guid].player] = false; 1801 1800 if (g_PlayerAssignments[guid].status || !g_IsNetworked) 1802 1801 Engine.GetGUIObjectByName("playerName[" + (g_PlayerAssignments[guid].player - 1) + "]").caption = '[color="0 255 0"]' + translate(getSetting(pData, pDefs, "Name")) + '[/color]'; 1803 1802 else 1804 1803 { 1805 1804 Engine.GetGUIObjectByName("playerName[" + (g_PlayerAssignments[guid].player - 1) + "]").caption = translate(getSetting(pData, pDefs, "Name")); 1806 1805 allReady = false; 1807 1806 } 1808 1807 } 1809 1808 // AIs are always ready. 1810 for ( var playerid = 0; playerid < MAX_PLAYERS; ++playerid)1811 { 1809 for (let playerid = 0; playerid < g_Settings.MaxPlayers; ++playerid) 1810 { 1812 1811 if (!g_GameAttributes.settings.PlayerData[playerid]) 1813 1812 continue; 1814 1813 var pData = g_GameAttributes.settings.PlayerData ? g_GameAttributes.settings.PlayerData[playerid] : {}; 1815 var pDefs = g_ DefaultPlayerData ? g_DefaultPlayerData[playerid] : {};1814 var pDefs = g_PlayerDefaults[playerid]; 1816 1815 if (isAI[playerid + 1]) 1817 1816 Engine.GetGUIObjectByName("playerName[" + playerid + "]").caption = '[color="0 255 0"]' + translate(getSetting(pData, pDefs, "Name")) + '[/color]'; 1818 1817 } 1819 1818 1820 1819 // The host is not allowed to start until everyone is ready. … … 1968 1967 "tnbp":tnbp, 1969 1968 "players":players 1970 1969 }; 1971 1970 Engine.SendRegisterGame(gameData); 1972 1971 } 1973 1974 function getVictoryConditions()1975 {1976 var r = {};1977 r.text = [translate("None")];1978 r.data = ["endless"];1979 r.scripts = [[]];1980 for (var vc in g_VictoryConditions)1981 {1982 r.data.push(vc);1983 r.text.push(g_VictoryConditions[vc].name);1984 r.scripts.push(g_VictoryConditions[vc].scripts);1985 }1986 return r;1987 } -
binaries/data/mods/public/gui/gamesetup/gamesetup.xml
1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 3 3 <objects> 4 4 5 <script file="gui/common/network.js"/>6 5 <script file="gui/common/functions_civinfo.js"/> 7 6 <script file="gui/common/functions_global_object.js"/> 8 7 <script file="gui/common/functions_utility.js"/> 8 <script file="gui/common/network.js"/> 9 <script file="gui/common/settings.js"/> 9 10 <script file="gui/gamesetup/gamesetup.js"/> 10 <!-- After gamesetup.js which defines g_VictoryConditions -->11 <script directory="gui/gamesetup/victory_conditions/"/>12 11 13 12 <!-- Add a translucent black background to fade out the menu page --> 14 13 <object type="image" style="ModernWindow" size="0 0 100% 100%"> 15 14 16 15 <object style="TitleText" type="text" size="50%-128 4 50%+128 36"> … … 237 236 style="StoneButton" 238 237 size="100%-308 100%-52 100%-168 100%-24" 239 238 tooltip_style="onscreenToolTip" 240 239 > 241 240 <translatableAttribute id="caption">Back</translatableAttribute> 242 <action on="Press"> 243 <![CDATA[ 244 cancelSetup(); 245 if(!Engine.HasXmppClient()) 246 Engine.SwitchGuiPage("page_pregame.xml"); 247 else 248 Engine.SwitchGuiPage("page_lobby.xml"); 249 ]]> 250 </action> 241 <action on="Press">cancelAndReturn();</action> 251 242 </object> 252 243 253 244 <!-- Options --> 254 245 <object name="gameOptionsBox" size="100%-425 529 100%-25 525"> 255 246 <!-- More Options Button --> -
binaries/data/mods/public/gui/gamesetup/victory_conditions/conquest.js
1 g_VictoryConditions.conquest = {2 "name" : translate("Conquest"),3 "description" : translate("Defeat all opponents"),4 "scripts" : ["scripts/ConquestCommon.js", "scripts/TriggerHelper.js", "scripts/Conquest.js"]5 }; -
binaries/data/mods/public/gui/gamesetup/victory_conditions/conquestStructures.js
1 g_VictoryConditions.conquestStructure = {2 "name" : translate("Conquest Structures"),3 "description" : translate("Destroy all structures of enemies"),4 "scripts" : ["scripts/ConquestCommon.js", "scripts/TriggerHelper.js", "scripts/ConquestStructures.js"]5 }; -
binaries/data/mods/public/gui/gamesetup/victory_conditions/conquestUnits.js
1 g_VictoryConditions.conquestUnits = {2 "name" : translate("Conquest Units"),3 "description" : translate("Destroy all units of enemies"),4 "scripts" : ["scripts/ConquestCommon.js", "scripts/TriggerHelper.js", "scripts/ConquestUnits.js"]5 }; -
binaries/data/mods/public/gui/gamesetup/victory_conditions/wonder.js
1 g_VictoryConditions.wonder = {2 "name" : translate("Wonder"),3 "description" : translate("Build a wonder to win"),4 "scripts" : ["scripts/ConquestCommon.js", "scripts/TriggerHelper.js", "scripts/Conquest.js", "scripts/WonderVictory.js"]5 }; -
binaries/data/mods/public/gui/lobby/lobby.js
1 const g_specialKey = Math.random(); 2 const g_timestamp = Engine.ConfigDB_GetValue("user", "lobby.chattimestamp") == "true"; 3 const g_modPrefix = "@"; 4 const SPAM_BLOCK_LENGTH = 30; 5 1 6 var g_ChatMessages = []; 2 7 var g_Name = "unknown"; 3 8 var g_GameList = {} 4 9 var g_GameListSortBy = "name"; 5 10 var g_PlayerListSortBy = "name"; 6 11 var g_GameListOrder = 1; // 1 for ascending sort, and -1 for descending 7 12 var g_PlayerListOrder = 1; 8 var g_specialKey = Math.random();9 13 // This object looks like {"name":[numMessagesSinceReset, lastReset, timeBlocked]} when in use. 10 14 var g_spamMonitor = {}; 11 var g_timestamp = Engine.ConfigDB_GetValue("user", "lobby.chattimestamp") == "true";12 var g_mapSizes = {};13 const g_mapTypesText = [translateWithContext("map", "Skirmish"), translateWithContext("map", "Random"), translate("Scenario")];14 const g_mapTypes = ["skirmish", "random", "scenario"];15 15 var g_userRating = ""; // Rating of user, defaults to Unrated 16 var g_modPrefix = "@";17 16 var g_joined = false; 18 // Block spammers for 30 seconds.19 var SPAM_BLOCK_LENGTH = 30;20 17 21 18 //////////////////////////////////////////////////////////////////////////////////////////////// 22 19 23 20 function init(attribs) 24 21 { 22 if (!validSettings(returnToMainMenu)) 23 return; 24 25 25 // Play menu music 26 26 initMusic(); 27 27 global.music.setState(global.music.states.MENU); 28 28 29 g_Name = Engine.LobbyGetNick(); 30 31 g_mapSizes = initMapSizes(); 32 g_mapSizes.shortNames.splice(0, 0, translateWithContext("map size", "Any")); 33 g_mapSizes.tiles.splice(0, 0, ""); 34 29 // Setup mapsize filter 35 30 var mapSizeFilter = Engine.GetGUIObjectByName("mapSizeFilter"); 36 mapSizeFilter.list = g_mapSizes.shortNames; 37 mapSizeFilter.list_data = g_mapSizes.tiles; 31 var mapSizes = prepareForDropdown("MapSizes"); 32 mapSizeFilter.list = [translateWithContext("map size", "Any")].concat(mapSizes.Name); 33 mapSizeFilter.list_data = [""].concat(mapSizes.Tiles); 38 34 35 // Setup playercount filter 36 var playersArray = Array(g_Settings.MaxPlayers - 1).fill(0).map((value, index) => index + 2); // 2, 3, ... MaxPlayers 39 37 var playersNumberFilter = Engine.GetGUIObjectByName("playersNumberFilter"); 40 playersNumberFilter.list = [translateWithContext("player number", "Any") ,2,3,4,5,6,7,8];41 playersNumberFilter.list_data = ["" ,2,3,4,5,6,7,8];38 playersNumberFilter.list = [translateWithContext("player number", "Any")].concat(playersArray); 39 playersNumberFilter.list_data = [""].concat(playersArray); 42 40 41 // Setup maptype filter 43 42 var mapTypeFilter = Engine.GetGUIObjectByName("mapTypeFilter"); 44 mapTypeFilter.list = [translateWithContext("map", "Any")].concat(g_mapTypesText); 45 mapTypeFilter.list_data = [""].concat(g_mapTypes); 43 var mapTypes = prepareForDropdown("MapTypes"); 44 mapTypeFilter.list = [translateWithContext("map type", "Any")].concat(mapTypes.Title); 45 mapTypeFilter.list_data = [""].concat(mapTypes.Name); 46 46 47 // Init GUI elements 48 g_Name = Engine.LobbyGetNick(); 47 49 Engine.LobbySetPlayerPresence("available"); 48 50 Engine.SendGetGameList(); 49 51 Engine.SendGetBoardList(); 50 52 Engine.SendGetRatingList(); 51 53 updatePlayerList(); … … 468 470 else 469 471 name = '[color="255 0 0"]' + name + '[/color]'; 470 472 list_name.push(name); 471 473 list_ip.push(g.ip); 472 474 list_mapName.push(translate(g.niceMapName)); 473 list_mapSize.push(translatedMapSize(g.mapSize)); 474 let idx = g_mapTypes.indexOf(g.mapType); 475 list_mapType.push(idx != -1 ? g_mapTypesText[idx] : ""); 475 list_mapSize.push(translateMapSize(g.mapSize)); 476 list_mapType.push(translateMapType(g.mapType)); 476 477 list_nPlayers.push(g.nbp + "/" +g.tnbp); 477 478 list.push(name); 478 479 list_data.push(c); 479 480 } 480 481 c++; … … 546 547 // Push this player's name and status onto the list 547 548 return [formattedName, formattedStatus, formattedRating]; 548 549 } 549 550 550 551 /** 551 * Given a map size, returns that map size translated into the current552 * language.553 */554 function translatedMapSize(mapSize)555 {556 if (+mapSize !== +mapSize) // NaN557 return translate(mapSize);558 else559 return g_mapSizes.shortNames[g_mapSizes.tiles.indexOf(+mapSize)];560 }561 562 /**563 552 * Populate the game info area with information on the current game selection. 564 553 */ 565 554 function updateGameSelection() 566 555 { 567 556 var selected = Engine.GetGUIObjectByName("gamesBox").selected; … … 572 561 Engine.GetGUIObjectByName("joinGameButton").hidden = true; 573 562 Engine.GetGUIObjectByName("gameInfoEmpty").hidden = false; 574 563 return; 575 564 } 576 565 577 var mapData;578 566 var g = Engine.GetGUIObjectByName("gamesBox").list_data[selected]; 579 567 580 // Load map data581 if (g_GameList[g].mapType == "random" && g_GameList[g].mapName == "random")582 mapData = {"settings": {"Description": translate("A randomly selected map.")}};583 else if (g_GameList[g].mapType == "random" && Engine.FileExists(g_GameList[g].mapName + ".json"))584 mapData = Engine.ReadJSONFile(g_GameList[g].mapName + ".json");585 else if (Engine.FileExists(g_GameList[g].mapName + ".xml"))586 mapData = Engine.LoadMapSettings(g_GameList[g].mapName + ".xml");587 else588 // Warn the player if we can't find the map.589 warn(sprintf("Map '%(mapName)s' not found locally.", { mapName: g_GameList[g].mapName }));590 591 568 // Show the game info panel and join button. 592 569 Engine.GetGUIObjectByName("gameInfo").hidden = false; 593 570 Engine.GetGUIObjectByName("joinGameButton").hidden = false; 594 571 Engine.GetGUIObjectByName("gameInfoEmpty").hidden = true; 595 572 596 573 // Display the map name, number of players, the names of the players, the map size and the map type. 597 574 Engine.GetGUIObjectByName("sgMapName").caption = translate(g_GameList[g].niceMapName); 598 575 Engine.GetGUIObjectByName("sgNbPlayers").caption = g_GameList[g].nbp + "/" + g_GameList[g].tnbp; 599 576 Engine.GetGUIObjectByName("sgPlayersNames").caption = g_GameList[g].players; 600 Engine.GetGUIObjectByName("sgMapSize").caption = translatedMapSize(g_GameList[g].mapSize); 601 let idx = g_mapTypes.indexOf(g_GameList[g].mapType); 602 Engine.GetGUIObjectByName("sgMapType").caption = idx != -1 ? g_mapTypesText[idx] : ""; 603 604 // Display map description if it exists, otherwise display a placeholder. 605 if (mapData && mapData.settings.Description) 606 var mapDescription = translate(mapData.settings.Description); 607 else 608 var mapDescription = translate("Sorry, no description available."); 577 Engine.GetGUIObjectByName("sgMapSize").caption = translateMapSize(g_GameList[g].mapSize); 578 Engine.GetGUIObjectByName("sgMapType").caption = translateMapType(g_GameList[g].mapType); 609 579 610 // Display map preview if it exists, otherwise display a placeholder. 611 if (mapData && mapData.settings.Preview) 612 var mapPreview = mapData.settings.Preview; 613 else 614 var mapPreview = "nopreview.png"; 615 616 Engine.GetGUIObjectByName("sgMapDescription").caption = mapDescription; 617 Engine.GetGUIObjectByName("sgMapPreview").sprite = "cropped:(0.7812,0.5859)session/icons/mappreview/" + mapPreview; 580 // Display map description and preview (or placeholder) 581 let mapData = getMapDescriptionAndPreview(g_GameList[g].mapType, g_GameList[g].mapName); 582 Engine.GetGUIObjectByName("sgMapDescription").caption = mapData.description; 583 Engine.GetGUIObjectByName("sgMapPreview").sprite = "cropped:(0.7812,0.5859)session/icons/mappreview/" + mapData.preview; 618 584 } 619 585 620 586 /** 621 587 * Start the joining process on the currectly selected game. 622 588 */ … … 859 825 break; 860 826 case "ban": // TODO: Split reason from nick and pass it too, for now just support "/ban nick" 861 827 Engine.LobbyBan(nick, ""); 862 828 break; 863 829 case "quit": 864 lobbyStop(); 865 Engine.SwitchGuiPage("page_pregame.xml"); 830 returnToMainMenu(); 866 831 break; 867 832 case "say": 868 833 case "me": 869 834 return false; 870 835 default: … … 1088 1053 } 1089 1054 } 1090 1055 1091 1056 } 1092 1057 1058 function returnToMainMenu() 1059 { 1060 lobbyStop(); 1061 Engine.SwitchGuiPage("page_pregame.xml"); 1062 } 1063 1093 1064 /* Utilities */ 1094 1065 // Generate a (mostly) unique color for this player based on their name. 1095 1066 // See http://stackoverflow.com/questions/3426404/create-a-hexadecimal-colour-based-on-a-string-with-jquery-javascript 1096 1067 function getPlayerColor(playername) 1097 1068 { -
binaries/data/mods/public/gui/lobby/lobby.xml
3 3 <objects> 4 4 <script file="gui/common/functions_global_object.js"/> 5 5 <script file="gui/common/functions_utility.js"/> 6 6 <script file="gui/common/timer.js"/> 7 7 <script file="gui/common/music.js"/> 8 <script file="gui/common/settings.js"/> 8 9 9 10 <script file="gui/lobby/lobby.js"/> 10 11 11 12 <object type="image" style="ModernWindow" size="0 0 100% 100%" name="lobbyWindow"> 12 13 … … 161 162 </action> 162 163 </object> 163 164 164 165 <object type="button" style="ModernButtonRed" size="0 100%-25 100% 100%"> 165 166 <translatableAttribute id="caption">Main Menu</translatableAttribute> 166 <action on="Press"> 167 lobbyStop(); 168 Engine.SwitchGuiPage("page_pregame.xml"); 169 </action> 167 <action on="Press">returnToMainMenu();</action> 170 168 </object> 171 169 </object> 172 170 173 171 <!-- Middle panel: Filters, game list, chat box. --> 174 172 <object name="middlePanel" size="20%+5 5% 100%-255 97.2%"> -
binaries/data/mods/public/gui/session/session.js
11 11 // Cache the basic player data (name, civ, color) 12 12 var g_Players = []; 13 13 // Cache the useful civ data 14 14 var g_CivData = {}; 15 15 16 var g_GameSpeeds = {};17 var g_CurrentSpeed;18 19 16 var g_PlayerAssignments = { "local": { "name": translate("You"), "player": 1 } }; 20 17 21 18 // Cache dev-mode settings that are frequently or widely used 22 19 var g_DevSettings = { 23 20 controlAll: false … … 142 139 } 143 140 144 141 return g_TechnologyData[technologyName]; 145 142 } 146 143 147 // Init148 144 function init(initData, hotloadData) 149 145 { 146 initMusic(); 147 148 if (!validSettings(() => { leaveGame(true); })) 149 return; 150 150 151 if (initData) 151 152 { 152 153 g_IsNetworked = initData.isNetworked; // Set network mode 153 154 g_IsController = initData.isController; // Set controller mode 154 155 g_PlayerAssignments = initData.playerAssignments; … … 175 176 if (Engine.GetPlayerID() <= 0) 176 177 g_IsObserver = true; 177 178 178 179 updateTopPanel(); 179 180 180 g_GameSpeeds = initGameSpeeds();181 g_CurrentSpeed = Engine.GetSimRate();182 181 var gameSpeed = Engine.GetGUIObjectByName("gameSpeed"); 183 gameSpeed.list = g_GameSpeeds.names; 184 gameSpeed.list_data = g_GameSpeeds.speeds; 185 var idx = g_GameSpeeds.speeds.indexOf(g_CurrentSpeed); 186 gameSpeed.selected = idx != -1 ? idx : g_GameSpeeds["default"]; 182 var gameSpeeds = prepareForDropdown("GameSpeeds"); 183 gameSpeed.list = gameSpeeds.Title; 184 gameSpeed.list_data = gameSpeeds.Speed; 185 var idx = gameSpeed.list_data.indexOf(Engine.GetSimRate()); 186 gameSpeed.selected = idx != -1 ? idx : gameSpeeds.default; 187 187 gameSpeed.onSelectionChange = function() { changeGameSpeed(+this.list_data[this.selected]); } 188 188 initMenuPosition(); // set initial position 189 189 190 190 // Populate player selection dropdown 191 191 var playerNames = []; … … 207 207 208 208 if (hotloadData) 209 209 g_Selection.selected = hotloadData.selection; 210 210 211 211 // Starting for the first time: 212 initMusic();213 212 if (!g_IsObserver) 214 213 { 215 214 var civMusic = g_CivData[g_Players[Engine.GetPlayerID()].civ].Music; 216 215 global.music.storeTracks(civMusic); 217 216 } … … 398 397 /** 399 398 * Called every frame. 400 399 */ 401 400 function onTick() 402 401 { 402 if (!g_Settings) 403 return; 404 403 405 var now = new Date; 404 406 var tickLength = new Date - lastTickTime; 405 407 lastTickTime = now; 406 408 407 409 checkPlayerState(); … … 507 509 508 510 function changeGameSpeed(speed) 509 511 { 510 512 // For non-networked games only 511 513 if (!g_IsNetworked) 512 {513 514 Engine.SetSimRate(speed); 514 g_CurrentSpeed = speed;515 }516 515 } 517 516 518 517 /** 519 518 * Recomputes GUI state that depends on simulation state or selection state. Called directly every simulation 520 519 * update (see session.xml), or from onTick when the selection has changed. -
binaries/data/mods/public/gui/session/session.xml
6 6 <script file="gui/common/functions_civinfo.js"/> 7 7 <script file="gui/common/functions_global_object.js"/> 8 8 <script file="gui/common/functions_utility.js"/> 9 9 <script file="gui/common/l10n.js"/> 10 10 <script file="gui/common/music.js"/> 11 <script file="gui/common/settings.js"/> 11 12 <script file="gui/common/timer.js"/> 12 13 <script file="gui/common/tooltips.js"/> 13 14 <!-- load all scripts in this directory --> 14 15 <script directory="gui/session/"/> 15 16 -
binaries/data/mods/public/gui/summary/layout.js
137 137 { 138 138 for (var h = 0; h < MAX_HEADINGTITLE; ++h) 139 139 { 140 140 Engine.GetGUIObjectByName("titleHeading["+ h +"]").hidden = true; 141 141 Engine.GetGUIObjectByName("Heading[" + h + "]").hidden = true; 142 for ( var p = 0; p < MAX_SLOTS; ++p)142 for (let p = 0; p < g_Settings.MaxPlayers; ++p) 143 143 { 144 144 Engine.GetGUIObjectByName("valueData[" + p + "][" + h + "]").hidden = true; 145 for ( var t = 0; t < MAX_TEAMS; ++t)145 for (let t = 0; t < g_Settings.MaxTeams; ++t) 146 146 { 147 147 Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + p + "][" + h + "]").hidden = true; 148 148 Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + h + "]").hidden = true; 149 149 } 150 150 } … … 187 187 188 188 function updateGeneralPanelCounter(counters) 189 189 { 190 190 var rowPlayerObjectWidth = 0; 191 191 var left = 0; 192 for ( var p = 0; p < MAX_SLOTS; ++p)192 for (let p = 0; p < g_Settings.MaxPlayers; ++p) 193 193 { 194 194 left = 240; 195 195 var counterObject; 196 196 for (var w in counters) 197 197 { … … 202 202 } 203 203 if (rowPlayerObjectWidth == 0) 204 204 rowPlayerObjectWidth = left; 205 205 206 206 var counterTotalObject; 207 for ( var t = 0; t < MAX_TEAMS; ++t)207 for (let t = 0; t < g_Settings.MaxTeams; ++t) 208 208 { 209 209 left = 240; 210 210 for (var w in counters) 211 211 { 212 212 counterObject = Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + p + "][" + w + "]"); … … 262 262 Engine.GetGUIObjectByName("playerNameHeading").caption = ""; 263 263 } 264 264 265 265 function updateObjectPlayerPosition() 266 266 { 267 for ( var h = 0; h < MAX_SLOTS; ++h)267 for (let h = 0; h < g_Settings.MaxPlayers; ++h) 268 268 { 269 269 var playerBox = Engine.GetGUIObjectByName("playerBox[" + h + "]"); 270 270 var boxSize = playerBox.size; 271 271 boxSize.top += h * (PLAYER_BOX_Y_SIZE + PLAYER_BOX_GAP); 272 272 boxSize.bottom = boxSize.top + PLAYER_BOX_Y_SIZE; 273 273 playerBox.size = boxSize; 274 274 275 for ( var i = 0; i < MAX_TEAMS; ++i)275 for (let i = 0; i < g_Settings.MaxTeams; ++i) 276 276 { 277 277 var playerBoxt = Engine.GetGUIObjectByName("playerBoxt[" + i + "][" + h + "]"); 278 278 boxSize = playerBoxt.size; 279 279 boxSize.top += h * (PLAYER_BOX_Y_SIZE + PLAYER_BOX_GAP); 280 280 boxSize.bottom = boxSize.top + PLAYER_BOX_Y_SIZE; -
binaries/data/mods/public/gui/summary/summary.js
1 // Max player slots for any map (TODO: should read from config)2 const MAX_SLOTS = 8;3 const MAX_TEAMS = 4;4 1 const MAX_HEADINGTITLE = 8; 5 2 6 3 // const for filtering long collective headings 7 4 const LONG_HEADING_WIDTH = 250; 8 5 // Vertical size of player box … … 43 40 * Select active panel 44 41 * @param panelNumber Number of panel, which should get active state (integer) 45 42 */ 46 43 function selectPanel(panelNumber) 47 44 { 45 if (!g_Settings) 46 return; 47 48 48 var panelNames = [ 'scorePanel', 'buildingsPanel', 'unitsPanel', 'resourcesPanel', 'marketPanel', 'miscPanel']; 49 49 50 50 function adjustTabDividers(tabSize) 51 51 { 52 52 var leftSpacer = Engine.GetGUIObjectByName("tabDividerLeft"); … … 130 130 teamCounterFn(panelInfo.counters); 131 131 } 132 132 133 133 function init(data) 134 134 { 135 if (!g_Settings) 136 return; 137 135 138 updateObjectPlayerPosition(); 136 139 g_GameData = data; 137 140 138 // Map139 var mapDisplayType = translate("Scenario");140 141 141 Engine.GetGUIObjectByName("timeElapsed").caption = sprintf(translate("Game time elapsed: %(time)s"), { time: timeToString(data.timeElapsed) }); 142 142 143 143 Engine.GetGUIObjectByName("summaryText").caption = data.gameResult; 144 144 145 // This is only defined for random maps 146 if (data.mapSettings.Size) 147 { 148 // load the map sizes from the JSON file 149 var mapSizes = initMapSizes(); 150 151 // retrieve the index of the map size 152 for (var mapSizeIndex in mapSizes.tiles) 153 { 154 if (mapSizes.tiles[mapSizeIndex] == data.mapSettings.Size) 155 { 156 mapDisplayType = mapSizes.names[mapSizeIndex]; 157 break; 158 } 159 } 160 } 161 162 Engine.GetGUIObjectByName("mapName").caption = sprintf(translate("%(mapName)s - %(mapType)s"), { mapName: translate(data.mapSettings.Name), mapType: mapDisplayType}); 145 var mapDisplayType = data.mapSettings.mapType == "random" ? translateMapSize(data.mapSettings.Size) : translateMapType(data.mapSettings.mapType); 146 Engine.GetGUIObjectByName("mapName").caption = sprintf(translate("%(mapName)s - %(mapType)s"), 147 { "mapName": translate(data.mapSettings.Name), "mapType": mapDisplayType }); 163 148 164 149 // Panels 165 150 g_MaxPlayers = data.playerStates.length - 1; 166 151 167 152 if (data.mapSettings.LockTeams) // teams ARE locked -
binaries/data/mods/public/gui/summary/summary.xml
8 8 9 9 <objects> 10 10 <script file="gui/common/functions_global_object.js"/> 11 11 <script file="gui/common/functions_civinfo.js"/> 12 12 <script file="gui/common/functions_utility.js"/> 13 <script file="gui/common/settings.js"/> 13 14 <script file="gui/summary/counters.js"/> 14 15 <script file="gui/summary/layout.js"/> 15 16 <script file="gui/summary/summary.js"/> 16 17 17 18 <object type="image" -
binaries/data/mods/public/l10n/messages.json
451 451 } 452 452 }, 453 453 { 454 454 "extractor": "json", 455 455 "filemasks": [ 456 "simulation/data/game_speeds.json", 457 "simulation/data/player_defaults.json" 456 "simulation/data/settings/AIDifficulties.json" 458 457 ], 459 458 "options": { 460 "keywords": [ 461 "Name" 462 ] 459 "keywords": ["Title"], 460 "context": "aiDiff" 463 461 } 464 462 }, 465 463 { 466 464 "extractor": "json", 467 465 "filemasks": [ 468 "simulation/data/ map_sizes.json"466 "simulation/data/settings/Ceasefire.json" 469 467 ], 470 468 "options": { 471 "keywords": [ 472 "Name", 473 "LongName" 474 ] 469 "keywords": ["Title"], 470 "context": "ceasefire" 471 } 472 }, 473 { 474 "extractor": "json", 475 "filemasks": [ 476 "simulation/data/settings/GameSpeeds.json", 477 "simulation/data/settings/PopulationCapacity.json" 478 ], 479 "options": { 480 "keywords": ["Title"] 481 } 482 }, 483 { 484 "extractor": "json", 485 "filemasks": [ 486 "simulation/data/settings/GameTypes/*.json", 487 ], 488 "options": { 489 "keywords": ["Title", "Description"] 490 } 491 }, 492 { 493 "extractor": "json", 494 "filemasks": [ 495 "simulation/data/settings/PlayerDefaults.json" 496 ], 497 "options": { 498 "keywords": ["Name"] 499 } 500 }, 501 { 502 "extractor": "json", 503 "filemasks": [ 504 "simulation/data/settings/MapSizes.json" 505 ], 506 "options": { 507 "keywords": ["Name", "LongName"] 508 } 509 }, 510 { 511 "extractor": "json", 512 "filemasks": [ 513 "simulation/data/settings/MapTypes.json" 514 ], 515 "options": { 516 "keywords": ["Title"], 517 "context": "map" 518 } 519 }, 520 { 521 "extractor": "json", 522 "filemasks": [ 523 "simulation/data/settings/StartingResources.json" 524 ], 525 "options": { 526 "keywords": ["Title"], 527 "context": "startingResources" 475 528 } 476 529 }, 477 530 { 478 531 "extractor": "json", 479 532 "filemasks": [ -
binaries/data/mods/public/simulation/data/game_speeds.json
1 {2 "Speeds":3 [4 {5 "Name": "Turtle (0.1x)",6 "Speed": 0.107 },8 {9 "Name": "Slow (0.25x)",10 "Speed": 0.2511 },12 {13 "Name": "Leisurely (0.5x)",14 "Speed": 0.5015 },16 {17 "Name": "Relaxed (0.75x)",18 "Speed": 0.7519 },20 {21 "Name": "Normal (1x)",22 "Speed": 1.0,23 "Default": true24 },25 {26 "Name": "Fast (1.25x)",27 "Speed": 1.2528 },29 {30 "Name": "Very Fast (1.5x)",31 "Speed": 1.532 },33 {34 "Name": "Insane (2x)",35 "Speed": 2.036 }37 ]38 } -
binaries/data/mods/public/simulation/data/map_sizes.json
1 {2 "Sizes":3 [4 {5 "Name": "Tiny",6 "LongName": "Tiny",7 "Tiles": 1288 },9 {10 "Name": "Small",11 "LongName": "Small (2 players)",12 "Tiles": 19213 },14 {15 "Name": "Medium",16 "LongName": "Medium (3 players)",17 "Tiles": 256,18 "Default": true19 },20 {21 "Name": "Normal",22 "LongName": "Normal (4 players)",23 "Tiles": 32024 },25 {26 "Name": "Large",27 "LongName": "Large (6 players)",28 "Tiles": 38429 },30 {31 "Name": "Very Large",32 "LongName": "Very Large (8 players)",33 "Tiles": 44834 },35 {36 "Name": "Giant",37 "LongName": "Giant",38 "Tiles": 51239 }40 ]41 } -
binaries/data/mods/public/simulation/data/player_defaults.json
1 {2 "PlayerData":3 [4 {5 "Name": "Gaia",6 "Civ": "gaia",7 "Color": { "r": 255, "g": 255, "b": 255 },8 "AI": "",9 "AIDiff": 310 },11 {12 "Name": "Player 1",13 "Civ": "athen",14 "Color": { "r": 46, "g": 46, "b": 200 },15 "AI": "",16 "AIDiff": 317 },18 {19 "Name": "Player 2",20 "Civ": "cart",21 "Color": { "r": 150, "g": 20, "b": 20 },22 "AI": "petra",23 "AIDiff": 324 },25 {26 "Name": "Player 3",27 "Civ": "gaul",28 "Color": { "r": 50, "g": 165, "b": 5 },29 "AI": "petra",30 "AIDiff": 331 },32 {33 "Name": "Player 4",34 "Civ": "iber",35 "Color": { "r": 230, "g": 230, "b": 75 },36 "AI": "petra",37 "AIDiff": 338 },39 {40 "Name": "Player 5",41 "Civ": "mace",42 "Color": { "r": 50, "g": 170, "b": 170 },43 "AI": "petra",44 "AIDiff": 345 },46 {47 "Name": "Player 6",48 "Civ": "maur",49 "Color": { "r": 160, "g": 80, "b": 200 },50 "AI": "petra",51 "AIDiff": 352 },53 {54 "Name": "Player 7",55 "Civ": "pers",56 "Color": { "r": 235, "g": 120, "b": 20 },57 "AI": "petra",58 "AIDiff": 359 },60 {61 "Name": "Player 8",62 "Civ": "rome",63 "Color": { "r": 64, "g": 64, "b": 64 },64 "AI": "petra",65 "AIDiff": 366 }67 ]68 } -
binaries/data/mods/public/simulation/data/settings/AIDifficulties.json
1 { 2 "TranslatedKeys": { "Title": "aiDiff" }, 3 "AIDifficulties": 4 [ 5 { 6 "Name": "sandbox", 7 "Title": "Sandbox" 8 }, 9 { 10 "Name": "very easy", 11 "Title": "Very Easy" 12 }, 13 { 14 "Name": "easy", 15 "Title": "Easy" 16 }, 17 { 18 "Name": "medium", 19 "Title": "Medium", 20 "Default": true 21 }, 22 { 23 "Name": "hard", 24 "Title": "Hard" 25 }, 26 { 27 "Name": "very hard", 28 "Title": "Very Hard" 29 } 30 ] 31 } -
binaries/data/mods/public/simulation/data/settings/Ceasefire.json
1 { 2 "TranslatedKeys": { "Title": "ceasefire" }, 3 "Ceasefire": 4 [ 5 { 6 "Duration": 0, 7 "Title": "No ceasefire", 8 "Default": true 9 }, 10 { 11 "Duration": 1, 12 "Title": "1 minute" 13 }, 14 { 15 "Duration": 2, 16 "Title": "2 minutes" 17 }, 18 { 19 "Duration": 3, 20 "Title": "3 minutes" 21 }, 22 { 23 "Duration": 4, 24 "Title": "4 minutes" 25 }, 26 { 27 "Duration": 5, 28 "Title": "5 minutes" 29 }, 30 { 31 "Duration": 10, 32 "Title": "10 minutes" 33 }, 34 { 35 "Duration": 15, 36 "Title": "15 minutes" 37 }, 38 { 39 "Duration": 20, 40 "Title": "20 minutes" 41 }, 42 { 43 "Duration": 30, 44 "Title": "30 minutes" 45 }, 46 { 47 "Duration": 45, 48 "Title": "45 minutes" 49 }, 50 { 51 "Duration": 60, 52 "Title": "60 minutes" 53 } 54 ] 55 } -
binaries/data/mods/public/simulation/data/settings/GameSpeeds.json
1 { 2 "TranslatedKeys": ["Title"], 3 "GameSpeeds": 4 [ 5 { 6 "Speed": 0.10, 7 "Title": "Turtle (0.1x)" 8 }, 9 { 10 "Speed": 0.25, 11 "Title": "Slow (0.25x)" 12 }, 13 { 14 "Speed": 0.50, 15 "Title": "Leisurely (0.5x)" 16 }, 17 { 18 "Speed": 0.75, 19 "Title": "Relaxed (0.75x)" 20 }, 21 { 22 "Speed": 1.0, 23 "Title": "Normal (1x)", 24 "Default": true 25 }, 26 { 27 "Speed": 1.25, 28 "Title": "Fast (1.25x)" 29 }, 30 { 31 "Speed": 1.5, 32 "Title": "Very Fast (1.5x)" 33 }, 34 { 35 "Speed": 2.0, 36 "Title": "Insane (2x)" 37 } 38 ] 39 } -
binaries/data/mods/public/simulation/data/settings/GameTypes/Conquest.json
1 { 2 "TranslatedKeys" : ["Name", "Title"], 3 "Conquest" : 4 { 5 "Name": "conquest", 6 "Title": "Conquest", 7 "Description": "Defeat all opponents", 8 "Scripts": 9 [ 10 "scripts/TriggerHelper.js", 11 "scripts/ConquestCommon.js", 12 "scripts/Conquest.js" 13 ], 14 "Default": true 15 } 16 } -
binaries/data/mods/public/simulation/data/settings/GameTypes/ConquestStructures.json
1 { 2 "TranslatedKeys" : ["Name", "Title"], 3 "ConquestStructures" : 4 { 5 "Name": "conquestStructures", 6 "Title": "Conquest Structures", 7 "Description": "Destroy all structures of enemies", 8 "Scripts": 9 [ 10 "scripts/TriggerHelper.js", 11 "scripts/ConquestCommon.js", 12 "scripts/ConquestStructures.js" 13 ] 14 } 15 } -
binaries/data/mods/public/simulation/data/settings/GameTypes/ConquestUnits.json
1 { 2 "TranslatedKeys" : ["Name", "Title"], 3 "ConquestUnits" : 4 { 5 "Name": "conquestUnits", 6 "Title": "Conquest Units", 7 "Description": "Kill all enemy units", 8 "Scripts": 9 [ 10 "scripts/TriggerHelper.js", 11 "scripts/ConquestCommon.js", 12 "scripts/ConquestUnits.js" 13 ] 14 } 15 } -
binaries/data/mods/public/simulation/data/settings/GameTypes/Endless.json
1 { 2 "TranslatedKeys" : ["Name", "Title"], 3 "Endless" : 4 { 5 "Name": "endless", 6 "Title": "None", 7 "Description": "Endless Game", 8 "Scripts": [] 9 } 10 } -
binaries/data/mods/public/simulation/data/settings/GameTypes/Wonder.json
1 { 2 "TranslatedKeys" : ["Name", "Title"], 3 "Wonder" : 4 { 5 "Name": "wonder", 6 "Title": "Wonder", 7 "Description": "Build and protect a wonder to win", 8 "Scripts": 9 [ 10 "scripts/TriggerHelper.js", 11 "scripts/ConquestCommon.js", 12 "scripts/Conquest.js", 13 "scripts/WonderVictory.js" 14 ] 15 } 16 } -
binaries/data/mods/public/simulation/data/settings/MapSizes.json
1 { 2 "TranslatedKeys": ["Name", "LongName"], 3 "MapSizes": 4 [ 5 { 6 "Tiles": 128, 7 "Name": "Tiny", 8 "LongName": "Tiny" 9 }, 10 { 11 "Tiles": 192, 12 "Name": "Small", 13 "LongName": "Small (2 players)" 14 }, 15 { 16 "Tiles": 256, 17 "Name": "Medium", 18 "LongName": "Medium (3 players)", 19 "Default": true 20 }, 21 { 22 "Tiles": 320, 23 "Name": "Normal", 24 "LongName": "Normal (4 players)" 25 }, 26 { 27 "Tiles": 384, 28 "Name": "Large", 29 "LongName": "Large (6 players)" 30 }, 31 { 32 "Tiles": 448, 33 "Name": "Very Large", 34 "LongName": "Very Large (8 players)" 35 }, 36 { 37 "Tiles": 512, 38 "Name": "Giant", 39 "LongName": "Giant" 40 } 41 ] 42 } -
binaries/data/mods/public/simulation/data/settings/MapTypes.json
1 { 2 "TranslatedKeys": { "Title": "map" }, 3 "MapTypes": 4 [ 5 { 6 "Name": "skirmish", 7 "Title": "Skirmish", 8 "Default": true 9 }, 10 { 11 "Name": "random", 12 "Title": "Random" 13 }, 14 { 15 "Name": "scenario", 16 "Title": "Scenario" 17 } 18 ] 19 } -
binaries/data/mods/public/simulation/data/settings/PlayerDefaults.json
1 { 2 "TranslatedKeys": ["Name"], 3 "PlayerDefaults": 4 [ 5 { 6 "Name": "Gaia", 7 "Civ": "gaia", 8 "Color": { "r": 255, "g": 255, "b": 255 }, 9 "AI": "", 10 "AIDiff": 3 11 }, 12 { 13 "Name": "Player 1", 14 "Civ": "athen", 15 "Color": { "r": 46, "g": 46, "b": 200 }, 16 "AI": "", 17 "AIDiff": 3 18 }, 19 { 20 "Name": "Player 2", 21 "Civ": "cart", 22 "Color": { "r": 150, "g": 20, "b": 20 }, 23 "AI": "petra", 24 "AIDiff": 3 25 }, 26 { 27 "Name": "Player 3", 28 "Civ": "gaul", 29 "Color": { "r": 50, "g": 165, "b": 5 }, 30 "AI": "petra", 31 "AIDiff": 3 32 }, 33 { 34 "Name": "Player 4", 35 "Civ": "iber", 36 "Color": { "r": 230, "g": 230, "b": 75 }, 37 "AI": "petra", 38 "AIDiff": 3 39 }, 40 { 41 "Name": "Player 5", 42 "Civ": "mace", 43 "Color": { "r": 50, "g": 170, "b": 170 }, 44 "AI": "petra", 45 "AIDiff": 3 46 }, 47 { 48 "Name": "Player 6", 49 "Civ": "maur", 50 "Color": { "r": 160, "g": 80, "b": 200 }, 51 "AI": "petra", 52 "AIDiff": 3 53 }, 54 { 55 "Name": "Player 7", 56 "Civ": "pers", 57 "Color": { "r": 235, "g": 120, "b": 20 }, 58 "AI": "petra", 59 "AIDiff": 3 60 }, 61 { 62 "Name": "Player 8", 63 "Civ": "rome", 64 "Color": { "r": 64, "g": 64, "b": 64 }, 65 "AI": "petra", 66 "AIDiff": 3 67 } 68 ] 69 } -
binaries/data/mods/public/simulation/data/settings/PlayerLimit.json
1 { 2 "MaxPlayers": 8, 3 "MaxTeams": 4 4 } -
binaries/data/mods/public/simulation/data/settings/PopulationCapacity.json
1 { 2 "TranslatedKeys": ["Title"], 3 "PopulationCapacity": 4 [ 5 { 6 "Population": 50, 7 "Title": "50" 8 }, 9 { 10 "Population": 100, 11 "Title": "100" 12 }, 13 { 14 "Population": 150, 15 "Title": "150" 16 }, 17 { 18 "Population": 200, 19 "Title": "200" 20 }, 21 { 22 "Population": 250, 23 "Title": "250" 24 }, 25 { 26 "Population": 300, 27 "Title": "300", 28 "Default": true 29 }, 30 { 31 "Population": 10000, 32 "Title": "Unlimited" 33 } 34 ] 35 } -
binaries/data/mods/public/simulation/data/settings/StartingResources.json
1 { 2 "TranslatedKeys": { "Title": "startingResources" }, 3 "StartingResources": 4 [ 5 { 6 "Resources": 100, 7 "Title": "Very Low" 8 }, 9 { 10 "Resources": 300, 11 "Title": "Low", 12 "Default": true 13 }, 14 { 15 "Resources": 500, 16 "Title": "Medium" 17 }, 18 { 19 "Resources": 1000, 20 "Title": "High" 21 }, 22 { 23 "Resources": 3000, 24 "Title": "Very High" 25 }, 26 { 27 "Resources": 50000, 28 "Title": "Deathmatch" 29 } 30 ] 31 } -
binaries/data/mods/public/simulation/helpers/Player.js
13 13 // Default settings 14 14 if (!settings) 15 15 settings = {}; 16 16 17 17 // Get default player data 18 var rawData = Engine.ReadJSONFile(" player_defaults.json");19 if (! (rawData && rawData.PlayerData))20 throw("Player.js: Error reading player_defaults.json");18 var rawData = Engine.ReadJSONFile("settings/PlayerDefaults.json"); 19 if (!rawData || !rawData.PlayerDefaults) 20 throw("Player.js: Error reading PlayerDefaults.json"); 21 21 22 22 // Add gaia to simplify iteration 23 23 if (settings.PlayerData && settings.PlayerData[0]) 24 24 settings.PlayerData.unshift(null); 25 25 26 var playerDefaults = rawData.PlayerD ata;26 var playerDefaults = rawData.PlayerDefaults; 27 27 var playerData = settings.PlayerData; 28 28 29 29 // Get player manager 30 30 var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 31 31 var numPlayers = cmpPlayerManager.GetNumPlayers(); … … 168 168 var cmpPlayer = Engine.QueryInterface(cmpPlayerManager.GetPlayerByID(i), IID_Player); 169 169 cmpPlayer.SetLockTeams(true); 170 170 } 171 171 172 172 // Disable the AIIinterface when no AI players are present 173 if (playerData && !playerData.some(function(v) { return v && v.AI ? true : false; }))173 if (playerData && playerData.every(player => !player || !player.AI)) 174 174 Engine.QueryInterface(SYSTEM_ENTITY, IID_AIInterface).Disable(); 175 175 } 176 176 177 177 // Get a setting if it exists or return default 178 178 function getSetting(settings, defaults, idx, property) -
source/simulation2/Simulation2.cpp
879 879 return file.DecodeUTF8(); // assume it's UTF-8 880 880 } 881 881 882 882 std::string CSimulation2::GetPlayerDefaults() 883 883 { 884 return ReadJSON(L"simulation/data/ player_defaults.json");884 return ReadJSON(L"simulation/data/settings/PlayerDefaults.json"); 885 885 } 886 886 887 887 std::string CSimulation2::GetMapSizes() 888 888 { 889 return ReadJSON(L"simulation/data/ map_sizes.json");889 return ReadJSON(L"simulation/data/settings/MapSizes.json"); 890 890 } 891 891 892 892 std::string CSimulation2::GetAIData() 893 893 { 894 894 ScriptInterface& scriptInterface = GetScriptInterface(); -
source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.cpp
139 139 sizer->Add(Tooltipped(new wxTextCtrl(this, ID_MapDescription, wxEmptyString, wxDefaultPosition, wxSize(-1, 100), wxTE_MULTILINE), 140 140 _("Short description used on the map selection screen")), wxSizerFlags().Expand()); 141 141 142 142 sizer->AddSpacer(5); 143 143 144 // TODO: load from GameTypes.json 144 145 wxArrayString gameTypes; 145 146 gameTypes.Add(_T("conquest")); 147 gameTypes.Add(_T("conquestStructures")); 148 gameTypes.Add(_T("conquestUnits")); 146 149 gameTypes.Add(_T("wonder")); 147 150 gameTypes.Add(_T("endless")); 148 151 149 152 wxFlexGridSizer* gridSizer = new wxFlexGridSizer(2, 5, 5); 150 153 gridSizer->AddGrowableCol(1); … … 368 371 // Load the map sizes list 369 372 AtlasMessage::qGetMapSizes qrySizes; 370 373 qrySizes.Post(); 371 374 AtObj sizes = AtlasObject::LoadFromJSON(*qrySizes.sizes); 372 375 wxChoice* sizeChoice = wxDynamicCast(FindWindow(ID_RandomSize), wxChoice); 373 for (AtIter s = sizes[" Sizes"]["item"]; s.defined(); ++s)376 for (AtIter s = sizes["MapSizes"]["item"]; s.defined(); ++s) 374 377 { 375 378 long tiles = 0; 376 379 wxString(s["Tiles"]).ToLong(&tiles); 377 380 sizeChoice->Append(wxString(s["Name"]), (void*)(intptr_t)tiles); 378 381 } -
source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Object/Object.cpp
535 535 // Get player names 536 536 wxArrayString players; 537 537 AtlasMessage::qGetPlayerDefaults qryPlayers; 538 538 qryPlayers.Post(); 539 539 AtObj playerData = AtlasObject::LoadFromJSON(*qryPlayers.defaults); 540 AtObj playerDefs = *playerData["PlayerD ata"];540 AtObj playerDefs = *playerData["PlayerDefaults"]; 541 541 for (AtIter p = playerDefs["item"]; p.defined(); ++p) 542 {543 542 players.Add(wxString(p["Name"])); 544 } 543 545 544 wxDynamicCast(FindWindow(ID_PlayerSelect), PlayerComboBox)->SetPlayers(players); 546 545 547 546 // Initialise the game with the default settings 548 547 POST_MESSAGE(SetViewParamB, (AtlasMessage::eRenderView::ACTOR, L"wireframe", m_ViewerWireframe)); 549 548 POST_MESSAGE(SetViewParamB, (AtlasMessage::eRenderView::ACTOR, L"walk", m_ViewerMove)); -
source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Player/Player.cpp
517 517 POST_MESSAGE(LoadPlayerSettings, (true)); 518 518 m_MapSettings.NotifyObservers(); 519 519 } 520 520 } 521 521 522 // TODO: we shouldn't hardcode this, but instead dynamically create 523 // new player notebook pages on demand; of course the default data 524 // will be limited by the entries in player_defaults.json 522 // TODO: Load value from PlayerLimit.json 525 523 static const size_t MAX_NUM_PLAYERS = 8; 526 524 527 525 bool m_InGUIUpdate; 528 526 AtObj m_PlayerDefaults; 529 527 PlayerNotebook* m_Players; … … 640 638 void PlayerSettingsControl::LoadDefaults() 641 639 { 642 640 AtlasMessage::qGetPlayerDefaults qryPlayers; 643 641 qryPlayers.Post(); 644 642 AtObj playerData = AtlasObject::LoadFromJSON(*qryPlayers.defaults); 645 m_PlayerDefaults = *playerData["PlayerD ata"];643 m_PlayerDefaults = *playerData["PlayerDefaults"]; 646 644 } 647 645 648 646 void PlayerSettingsControl::ReadFromEngine() 649 647 { 650 648 AtlasMessage::qGetMapSettings qry; -
source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Terrain/Terrain.cpp
284 284 285 285 // Load the map sizes list 286 286 AtlasMessage::qGetMapSizes qrySizes; 287 287 qrySizes.Post(); 288 288 AtObj sizes = AtlasObject::LoadFromJSON(*qrySizes.sizes); 289 for (AtIter s = sizes[" Sizes"]["item"]; s.defined(); ++s)289 for (AtIter s = sizes["MapSizes"]["item"]; s.defined(); ++s) 290 290 { 291 291 long tiles = 0; 292 292 wxString(s["Tiles"]).ToLong(&tiles); 293 293 sizeNames.Add(wxString(s["Name"])); 294 294 sizeTiles.push_back((size_t)tiles); -
source/tools/i18n/extractors/extractors.py
303 303 304 304 def __init__(self, directoryPath=None, filemasks=[], options={}): 305 305 super(json, self).__init__(directoryPath, filemasks, options) 306 306 self.breadcrumbs = [] 307 307 self.keywords = self.options.get("keywords", {}) 308 self.context = self.options.get("context", None) 308 309 309 310 def setOptions(self, options): 310 311 self.options = options 311 312 self.keywords = self.options.get("keywords", {}) 313 self.context = self.options.get("context", None) 312 314 313 315 @staticmethod 314 316 def formatBreadcrumbs(breadcrumbs): 315 317 firstPiece = breadcrumbs[0] 316 318 if isinstance(firstPiece, int): outputString = "[" + str(firstPiece) + "]" … … 321 323 return outputString 322 324 323 325 def extractFromFile(self, filepath): 324 326 with codecs.open(filepath, "r", 'utf-8') as fileObject: 325 327 for message, breadcrumbs in self.extractFromString(fileObject.read()): 326 yield message, None, None, self.formatBreadcrumbs(breadcrumbs), -1, []328 yield message, None, self.context, self.formatBreadcrumbs(breadcrumbs), -1, [] 327 329 328 330 def extractFromString(self, string): 329 331 self.breadcrumbs = [] 330 332 jsonDocument = jsonParser.loads(string) 331 333 if isinstance(jsonDocument, list):