The base class for all savegame stuff. More...
#include <savegame.hpp>
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_game & | gamestate () 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_class > | save_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_game & | gamestate_ |
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 |
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.
Enumerator | |
---|---|
YES_NO | |
OK_CANCEL |
Definition at line 162 of file savegame.hpp.
|
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.
|
inlinevirtual |
Definition at line 164 of file savegame.hpp.
|
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.
|
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().
|
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.
|
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().
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.
|
privatepure virtual |
Subclass-specific part of filename building.
Implemented in savegame::scenariostart_savegame, savegame::autosave_savegame, savegame::replay_savegame, and savegame::ingame_savegame.
|
inline |
Definition at line 178 of file savegame.hpp.
References filename_.
Referenced by savegame::autosave_savegame::create_initial_filename(), and game_launcher::single_unit_test().
|
private |
Update the save_index.
Definition at line 530 of file savegame.cpp.
References _(), e, and config_writer::good().
|
inlineprotected |
Definition at line 203 of file savegame.hpp.
Referenced by savegame::ingame_savegame::create_initial_filename(), savegame::replay_savegame::create_initial_filename(), savegame::autosave_savegame::create_initial_filename(), savegame::scenariostart_savegame::create_initial_filename(), savegame::ingame_savegame::write_game(), savegame::replay_savegame::write_game(), and savegame::scenariostart_savegame::write_game().
|
private |
Throws game::save_game_failed.
Definition at line 542 of file savegame.cpp.
References e, label, and filesystem::ostream_file().
|
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().
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().
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().
|
inlineprotected |
Customize the standard error message.
Definition at line 200 of file savegame.hpp.
Referenced by savegame::autosave_savegame::autosave_savegame().
|
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().
|
inlineprotected |
Definition at line 202 of file savegame.hpp.
Referenced by savegame::oos_savegame::show_save_dialog().
|
protectedvirtual |
Writing the savegame config to a file.
Reimplemented in savegame::scenariostart_savegame, savegame::replay_savegame, and savegame::ingame_savegame.
Definition at line 521 of file savegame.cpp.
References log_scope, game_config::wesnoth_version, and config_writer::write_key_val().
Referenced by savegame::ingame_savegame::write_game(), savegame::replay_savegame::write_game(), and savegame::scenariostart_savegame::write_game().
|
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.
|
friend |
Definition at line 240 of file savegame.hpp.
|
private |
Determines if a confirmation of successful saving the game is shown.
Definition at line 248 of file savegame.hpp.
|
private |
Definition at line 244 of file savegame.hpp.
|
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().
|
private |
Definition at line 242 of file savegame.hpp.
|
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.
|
private |
Error message to be displayed if the savefile could not be generated.
Definition at line 246 of file savegame.hpp.
|
protected |
Title of the savegame dialog.
Definition at line 215 of file savegame.hpp.
Referenced by savegame::oos_savegame::set_title().