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 153 of file savegame.hpp.
Enumerator | |
---|---|
YES_NO | |
OK_CANCEL |
Definition at line 161 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 355 of file savegame.cpp.
|
inlinevirtual |
Definition at line 163 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 454 of file savegame.cpp.
|
protected |
Check, if the filename contains illegal constructs like ".gz".
Definition at line 434 of file savegame.cpp.
References _(), 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 422 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 180 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 449 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 177 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 534 of file savegame.cpp.
References _(), e, and config_writer::good().
|
inlineprotected |
Definition at line 202 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 546 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 458 of file savegame.cpp.
References _(), e, persist_manager::end_transaction(), ERR_SAVE, filename_, LOG_SAVE, resources::persist, gui2::show_error_message(), gui2::show_transient_message(), editor::start(), 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 366 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().
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 383 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().
|
inlineprotected |
Customize the standard error message.
Definition at line 199 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 401 of file savegame.cpp.
References gui2::CANCEL, filename_, gui2::dialogs::modal_dialog::get_retval(), and gui2::dialogs::modal_dialog::show().
|
inlineprotected |
Definition at line 201 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 525 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 503 of file savegame.cpp.
References _(), filename_, compression::format_extension(), and LOG_SAVE.
|
friend |
Definition at line 239 of file savegame.hpp.
|
private |
Determines if a confirmation of successful saving the game is shown.
Definition at line 247 of file savegame.hpp.
|
private |
Definition at line 243 of file savegame.hpp.
|
protected |
Filename of the savegame file on disk.
Definition at line 211 of file savegame.hpp.
Referenced by savegame::scenariostart_savegame::scenariostart_savegame(), and savegame::oos_savegame::show_save_dialog().
|
private |
Definition at line 241 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 221 of file savegame.hpp.
|
private |
Error message to be displayed if the savefile could not be generated.
Definition at line 245 of file savegame.hpp.
|
protected |
Title of the savegame dialog.
Definition at line 214 of file savegame.hpp.
Referenced by savegame::oos_savegame::set_title().