Skip to content

Commit c546093

Browse files
authored
Save game on window exit (#3339)
The game does not bother saving when the user exits the game via the window (or keybinds, etc). This fixes that.
1 parent 6697d02 commit c546093

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

src/supertux/game_manager.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ GameManager::GameManager() :
3838
{
3939
}
4040

41+
void
42+
GameManager::save()
43+
{
44+
if (m_savegame)
45+
m_savegame->save();
46+
}
47+
4148
void
4249
GameManager::start_level(const World& world, const std::string& level_filename,
4350
const std::optional<std::pair<std::string, Vector>>& start_pos)

src/supertux/game_manager.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class GameManager final : public Currenton<GameManager>
3131
{
3232
public:
3333
GameManager();
34+
35+
void save();
3436

3537
bool start_worldmap(const World& world, const std::string& worldmap_filename = "",
3638
const std::string& sector = "", const std::string& spawnpoint = "");

src/supertux/screen_manager.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "supertux/constants.hpp"
3232
#include "supertux/controller_hud.hpp"
3333
#include "supertux/debug.hpp"
34+
#include "supertux/game_manager.hpp"
3435
#include "supertux/game_session.hpp"
3536
#include "supertux/gameconfig.hpp"
3637
#include "supertux/globals.hpp"
@@ -183,6 +184,8 @@ ScreenManager::quit(std::unique_ptr<ScreenFade> screen_fade)
183184
{
184185
Integration::close_all();
185186

187+
GameManager::current()->save();
188+
186189
#ifdef __EMSCRIPTEN__
187190
g_config->save();
188191
#endif

0 commit comments

Comments
 (0)