4 function selectDescription()
6 let gameSelection = Engine.GetGUIObjectByName("gameSelection");
7 if (gameSelection.selected == -1)
10 let gameID = gameSelection.list_data[gameSelection.selected];
11 Engine.GetGUIObjectByName("deleteGameButton").enabled = true;
12 Engine.GetGUIObjectByName("saveGameDesc").caption = g_Descriptions[gameID];
17 g_SavedGameData = data && data.savedGameData || {};
18 let simulationState = Engine.GuiInterfaceCall("GetSimulationState");
19 g_SavedGameData.timeElapsed = simulationState.timeElapsed;
20 g_SavedGameData.states = simulationState.players.map(pState => pState.state);
22 let gameSelection = Engine.GetGUIObjectByName("gameSelection");
23 Engine.GetGUIObjectByName("deleteGameButton").enabled = false;
25 let savedGames = Engine.GetSavedGames().sort(sortDecreasingDate);
26 if (!savedGames.length)
28 gameSelection.list = [translate("No saved games found")];
29 gameSelection.selected = -1;
34 for (let game of savedGames)
35 g_Descriptions[game.id] = game.metadata.description || "";
37 gameSelection.list = savedGames.map(game => generateLabel(game.metadata));
38 gameSelection.list_data = savedGames.map(game => game.id);
39 gameSelection.selected = -1;
41 Engine.GetGUIObjectByName("deleteGameButton").tooltip = deleteTooltip();
46 let gameSelection = Engine.GetGUIObjectByName("gameSelection");
47 let gameLabel = gameSelection.list[gameSelection.selected];
48 let gameID = gameSelection.list_data[gameSelection.selected];
49 let desc = Engine.GetGUIObjectByName("saveGameDesc").caption;
50 let name = gameID || "savegame";
52 if (gameSelection.selected == -1)
54 reallySaveGame(name, desc, true);
60 sprintf(translate("\"%(label)s\""), { "label": gameLabel }) + "\n" +
61 translate("Saved game will be permanently overwritten, are you sure?"),
62 translate("OVERWRITE SAVE"),
63 [translate("No"), translate("Yes")],
64 [null, function(){ reallySaveGame(name, desc, false); }]
68 function reallySaveGame(name, desc, nameIsPrefix)
71 Engine.SaveGamePrefix(name, desc, g_SavedGameData);
73 Engine.SaveGame(name, desc, g_SavedGameData);
80 Engine.PopGuiPageCB(0);
83 // HACK: Engine.SaveGame* expects this function to be defined on the current page.
84 // That's why we have to pass the data to this page even if we don't need it.
85 function getSavedGameData()
87 return g_SavedGameData;