Ticket #3258: replay_menu_v8_16864.patch
File replay_menu_v8_16864.patch, 91.1 KB (added by , 9 years ago) |
---|
-
binaries/data/mods/public/gui/aiconfig/aiconfig.js
1 1 var g_AIs; // [ {"id": ..., "data": {"name": ..., "description": ..., ...} }, ... ] 2 var g_AIDiffs; // translated AI difficulties 2 3 var g_PlayerSlot; 3 4 4 5 function init(settings) 5 6 { 6 7 g_PlayerSlot = settings.playerSlot; 7 8 8 translateObjectKeys(settings.ais, ["name", "description"]);9 9 g_AIs = [ 10 10 {id: "", data: {name: translateWithContext("ai", "None"), description: translate("AI will be disabled for this player.")}} 11 11 ].concat(settings.ais); 12 12 13 13 var aiSelection = Engine.GetGUIObjectByName("aiSelection"); … … 22 22 break; 23 23 } 24 24 } 25 25 aiSelection.selected = selected; 26 26 27 g_AIDiffs = initAIDifficulties(); // translated AI difficulties 27 28 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")]; 29 aiDiff.list = g_AIDiffs.titles; 30 30 aiDiff.selected = settings.difficulty; 31 31 } 32 32 33 33 function selectAI(idx) 34 34 { -
binaries/data/mods/public/gui/aiconfig/aiconfig.xml
1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 3 3 <objects> 4 4 5 5 <script file="gui/aiconfig/aiconfig.js"/> 6 <script file="gui/common/functions_utility.js"/> 6 7 7 8 <!-- Add a translucent black background to fade out the menu page --> 8 9 <object type="image" sprite="ModernFade"/> 9 10 10 11 <object type="image" style="ModernDialog" size="50%-230 50%-130 50%+230 50%+130"> -
binaries/data/mods/public/gui/common/functions_utility.js
101 101 // ==================================================================== 102 102 103 103 // Load map size data 104 104 function initMapSizes() 105 105 { 106 varsizes = {106 let sizes = { 107 107 "shortNames":[], 108 108 "names":[], 109 109 "tiles": [], 110 110 "default": 0 111 111 }; 112 112 113 vardata = Engine.ReadJSONFile("simulation/data/map_sizes.json");113 let data = Engine.ReadJSONFile("simulation/data/map_sizes.json"); 114 114 if (!data || !data.Sizes) 115 115 { 116 116 error("Failed to parse map sizes in map_sizes.json (check for valid JSON data)"); 117 117 return sizes; 118 118 } 119 119 120 120 translateObjectKeys(data, ["Name", "LongName"]); 121 for ( vari = 0; i < data.Sizes.length; ++i)121 for (let i = 0; i < data.Sizes.length; ++i) 122 122 { 123 123 sizes.shortNames.push(data.Sizes[i].Name); 124 124 sizes.names.push(data.Sizes[i].LongName); 125 125 sizes.tiles.push(data.Sizes[i].Tiles); 126 126 127 127 if (data.Sizes[i].Default) 128 sizes ["default"]= i;128 sizes.default = i; 129 129 } 130 130 131 131 return sizes; 132 132 } 133 133 134 // Returns translated map size for a given a numeric size. Requires g_MapSizes to be present. 135 function translateMapSize(mapSize) 136 { 137 let index = g_MapSizes.tiles.indexOf(parseInt(mapSize)) 138 if (index > -1) 139 return g_MapSizes.shortNames[index]; 140 else 141 return translateWithContext("map size", "Default"); 142 } 143 144 // ==================================================================== 145 146 // Load map size data 147 function initPopulationCapacity() 148 { 149 let population = { 150 "population":[], 151 "titles": [], 152 "default": 0 153 }; 154 155 let data = Engine.ReadJSONFile("simulation/data/population_capacity.json"); 156 if (!data || !data.PopulationCapacity) 157 { 158 error("Failed to parse map sizes in population_capacity.json (check for valid JSON data)"); 159 return population; 160 } 161 162 translateObjectKeys(data, ["Title"]); 163 for (let i = 0; i < data.PopulationCapacity.length; ++i) 164 { 165 population.population.push(data.PopulationCapacity[i].Population); 166 population.titles.push(data.PopulationCapacity[i].Title); 167 168 if (data.PopulationCapacity[i].Default) 169 population.default = i; 170 } 171 172 return population; 173 } 174 175 // Returns the translation for a given numeric value. Requires g_PopCaps to be present. 176 function translatePopulationCapacity(popCap) 177 { 178 let index = g_PopCaps.population.indexOf(parseInt(popCap)) 179 if (index > -1) 180 return g_PopCaps.titles[index]; 181 else 182 return translateWithContext("population capacity", "Unknown"); 183 } 184 185 // ==================================================================== 186 187 // Load map type data 188 function initMapTypes() 189 { 190 let types = { 191 "names":[], 192 "titles":[], 193 "default": 0 194 }; 195 196 let data = Engine.ReadJSONFile("simulation/data/map_types.json"); 197 if (!data || !data.Types) 198 { 199 error("Failed to parse map types in map_types.json (check for valid JSON data)"); 200 return types; 201 } 202 203 translateObjectKeys(data, ["Title"]); 204 for (let i = 0; i < data.Types.length; ++i) 205 { 206 types.names.push(data.Types[i].Name); 207 types.titles.push(data.Types[i].Title); 208 209 if (data.Types[i].Default) 210 types.default = i; 211 } 212 213 return types; 214 } 215 216 // Returns the translation of the given map type. Requires g_MapTypes to be present. 217 function translateMapType(mapType) 218 { 219 let index = g_MapTypes.names.indexOf(mapType) 220 if (index > -1) 221 return g_MapTypes.titles[index]; 222 else 223 return translateWithContext("map type", "Unknown"); 224 } 225 226 // ==================================================================== 227 228 function initAIDescription() 229 { 230 let AIs = Engine.GetAIs(); 231 translateObjectKeys(AIs, ["name", "description"]); 232 // Sort AIs by displayed name 233 AIs.sort(function (a, b) { 234 return a.data.name < b.data.name ? -1 : b.data.name < a.data.name ? +1 : 0; 235 }); 236 return AIs; 237 } 238 239 // Returns the translation of the given AI name (like "petra"). Requires g_AIs to be present. 240 function translateAIName(aiName) 241 { 242 let AI_description = g_AIs.filter(ai => ai.id == aiName); 243 if (AI_description.length > 0) 244 return translate(AI_description[0].data.name); 245 else 246 return translateWithContext("AI name", "Unknown"); 247 } 248 249 // ==================================================================== 250 251 function initAIDifficulties() 252 { 253 let difficulties = { 254 "names":[], 255 "titles":[], 256 "default": 0 257 }; 258 259 let data = Engine.ReadJSONFile("simulation/ai/difficulties.json"); 260 if (!data || !data.Difficulties) 261 { 262 error("Failed to parse AI difficulties (check difficulties.json for valid data)"); 263 return ["Default"]; 264 } 265 266 translateObjectKeys(data, ["Title"]); 267 for (let i = 0; i < data.Difficulties.length; ++i) 268 { 269 difficulties.names.push(data.Difficulties[i].Name); 270 difficulties.titles.push(data.Difficulties[i].Title); 271 272 if (data.Difficulties[i].Default) 273 difficulties.default = i; 274 } 275 return difficulties; 276 } 277 278 // Returns the translation of the given AI difficulty. Requires g_AIDiffs to be present. 279 function translateAIDifficulty(index) 280 { 281 if (0 <= index && index < g_AIDiffs.titles.length) 282 return g_AIDiffs.titles[index]; 283 else 284 return translateWithContext("aiDiff", "Unknown"); 285 } 286 287 // ==================================================================== 288 289 // Returns the translation of the given map type. Requires g_VictoryConditions to be present. 290 function translateGameType(gameType) 291 { 292 if (g_VictoryConditions.hasOwnProperty(gameType)) 293 return g_VictoryConditions[gameType].name; 294 else 295 return translateWithContext("game type", "Unknown"); 296 } 297 134 298 // ==================================================================== 135 299 136 300 // Load game speed data 137 301 function initGameSpeeds() 138 302 { -
binaries/data/mods/public/gui/common/functions_utility_loadsave.js
23 23 /** 24 24 * Check the version compatibility between the saved game to be loaded and the engine 25 25 */ 26 26 function hasSameVersion(metadata, engineInfo) 27 27 { 28 return (metadata.version_major == engineInfo.version_major );28 return (metadata.version_major == engineInfo.version_major && metadata.hasOwnProperty("engine_version") && metadata.engine_version == engineInfo.engine_version); 29 29 } 30 30 31 31 /** 32 32 * Check the mod compatibility between the saved game to be loaded and the engine 33 33 */ -
binaries/data/mods/public/gui/gamesetup/gamesetup.js
2 2 // Constants 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 8 7 // 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 8 // Translation: Amount of starting resources. 14 9 const STARTING_RESOURCES = [translateWithContext("startingResources", "Very Low"), translateWithContext("startingResources", "Low"), translateWithContext("startingResources", "Medium"), translateWithContext("startingResources", "High"), translateWithContext("startingResources", "Very High"), translateWithContext("startingResources", "Deathmatch")]; 15 10 const STARTING_RESOURCES_DATA = [100, 300, 500, 1000, 3000, 50000]; 16 11 const STARTING_RESOURCES_DEFAULTIDX = 1; 17 12 // Translation: Ceasefire. … … 55 50 var g_DefaultPlayerData = []; 56 51 var g_GameAttributes = { 57 52 settings: {} 58 53 }; 59 54 60 var g_GameSpeeds = {};61 var g_MapSizes = {};62 55 var g_GameSpeeds = []; 56 var g_MapSizes = []; 57 var g_MapTypes = []; 63 58 var g_AIs = []; 64 59 var g_PopCaps = []; 65 60 var g_ChatMessages = []; 66 61 67 62 // Data caches 68 63 var g_MapData = {}; 69 64 var g_CivData = {}; … … 116 111 117 112 // Called after the map data is loaded and cached 118 113 function initMain() 119 114 { 120 115 // 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 }); 116 g_AIs = initAIDescription(); 127 117 128 118 // Get default player data - remove gaia 129 119 g_DefaultPlayerData = initPlayerDefaults(); 130 120 g_DefaultPlayerData.shift(); 131 121 for (var i = 0; i < g_DefaultPlayerData.length; ++i) 132 122 g_DefaultPlayerData[i].Civ = "random"; 133 123 134 124 g_GameSpeeds = initGameSpeeds(); 135 125 g_MapSizes = initMapSizes(); 126 g_MapTypes = initMapTypes(); 127 g_PopCaps = initPopulationCapacity(); 136 128 137 129 // Init civs 138 130 initCivNameList(); 139 131 140 132 // Init map types 141 133 var mapTypes = Engine.GetGUIObjectByName("mapTypeSelection"); 142 mapTypes.list = [translateWithContext("map", "Skirmish"), translateWithContext("map", "Random"), translate("Scenario")];143 mapTypes.list_data = ["skirmish","random","scenario"];134 mapTypes.list = g_MapTypes.titles; 135 mapTypes.list_data = g_MapTypes.names; 144 136 145 137 // Setup map filters - will appear in order they are added 146 138 addFilter("default", translate("Default"), function(settings) { return settings && (settings.Keywords === undefined || !keywordTestOR(settings.Keywords, ["naval", "demo", "hidden"])); }); 147 139 addFilter("naval", translate("Naval Maps"), function(settings) { return settings && settings.Keywords !== undefined && keywordTestAND(settings.Keywords, ["naval"]); }); 148 140 addFilter("demo", translate("Demo Maps"), function(settings) { return settings && settings.Keywords !== undefined && keywordTestAND(settings.Keywords, ["demo"]); }); … … 186 178 updateGameAttributes(); 187 179 } 188 180 gameSpeed.selected = g_GameSpeeds["default"]; 189 181 190 182 var populationCaps = Engine.GetGUIObjectByName("populationCap"); 191 populationCaps.list = POPULATION_CAP;192 populationCaps.list_data = POPULATION_CAP_DATA;193 populationCaps.selected = POPULATION_CAP_DEFAULTIDX;183 populationCaps.list = g_PopCaps.titles; 184 populationCaps.list_data = g_PopCaps.population; 185 populationCaps.selected = g_PopCaps.default; 194 186 populationCaps.onSelectionChange = function() { 195 187 if (this.selected != -1) 196 g_GameAttributes.settings.PopulationCap = POPULATION_CAP_DATA[this.selected];188 g_GameAttributes.settings.PopulationCap = g_PopCaps.population[this.selected]; 197 189 198 190 updateGameAttributes(); 199 191 } 200 192 201 193 var startingResourcesL = Engine.GetGUIObjectByName("startingResources"); … … 487 479 } 488 480 Engine.SwitchGuiPage("page_loading.xml", { 489 481 "attribs": g_GameAttributes, 490 482 "isNetworked" : g_IsNetworked, 491 483 "playerAssignments": g_PlayerAssignments, 492 "isController": g_IsController 484 "isController": g_IsController, 485 "g_IsReplay" : false 493 486 }); 494 487 break; 495 488 496 489 case "chat": 497 490 addChatMessage({ "type": "message", "guid": message.guid, "text": message.text }); … … 1222 1215 } 1223 1216 else 1224 1217 enableRatingText.caption = "Unknown"; 1225 1218 gameSpeedText.caption = g_GameSpeeds.names[speedIdx]; 1226 1219 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];1220 populationCap.selected = (mapSettings.PopulationCap !== undefined && g_PopCaps.population.indexOf(mapSettings.PopulationCap) != -1 ? g_PopCaps.population.indexOf(mapSettings.PopulationCap) : g_PopCaps.default); 1221 populationCapText.caption = g_PopCaps.titles[populationCap.selected]; 1229 1222 startingResources.selected = (mapSettings.StartingResources !== undefined && STARTING_RESOURCES_DATA.indexOf(mapSettings.StartingResources) != -1 ? STARTING_RESOURCES_DATA.indexOf(mapSettings.StartingResources) : STARTING_RESOURCES_DEFAULTIDX); 1230 1223 startingResourcesText.caption = STARTING_RESOURCES[startingResources.selected]; 1231 1224 ceasefire.selected = (mapSettings.Ceasefire !== undefined && CEASEFIRE_DATA.indexOf(mapSettings.Ceasefire) != -1 ? CEASEFIRE_DATA.indexOf(mapSettings.Ceasefire) : CEASEFIRE_DEFAULTIDX); 1232 1225 ceasefireText.caption = CEASEFIRE[ceasefire.selected]; 1233 1226 -
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/aiconfig/aiconfig.js"/> 5 6 <script file="gui/common/network.js"/> 6 7 <script file="gui/common/functions_civinfo.js"/> 7 8 <script file="gui/common/functions_global_object.js"/> 8 9 <script file="gui/common/functions_utility.js"/> 9 10 <script file="gui/gamesetup/gamesetup.js"/> -
binaries/data/mods/public/gui/lobby/lobby.js
7 7 var g_PlayerListOrder = 1; 8 8 var g_specialKey = Math.random(); 9 9 // This object looks like {"name":[numMessagesSinceReset, lastReset, timeBlocked]} when in use. 10 10 var g_spamMonitor = {}; 11 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"]; 12 var g_MapSizes = {}; 13 var g_MapTypes = {}; 15 14 var g_userRating = ""; // Rating of user, defaults to Unrated 16 15 var g_modPrefix = "@"; 17 16 var g_joined = false; 18 17 // Block spammers for 30 seconds. 19 18 var SPAM_BLOCK_LENGTH = 30; … … 26 25 initMusic(); 27 26 global.music.setState(global.music.states.MENU); 28 27 29 28 g_Name = Engine.LobbyGetNick(); 30 29 31 g_ mapSizes = initMapSizes();32 g_ mapSizes.shortNames.splice(0, 0, translateWithContext("map size", "Any"));33 g_ mapSizes.tiles.splice(0, 0, "");30 g_MapSizes = initMapSizes(); 31 g_MapSizes.shortNames.splice(0, 0, translateWithContext("map size", "Any")); 32 g_MapSizes.tiles.splice(0, 0, ""); 34 33 35 34 var mapSizeFilter = Engine.GetGUIObjectByName("mapSizeFilter"); 36 mapSizeFilter.list = g_ mapSizes.shortNames;37 mapSizeFilter.list_data = g_ mapSizes.tiles;35 mapSizeFilter.list = g_MapSizes.shortNames; 36 mapSizeFilter.list_data = g_MapSizes.tiles; 38 37 39 38 var playersNumberFilter = Engine.GetGUIObjectByName("playersNumberFilter"); 40 39 playersNumberFilter.list = [translateWithContext("player number", "Any"),2,3,4,5,6,7,8]; 41 40 playersNumberFilter.list_data = ["",2,3,4,5,6,7,8]; 42 41 42 g_MapTypes = initMapTypes(); 43 g_MapTypes.titles.splice(0, 0, translateWithContext("map type", "Any")); 44 g_MapTypes.names.splice(0, 0, ""); 45 43 46 var mapTypeFilter = Engine.GetGUIObjectByName("mapTypeFilter"); 44 mapTypeFilter.list = [translateWithContext("map", "Any")].concat(g_mapTypesText);45 mapTypeFilter.list_data = [""].concat(g_mapTypes);47 mapTypeFilter.list = g_MapTypes.titles; 48 mapTypeFilter.list_data = g_MapTypes.names; 46 49 47 50 Engine.LobbySetPlayerPresence("available"); 48 51 Engine.SendGetGameList(); 49 52 Engine.SendGetBoardList(); 50 53 Engine.SendGetRatingList(); … … 468 471 else 469 472 name = '[color="255 0 0"]' + name + '[/color]'; 470 473 list_name.push(name); 471 474 list_ip.push(g.ip); 472 475 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] : ""); 476 list_mapSize.push(translateMapSize(g.mapSize)); 477 list_mapType.push(translateMapType(g.mapType)); 476 478 list_nPlayers.push(g.nbp + "/" +g.tnbp); 477 479 list.push(name); 478 480 list_data.push(c); 479 481 } 480 482 c++; … … 546 548 // Push this player's name and status onto the list 547 549 return [formattedName, formattedStatus, formattedRating]; 548 550 } 549 551 550 552 /** 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 553 * Populate the game info area with information on the current game selection. 564 554 */ 565 555 function updateGameSelection() 566 556 { 567 557 var selected = Engine.GetGUIObjectByName("gamesBox").selected; … … 595 585 596 586 // Display the map name, number of players, the names of the players, the map size and the map type. 597 587 Engine.GetGUIObjectByName("sgMapName").caption = translate(g_GameList[g].niceMapName); 598 588 Engine.GetGUIObjectByName("sgNbPlayers").caption = g_GameList[g].nbp + "/" + g_GameList[g].tnbp; 599 589 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] : ""; 590 Engine.GetGUIObjectByName("sgMapSize").caption = translateMapSize(g_GameList[g].mapSize); 591 Engine.GetGUIObjectByName("sgMapType").caption = translateMapType(g_GameList[g].mapType); 603 592 604 593 // Display map description if it exists, otherwise display a placeholder. 605 594 if (mapData && mapData.settings.Description) 606 595 var mapDescription = translate(mapData.settings.Description); 607 596 else -
binaries/data/mods/public/gui/page_replaymenu.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <page> 3 <include>common/modern/setup.xml</include> 4 <include>common/modern/styles.xml</include> 5 <include>common/modern/sprites.xml</include> 6 7 <include>common/setup.xml</include> 8 <include>common/sprite1.xml</include> 9 <include>common/styles.xml</include> 10 <include>common/common_sprites.xml</include> 11 <include>common/common_styles.xml</include> 12 13 <include>replaymenu/styles.xml</include> 14 <include>replaymenu/replaymenu.xml</include> 15 </page> -
binaries/data/mods/public/gui/pregame/mainmenu.xml
344 344 Engine.PushGuiPage("page_locale.xml"); 345 345 ]]> 346 346 </action> 347 347 </object> 348 348 349 <object name="submenuReplayButton" 350 type="button" 351 style="StoneButtonFancy" 352 size="0 64 100% 92" 353 tooltip_style="pgToolTip" 354 > 355 <translatableAttribute id="caption">Replay</translatableAttribute> 356 <translatableAttribute id="tooltip">Shows a replay of a past game.</translatableAttribute> 357 <action on="Press"> 358 closeMenu(); 359 Engine.SwitchGuiPage("page_replaymenu.xml"); 360 </action> 361 </object> 362 349 363 <object name="submenuEditorButton" 350 364 style="StoneButtonFancy" 351 365 type="button" 352 size="0 64 100% 92"366 size="0 96 100% 124" 353 367 tooltip_style="pgToolTip" 354 368 > 355 369 <translatableAttribute id="caption">Scenario Editor</translatableAttribute> 356 370 <translatableAttribute id="tooltip">Open the Atlas Scenario Editor in a new window. You can run this more reliably by starting the game with the command-line argument "-editor".</translatableAttribute> 357 371 <action on="Press"> … … 360 374 </object> 361 375 362 376 <object name="submenuWelcomeScreenButton" 363 377 style="StoneButtonFancy" 364 378 type="button" 365 size="0 96 100% 124"379 size="0 128 100% 156" 366 380 tooltip_style="pgToolTip" 367 381 > 368 382 <translatableAttribute id="caption">Welcome Screen</translatableAttribute> 369 383 <translatableAttribute id="tooltip">Show the Welcome Screen. Useful if you hid it by mistake.</translatableAttribute> 370 384 <action on="Press"> … … 375 389 </action> 376 390 </object> 377 391 <object name="submenuModSelection" 378 392 style="StoneButtonFancy" 379 393 type="button" 380 size="0 1 28 100% 156"394 size="0 156 100% 188" 381 395 tooltip_style="pgToolTip" 382 396 > 383 397 <translatableAttribute id="caption">Mod Selection</translatableAttribute> 384 398 <translatableAttribute id="tooltip">Select mods to use.</translatableAttribute> 385 399 <action on="Press"> … … 482 496 > 483 497 <translatableAttribute id="caption">Tools & Options</translatableAttribute> 484 498 <translatableAttribute id="tooltip">Game options and scenario design tools.</translatableAttribute> 485 499 <action on="Press"> 486 500 closeMenu(); 487 openMenu("submenuToolsAndOptions", (this.parent.size.top+this.size.top), (this.size.bottom-this.size.top), 5);501 openMenu("submenuToolsAndOptions", (this.parent.size.top+this.size.top), (this.size.bottom-this.size.top), 6); 488 502 </action> 489 503 </object> 490 504 491 505 <!-- EXIT BUTTON --> 492 506 <object name="menuExitButton" -
binaries/data/mods/public/gui/replaymenu/replaymenu.js
1 var g_Replays = []; // All replays found including metadata 2 var g_ReplaysFiltered = []; // List of replays after filtering 3 var g_Playernames = []; // All playernames of all replays, used for autocomplete 4 var g_MapNames = []; // All map names of all replays 5 var g_ReplayListSortBy = "name"; // Used by sorting 6 var g_ReplayListOrder = -1; // Used by sorting 7 var g_AIs = initAIDescription(); // translated AI names and description 8 var g_AIDiffs = initAIDifficulties(); // translated AI difficulties 9 const g_VictoryConditions = {}; // translated game types 10 const g_MapSizes = initMapSizes(); // translated map sizes 11 const g_MapTypes = initMapTypes(); // translated map types 12 const g_PopCaps = initPopulationCapacity(); // translated population capacities 13 const g_CivData = loadCivData(); // names and description of civs 14 const g_EngineInfo = Engine.GetEngineInfo(); // current engine version 15 const g_DefaultPlayerData = initPlayerDefaults(); 16 const g_maxPlayerlistChars = 70; 17 const g_DurationFilterMin = [ 0, 0, 15, 30, 45, 60, 90, 120]; 18 const g_DurationFilterMax = [-1, 15, 30, 45, 60, 90, 120, -1]; 19 20 function init() 21 { 22 loadReplays(); 23 updateReplayList(); 24 } 25 26 function loadReplays() 27 { 28 g_Playernames = []; 29 g_Replays = Engine.GetReplays(); 30 for (let replay of g_Replays) 31 { 32 // Use time saved in file, otherwise file mod date 33 replay.timestamp = replay.attribs.hasOwnProperty("timestamp") ? replay.attribs.timestamp : replay.filemod_timestamp; 34 35 // Skirmish maps don't have that attribute 36 if (!replay.attribs.settings.hasOwnProperty("Size")) 37 replay.attribs.settings.Size = -1; 38 39 // Extract all map names 40 if (g_MapNames.indexOf(replay.attribs.settings.Name) == -1) 41 g_MapNames.push(replay.attribs.settings.Name); 42 43 // Extract all playernames, used by autocomplete feature 44 for (let playerData of replay.attribs.settings.PlayerData) 45 { 46 if (playerData) 47 { 48 let name = playerData.Name; 49 if (g_Playernames.indexOf(name) == -1) 50 g_Playernames.push({"name": name}); 51 } 52 } 53 } 54 g_MapNames.sort(); 55 } 56 57 function updateReplayList() 58 { 59 let replaySelection = Engine.GetGUIObjectByName("replaySelection"); 60 61 // Filters depend on the replay list 62 initFilters(); 63 64 if (g_Replays.length == 0) 65 replaySelection.selected = -1; 66 67 // Sort replays 68 g_Replays.sort(function(a,b) 69 { 70 let cmpA, cmpB; 71 switch (g_ReplayListSortBy) 72 { 73 case 'name': 74 cmpA = a.timestamp; 75 cmpB = b.timestamp; 76 break; 77 case 'duration': 78 cmpA = a.duration; 79 cmpB = b.duration; 80 break; 81 case 'players': 82 cmpA = a.attribs.settings.PlayerData.length; 83 cmpB = b.attribs.settings.PlayerData.length; 84 break; 85 case 'mapName': 86 cmpA = getReplayMapName(a); 87 cmpB = getReplayMapName(b); 88 break; 89 case 'mapSize': 90 cmpA = a.attribs.settings.Size; 91 cmpB = b.attribs.settings.Size; 92 break; 93 case 'popCapacity': 94 cmpA = a.attribs.settings.PopulationCap; 95 cmpB = b.attribs.settings.PopulationCap; 96 break; 97 } 98 99 // Sort by selected column 100 if (cmpA < cmpB) 101 return -g_ReplayListOrder; 102 else if (cmpA > cmpB) 103 return g_ReplayListOrder; 104 105 // Sort by date/time as a tiebreaker and keep most recent replays at the top 106 if (a.timestamp < b.timestamp) 107 return 1; 108 else if (a.timestamp > b.timestamp) 109 return -1; 110 111 return 0; 112 }); 113 114 // Filter replays and create GUI list data 115 let replayListLabels = []; 116 let replayListDirectories = []; 117 let list_name = []; 118 let list_players = []; 119 let list_mapName = []; 120 let list_mapSize = []; 121 let list_popCapacity = []; 122 let list_duration = []; 123 g_ReplaysFiltered = []; 124 for (let replay of g_Replays) 125 { 126 if (filterReplay(replay)) 127 continue; 128 129 g_ReplaysFiltered.push(replay); 130 replayListLabels.push(replay.directory); 131 replayListDirectories.push(replay.directory); 132 133 list_name.push(Greyout(replay, getReplayDateTime(replay))); 134 list_players.push(Greyout(replay, getReplayPlayernames(replay, true))); 135 list_mapName.push(Greyout(replay, getReplayMapName(replay))); 136 list_mapSize.push(Greyout(replay, translateMapSize(replay.attribs.settings.Size))); 137 list_popCapacity.push(Greyout(replay, translatePopulationCapacity(replay.attribs.settings.PopulationCap))); 138 list_duration.push(Greyout(replay, getReplayDuration(replay))); 139 } 140 141 // TODO: enhancement: remember last selection, like #3244 142 if (replaySelection.selected >= list_name.length) 143 replaySelection.selected = -1; 144 145 // Update list 146 replaySelection.list_name = list_name; 147 replaySelection.list_players = list_players; 148 replaySelection.list_mapName = list_mapName; 149 replaySelection.list_mapSize = list_mapSize; 150 replaySelection.list_popCapacity = list_popCapacity; 151 replaySelection.list_duration = list_duration; 152 153 replaySelection.list = replayListLabels; 154 replaySelection.list_data = replayListDirectories; 155 } 156 157 function updateReplayListOrderSelection() 158 { 159 g_ReplayListSortBy = Engine.GetGUIObjectByName("replaySelection").selected_column; 160 g_ReplayListOrder = Engine.GetGUIObjectByName("replaySelection").selected_column_order; 161 applyFilters(); 162 } 163 164 function Greyout(replay, text) 165 { 166 if (isReplayCompatible(replay)) 167 return text; 168 else 169 return '[color="128 128 128"]' + text + '[/color]'; 170 } 171 172 function getReplayDateTime(replay) 173 { 174 // TODO: enhancement: use local time instead of UTC 175 return Engine.FormatMillisecondsIntoDateString(replay.timestamp * 1000, translate("yyyy-MM-dd HH:mm")) 176 } 177 178 function getReplayPlayernames(replay, shorten) 179 { 180 // Extract playernames 181 let playernames = []; 182 for (let playerData of replay.attribs.settings.PlayerData) 183 { 184 if (playerData) 185 { 186 let playername = escapeText(playerData.Name); 187 188 // TODO: enhancement: colorize playernames like in lobby using colorPlayerName 189 // #3205 moves the function to common/color.js 190 playernames.push(playername); 191 } 192 } 193 194 if (!shorten) 195 return playernames; 196 197 playernames = playernames.join(", "); 198 199 // Shorten if too long 200 if (playernames.length > g_maxPlayerlistChars) 201 return playernames.substr(0, g_maxPlayerlistChars) + "..."; 202 else 203 return playernames; 204 } 205 206 function getReplayMapName(replay) 207 { 208 return escapeText(translate(replay.attribs.settings.Name)); 209 } 210 211 function getReplayMonth(replay) 212 { 213 return Engine.FormatMillisecondsIntoDateString(replay.timestamp * 1000, translate("yyyy-MM")); 214 } 215 216 function getReplayDuration(replay) 217 { 218 return timeToString(replay.duration * 1000); 219 } 220 221 function getReplayTeamText(replay) 222 { 223 let metadata = Engine.GetReplayMetadata(replay.directory); 224 let spoiler = Engine.GetGUIObjectByName("showSpoiler").checked; 225 226 // Extract players and civs by team 227 let teams = {}; 228 let teamCount = 0; 229 let i = 1; 230 for (let playerData of replay.attribs.settings.PlayerData) 231 { 232 if (!playerData) 233 continue; 234 235 // Get player info 236 let playerCiv = translate(g_CivData[playerData.Civ].Name); 237 // TODO: enhancement: too few contrast, see #3205 238 let playerColor = playerData.Color ? playerData.Color : g_DefaultPlayerData[i].Color; 239 let playerName = '[color="' + playerColor.r + " " + playerColor.g + " " + playerColor.b + '"]' + escapeText(playerData.Name) + "[/color]"; 240 let showDefeated = spoiler && metadata.playerStates && metadata.playerStates[i].state == "defeated"; 241 let isAI = (playerData.AI); 242 let AIname = translateAIName(playerData.AI); 243 let AIdiff = translateAIDifficulty(playerData.AIDiff); 244 245 // Create player text 246 let playerDetails; 247 if (!isAI && !showDefeated) 248 playerDetails = sprintf(translateWithContext("replay player description", "%(playerName)s (%(civilization)s)"), 249 { "playerName": playerName, "civilization": playerCiv}); 250 else if (isAI && !showDefeated) 251 playerDetails = sprintf(translateWithContext("replay player description", "%(playerName)s (%(civilization)s, %(AIdifficulty)s %(AIname)s)"), 252 { "playerName": playerName, "civilization": playerCiv, "AIdifficulty": AIdiff, "AIname": AIname }); 253 else if (!isAI && showDefeated) 254 playerDetails = sprintf(translateWithContext("replay player description", "%(playerName)s (%(civilization)s, defeated)"), 255 { "playerName": playerName, "civilization": playerCiv}); 256 else 257 playerDetails = sprintf(translateWithContext("replay player description", "%(playerName)s (%(civilization)s, %(AIdifficulty)s %(AIname)s, defeated)"), 258 { "playerName": playerName, "civilization": playerCiv, "AIdifficulty": AIdiff, "AIname": AIname }); 259 260 // Add player text to playerlist 261 let team = playerData.Team; 262 if (teams.hasOwnProperty(team)) 263 teams[team].push(playerDetails); 264 else 265 { 266 teams[team] = [playerDetails]; 267 teamCount++; 268 } 269 i++; 270 } 271 272 // Create player info text sorted by team 273 let teamString = ""; 274 for (let team in teams) 275 { 276 if (teamCount > 1) 277 { 278 if (team == -1) 279 teamString += '[font="sans-bold-14"]No Team:[/font]\n'; 280 else 281 teamString += '[font="sans-bold-14"]Team ' + (parseInt(team) + 1) + "[/font]:\n"; 282 } 283 teamString += teams[team].join("\n") + "\n"; 284 } 285 286 return teamString; 287 } 288 289 function isReplayCompatible(replay) 290 { 291 if (!isReplayCompatible_EngineVersion(replay)) 292 return false; 293 294 // Now check mods 295 let gameMods = replay.attribs.mods ? replay.attribs.mods : []; 296 297 if (gameMods.length != g_EngineInfo.mods.length) 298 return false; 299 300 for (let i = 0; i < gameMods.length; ++i) 301 if (gameMods[i] != g_EngineInfo.mods[i]) 302 return false; 303 304 return true; 305 } 306 307 function isReplayCompatible_EngineVersion(replay) 308 { 309 return replay.attribs.hasOwnProperty("engine_version") 310 && replay.attribs.engine_version == g_EngineInfo.engine_version; 311 } 312 313 function initFilters() 314 { 315 initDateFilter(); 316 initMapNameFilter(); 317 initMapSizeFilter(); 318 initPopCapFilter(); 319 initDurationFilter(); 320 } 321 322 function initDateFilter() 323 { 324 let months = [translateWithContext("DateTime", "Any")]; 325 for (let replay of g_Replays) 326 { 327 let month = getReplayMonth(replay); 328 329 if (months.indexOf(month) == -1) 330 months.push(month); 331 } 332 333 let dateTimeFilter = Engine.GetGUIObjectByName("dateTimeFilter"); 334 dateTimeFilter.list = months; 335 dateTimeFilter.list_data = months; 336 337 if (dateTimeFilter.selected == -1 || dateTimeFilter.selected >= dateTimeFilter.list.length) 338 dateTimeFilter.selected = 0; 339 } 340 341 function initMapSizeFilter() 342 { 343 let mapSizeFilter = Engine.GetGUIObjectByName("mapSizeFilter"); 344 mapSizeFilter.list = [translateWithContext("map size", "Any")].concat(g_MapSizes.names); 345 mapSizeFilter.list_data = [-1].concat(g_MapSizes.tiles); 346 347 if (mapSizeFilter.selected == -1 || mapSizeFilter.selected >= mapSizeFilter.list.length) 348 mapSizeFilter.selected = 0; 349 } 350 351 function initMapNameFilter() 352 { 353 let mapNameFilter = Engine.GetGUIObjectByName("mapNameFilter"); 354 mapNameFilter.list = [translateWithContext("map name", "Any")].concat(g_MapNames); 355 mapNameFilter.list_data = [""].concat(g_MapNames.map(mapName => translate(mapName))); 356 357 if (mapNameFilter.selected == -1 || mapNameFilter.selected >= mapNameFilter.list.length) 358 mapNameFilter.selected = 0; 359 } 360 361 function initPopCapFilter() 362 { 363 let populationFilter = Engine.GetGUIObjectByName("populationFilter"); 364 populationFilter.list = [translateWithContext("population capacity", "Any")].concat(g_PopCaps.titles); 365 populationFilter.list_data = [""].concat(g_PopCaps.population); 366 367 if (populationFilter.selected == -1 || populationFilter.selected >= populationFilter.list.length) 368 populationFilter.selected = 0; 369 } 370 371 function initDurationFilter() 372 { 373 let data = [-1]; 374 let labels = ["Any"]; 375 376 for (let i in g_DurationFilterMin) 377 { 378 let label; 379 if (i == 0) 380 continue; 381 else if (i == 1) 382 label = sprintf(translateWithContext("duration filter", "< %(min)s min"), { "min": g_DurationFilterMax[i] }); 383 else if (i == g_DurationFilterMin.length -1) 384 label = sprintf(translateWithContext("duration filter", "> %(min)s min"), { "min": g_DurationFilterMin[i] }); 385 else 386 label = sprintf(translateWithContext("duration filter", "%(min1)s - %(min2)s min"), { "min1": g_DurationFilterMin[i], "min2": g_DurationFilterMax[i] }); 387 388 data.push(i); 389 labels.push(label); 390 } 391 392 let durationFilter = Engine.GetGUIObjectByName("durationFilter"); 393 durationFilter.list = labels; 394 durationFilter.list_data = data; 395 396 if (durationFilter.selected == -1 || durationFilter.selected >= data.length) 397 durationFilter.selected = 0; 398 } 399 400 function applyFilters() 401 { 402 // Update the list of replays 403 updateReplayList(); 404 405 // Update info box about the replay currently selected 406 updateReplaySelection(); 407 } 408 409 // Returns true if the replay should not be listed. 410 function filterReplay(replay) 411 { 412 let dateTimeFilter = Engine.GetGUIObjectByName("dateTimeFilter"); 413 let playersFilter = Engine.GetGUIObjectByName("playersFilter"); 414 let mapNameFilter = Engine.GetGUIObjectByName("mapNameFilter"); 415 let mapSizeFilter = Engine.GetGUIObjectByName("mapSizeFilter"); 416 let populationFilter = Engine.GetGUIObjectByName("populationFilter"); 417 let durationFilter = Engine.GetGUIObjectByName("durationFilter"); 418 let compabilityFilter = Engine.GetGUIObjectByName("compabilityFilter"); 419 420 // Check for compability first (most likely to filter) 421 if (compabilityFilter.checked && !isReplayCompatible(replay)) 422 return true; 423 424 // Filter date/time (select a month) 425 if (dateTimeFilter.selected > 0) 426 { 427 let selectedMonth = dateTimeFilter.list_data[dateTimeFilter.selected]; 428 if (getReplayMonth(replay) != selectedMonth) 429 return true; 430 } 431 432 // Filter selected players 433 let playerText = playersFilter.caption; 434 if (playerText.length) 435 { 436 // Player and botnames can contain spaces 437 // We just check if all words of all players are somewhere in the playerlist 438 playerText = playerText.toLowerCase().split(" "); 439 let replayPlayers = replay.attribs.settings.PlayerData.map(function(player){ return player ? player.Name.toLowerCase() : "" }).join(" "); 440 for (let word of playerText) 441 { 442 if (replayPlayers.indexOf(word) == -1) 443 return true; 444 } 445 } 446 447 // Filter map name 448 if (mapNameFilter.selected > 0 && getReplayMapName(replay) != mapNameFilter.list_data[mapNameFilter.selected]) 449 return true; 450 451 // Filter map size 452 if (mapSizeFilter.selected > 0 && replay.attribs.settings.Size != mapSizeFilter.list_data[mapSizeFilter.selected]) 453 return true; 454 455 // Filter population capacity 456 if (populationFilter.selected > 0 && replay.attribs.settings.PopulationCap != populationFilter.list_data[populationFilter.selected]) 457 return true; 458 459 // Filter game duration 460 if (durationFilter.selected > 0) 461 { 462 let minutes = replay.duration / 60; 463 let min = g_DurationFilterMin[durationFilter.selected]; 464 let max = g_DurationFilterMax[durationFilter.selected]; 465 466 if (minutes < min || (max > -1 && minutes > max)) 467 return true; 468 } 469 470 return false; 471 } 472 473 function updateReplaySelection() 474 { 475 let selected = Engine.GetGUIObjectByName("replaySelection").selected; 476 let replaySelected = selected > -1; 477 478 Engine.GetGUIObjectByName("replayInfo").hidden = !replaySelected; 479 Engine.GetGUIObjectByName("replayInfoEmpty").hidden = replaySelected; 480 Engine.GetGUIObjectByName("startReplayButton").enabled = replaySelected; 481 Engine.GetGUIObjectByName("deleteReplayButton").enabled = replaySelected; 482 Engine.GetGUIObjectByName("summaryButton").enabled = replaySelected; 483 484 if (!replaySelected) 485 return; 486 487 let replay = g_ReplaysFiltered[selected]; 488 489 // Load map data 490 let mapData = {}; 491 if (replay.attribs.settings.mapType == "random" && replay.attribs.map == "random") 492 mapData = {"settings": {"Description": translate("A randomly selected map.")}}; 493 else if (replay.attribs.settings.mapType == "random" && Engine.FileExists(replay.attribs.map + ".json")) 494 mapData = Engine.ReadJSONFile(replay.attribs.map + ".json"); 495 else if (Engine.FileExists(replay.attribs.map + ".xml")) 496 mapData = Engine.LoadMapSettings(replay.attribs.map + ".xml"); 497 else 498 // Warn the player if we can't find the map. 499 warn(sprintf("Map '%(mapName)s' not found locally.", { mapName: replay.attribs.map })); 500 501 // Load map description 502 let mapDescription; 503 if (mapData && mapData.settings.Description) 504 mapDescription = translate(mapData.settings.Description); 505 else 506 mapDescription = translate("Sorry, no description available."); 507 508 // Load map preview image 509 let mapPreview; 510 if (mapData && mapData.settings.Preview) 511 mapPreview = mapData.settings.Preview; 512 else 513 mapPreview = "nopreview.png"; 514 515 // Update GUI, compare with gamesetup.js for translations 516 Engine.GetGUIObjectByName("sgMapName").caption = translate(replay.attribs.settings.Name); 517 Engine.GetGUIObjectByName("sgMapSize").caption = translateMapSize(replay.attribs.settings.Size); 518 Engine.GetGUIObjectByName("sgMapType").caption = translateMapType(replay.attribs.settings.mapType); 519 Engine.GetGUIObjectByName("sgVictory").caption = translateGameType(replay.attribs.settings.GameType); 520 Engine.GetGUIObjectByName("sgNbPlayers").caption = replay.attribs.settings.PlayerData.length; 521 Engine.GetGUIObjectByName("sgPlayersNames").caption = getReplayTeamText(replay); 522 Engine.GetGUIObjectByName("sgMapDescription").caption = mapDescription; 523 Engine.GetGUIObjectByName("sgMapPreview").sprite = "cropped:(0.7812,0.5859)session/icons/mappreview/" + mapPreview; 524 } 525 526 function startReplay() 527 { 528 let selected = Engine.GetGUIObjectByName("replaySelection").selected; 529 if (selected == -1) 530 return; 531 532 let replay = g_ReplaysFiltered[selected]; 533 if (isReplayCompatible(replay)) 534 reallyStartVisualReplay(replay.directory); 535 else 536 displayReplayCompatibilityError(replay); 537 } 538 539 function reallyStartVisualReplay(replayDirectory) 540 { 541 // TODO: enhancement: remember filter settings and selected item. restore settings when returning from the replay. 542 Engine.StartVisualReplay(replayDirectory); 543 Engine.SwitchGuiPage("page_loading.xml", { 544 "attribs": Engine.GetReplayAttributes(replayDirectory), 545 "isNetworked" : false, 546 "playerAssignments": {}, 547 "savedGUIData": "", 548 "isReplay" : true 549 }); 550 } 551 552 function displayReplayCompatibilityError(replay) 553 { 554 let errMsg; 555 if (isReplayCompatible_EngineVersion(replay)) 556 { 557 let gameMods; 558 if (replay.attribs.mods) 559 gameMods = replay.attribs.mods; 560 else 561 gameMods = []; 562 563 errMsg = translate("The replay is compatible with your version of the game, but you don't have the same mods as in the replay.") + "\n"; 564 errMsg += sprintf(translate("Mods enabled in the replay: %(mods)s"), { "mods": gameMods.join(",") }) + "\n"; 565 errMsg += sprintf(translate("Currently enabled mods: %(mods)s"), { "mods": g_EngineInfo.mods.join(",") }); 566 } 567 else 568 { 569 errMsg = translate("This replay is not compatible with your version of the game!"); 570 } 571 572 let btCaptions = [translate("Ok")]; 573 let btCode = [null]; 574 messageBox(500, 200, errMsg, translate("REPLAY INCOMPATIBLE"), 0, btCaptions, btCode); 575 } 576 577 function showReplaySummary() 578 { 579 let selected = Engine.GetGUIObjectByName("replaySelection").selected; 580 if (selected == -1) 581 return; 582 583 let replay = g_ReplaysFiltered[selected]; 584 let summary = Engine.GetReplayMetadata(replay.directory); 585 586 if (Object.keys(summary) == 0) 587 { 588 let btCaptions = [translate("Ok")]; 589 let btCode = [null]; 590 messageBox(500, 200, translateWithContext("replay", "No summary data found!"), translate("ERROR"), 0, btCaptions, btCode); 591 return; 592 } 593 594 summary.isReplay = true; 595 summary.gameResult = translateWithContext("replay", "Scores at the end of the game."); 596 597 Engine.SwitchGuiPage("page_summary.xml", summary); 598 } 599 600 function deleteReplay() 601 { 602 let selected = Engine.GetGUIObjectByName("replaySelection").selected; 603 if (selected == -1) 604 return; 605 606 // Ask for confirmation 607 let replay = g_ReplaysFiltered[selected]; 608 let btCaptions = [translate("Yes"), translate("No")]; 609 let btCode = [function(){ reallyDeleteReplay(replay.directory); }, null]; 610 messageBox(500, 200, translate("Are you sure to delete this replay permanently?") + "\n" + replay.file, translate("DELETE"), 0, btCaptions, btCode); 611 } 612 613 function deleteReplayWithoutConfirmation() 614 { 615 let selected = Engine.GetGUIObjectByName("replaySelection").selected; 616 if (selected > -1) 617 reallyDeleteReplay(g_ReplaysFiltered[selected].directory); 618 } 619 620 function reallyDeleteReplay(replayDirectory) 621 { 622 if (!Engine.DeleteReplay(replayDirectory)) 623 error(sprintf("Could not delete replay '%(id)s'", { id: replayDirectory })); 624 625 // Refresh replay list 626 init(); 627 } 628 No newline at end of file -
binaries/data/mods/public/gui/replaymenu/replaymenu.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 3 <objects> 4 5 <script file="gui/aiconfig/aiconfig.js"/> 6 <script file="gui/common/functions_civinfo.js" /> 7 <script file="gui/common/functions_global_object.js" /> 8 <script file="gui/common/functions_utility.js" /> 9 <script file="gui/replaymenu/replaymenu.js" /> 10 <script directory="gui/gamesetup/victory_conditions/"/> 11 12 <object type="image" style="ModernWindow" size="0 0 100% 100%" name="replayWindow"> 13 14 <object style="ModernLabelText" type="text" size="50%-128 0%+4 50%+128 36"> 15 <translatableAttribute id="caption">Replay Games</translatableAttribute> 16 </object> 17 18 <!-- Left Panel: Filters & Replay List --> 19 <object name="leftPanel" size="3% 5% 100%-255 100%-80"> 20 21 <!-- Filters --> 22 <object name="filterPanel" size="0 0 100% 24"> 23 <object name="dateTimeFilter" 24 type="dropdown" 25 style="ModernDropDown" 26 size="5 0 110-10 100%" 27 font="sans-bold-13"> 28 <action on="SelectionChange">applyFilters();</action> 29 </object> 30 <object name="playersFilter" 31 type="input" 32 style="ModernInput" 33 size="110-5 0 110+400-10 100%" 34 font="sans-bold-13"> 35 <action on="Press">applyFilters();</action> 36 <action on="Tab">autoCompleteNick("playersFilter", g_Playernames);</action> 37 </object> 38 <object name="mapNameFilter" 39 type="dropdown" 40 style="ModernDropDown" 41 size="110+400-5 0 110+400+140-10 100%" 42 font="sans-bold-13"> 43 <action on="SelectionChange">applyFilters();</action> 44 </object> 45 <object name="mapSizeFilter" 46 type="dropdown" 47 style="ModernDropDown" 48 size="110+400+140-5 0 110+400+140+80-10 100%" 49 font="sans-bold-13"> 50 <action on="SelectionChange">applyFilters();</action> 51 </object> 52 <object name="populationFilter" 53 type="dropdown" 54 style="ModernDropDown" 55 size="110+400+140+80-5 0 110+400+140+80+80-10 100%" 56 font="sans-bold-13"> 57 <action on="SelectionChange">applyFilters();</action> 58 </object> 59 <object name="durationFilter" 60 type="dropdown" 61 style="ModernDropDown" 62 size="110+400+140+80+80-5 0 110+400+140+80+80+80-10 100%" 63 font="sans-bold-13"> 64 <action on="SelectionChange">applyFilters();</action> 65 </object> 66 <object name="compabilityFilter" 67 type="checkbox" 68 checked="true" 69 style="ModernTickBox" 70 size="110+400+140+80+80+73 4 110+400+140+80+80+70+20 100%" 71 font="sans-bold-13"> 72 <action on="Press">applyFilters();</action> 73 </object> 74 <object type="text" size="110+400+140+80+80+80+10 2 100% 100%" text_align="left" textcolor="white"> 75 <translatableAttribute id="caption">Compatible</translatableAttribute> 76 </object> 77 </object> 78 79 <!-- Replay list --> 80 <object name="replaySelection" size="0 35 100% 100%" style="ModernList" type="olist" sortable="true" default_column="name" sprite_asc="ModernArrowDown" sprite_desc="ModernArrowUp" sprite_not_sorted="ModernNotSorted" font="sans-stroke-13"> 81 <action on="SelectionChange">updateReplaySelection();</action> 82 <action on="SelectionColumnChange">updateReplayListOrderSelection();</action> 83 <!-- Columns --> 84 <!-- 0ad crashes if there is no column with the id "name"! --> 85 <def id="name" color="0 128 128" width="110"> 86 <translatableAttribute id="heading" context="replay">Date / Time</translatableAttribute> 87 </def> 88 <def id="players" color="0 128 128" width="400"> 89 <translatableAttribute id="heading" context="replay">Players</translatableAttribute> 90 </def> 91 <def id="mapName" color="0 128 128" width="140"> 92 <translatableAttribute id="heading" context="replay">Map Name</translatableAttribute> 93 </def> 94 <def id="mapSize" color="0 128 128" width="80"> 95 <translatableAttribute id="heading" context="replay">Size</translatableAttribute> 96 </def> 97 <def id="popCapacity" color="0 128 128" width="80"> 98 <translatableAttribute id="heading" context="replay">Population</translatableAttribute> 99 </def> 100 <def id="duration" color="0 128 128" width="80"> 101 <translatableAttribute id="heading" context="replay">Duration</translatableAttribute> 102 </def> 103 </object> 104 </object> 105 106 <!-- Right Panel: Replay Details --> 107 <object name="rightPanel" size="100%-250 30 100%-20 100%-20" > 108 109 <object name="replayInfoEmpty" size="0 0 100% 100%-60" type="image" sprite="ModernDarkBoxGold" hidden="false"> 110 <object name="logo" size="50%-110 40 50%+110 140" type="image" sprite="logo"/> 111 <object name="subjectBox" type="image" sprite="ModernDarkBoxWhite" size="3% 180 97% 99%"> 112 <object name="subject" size="5 5 100%-5 100%-5" type="text" style="ModernText" text_align="center"/> 113 </object> 114 </object> 115 116 <object name="replayInfo" size="0 0 100% 100%-60" type="image" sprite="ModernDarkBoxGold" hidden="true"> 117 118 <!-- Map Name --> 119 <object name="sgMapName" size="0 5 100% 20" type="text" style="ModernLabelText"/> 120 121 <!-- Map Preview --> 122 <object name="sgMapPreview" size="5 25 100%-5 190" type="image" sprite=""/> 123 124 <object size="5 194 100%-5 195" type="image" sprite="ModernWhiteLine" z="25"/> 125 126 <!-- Map Type --> 127 <object size="5 195 50% 225" type="image" sprite="ModernItemBackShadeLeft"> 128 <object size="0 0 100%-10 100%" type="text" style="ModernLabelText" text_align="right"> 129 <translatableAttribute id="caption">Map Type:</translatableAttribute> 130 </object> 131 </object> 132 <object size="50% 195 100%-5 225" type="image" sprite="ModernItemBackShadeRight"> 133 <object name="sgMapType" size="0 0 100% 100%" type="text" style="ModernLabelText" text_align="left"/> 134 </object> 135 136 <object size="5 224 100%-5 225" type="image" sprite="ModernWhiteLine" z="25"/> 137 138 <!-- Map Size --> 139 <object size="5 225 50% 255" type="image" sprite="ModernItemBackShadeLeft"> 140 <object size="0 0 100%-10 100%" type="text" style="ModernLabelText" text_align="right"> 141 <translatableAttribute id="caption">Map Size:</translatableAttribute> 142 </object> 143 </object> 144 <object size="50% 225 100%-5 255" type="image" sprite="ModernItemBackShadeRight"> 145 <object name="sgMapSize" size="0 0 100% 100%" type="text" style="ModernLabelText" text_align="left"/> 146 </object> 147 148 <object size="5 254 100%-5 255" type="image" sprite="ModernWhiteLine" z="25"/> 149 150 <!-- Victory Condition --> 151 <object size="5 255 50% 285" type="image" sprite="ModernItemBackShadeLeft"> 152 <object size="0 0 100%-10 100%" type="text" style="ModernLabelText" text_align="right"> 153 <translatableAttribute id="caption">Victory:</translatableAttribute> 154 </object> 155 </object> 156 <object size="50% 255 100%-5 285" type="image" sprite="ModernItemBackShadeRight"> 157 <object name="sgVictory" size="0 0 100% 100%" type="text" style="ModernLabelText" text_align="left"/> 158 </object> 159 160 <object size="5 284 100%-5 285" type="image" sprite="ModernWhiteLine" z="25"/> 161 162 <!-- Map Description --> 163 <object type="image" sprite="ModernDarkBoxWhite" size="3% 290 97% 70%"> 164 <object name="sgMapDescription" size="0 0 100% 100%" type="text" style="ModernText" font="sans-12"/> 165 </object> 166 167 <object type="image" sprite="ModernDarkBoxWhite" size="3% 70%+5 97% 100%-30"> 168 <!-- Number of Players --> 169 <object size="0% 3% 57% 12%" type="text" style="ModernRightLabelText"> 170 <translatableAttribute id="caption">Players:</translatableAttribute> 171 </object> 172 <object name="sgNbPlayers" size="58% 3% 70% 12%" type="text" style="ModernLeftLabelText" text_align="left"/> 173 174 <!-- Player Names --> 175 <object name="sgPlayersNames" size="0 15% 100% 100%" type="text" style="MapPlayerList"/> 176 </object> 177 178 <object name="showSpoiler" 179 type="checkbox" 180 checked="false" 181 style="ModernTickBox" 182 size="10 100%-27 30 100%" 183 font="sans-bold-13"> 184 <action on="Press">updateReplaySelection();</action> 185 </object> 186 <object type="text" size="30 100%-28 100% 100%" text_align="left" textcolor="white"> 187 <translatableAttribute id="caption">Spoiler</translatableAttribute> 188 </object> 189 190 </object> 191 </object> 192 193 <!-- Bottom Panel: Buttons. --> 194 <object name="bottomPanel" size="25 100%-55 100%-5 100%-25" > 195 196 <object type="button" style="StoneButton" size="0%+25 0 17%+25 100%"> 197 <translatableAttribute id="caption">Main Menu</translatableAttribute> 198 <action on="Press"> 199 Engine.SwitchGuiPage("page_pregame.xml"); 200 </action> 201 </object> 202 203 <object name="deleteReplayButton" type="button" style="StoneButton" size="20%+25 0 37%+25 100%" hotkey="session.savedgames.delete"> 204 <translatableAttribute id="caption">Delete</translatableAttribute> 205 <action on="Press"> 206 if (!this.enabled) 207 return; 208 if (Engine.HotkeyIsPressed("session.savedgames.noConfirmation")) 209 deleteReplayWithoutConfirmation(); 210 else 211 deleteReplay(); 212 </action> 213 </object> 214 215 <object name="summaryButton" type="button" style="StoneButton" size="65%-50 0 82%-50 100%"> 216 <translatableAttribute id="caption">Summary</translatableAttribute> 217 <action on="Press"> 218 showReplaySummary(); 219 </action> 220 </object> 221 222 <object name="startReplayButton" type="button" style="StoneButton" size="83%-25 0 100%-25 100%"> 223 <translatableAttribute id="caption">Start Replay</translatableAttribute> 224 <action on="Press"> 225 startReplay(); 226 </action> 227 </object> 228 229 </object> 230 </object> 231 </objects> -
binaries/data/mods/public/gui/replaymenu/styles.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 3 <styles> 4 <style name="MapPlayerList" 5 buffer_zone="8" 6 font="sans-14" 7 scrollbar="true" 8 scrollbar_style="ModernScrollBar" 9 scroll_bottom="true" 10 textcolor="white" 11 text_align="left" 12 text_valign="top" 13 /> 14 </styles> -
binaries/data/mods/public/gui/session/session.js
5 5 var g_IsController; 6 6 // Match ID for tracking 7 7 var g_MatchID; 8 8 // Is this user an observer? 9 9 var g_IsObserver = false; 10 var g_IsReplay = false; 10 11 11 12 // Cache the basic player data (name, civ, color) 12 13 var g_Players = []; 13 14 // Cache the useful civ data 14 15 var g_CivData = {}; … … 149 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 155 g_IsReplay = initData.isReplay; // Set replay mode 154 156 g_PlayerAssignments = initData.playerAssignments; 155 157 g_MatchID = initData.attribs.matchID; 156 158 157 159 // Cache the player data 158 160 // (This may be updated at runtime by handleNetMessage) … … 310 312 * @param willRejoin If player is going to be rejoining a networked game. 311 313 */ 312 314 function leaveGame(willRejoin) 313 315 { 314 316 var extendedSimState = Engine.GuiInterfaceCall("GetExtendedSimulationState"); 315 var mapSettings = Engine.GetMapSettings();316 317 var gameResult; 317 318 318 if (g_IsObserver) 319 319 { 320 320 // Observers don't win/lose. 321 321 gameResult = translate("You have left the game."); 322 322 global.music.setState(global.music.states.VICTORY); … … 342 342 } 343 343 } 344 344 } 345 345 346 346 stopAmbient(); 347 Engine.EndGame();348 347 348 // Save summary screen data before ending the game 349 // TODO: enhancement: how to save the data if the user exits with Alt+F4? 350 let summary = { 351 "timeElapsed" : extendedSimState.timeElapsed, 352 "playerStates": extendedSimState.players, 353 "players": g_Players, 354 "mapSettings": Engine.GetMapSettings() 355 }; 356 if (!g_IsReplay) 357 Engine.SaveReplayMetadata(JSON.stringify(summary)); 358 summary.isReplay = g_IsReplay; 359 summary.gameResult = gameResult; 360 361 Engine.EndGame(); 349 362 if (g_IsController && Engine.HasXmppClient()) 350 363 Engine.SendUnregisterGame(); 351 364 352 Engine.SwitchGuiPage("page_summary.xml", { 353 "gameResult" : gameResult, 354 "timeElapsed" : extendedSimState.timeElapsed, 355 "playerStates": extendedSimState.players, 356 "players": g_Players, 357 "mapSettings": mapSettings 358 }); 365 Engine.SwitchGuiPage("page_summary.xml", summary); 359 366 } 360 367 361 368 // Return some data that we'll use when hotloading this file after changes 362 369 function getHotloadData() 363 370 { -
binaries/data/mods/public/gui/summary/summary.js
28 28 const INCOME_COLOR = '[color="201 255 200"]'; 29 29 const OUTCOME_COLOR = '[color="255 213 213"]'; 30 30 31 31 const DEFAULT_DECIMAL = "0.00"; 32 32 const INFINITE_SYMBOL = "\u221E"; 33 var g_IsReplay = false; 33 34 // Load data 34 35 var g_CivData = loadCivData(); 35 36 var g_Teams = []; 36 37 // TODO set g_MaxPlayers as playerCounters.length 37 38 var g_MaxPlayers = 0; … … 132 133 133 134 function init(data) 134 135 { 135 136 updateObjectPlayerPosition(); 136 137 g_GameData = data; 138 g_IsReplay = data.isReplay; 137 139 138 140 // Map 139 141 var mapDisplayType = translate("Scenario"); 140 142 141 143 Engine.GetGUIObjectByName("timeElapsed").caption = sprintf(translate("Game time elapsed: %(time)s"), { time: timeToString(data.timeElapsed) }); -
binaries/data/mods/public/gui/summary/summary.xml
155 155 </object> 156 156 157 157 <object type="button" style="ModernButtonRed" size="100%-160 100%-48 100%-20 100%-20"> 158 158 <translatableAttribute id="caption">Continue</translatableAttribute> 159 159 <action on="Press"><![CDATA[ 160 if ( !Engine.HasXmppClient())160 if (Engine.HasXmppClient()) 161 161 { 162 Engine.SwitchGuiPage("page_pregame.xml"); 162 Engine.LobbySetPlayerPresence("available"); 163 Engine.SwitchGuiPage("page_lobby.xml"); 164 } 165 else if (g_IsReplay) 166 { 167 Engine.SwitchGuiPage("page_replaymenu.xml"); 163 168 } 164 169 else 165 170 { 166 Engine.LobbySetPlayerPresence("available"); 167 Engine.SwitchGuiPage("page_lobby.xml"); 171 Engine.SwitchGuiPage("page_pregame.xml"); 168 172 } 169 173 ]]> 170 174 </action> 171 175 </object> 172 176 </object> -
binaries/data/mods/public/l10n/messages.json
463 463 } 464 464 }, 465 465 { 466 466 "extractor": "json", 467 467 "filemasks": [ 468 "simulation/data/map_types.json" 469 ], 470 "options": { 471 "keywords": [ 472 "Title" 473 ] 474 } 475 }, 476 { 477 "extractor": "json", 478 "filemasks": [ 468 479 "simulation/data/map_sizes.json" 469 480 ], 470 481 "options": { 471 482 "keywords": [ 472 483 "Name", … … 475 486 } 476 487 }, 477 488 { 478 489 "extractor": "json", 479 490 "filemasks": [ 491 "simulation/data/population_capacity.json" 492 ], 493 "options": { 494 "keywords": [ 495 "Title" 496 ] 497 } 498 }, 499 { 500 "extractor": "json", 501 "filemasks": [ 480 502 "simulation/ai/**.json" 481 503 ], 482 504 "options": { 483 505 "keywords": [ 484 506 "name", 485 507 "description" 486 508 ] 487 509 } 488 } 510 }, 511 { 512 "extractor": "json", 513 "filemasks": [ 514 "simulation/ai/difficulties.json" 515 ], 516 "options": { 517 "keywords": [ 518 "Title" 519 ] 520 } 521 }, 489 522 ] 490 523 }, 491 524 { 492 525 "output": "public-maps.pot", 493 526 "inputRoot": "..", -
binaries/data/mods/public/simulation/ai/difficulties.json
1 { 2 "Difficulties": 3 [ 4 { 5 "Name": "sandbox", 6 "Title": "Sandbox" 7 }, 8 { 9 "Name": "very easy", 10 "Title": "Very Easy" 11 }, 12 { 13 "Name": "easy", 14 "Title": "Easy" 15 }, 16 { 17 "Name": "medium", 18 "Title": "Medium", 19 "Default": true 20 }, 21 { 22 "Name": "hard", 23 "Title": "Hard" 24 }, 25 { 26 "Name": "very hard", 27 "Title": "Very Hard" 28 } 29 ] 30 } 31 No newline at end of file -
binaries/data/mods/public/simulation/data/game_speeds.json
31 31 "Speed": 1.5 32 32 }, 33 33 { 34 34 "Name": "Insane (2x)", 35 35 "Speed": 2.0 36 }, 37 { 38 "Name": "Fast forward (5x)", 39 "Speed": 5.0 40 }, 41 { 42 "Name": "Faster forward (10x)", 43 "Speed": 10.0 44 }, 45 { 46 "Name": "Very fast forward (20x)", 47 "Speed": 20.0 36 48 } 37 49 ] 38 50 } -
binaries/data/mods/public/simulation/data/map_types.json
1 { 2 "Types": 3 [ 4 { 5 "Name": "skirmish", 6 "Title": "Skirmish", 7 "Default": true 8 }, 9 { 10 "Name": "random", 11 "Title": "Random" 12 }, 13 { 14 "Name": "scenario", 15 "Title": "Scenario" 16 } 17 ] 18 } 19 No newline at end of file -
binaries/data/mods/public/simulation/data/population_capacity.json
1 { 2 "PopulationCapacity": 3 [ 4 { 5 "Population": 50, 6 "Title": "50" 7 }, 8 { 9 "Population": 100, 10 "Title": "100" 11 }, 12 { 13 "Population": 150, 14 "Title": "150" 15 }, 16 { 17 "Population": 200, 18 "Title": "200" 19 }, 20 { 21 "Population": 250, 22 "Title": "250" 23 }, 24 { 25 "Population": 300, 26 "Title": "300", 27 "Default": true 28 }, 29 { 30 "Population": 10000, 31 "Title": "Unlimited" 32 } 33 ] 34 } -
source/gui/scripting/ScriptFunctions.cpp
48 48 #include "ps/Globals.h" // g_frequencyFilter 49 49 #include "ps/Hotkey.h" 50 50 #include "ps/ProfileViewer.h" 51 51 #include "ps/Pyrogenesis.h" 52 52 #include "ps/SavedGame.h" 53 #include "ps/VisualReplay.h" 53 54 #include "ps/UserReport.h" 54 55 #include "ps/World.h" 55 56 #include "ps/scripting/JSInterface_ConfigDB.h" 56 57 #include "ps/scripting/JSInterface_Console.h" 57 58 #include "ps/scripting/JSInterface_Mod.h" … … 281 282 shared_ptr<ScriptInterface::StructuredClone> GUIMetadataClone = pCxPrivate->pScriptInterface->WriteStructuredClone(GUIMetadata); 282 283 if (SavedGames::SavePrefix(prefix, description, *g_Game->GetSimulation2(), GUIMetadataClone, g_Game->GetPlayerID()) < 0) 283 284 LOGERROR("Failed to save game"); 284 285 } 285 286 287 void StartVisualReplay(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::wstring directoryName) 288 { 289 ENSURE(!g_NetServer); 290 ENSURE(!g_NetClient); 291 ENSURE(!g_Game); 292 293 std::wstring replayFilePath = OsPath(VisualReplay::GetDirectoryName() / directoryName / L"commands.txt").string(); 294 std::string replayFile( replayFilePath.begin(), replayFilePath.end() ); 295 296 if (FileExists(OsPath(replayFile))) 297 { 298 g_Game = new CGame(false, false); 299 g_Game->StartReplay(replayFile); 300 } 301 } 302 303 JS::Value GetReplayAttributes(ScriptInterface::CxPrivate* pCxPrivate, std::wstring directoryName) 304 { 305 return VisualReplay::GetReplayAttributes(pCxPrivate, directoryName); 306 } 307 308 void SaveReplayMetadata(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::wstring data) 309 { 310 VisualReplay::SaveReplayMetadata(data); 311 } 312 313 JS::Value GetReplayMetadata(ScriptInterface::CxPrivate* pCxPrivate, std::wstring directoryName) 314 { 315 return VisualReplay::GetReplayMetadata(pCxPrivate, directoryName); 316 } 317 286 318 void SetNetworkGameAttributes(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue attribs1) 287 319 { 288 320 ENSURE(g_NetServer); 289 321 //TODO: This is a workaround because we need to pass a MutableHandle to a JSAPI functions somewhere 290 322 // (with no obvious reason). … … 415 447 bool DeleteSavedGame(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::wstring name) 416 448 { 417 449 return SavedGames::DeleteSavedGame(name); 418 450 } 419 451 452 JS::Value GetReplays(ScriptInterface::CxPrivate* pCxPrivate) 453 { 454 return VisualReplay::GetReplays(*(pCxPrivate->pScriptInterface)); 455 } 456 457 bool DeleteReplay(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::wstring replayFile) 458 { 459 return VisualReplay::DeleteReplay(replayFile); 460 } 461 420 462 void OpenURL(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string url) 421 463 { 422 464 sys_open_url(url); 423 465 } 424 466 … … 974 1016 scriptInterface.RegisterFunction<void, std::wstring, std::wstring, JS::HandleValue, &SaveGame>("SaveGame"); 975 1017 scriptInterface.RegisterFunction<void, std::wstring, std::wstring, JS::HandleValue, &SaveGamePrefix>("SaveGamePrefix"); 976 1018 scriptInterface.RegisterFunction<void, &QuickSave>("QuickSave"); 977 1019 scriptInterface.RegisterFunction<void, &QuickLoad>("QuickLoad"); 978 1020 1021 // Visual replay 1022 scriptInterface.RegisterFunction<JS::Value, &GetReplays>("GetReplays"); 1023 scriptInterface.RegisterFunction<bool, std::wstring, &DeleteReplay>("DeleteReplay"); 1024 scriptInterface.RegisterFunction<void, std::wstring, &StartVisualReplay>("StartVisualReplay"); 1025 scriptInterface.RegisterFunction<JS::Value, std::wstring, &GetReplayAttributes>("GetReplayAttributes"); 1026 scriptInterface.RegisterFunction<JS::Value, std::wstring, &GetReplayMetadata>("GetReplayMetadata"); 1027 scriptInterface.RegisterFunction<void, std::wstring, &SaveReplayMetadata>("SaveReplayMetadata"); 1028 979 1029 // Misc functions 980 1030 scriptInterface.RegisterFunction<std::wstring, std::wstring, &SetCursor>("SetCursor"); 981 1031 scriptInterface.RegisterFunction<int, &GetPlayerID>("GetPlayerID"); 982 1032 scriptInterface.RegisterFunction<void, int, &SetPlayerID>("SetPlayerID"); 983 1033 scriptInterface.RegisterFunction<void, std::string, &OpenURL>("OpenURL"); -
source/lobby/XmppClient.cpp
22 22 #include "glooxwrapper/glooxwrapper.h" 23 23 #include "i18n/L10n.h" 24 24 #include "lib/utf8.h" 25 25 #include "ps/CLogger.h" 26 26 #include "ps/ConfigDB.h" 27 #include "ps/EngineVersion.h" 27 28 #include "scriptinterface/ScriptInterface.h" 28 29 29 30 //debug 30 31 #if 1 31 32 #define DbgXMPP(x) … … 95 96 const int mechs = gloox::SaslMechAll ^ gloox::SaslMechPlain; 96 97 m_client->setSASLMechanisms(mechs); 97 98 98 99 m_client->registerConnectionListener(this); 99 100 m_client->setPresence(gloox::Presence::Available, -1); 100 m_client->disco()->setVersion("Pyrogenesis", "0.0.19");101 m_client->disco()->setVersion("Pyrogenesis", utf8_from_wstring(engine_version)); 101 102 m_client->disco()->setIdentity("client", "bot"); 102 103 m_client->setCompression(false); 103 104 104 105 m_client->registerStanzaExtension(new GameListQuery()); 105 106 m_client->registerIqHandler(this, EXTGAMELISTQUERY); -
source/network/NetTurnManager.cpp
533 533 ENSURE(m_Simulation2.ComputeStateHash(hash, quickHash)); 534 534 hash = Hexify(hash); 535 535 536 536 if (hash != expectedHash) 537 537 DisplayOOSError(turn, hash, expectedHash, true); 538 539 if (turn == m_FinalReplayTurn) 540 g_GUI->SendEventToAll("ReplayFinished"); 538 541 } 539 542 540 543 void CNetReplayTurnManager::DoTurn(u32 turn) 541 544 { 542 545 // Save turn length -
source/ps/EngineVersion.h
1 const wchar_t engine_version[] = L"0.0.19"; -
source/ps/Game.cpp
134 134 if (type == "turn") 135 135 { 136 136 u32 turn = 0; 137 137 u32 turnLength = 0; 138 138 *m_ReplayStream >> turn >> turnLength; 139 if (turn == 0 && turn != currentTurn) 140 LOGERROR("Looks like you tried to replay a commands.txt file of a rejoined client.\n"); 139 141 ENSURE(turn == currentTurn); 140 142 replayTurnMgr->StoreReplayTurnLength(currentTurn, turnLength); 141 143 } 142 144 else if (type == "cmd") 143 145 { … … 162 164 else 163 165 { 164 166 CancelLoad(L"Failed to load replay data (unrecognized content)"); 165 167 } 166 168 } 169 m_ReplayStream->close(); 167 170 m_FinalReplayTurn = currentTurn; 168 171 replayTurnMgr->StoreFinalReplayTurn(currentTurn); 169 172 return 0; 170 173 } 171 174 … … 389 392 { 390 393 { 391 394 PROFILE3("gui sim update"); 392 395 g_GUI->SendEventToAll("SimulationUpdate"); 393 396 } 394 if (m_IsReplay && m_TurnManager->GetCurrentTurn() == m_FinalReplayTurn - 1)395 g_GUI->SendEventToAll("ReplayFinished");396 397 397 398 GetView()->GetLOSTexture().MakeDirty(); 398 399 } 399 400 400 401 if (CRenderer::IsInitialised()) 401 402 g_Renderer.GetTimeManager().Update(deltaSimTime); 402 403 } 403 404 404 405 if (doInterpolate) -
source/ps/Game.h
176 176 bool m_IsSavedGame; // true if loading a saved game; false for a new game 177 177 178 178 int LoadReplayData(); 179 179 std::string m_ReplayPath; 180 180 bool m_IsReplay; 181 std::i stream* m_ReplayStream;181 std::ifstream* m_ReplayStream; 182 182 u32 m_FinalReplayTurn; 183 183 }; 184 184 185 185 extern CGame *g_Game; 186 186 -
source/ps/GameSetup/GameSetup.cpp
879 879 srand(time(NULL)); // NOTE: this rand should *not* be used for simulation! 880 880 } 881 881 882 882 bool Autostart(const CmdLineArgs& args); 883 883 884 // Returns true if and only if the user has intended to replay a file 885 bool VisualReplay(const std::string replayFile); 884 bool StartVisualReplay(const std::string replayFile); 886 885 887 886 bool Init(const CmdLineArgs& args, int flags) 888 887 { 889 888 h_mgr_init(); 890 889 … … 1078 1077 if (VfsDirectoryExists(L"maps/")) 1079 1078 CXeromyces::AddValidator(g_VFS, "map", "maps/scenario.rng"); 1080 1079 1081 1080 try 1082 1081 { 1083 if (! VisualReplay(args.Get("replay-visual")) && !Autostart(args))1082 if (!StartVisualReplay(args.Get("replay-visual")) && !Autostart(args)) 1084 1083 { 1085 1084 const bool setup_gui = ((flags & INIT_NO_GUI) == 0); 1086 1085 // We only want to display the splash screen at startup 1087 1086 shared_ptr<ScriptInterface> scriptInterface = g_GUI->GetScriptInterface(); 1088 1087 JSContext* cx = scriptInterface->GetContext(); … … 1475 1474 } 1476 1475 1477 1476 return true; 1478 1477 } 1479 1478 1480 bool VisualReplay(const std::string replayFile)1479 bool StartVisualReplay(const std::string replayFile) 1481 1480 { 1482 1481 if (!FileExists(OsPath(replayFile))) 1483 1482 return false; 1484 1483 1485 1484 g_Game = new CGame(false, false); -
source/ps/Pyrogenesis.cpp
1 /* Copyright (C) 20 09Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify 5 5 * it under the terms of the GNU General Public License as published by 6 6 * the Free Software Foundation, either version 2 of the License, or … … 19 19 20 20 #include <cstdio> 21 21 22 22 #include "Pyrogenesis.h" 23 23 24 #include "ps/EngineVersion.h" 24 25 #include "lib/sysdep/sysdep.h" 25 26 #include "lib/svn_revision.h" 26 27 27 28 static const wchar_t* translate_no_mem = L"(no mem)"; 28 29 … … 71 72 72 73 // for user convenience, bundle all logs into this file: 73 74 void psBundleLogs(FILE* f) 74 75 { 75 76 fwprintf(f, L"SVN Revision: %ls\n\n", svn_revision); 77 fwprintf(f, L"Engine Version: %ls\n\n", engine_version); 76 78 77 79 fwprintf(f, L"System info:\n\n"); 78 80 OsPath path1 = psLogDir()/"system_info.txt"; 79 81 AppendAsciiFile(f, path1); 80 82 fwprintf(f, L"\n\n====================================\n\n"); -
source/ps/Replay.cpp
22 22 #include "graphics/TerrainTextureManager.h" 23 23 #include "lib/timer.h" 24 24 #include "lib/file/file_system.h" 25 25 #include "lib/res/h_mgr.h" 26 26 #include "lib/tex/tex.h" 27 #include "ps/EngineVersion.h" 27 28 #include "ps/Game.h" 28 29 #include "ps/Loader.h" 29 30 #include "ps/Profile.h" 31 #include "ps/Mod.h" 30 32 #include "ps/ProfileViewer.h" 31 33 #include "scriptinterface/ScriptInterface.h" 32 34 #include "scriptinterface/ScriptStats.h" 33 35 #include "simulation2/Simulation2.h" 34 36 #include "simulation2/helpers/SimulationCommand.h" … … 50 52 str << std::setfill('0') << std::setw(2) << (int)(unsigned char)s[i]; 51 53 return str.str(); 52 54 } 53 55 54 56 CReplayLogger::CReplayLogger(ScriptInterface& scriptInterface) : 55 m_ScriptInterface(scriptInterface) 57 m_ScriptInterface(scriptInterface), m_Stream(NULL) 58 { 59 } 60 61 CReplayLogger::~CReplayLogger() 62 { 63 delete m_Stream; 64 } 65 66 void CReplayLogger::StartGame(JS::MutableHandleValue attribs) 56 67 { 57 68 // Construct the directory name based on the PID, to be relatively unique. 58 69 // Append "-1", "-2" etc if we run multiple matches in a single session, 59 70 // to avoid accidentally overwriting earlier logs. 60 71 … … 63 74 64 75 static int run = -1; 65 76 if (++run) 66 77 name << "-" << run; 67 78 68 OsPath path = psLogDir() / L"sim_log" / name.str() / L"commands.txt";69 CreateDirectories(path.Parent(), 0700);70 m_S tream = new std::ofstream(OsString(path).c_str(), std::ofstream::out | std::ofstream::trunc);71 } 72 73 CReplayLogger::~CReplayLogger() 74 { 75 delete m_Stream;76 } 77 78 void CReplayLogger::StartGame(JS::MutableHandleValue attribs) 79 { 79 // Add timestamp and engine version to game attributes 80 m_ScriptInterface.SetProperty(attribs, "timestamp", std::time(0)); 81 m_ScriptInterface.SetProperty(attribs, "engine_version", utf8_from_wstring(engine_version)); 82 m_ScriptInterface.SetProperty(attribs, "mods", g_modsLoaded); 83 84 // Remember the directory, so that we can save additional files to it 85 m_Directory = psLogDir() / L"sim_log" / name.str(); 86 OsPath filepath = m_Directory / L"commands.txt"; 87 88 // Open the file when starting the game to prevent empty files 89 CreateDirectories(m_Directory, 0700); 90 m_Stream = new std::ofstream(OsString(filepath).c_str(), std::ofstream::out | std::ofstream::trunc); 80 91 *m_Stream << "start " << m_ScriptInterface.StringifyJSON(attribs, false) << "\n"; 81 92 } 82 93 83 94 void CReplayLogger::Turn(u32 n, u32 turnLength, std::vector<SimulationCommand>& commands) 84 95 { … … 100 111 *m_Stream << "hash-quick " << Hexify(hash) << "\n"; 101 112 else 102 113 *m_Stream << "hash " << Hexify(hash) << "\n"; 103 114 } 104 115 116 OsPath CReplayLogger::GetReplayDirectory() 117 { 118 return m_Directory; 119 } 105 120 //////////////////////////////////////////////////////////////// 106 121 107 122 CReplayPlayer::CReplayPlayer() : 108 123 m_Stream(NULL) 109 124 { … … 157 172 JSContext* cx = g_Game->GetSimulation2()->GetScriptInterface().GetContext(); 158 173 JSAutoRequest rq(cx); 159 174 std::string type; 160 175 while ((*m_Stream >> type).good()) 161 176 { 162 // if (turn >= 1400) break;163 164 177 if (type == "start") 165 178 { 166 179 std::string line; 167 180 std::getline(*m_Stream, line); 168 181 JS::RootedValue attribs(cx); … … 198 211 std::string replayHash; 199 212 *m_Stream >> replayHash; 200 213 201 214 bool quick = (type == "hash-quick"); 202 215 203 // if (turn >= 1300)204 // if (turn >= 0)205 216 if (turn % 100 == 0) 206 217 { 207 218 std::string hash; 208 219 bool ok = g_Game->GetSimulation2()->ComputeStateHash(hash, quick); 209 220 ENSURE(ok); … … 224 235 225 236 g_Game->GetSimulation2()->Update(turnLength, commands); 226 237 commands.clear(); 227 238 } 228 239 229 // std::string hash;230 // bool ok = g_Game->GetSimulation2()->ComputeStateHash(hash, true);231 // ENSURE(ok);232 // debug_printf("%s\n", Hexify(hash).c_str());233 234 240 g_Profiler.Frame(); 235 241 236 // if (turn % 1000 == 0)237 // JS_GC(g_Game->GetSimulation2()->GetScriptInterface().GetContext());238 239 242 if (turn % 20 == 0) 240 243 g_ProfileViewer.SaveToFile(); 241 244 } 242 245 else 243 246 { 244 247 debug_printf("Unrecognised replay token %s\n", type.c_str()); 245 248 } 246 249 } 247 250 } 248 251 m_Stream->close(); 249 252 g_Profiler2.SaveToFile(); 250 253 251 254 std::string hash; 252 255 bool ok = g_Game->GetSimulation2()->ComputeStateHash(hash, false); 253 256 ENSURE(ok); -
source/ps/Replay.h
45 45 46 46 /** 47 47 * Optional hash of simulation state (for sync checking). 48 48 */ 49 49 virtual void Hash(const std::string& hash, bool quick) = 0; 50 51 /** 52 * Returns the directory that contains the replay file. 53 */ 54 virtual OsPath GetReplayDirectory() = 0; 50 55 }; 51 56 52 57 /** 53 58 * Implementation of IReplayLogger that simply throws away all data. 54 59 */ … … 56 61 { 57 62 public: 58 63 virtual void StartGame(JS::MutableHandleValue UNUSED(attribs)) { } 59 64 virtual void Turn(u32 UNUSED(n), u32 UNUSED(turnLength), std::vector<SimulationCommand>& UNUSED(commands)) { } 60 65 virtual void Hash(const std::string& UNUSED(hash), bool UNUSED(quick)) { } 66 virtual OsPath GetReplayDirectory() { return OsPath();} 61 67 }; 62 68 63 69 /** 64 70 * Implementation of IReplayLogger that saves data to a file in the logs directory. 65 71 */ … … 71 77 ~CReplayLogger(); 72 78 73 79 virtual void StartGame(JS::MutableHandleValue attribs); 74 80 virtual void Turn(u32 n, u32 turnLength, std::vector<SimulationCommand>& commands); 75 81 virtual void Hash(const std::string& hash, bool quick); 82 virtual OsPath GetReplayDirectory(); 76 83 77 84 private: 78 85 ScriptInterface& m_ScriptInterface; 79 86 std::ostream* m_Stream; 87 OsPath m_Directory; 80 88 }; 81 89 82 90 /** 83 91 * Replay log replayer. Runs the log with no graphics and dumps some info to stdout. 84 92 */ … … 90 98 91 99 void Load(const std::string& path); 92 100 void Replay(bool serializationtest, bool ooslog); 93 101 94 102 private: 95 std::i stream* m_Stream;103 std::ifstream* m_Stream; 96 104 }; 97 105 98 106 #endif // INCLUDED_REPLAY -
source/ps/SavedGame.cpp
1 /* Copyright (C) 201 4Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify 5 5 * it under the terms of the GNU General Public License as published by 6 6 * the Free Software Foundation, either version 2 of the License, or … … 24 24 #include "lib/allocators/shared_ptr.h" 25 25 #include "lib/file/archive/archive_zip.h" 26 26 #include "i18n/L10n.h" 27 27 #include "lib/utf8.h" 28 28 #include "ps/CLogger.h" 29 #include "ps/EngineVersion.h" 29 30 #include "ps/Filesystem.h" 30 31 #include "ps/Game.h" 31 32 #include "ps/Mod.h" 32 33 #include "scriptinterface/ScriptInterface.h" 33 34 #include "simulation2/Simulation2.h" … … 84 85 JS::RootedValue metadata(cx); 85 86 JS::RootedValue initAttributes(cx, simulation.GetInitAttributes()); 86 87 simulation.GetScriptInterface().Eval("({})", &metadata); 87 88 simulation.GetScriptInterface().SetProperty(metadata, "version_major", SAVED_GAME_VERSION_MAJOR); 88 89 simulation.GetScriptInterface().SetProperty(metadata, "version_minor", SAVED_GAME_VERSION_MINOR); 90 simulation.GetScriptInterface().SetProperty(metadata, "engine_version", utf8_from_wstring(engine_version)); 89 91 simulation.GetScriptInterface().SetProperty(metadata, "mods", g_modsLoaded); 90 92 simulation.GetScriptInterface().SetProperty(metadata, "time", (double)now); 91 93 simulation.GetScriptInterface().SetProperty(metadata, "player", playerID); 92 94 simulation.GetScriptInterface().SetProperty(metadata, "initAttributes", initAttributes); 93 95 … … 298 300 299 301 JS::RootedValue metainfo(cx); 300 302 scriptInterface.Eval("({})", &metainfo); 301 303 scriptInterface.SetProperty(metainfo, "version_major", SAVED_GAME_VERSION_MAJOR); 302 304 scriptInterface.SetProperty(metainfo, "version_minor", SAVED_GAME_VERSION_MINOR); 303 scriptInterface.SetProperty(metainfo, "mods" , g_modsLoaded); 305 scriptInterface.SetProperty(metainfo, "engine_version", utf8_from_wstring(engine_version)); 306 scriptInterface.SetProperty(metainfo, "mods", g_modsLoaded); 304 307 return metainfo; 305 308 } 306 309 -
source/ps/VisualReplay.cpp
1 /* Copyright (C) 2015 Wildfire Games. 2 * This file is part of 0 A.D. 3 * 4 * 0 A.D. is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * 0 A.D. is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #include "precompiled.h" 19 20 #include "VisualReplay.h" 21 #include "graphics/GameView.h" 22 #include "gui/GUIManager.h" 23 #include "lib/allocators/shared_ptr.h" 24 #include "lib/utf8.h" 25 #include "ps/CLogger.h" 26 #include "ps/EngineVersion.h" 27 #include "ps/Filesystem.h" 28 #include "ps/Game.h" 29 #include "ps/Replay.h" 30 #include "scriptinterface/ScriptInterface.h" 31 32 OsPath VisualReplay::GetDirectoryName() 33 { 34 return OsPath(psLogDir() / L"sim_log"); 35 } 36 37 JS::Value VisualReplay::GetReplays(ScriptInterface& scriptInterface) 38 { 39 // TODO: enhancement: make a cache file, so that only one file needs to be loaded 40 TIMER(L"GetReplays"); 41 JSContext* cx = scriptInterface.GetContext(); 42 JSAutoRequest rq(cx); 43 44 u32 i = 0; 45 DirectoryNames directories; 46 JS::RootedObject replays(cx, JS_NewArrayObject(cx, 0)); 47 GetDirectoryEntries(GetDirectoryName(), NULL, &directories); 48 for (auto& directory : directories) 49 { 50 JS::RootedValue replayData(cx, LoadReplayData(scriptInterface, directory)); 51 if (!replayData.isNull()) 52 JS_SetElement(cx, replays, i++, replayData); 53 } 54 return JS::ObjectValue(*replays); 55 } 56 57 JS::Value VisualReplay::LoadReplayData(ScriptInterface& scriptInterface, OsPath directory) 58 { 59 OsPath replayFile(GetDirectoryName() / directory / L"commands.txt"); 60 61 if (!FileExists(replayFile)) 62 return JSVAL_NULL; 63 64 // Get fileinfo (size, timestamp) 65 CFileInfo fileInfo; 66 GetFileInfo(replayFile, &fileInfo); 67 u64 fileTime = (u64)fileInfo.MTime() & ~1; // skip lowest bit, since zip and FAT don't preserve it (according to CCacheLoader::LooseCachePath) 68 u64 fileSize = (u64)fileInfo.Size(); 69 70 if (fileSize == 0) 71 return JSVAL_NULL; 72 73 // Open file 74 std::wstring filenameW = replayFile.string(); 75 std::string filename( filenameW.begin(), filenameW.end() ); 76 std::ifstream* replayStream = new std::ifstream(filename.c_str()); 77 78 // File must begin with "start" 79 std::string type; 80 ENSURE((*replayStream >> type).good() && type == "start"); 81 82 // Parse header 83 std::string header; 84 std::getline(*replayStream, header); 85 JSContext* cx = scriptInterface.GetContext(); 86 JSAutoRequest rq(cx); 87 JS::RootedValue attribs(cx); 88 if (!scriptInterface.ParseJSON(header, &attribs)) 89 return JSVAL_NULL; 90 91 // Parse commands & turns 92 u32 currentTurn = 0; 93 u64 duration = 0; 94 while ((*replayStream >> type).good()) 95 { 96 if (type == "turn") 97 { 98 // Store turn & turn length 99 u32 turn = 0; 100 u32 turnLength = 0; 101 *replayStream >> turn >> turnLength; 102 if (turn != currentTurn) // Happens for replays of rejoined clients 103 return JSVAL_NULL; 104 105 // Compute game duration 106 duration += turnLength; 107 } 108 else if (type == "cmd") 109 { 110 // Read command 111 std::string command; 112 std::getline(*replayStream, command); 113 } 114 else if (type == "hash" || type == "hash-quick") 115 { 116 // Skip hash values 117 std::string replayHash; 118 *replayStream >> replayHash; 119 } 120 else if (type == "end") 121 { 122 currentTurn++; 123 } 124 else 125 { 126 LOGERROR("Unrecognized replay data '%s' in file %s", type, filename.c_str()); 127 } 128 } 129 replayStream->close(); 130 131 duration = duration / 1000; 132 if (duration < 5) // Don't list too short replays 133 return JSVAL_NULL; 134 135 JS::RootedValue replayData(cx); 136 scriptInterface.Eval("({})", &replayData); 137 scriptInterface.SetProperty(replayData, "file", replayFile); 138 scriptInterface.SetProperty(replayData, "directory", directory); 139 scriptInterface.SetProperty(replayData, "filemod_timestamp", fileTime); 140 scriptInterface.SetProperty(replayData, "attribs", attribs); 141 scriptInterface.SetProperty(replayData, "duration", duration); 142 return replayData; 143 } 144 145 bool VisualReplay::DeleteReplay(const std::wstring replayDirectory) 146 { 147 if (replayDirectory == L"") 148 return false; 149 150 const OsPath directory = OsPath(GetDirectoryName() / replayDirectory); 151 return DirectoryExists(directory) && DeleteDirectory(directory) == INFO::OK; 152 } 153 154 155 JS::Value VisualReplay::GetReplayAttributes(ScriptInterface::CxPrivate* pCxPrivate, std::wstring directoryName) 156 { 157 std::wstring replayFilePath = OsPath(VisualReplay::GetDirectoryName() / directoryName / "commands.txt").string(); 158 std::string replayFile( replayFilePath.begin(), replayFilePath.end() ); 159 160 JSContext* cx = pCxPrivate->pScriptInterface->GetContext(); 161 JSAutoRequest rq(cx); 162 JS::RootedValue attribs(cx); 163 pCxPrivate->pScriptInterface->Eval("({})", &attribs); 164 165 if (!FileExists(OsPath(replayFile))) 166 return attribs; 167 168 std::ifstream* replayStream = new std::ifstream(replayFile.c_str()); 169 std::string type, line; 170 ENSURE((*replayStream >> type).good() && type == "start"); 171 172 std::getline(*replayStream, line); 173 pCxPrivate->pScriptInterface->ParseJSON(line, &attribs); 174 replayStream->close(); 175 return attribs; 176 } 177 178 void VisualReplay::SaveReplayMetadata(std::wstring data) 179 { 180 // Returns directory of the currently active replay 181 // TODO: enhancement: use JS::HandleValue similar to SaveGame 182 if (!g_Game) 183 return; 184 185 OsPath directory = g_Game->GetReplayLogger().GetReplayDirectory(); 186 CreateDirectories(directory, 0700); 187 188 OsPath filepath = OsPath(directory / L"metadata.json"); 189 190 std::wstring filenameW = filepath.string(); 191 std::string filename( filenameW.begin(), filenameW.end() ); 192 193 std::ofstream stream (filename.c_str(), std::ofstream::out | std::ofstream::trunc); 194 stream << utf8_from_wstring(data); 195 stream.close(); 196 } 197 198 JS::Value VisualReplay::GetReplayMetadata(ScriptInterface::CxPrivate* pCxPrivate, std::wstring directoryName) 199 { 200 std::wstring filePathW = OsPath(VisualReplay::GetDirectoryName() / directoryName / "metadata.json").string(); 201 std::string filePath( filePathW.begin(), filePathW.end() ); 202 203 JSContext* cx = pCxPrivate->pScriptInterface->GetContext(); 204 JSAutoRequest rq(cx); 205 JS::RootedValue metadata(cx); 206 207 if (FileExists(OsPath(filePathW))) 208 { 209 std::ifstream* stream = new std::ifstream(filePath.c_str()); 210 ENSURE(stream->good()); 211 212 std::string type, line; 213 std::getline(*stream, line); 214 pCxPrivate->pScriptInterface->ParseJSON(line, &metadata); 215 stream->close(); 216 } 217 else 218 { 219 pCxPrivate->pScriptInterface->Eval("({})", &metadata); 220 } 221 222 return metadata; 223 } -
source/ps/VisualReplay.h
1 /* Copyright (C) 2015 Wildfire Games. 2 * This file is part of 0 A.D. 3 * 4 * 0 A.D. is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * 0 A.D. is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #ifndef INCLUDED_REPlAY 19 #define INCLUDED_REPlAY 20 21 #include "scriptinterface/ScriptInterface.h" 22 class CSimulation2; 23 class CGUIManager; 24 25 /** 26 * Contains functions for visually replaying past games. 27 */ 28 29 namespace VisualReplay 30 { 31 32 /** 33 * Start replaying the given commands.txt. 34 * 35 * @param name filename of the commands.txt file (including path) 36 * @param scriptInterface 37 * @param[out] savedState serialized simulation state stored as string of bytes, 38 * loaded from simulation.dat inside the archive. 39 * @return INFO::OK if successfully loaded, else an error Status 40 */ 41 Status Load(const std::wstring& name, ScriptInterface& scriptInterface, std::string& savedState); 42 43 /** 44 * Returns the path to the sim-log directory (that contains the directories with the replay files. 45 * 46 * @param scriptInterface the ScriptInterface in which to create the return data. 47 * @return OsPath with an absolte file path 48 */ 49 OsPath GetDirectoryName(); 50 51 /** 52 * Get a list of replays (filenames and timestamps [later more information like playernames]) for GUI script usage 53 * 54 * @param scriptInterface the ScriptInterface in which to create the return data. 55 * @return array of objects containing saved game data 56 */ 57 JS::Value GetReplays(ScriptInterface& scriptInterface); 58 59 /** 60 * Parses a commands.txt file and extracts metadata. 61 * Works similarly to CGame::LoadReplayData(). 62 */ 63 JS::Value LoadReplayData(ScriptInterface& scriptInterface, OsPath replayFile); 64 65 /** 66 * Permanently deletes the visual replay (including the parent directory) 67 * 68 * @param replayFile path to commands.txt, whose parent directory will be deleted 69 * @return true if deletion was successful, or false on error 70 */ 71 bool DeleteReplay(const std::wstring replayFile); 72 73 /** 74 * Returns the parsed header of the replay file (commands.txt). 75 */ 76 JS::Value GetReplayAttributes(ScriptInterface::CxPrivate* pCxPrivate, std::wstring directoryName); 77 78 /** 79 * Returns the metadata of a replay. 80 */ 81 JS::Value GetReplayMetadata(ScriptInterface::CxPrivate* pCxPrivate, std::wstring directoryName); 82 83 /** 84 * Saves the metadata from the session to metadata.json 85 */ 86 void SaveReplayMetadata(std::wstring data); 87 88 } 89 90 #endif -
source/simulation2/components/ICmpAIManager.cpp
47 47 m_AIs.set(JS_NewArrayObject(cx, 0)); 48 48 } 49 49 50 50 void Run() 51 51 { 52 vfs::ForEachFile(g_VFS, L"simulation/ai/", Callback, (uintptr_t)this, L" *.json", vfs::DIR_RECURSIVE);52 vfs::ForEachFile(g_VFS, L"simulation/ai/", Callback, (uintptr_t)this, L"data.json", vfs::DIR_RECURSIVE); 53 53 } 54 54 55 55 static Status Callback(const VfsPath& pathname, const CFileInfo& UNUSED(fileInfo), const uintptr_t cbData) 56 56 { 57 57 GetAIsHelper* self = (GetAIsHelper*)cbData;