Author: jhinrichs
Date: Tue Apr 14 23:05:57 2009
New Revision: 34926
URL: http://svn.gna.org/viewcvs/wesnoth?rev=34926&view=rev
Log:
Savegame reorganization Step 1: Providing a simpler interface to saving and
loading.
Move gamestatus.cpp::load_game_summary to savegame.cpp and get rid of
gamestatus.cpp::read_save_file.
Modified:
trunk/src/dialogs.cpp
trunk/src/gamestatus.cpp
trunk/src/gamestatus.hpp
trunk/src/savegame.cpp
trunk/src/savegame.hpp
Modified: trunk/src/dialogs.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/dialogs.cpp?rev=34926&r1=34925&r2=34926&view=diff
==============================================================================
--- trunk/src/dialogs.cpp (original)
+++ trunk/src/dialogs.cpp Tue Apr 14 23:05:57 2009
@@ -34,6 +34,7 @@
#include "mouse_handler_base.hpp"
#include "minimap.hpp"
#include "replay.hpp"
+#include "savegame.hpp"
#include "thread.hpp"
#include "wml_separators.hpp"
#include "widgets/progressbar.hpp"
@@ -420,7 +421,7 @@
config& summary = *(*summaries_)[index_];
if (summary["label"] == ""){
try {
- load_game_summary((*info_)[index_].name, summary,
&dummy);
+ save_summary::load_summary((*info_)[index_].name,
summary, &dummy);
*(*summaries_)[index_] = summary;
} catch(game::load_game_failed&) {
summary["corrupt"] = "yes";
Modified: trunk/src/gamestatus.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gamestatus.cpp?rev=34926&r1=34925&r2=34926&view=diff
==============================================================================
--- trunk/src/gamestatus.cpp (original)
+++ trunk/src/gamestatus.cpp Tue Apr 14 23:05:57 2009
@@ -47,8 +47,6 @@
static void write_player(const player_info& player, config& cfg);
#endif /* _WIN32 */
-
-static void extract_summary_from_config(config& cfg_save, config& cfg_summary);
player_info* game_state::get_player(const std::string& id) {
std::map< std::string, player_info >::iterator found = players.find(id);
@@ -659,44 +657,6 @@
remove((get_saves_dir() + "/" + name).c_str());
remove((get_saves_dir() + "/" + modified_name).c_str());
-}
-
-void read_save_file(const std::string& name, config& cfg, std::string*
error_log)
-{
- std::string modified_name = name;
- replace_space2underbar(modified_name);
-
- // Try reading the file both with and without underscores
- scoped_istream file_stream = istream_file(get_saves_dir() + "/" +
modified_name);
- if (file_stream->fail())
- file_stream = istream_file(get_saves_dir() + "/" + name);
-
- cfg.clear();
- try{
- if(is_gzip_file(name)) {
- read_gz(cfg, *file_stream, error_log);
- } else {
- detect_format_and_read(cfg, *file_stream, error_log);
- }
- } catch (config::error &err)
- {
- ERR_NG << err.message;
- throw game::load_game_failed();
- }
-
- if(cfg.empty()) {
- ERR_NG << "Could not parse file data into config\n";
- throw game::load_game_failed();
- }
-}
-
-void load_game_summary(const std::string& name, config& cfg_summary,
std::string* error_log){
- log_scope("load_game_summary");
-
- config cfg;
- read_save_file(name,cfg,error_log);
-
- extract_summary_from_config(cfg, cfg_summary);
}
// Throws game::save_game_failed
Modified: trunk/src/gamestatus.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gamestatus.hpp?rev=34926&r1=34925&r2=34926&view=diff
==============================================================================
--- trunk/src/gamestatus.hpp (original)
+++ trunk/src/gamestatus.hpp Tue Apr 14 23:05:57 2009
@@ -315,8 +315,6 @@
/** Get a list of available saves. */
std::vector<save_info> get_saves_list(const std::string* dir = NULL, const
std::string* filter = NULL);
-void read_save_file(const std::string& name, config& cfg, std::string*
error_log);
-
void write_players(game_state& gamestate, config& cfg);
/** Returns true iff there is already a savegame with that name. */
@@ -325,10 +323,6 @@
/** Throws game::save_game_failed. */
scoped_ostream open_save_game(const std::string &label);
-/** Load/Save games. */
-void load_game(const std::string& name, game_state& gamestate, std::string*
error_log);
-void load_game_summary(const std::string& name, config& cfg_summary,
std::string* error_log);
-
/** Delete a savegame. */
void delete_game(const std::string& name);
@@ -337,5 +331,6 @@
void write_save_index();
void replace_underbar2space(std::string &name);
+void extract_summary_from_config(config& cfg_save, config& cfg_summary);
#endif
Modified: trunk/src/savegame.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/savegame.cpp?rev=34926&r1=34925&r2=34926&view=diff
==============================================================================
--- trunk/src/savegame.cpp (original)
+++ trunk/src/savegame.cpp Tue Apr 14 23:05:57 2009
@@ -106,6 +106,44 @@
}
#endif /* _WIN32 */
+static void read_save_file(const std::string& name, config& cfg, std::string*
error_log)
+{
+ std::string modified_name = name;
+ replace_space2underbar(modified_name);
+
+ // Try reading the file both with and without underscores
+ scoped_istream file_stream = istream_file(get_saves_dir() + "/" +
modified_name);
+ if (file_stream->fail())
+ file_stream = istream_file(get_saves_dir() + "/" + name);
+
+ cfg.clear();
+ try{
+ if(is_gzip_file(name)) {
+ read_gz(cfg, *file_stream, error_log);
+ } else {
+ detect_format_and_read(cfg, *file_stream, error_log);
+ }
+ } catch (config::error &err)
+ {
+ LOG_SAVE << err.message;
+ throw game::load_game_failed();
+ }
+
+ if(cfg.empty()) {
+ LOG_SAVE << "Could not parse file data into config\n";
+ throw game::load_game_failed();
+ }
+}
+
+void save_summary::load_summary(const std::string& name, config& cfg_summary,
std::string* error_log){
+ log_scope("load_game_summary");
+
+ config cfg;
+ read_save_file(name,cfg,error_log);
+
+ ::extract_summary_from_config(cfg, cfg_summary);
+}
+
loadgame::loadgame(display& gui, const config& game_config, game_state&
gamestate)
: game_config_(game_config)
, gui_(gui)
@@ -181,35 +219,6 @@
}
-void loadgame::read_save_file(const std::string& name, config& cfg,
std::string* error_log)
-{
- std::string modified_name = name;
- replace_space2underbar(modified_name);
-
- // Try reading the file both with and without underscores
- scoped_istream file_stream = istream_file(get_saves_dir() + "/" +
modified_name);
- if (file_stream->fail())
- file_stream = istream_file(get_saves_dir() + "/" + name);
-
- cfg.clear();
- try{
- if(is_gzip_file(name)) {
- read_gz(cfg, *file_stream, error_log);
- } else {
- detect_format_and_read(cfg, *file_stream, error_log);
- }
- } catch (config::error &err)
- {
- LOG_SAVE << err.message;
- throw game::load_game_failed();
- }
-
- if(cfg.empty()) {
- LOG_SAVE << "Could not parse file data into config\n";
- throw game::load_game_failed();
- }
-}
-
void loadgame::check_version_compatibility()
{
// do not load if too old, if either the savegame or the current game
@@ -306,7 +315,7 @@
gui::DIALOG_TYPE dialog_type, const bool has_exit_button,
const
bool ask_for_filename)
{
- interactive_ = true;
+ interactive_ = ask_for_filename;
create_filename();
const int res = dialogs::get_save_name(gui, message, _("Name: "),
&filename_, dialog_type, title_, has_exit_button, ask_for_filename);
Modified: trunk/src/savegame.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/savegame.hpp?rev=34926&r1=34925&r2=34926&view=diff
==============================================================================
--- trunk/src/savegame.hpp (original)
+++ trunk/src/savegame.hpp Tue Apr 14 23:05:57 2009
@@ -26,6 +26,15 @@
{
};
+class save_summary
+{
+public:
+ save_summary() {}
+ virtual ~save_summary() {}
+
+ static void load_summary(const std::string& name, config& cfg_summary,
std::string* error_log);
+};
+
class loadgame
{
public:
@@ -43,7 +52,6 @@
private:
void show_dialog(bool show_replay, bool cancel_orders);
- void read_save_file(const std::string& name, config& cfg, std::string*
error_log);
void check_version_compatibility();
void copy_era(config& cfg);
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits