Ticket #2385: checks.diff
File checks.diff, 9.9 KB (added by , 10 years ago) |
---|
-
binaries/data/mods/public/gui/common/functions_utility_loadsave.js
8 8 return n < 10 ? "0" + n : n; 9 9 } 10 10 11 function generateLabel(metadata )11 function generateLabel(metadata, engineInfo) 12 12 { 13 13 var t = new Date(metadata.time*1000); 14 15 14 var date = t.getFullYear()+"-"+twoDigits(1+t.getMonth())+"-"+twoDigits(t.getDate()); 16 15 var time = twoDigits(t.getHours())+":"+twoDigits(t.getMinutes())+":"+twoDigits(t.getSeconds()); 17 return "["+date+" "+time+"] "+metadata.initAttributes.map+(metadata.description ? " - "+metadata.description : ""); 16 var label = "["+date+" "+time+"] "; 17 18 if (engineInfo) 19 { 20 if (!hasSameVersion(metadata, engineInfo)) 21 label = "[color=\"red\"]" + label + "[/color]"; 22 else if (!hasSameMods(metadata, engineInfo)) 23 label = "[color=\"orange\"]" + label + "[/color]"; 24 } 25 26 label += metadata.initAttributes.map.replace("maps/","") 27 + (metadata.description ? " - "+metadata.description : ""); 28 return label; 18 29 } 30 31 /** 32 * Check the version compatibility between the saved game to be loaded and the engine 33 */ 34 function hasSameVersion(metadata, engineInfo) 35 { 36 return (metadata.version_major == engineInfo.version_major); 37 } 38 39 /** 40 * Check the mod compatibility between the saved game to be loaded and the engine 41 */ 42 function hasSameMods(metadata, engineInfo) 43 { 44 if (!metadata.mods) // only here for backwards compatibility with previous saved games 45 var gameMods = []; 46 else 47 var gameMods = metadata.mods; 48 49 if (gameMods.length != engineInfo.mods.length) 50 return false; 51 for (var i = 0; i < gameMods.length; ++i) 52 if (gameMods[i] != engineInfo.mods[i]) 53 return false; 54 return true; 55 } -
binaries/data/mods/public/gui/savedgames/load.js
1 var gameMetadatas = []; 2 1 3 function init() 2 4 { 3 5 var gameSelection = Engine.GetGUIObjectByName("gameSelection"); … … 3 5 4 6 var savedGames = Engine.GetSavedGames(); 5 if (savedGames.length == 0)6 {7 gameSelection.list = [ "No saved games found" ];8 gameSelection.selected = 0;9 Engine.GetGUIObjectByName("loadGameButton").enabled = false;10 Engine.GetGUIObjectByName("deleteGameButton").enabled = false;11 return;12 }13 7 8 // get current game version and loaded mods 9 var engineInfo = Engine.GetEngineInfo(); 10 14 11 savedGames.sort(sortDecreasingDate); 15 12 16 var gameListIDs = [ game.id for each (game in savedGames) ]; 17 var gameListLabels = [ generateLabel(game.metadata) for each (game in savedGames) ]; 13 var gameListIds = [ game.id for each (game in savedGames) ]; 14 var gameListLabels = [ generateLabel(game.metadata, engineInfo) for each (game in savedGames) ]; 15 gameMetadatas = [ game.metadata for each (game in savedGames) ]; 18 16 19 17 gameSelection.list = gameListLabels; 20 gameSelection.list_data = gameListIDs; 21 gameSelection.selected = 0; 18 gameSelection.list_data = gameListIds; 19 if (gameSelection.selected == -1) 20 gameSelection.selected = 0; 22 21 } 23 22 24 23 function loadGame() 25 24 { 26 25 var gameSelection = Engine.GetGUIObjectByName("gameSelection"); 27 var gameID = gameSelection.list_data[gameSelection.selected]; 26 var gameId = gameSelection.list_data[gameSelection.selected]; 27 var gameLabel = gameSelection.list[gameSelection.selected]; 28 var metadata = gameMetadatas[gameSelection.selected]; 28 29 29 var metadata = Engine.StartSavedGame(gameID); 30 // check game compatibility before really loading it 31 var engineInfo = Engine.GetEngineInfo(); 32 if (!hasSameVersion(metadata, engineInfo) || !hasSameMods(metadata, engineInfo)) 33 { 34 // version not compatible ... ask for confirmation 35 var btCaptions = ["Yes", "No"]; 36 var btCode = [function(){ reallyLoadGame(gameId); }, init]; 37 var message = "This saved game may not be compatible:"; 38 if (!hasSameVersion(metadata, engineInfo)) 39 message += "\nIt needs 0AD version " + metadata.version_major 40 + " while you are running version " + engineInfo.version_major + "."; 41 42 if (!hasSameMods(metadata, engineInfo)) 43 { 44 if (!metadata.mods) // only for backwards compatibility with previous saved games 45 metadata.mods = []; 46 if (metadata.mods.length == 0) 47 message += "\nIt does not need any mod" 48 + " while you are running with \"" + engineInfo.mods.join() + "\"."; 49 else if (engineInfo.mods.length == 0) 50 message += "\nIt needs the mod \"" + metadata.mods.join() + "\"" 51 + " while you are running without mod."; 52 else 53 message += "\nIt needs the mod \"" + metadata.mods.join() + "\"" 54 + " while you are running with \"" + engineInfo.mods.join() + "\"."; 55 } 56 message += "\nDo you still want to proceed ?"; 57 messageBox(500, 250, message, "Warning", 0, btCaptions, btCode); 58 } 59 else 60 reallyLoadGame(gameId); 61 } 62 63 function reallyLoadGame(gameId) 64 { 65 var metadata = Engine.StartSavedGame(gameId); 30 66 if (!metadata) 31 67 { 32 68 // Probably the file wasn't found 33 69 // Show error and refresh saved game list 34 error("Could not load saved game '"+gameI D+"'");70 error("Could not load saved game '"+gameId+"'"); 35 71 init(); 36 72 } -
source/gui/scripting/ScriptFunctions.cpp
194 194 g_Game->SetPlayerID(id); 195 195 } 196 196 197 CScriptValRooted GetEngineInfo(ScriptInterface::CxPrivate* pCxPrivate) 198 { 199 return SavedGames::GetEngineInfo(*(pCxPrivate->pScriptInterface)); 200 } 201 197 202 void StartNetworkGame(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) 198 203 { 199 204 ENSURE(g_NetServer); … … 822 827 scriptInterface.RegisterFunction<void, int, std::string, &AssignNetworkPlayer>("AssignNetworkPlayer"); 823 828 scriptInterface.RegisterFunction<void, std::wstring, &SendNetworkChat>("SendNetworkChat"); 824 829 scriptInterface.RegisterFunction<std::vector<CScriptValRooted>, &GetAIs>("GetAIs"); 830 scriptInterface.RegisterFunction<CScriptValRooted, &GetEngineInfo>("GetEngineInfo"); 825 831 826 832 // Saved games 827 833 scriptInterface.RegisterFunction<CScriptVal, std::wstring, &StartSavedGame>("StartSavedGame"); -
source/ps/GameSetup/Config.cpp
76 76 // If non-empty, specified map will be automatically loaded 77 77 CStr g_AutostartMap = ""; 78 78 79 std::vector<std::string> g_modsLoaded; 79 80 80 81 //---------------------------------------------------------------------------- 81 82 // config -
source/ps/GameSetup/Config.h
90 90 91 91 extern CStrW g_CursorName; 92 92 93 // list of mods currently loaded 94 extern std::vector<std::string> g_modsLoaded; 95 93 96 class CmdLineArgs; 94 97 extern void CONFIG_Init(const CmdLineArgs& args); 95 98 -
source/ps/GameSetup/GameSetup.cpp
391 391 static std::vector<CStr> GetMods(const CmdLineArgs& args, bool dev) 392 392 { 393 393 std::vector<CStr> mods = args.GetMultiple("mod"); 394 // List of the mods, to be used by the Gui 395 g_modsLoaded.clear(); 396 for (size_t i = 0; i < mods.size(); ++i) 397 g_modsLoaded.push_back((std::string)mods[i]); 394 398 // TODO: It would be nice to remove this hard-coding 395 399 mods.insert(mods.begin(), "public"); 396 400 -
source/ps/SavedGame.cpp
24 24 #include "lib/file/archive/archive_zip.h" 25 25 #include "ps/CLogger.h" 26 26 #include "ps/Filesystem.h" 27 #include "ps/GameSetup/Config.h" 27 28 #include "scriptinterface/ScriptInterface.h" 28 29 #include "simulation2/Simulation2.h" 29 30 … … 76 77 simulation.GetScriptInterface().Eval("({})", metadata); 77 78 simulation.GetScriptInterface().SetProperty(metadata.get(), "version_major", SAVED_GAME_VERSION_MAJOR); 78 79 simulation.GetScriptInterface().SetProperty(metadata.get(), "version_minor", SAVED_GAME_VERSION_MINOR); 80 simulation.GetScriptInterface().SetProperty(metadata.get(), "mods", g_modsLoaded); 79 81 simulation.GetScriptInterface().SetProperty(metadata.get(), "time", (double)now); 80 82 simulation.GetScriptInterface().SetProperty(metadata.get(), "player", playerID); 81 83 simulation.GetScriptInterface().SetProperty(metadata.get(), "initAttributes", simulation.GetInitAttributes()); … … 241 243 // Successfully deleted file 242 244 return true; 243 245 } 246 247 CScriptValRooted SavedGames::GetEngineInfo(ScriptInterface& scriptInterface) 248 { 249 CScriptValRooted metainfo; 250 scriptInterface.Eval("({})", metainfo); 251 scriptInterface.SetProperty(metainfo.get(), "version_major", SAVED_GAME_VERSION_MAJOR); 252 scriptInterface.SetProperty(metainfo.get(), "version_minor", SAVED_GAME_VERSION_MINOR); 253 scriptInterface.SetProperty(metainfo.get(), "mods" , g_modsLoaded); 254 return metainfo; 255 } 256 -
source/ps/SavedGame.h
92 92 */ 93 93 bool DeleteSavedGame(const std::wstring& name); 94 94 95 /** 96 * Gets info (version and mods loaded) on the running engine 97 * 98 * @param scriptInterface the ScriptInterface in which to create the return data. 99 * @return list of objects containing saved game data 100 */ 101 CScriptValRooted GetEngineInfo(ScriptInterface& scriptInterface); 102 95 103 } 96 104 97 105 #endif // INCLUDED_SAVEDGAME