1 var g_SavedGamesMetadata = [];
4 * Needed for formatPlayerInfo to show the player civs in the details.
6 const g_CivData = loadCivData();
10 let gameSelection = Engine.GetGUIObjectByName("gameSelection");
12 let savedGames = Engine.GetSavedGames().sort(sortDecreasingDate);
13 if (!savedGames.length)
15 gameSelection.list = [translate("No saved games found")];
16 gameSelection.selected = -1;
18 Engine.GetGUIObjectByName("loadGameButton").enabled = false;
19 Engine.GetGUIObjectByName("deleteGameButton").enabled = false;
23 // Get current game version and loaded mods
24 let engineInfo = Engine.GetEngineInfo();
26 g_SavedGamesMetadata = savedGames.map(game => game.metadata);
28 gameSelection.list = savedGames.map(game => generateLabel(game.metadata, engineInfo));
29 gameSelection.list_data = savedGames.map(game => game.id);
31 if (gameSelection.selected == -1)
32 gameSelection.selected = 0;
33 else if (gameSelection.selected >= savedGames.length) // happens when deleting the last saved game
34 gameSelection.selected = savedGames.length - 1;
38 Engine.GetGUIObjectByName("deleteGameButton").tooltip = deleteTooltip();
41 function selectionChanged()
43 let gameSelection = Engine.GetGUIObjectByName("gameSelection");
44 let selectionEmpty = gameSelection.selected == -1;
45 Engine.GetGUIObjectByName("invalidGame").hidden = !selectionEmpty;
46 Engine.GetGUIObjectByName("validGame").hidden = selectionEmpty;
51 let metadata = g_SavedGamesMetadata[gameSelection.selected];
53 Engine.GetGUIObjectByName("savedMapName").caption = translate(metadata.initAttributes.settings.Name);
54 let mapData = getMapDescriptionAndPreview(metadata.initAttributes.mapType, metadata.initAttributes.map);
55 setMapPreviewImage("savedInfoPreview", mapData.preview);
57 Engine.GetGUIObjectByName("savedPlayers").caption = metadata.initAttributes.settings.PlayerData.length - 1;
58 Engine.GetGUIObjectByName("savedPlayedTime").caption = timeToString(metadata.gui.timeElapsed ? metadata.gui.timeElapsed : 0);
59 Engine.GetGUIObjectByName("savedMapType").caption = translateMapType(metadata.initAttributes.mapType);
60 Engine.GetGUIObjectByName("savedMapSize").caption = translateMapSize(metadata.initAttributes.settings.Size);
61 Engine.GetGUIObjectByName("savedVictory").caption = translateVictoryCondition(metadata.initAttributes.settings.GameType);
63 let caption = sprintf(translate("Mods: %(mods)s"), { "mods": metadata.mods.join(translate(", ")) });
64 if (!hasSameMods(metadata, Engine.GetEngineInfo()))
65 caption = "[color=\"orange\"]" + caption + "[/color]";
66 Engine.GetGUIObjectByName("savedMods").caption = caption;
68 Engine.GetGUIObjectByName("savedPlayersNames").caption = formatPlayerInfo(
69 metadata.initAttributes.settings.PlayerData,
76 let gameSelection = Engine.GetGUIObjectByName("gameSelection");
77 let gameId = gameSelection.list_data[gameSelection.selected];
78 let metadata = g_SavedGamesMetadata[gameSelection.selected];
80 // Check compatibility before really loading it
81 let engineInfo = Engine.GetEngineInfo();
82 let sameMods = hasSameMods(metadata, engineInfo);
83 let sameEngineVersion = hasSameEngineVersion(metadata, engineInfo);
84 let sameSavegameVersion = hasSameSavegameVersion(metadata, engineInfo);
86 if (sameEngineVersion && sameSavegameVersion && sameMods)
88 reallyLoadGame(gameId);
92 // Version not compatible ... ask for confirmation
93 let message = translate("This saved game may not be compatible:");
95 if (!sameEngineVersion)
97 if (metadata.engine_version)
98 message += "\n" + sprintf(translate("It needs 0 A.D. version %(requiredVersion)s, while you are running version %(currentVersion)s."), {
99 "requiredVersion": metadata.engine_version,
100 "currentVersion": engineInfo.engine_version
103 message += "\n" + translate("It needs an older version of 0 A.D.");
106 if (!sameSavegameVersion)
107 message += "\n" + sprintf(translate("It needs 0 A.D. savegame version %(requiredVersion)s, while you have savegame version %(currentVersion)s."), {
108 "requiredVersion": metadata.version_major,
109 "currentVersion": engineInfo.version_major
117 message += translate("The savegame needs a different set of mods:") + "\n" +
118 sprintf(translate("Required: %(mods)s"), {
119 "mods": metadata.mods.join(translate(", "))
121 sprintf(translate("Active: %(mods)s"), {
122 "mods": engineInfo.mods.join(translate(", "))
126 message += "\n" + translate("Do you still want to proceed?");
131 translate("Warning"),
132 [translate("No"), translate("Yes")],
133 [init, function(){ reallyLoadGame(gameId); }]
137 function reallyLoadGame(gameId)
139 let metadata = Engine.StartSavedGame(gameId);
142 // Probably the file wasn't found
143 // Show error and refresh saved game list
144 error("Could not load saved game: " + gameId);
149 let pData = metadata.initAttributes.settings.PlayerData[metadata.playerID];
151 Engine.SwitchGuiPage("page_loading.xml", {
152 "attribs": metadata.initAttributes,
153 "isNetworked" : false,
154 "playerAssignments": {
156 "name": pData ? pData.Name : singleplayerName(),
157 "player": metadata.playerID
160 "savedGUIData": metadata.gui