The Battle for Wesnoth  1.15.2+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...
 
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 162 of file savegame.hpp.

Member Enumeration Documentation

◆ DIALOG_TYPE

Enumerator
YES_NO 
OK_CANCEL 

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

◆ ~savegame()

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

Definition at line 172 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 440 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 424 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 411 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 189 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 435 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 186 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

Update the save_index.

Definition at line 521 of file savegame.cpp.

References _(), e, config_writer::good(), and game::error::what().

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

References e, filesystem::ostream_file(), and game::error::what().

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

References _(), e, persist_manager::end_transaction(), ERR_SAVE, filename_, LOG_SAVE, game::error::message, resources::persist, gui2::show_error_message(), gui2::show_transient_message(), editor::start(), 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 355 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::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 371 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 208 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 389 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 210 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 488 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 248 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 256 of file savegame.hpp.

◆ error_message_

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

Definition at line 252 of file savegame.hpp.

◆ filename_

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

Filename of the savegame file on disk.

Definition at line 220 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 250 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 230 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 254 of file savegame.hpp.

◆ title_

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

Title of the savegame dialog.

Definition at line 223 of file savegame.hpp.


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