The Battle for Wesnoth  1.15.1+dev
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends | List of all members
savegame::savegame Class Referenceabstract

The base class for all savegame stuff. More...

#include <savegame.hpp>

Inheritance diagram for savegame::savegame:
Inheritance graph

Public Types

enum  DIALOG_TYPE { YES_NO, OK_CANCEL }
 

Public Member Functions

virtual ~savegame ()
 
bool save_game_automatic (bool ask_for_overwrite=false, const std::string &filename="")
 Saves a game without user interaction, unless the file exists and it should be asked to overwrite it. More...
 
bool save_game_interactive (const std::string &message, DIALOG_TYPE dialog_type)
 Save a game interactively through the savegame dialog. More...
 
const std::string & filename () const
 
std::string create_filename () const
 Build the filename according to the specific savegame's needs. More...
 
std::string create_filename (unsigned int turn_number) const
 Build the filename for the specified turn. More...
 

Protected Member Functions

 savegame (saved_game &gamestate, const compression::format compress_saves, const std::string &title="Save")
 The only constructor of savegame. More...
 
bool save_game (const std::string &filename="")
 Save a game without any further user interaction. More...
 
bool check_filename (const std::string &filename)
 Check, if the filename contains illegal constructs like ".gz". More...
 
void set_error_message (const std::string &error_message)
 Customize the standard error message. More...
 
const std::string & title () const
 
const saved_gamegamestate () const
 
void before_save ()
 If there needs to be some data fiddling before saving the game, this is the place to go. More...
 
virtual void write_game (config_writer &out)
 Writing the savegame config to a file. More...
 

Protected Attributes

std::string filename_
 Filename of the savegame file on disk. More...
 
std::string title_
 Title of the savegame dialog. More...
 

Private Member Functions

virtual std::string create_initial_filename (unsigned int turn_number) const =0
 Subclass-specific part of filename building. More...
 
virtual int show_save_dialog (const std::string &message, DIALOG_TYPE dialog_type)
 Display the save game dialog. More...
 
bool check_overwrite ()
 Ask the user if an existing file should be overwritten. More...
 
void write_game_to_disk (const std::string &filename)
 The actual method for saving the game to disk. More...
 
void finish_save_game (const config_writer &out)
 Update the save_index. More...
 
filesystem::scoped_ostream open_save_game (const std::string &label)
 Throws game::save_game_failed. More...
 

Private Attributes

saved_gamegamestate_
 
std::string error_message_
 
bool show_confirmation_
 Error message to be displayed if the savefile could not be generated. More...
 
compression::format compress_saves_
 Determines if a confirmation of successful saving the game is shown. More...
 

Friends

class save_info
 

Detailed Description

The base class for all savegame stuff.

This should not be used directly, as it does not directly produce usable saves. Instead, use one of the derived classes.

Definition at line 147 of file savegame.hpp.

Member Enumeration Documentation

◆ DIALOG_TYPE

Enumerator
YES_NO 
OK_CANCEL 

Definition at line 155 of file savegame.hpp.

Constructor & Destructor Documentation

◆ savegame()

savegame::savegame::savegame ( saved_game gamestate,
const compression::format  compress_saves,
const std::string &  title = "Save" 
)
protected

The only constructor of savegame.

The title parameter is only necessary if you intend to do interactive saves.

Definition at line 328 of file savegame.cpp.

◆ ~savegame()

virtual savegame::savegame::~savegame ( )
inlinevirtual

Definition at line 157 of file savegame.hpp.

Member Function Documentation

◆ before_save()

void savegame::savegame::before_save ( )
protected

If there needs to be some data fiddling before saving the game, this is the place to go.

Definition at line 422 of file savegame.cpp.

◆ check_filename()

bool savegame::savegame::check_filename ( const std::string &  filename)
protected

Check, if the filename contains illegal constructs like ".gz".

Definition at line 406 of file savegame.cpp.

References _(), filesystem::is_compressed_file(), and gui2::show_error_message().

Referenced by savegame::oos_savegame::show_save_dialog().

◆ check_overwrite()

bool savegame::savegame::check_overwrite ( )
private

Ask the user if an existing file should be overwritten.

Definition at line 393 of file savegame.cpp.

References _(), filename_, gui2::OK, savegame::save_game_exists(), gui2::show_message(), and gui2::dialogs::message::yes_no_buttons.

◆ create_filename() [1/2]

std::string savegame::savegame::create_filename ( ) const
inline

Build the filename according to the specific savegame's needs.

Definition at line 174 of file savegame.hpp.

Referenced by play_controller::hotkey_handler::expand_autosaves(), and savegame::scenariostart_savegame::scenariostart_savegame().

◆ create_filename() [2/2]

std::string savegame::savegame::create_filename ( unsigned int  turn_number) const

