The Battle for Wesnoth  1.19.7+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:

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...
 
std::shared_ptr< save_index_classsave_index_manager_
 Will (at the time of writing) be save_index_class::default_saves_dir(). 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.

Saves are only created in filesystem::get_saves_dir() - files can be loaded from elsewhere, but writes are only to that directory.

Definition at line 154 of file savegame.hpp.

Member Enumeration Documentation

◆ DIALOG_TYPE

Enumerator
YES_NO 
OK_CANCEL 

Definition at line 162 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 350 of file savegame.cpp.

◆ ~savegame()

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

Definition at line 164 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 449 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 429 of file savegame.cpp.

References _(), filename, filesystem::is_compressed_file(), filesystem::is_legal_user_file_name(), 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 417 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 181 of file savegame.hpp.

Referenced by foreach_autosave(), 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 444 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

◆ finish_save_game()

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

Update the save_index.

Definition at line 530 of file savegame.cpp.

References _(), e, and config_writer::good().

◆ 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

Throws game::save_game_failed.

Definition at line 542 of file savegame.cpp.

References e, label, and filesystem::ostream_file().

◆ save_game()

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

Save a game without any further user interaction.

The return value denotes, if the save was successful or not.

Definition at line 453 of file savegame.cpp.

References _(), e, persist_manager::end_transaction(), ERR_SAVE, filename, filename_, LOG_SAVE, resources::persist, gui2::show_error_message(), gui2::show_transient_message(), and persist_manager::start_transaction().

◆ 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 361 of file savegame.cpp.

References filename, and 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::single_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 378 of file savegame.cpp.

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

Referenced by 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 200 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 396 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 202 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 499 of file savegame.cpp.

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

Friends And Related Function Documentation

◆ save_info

friend class save_info
friend

Definition at line 240 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 248 of file savegame.hpp.

◆ error_message_

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

Definition at line 244 of file savegame.hpp.

◆ filename_

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

Filename of the savegame file on disk.

Definition at line 212 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 242 of file savegame.hpp.

◆ save_index_manager_

std::shared_ptr<save_index_class> savegame::savegame::save_index_manager_
protected

Will (at the time of writing) be save_index_class::default_saves_dir().

There may be different instances the index for different directories, however writing is only expected to happen in the default save directory.

Making this a class member anyway, while I'm refactoring.

Definition at line 222 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 246 of file savegame.hpp.

◆ title_

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

Title of the savegame dialog.

Definition at line 215 of file savegame.hpp.

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


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