Build the filename for the specified turn.

Definition at line 417 of file savegame.cpp.

◆ create_initial_filename()

virtual std::string savegame::savegame::create_initial_filename ( unsigned int  turn_number) const
privatepure virtual

Subclass-specific part of filename building.

Implemented in savegame::scenariostart_savegame, savegame::autosave_savegame, savegame::replay_savegame, and savegame::ingame_savegame.

◆ filename()

const std::string& savegame::savegame::filename ( ) const
inline

Definition at line 171 of file savegame.hpp.

References filename_.

Referenced by savegame::autosave_savegame::create_initial_filename().

◆ finish_save_game()

void savegame::savegame::finish_save_game ( const config_writer out)
private

◆ gamestate()

const saved_game& savegame::savegame::gamestate ( ) const
inlineprotected

◆ open_save_game()

filesystem::scoped_ostream savegame::savegame::open_save_game ( const std::string &  label)
private

◆ save_game()

bool savegame::savegame::save_game ( const std::string &  filename = "")
protected

◆ save_game_automatic()

bool savegame::savegame::save_game_automatic ( bool  ask_for_overwrite = false,
const std::string &  filename = "" 
)

Saves a game without user interaction, unless the file exists and it should be asked to overwrite it.

The return value denotes, if the save was successful or not. This is used by automatically generated replays, start-of-scenario saves, autosaves, and saves from the console (e.g. ":w").

Definition at line 337 of file savegame.cpp.

References filename_.

Referenced by savegame::autosave_savegame::autosave(), play_controller::do_consolesave(), campaign_controller::play_game(), play_controller::save_game_auto(), play_controller::save_replay_auto(), and game_launcher::unit_test().

◆ save_game_interactive()

bool savegame::savegame::save_game_interactive ( const std::string &  message,
DIALOG_TYPE  dialog_type 
)

Save a game interactively through the savegame dialog.

Used for manual midgame and replay saves. The return value denotes, if the save was successful or not.

Definition at line 353 of file savegame.cpp.

References filename_, gui2::OK, and throw_quit_game_exception().

Referenced by playmp_controller::linger(), playsingle_controller::play_scenario(), playmp_controller::process_oos(), play_controller::process_oos(), play_controller::save_game(), and play_controller::save_replay().

◆ set_error_message()

void savegame::savegame::set_error_message ( const std::string &  error_message)
inlineprotected

Customize the standard error message.

Definition at line 193 of file savegame.hpp.

Referenced by savegame::autosave_savegame::autosave_savegame().

◆ show_save_dialog()

int savegame::savegame::show_save_dialog ( const std::string &  message,
DIALOG_TYPE  dialog_type 
)
privatevirtual

Display the save game dialog.

Reimplemented in savegame::oos_savegame.

Definition at line 371 of file savegame.cpp.

References gui2::CANCEL, filename_, gui2::dialogs::modal_dialog::get_retval(), and gui2::dialogs::modal_dialog::show().

◆ title()

const std::string& savegame::savegame::title ( ) const
inlineprotected

Definition at line 195 of file savegame.hpp.

Referenced by savegame::oos_savegame::show_save_dialog().

◆ write_game()

void savegame::savegame::write_game ( config_writer out)
protectedvirtual

◆ write_game_to_disk()

void savegame::savegame::write_game_to_disk ( const std::string &  filename)
private

The actual method for saving the game to disk.

All interactive filename choosing and data manipulation has to happen before calling this method.

Definition at line 470 of file savegame.cpp.

References _(), filename_, compression::format_extension(), and LOG_SAVE.

Friends And Related Function Documentation

◆ save_info

friend class save_info
friend

Definition at line 226 of file savegame.hpp.

Member Data Documentation

◆ compress_saves_

compression::format savegame::savegame::compress_saves_
private

Determines if a confirmation of successful saving the game is shown.

Definition at line 234 of file savegame.hpp.

◆ error_message_

std::string savegame::savegame::error_message_
private

Definition at line 230 of file savegame.hpp.

◆ filename_

std::string savegame::savegame::filename_
protected

Filename of the savegame file on disk.

Definition at line 205 of file savegame.hpp.

Referenced by savegame::scenariostart_savegame::scenariostart_savegame(), and savegame::oos_savegame::show_save_dialog().

◆ gamestate_

saved_game& savegame::savegame::gamestate_
private

Definition at line 228 of file savegame.hpp.

◆ show_confirmation_

bool savegame::savegame::show_confirmation_
private

Error message to be displayed if the savefile could not be generated.

Definition at line 232 of file savegame.hpp.

◆ title_

std::string savegame::savegame::title_
protected

Title of the savegame dialog.

Definition at line 208 of file savegame.hpp.


The documentation for this class was generated from the following files: