From e7eb08d0cd2d57b55bf084b669fbeec8d283db33 Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Thu, 10 Jul 2014 19:12:14 -0400 Subject: [PATCH] fix bug 22086, by storing map data correctly in savegame summaries The bug was that minimap previews for save games were not appearing, or that the wrong ones were appearing. It seems that because of more relics from this commit / related, https://github.com/wesnoth/wesnoth/commit/c17d84b12 the savegame summaries generated by "extract savegame summary" were bugged and didn't store the map data correctly. This bug wasn't obvious because the save game load dialog tries to scavenge what ever the current game config is for map data if it can't find this, but all of the saveindex data was being generated incorrectly. After this commit all the save files seem to work correctly, except for start-of-scenario saves for reasons that aren't clear to me, and which I think is a separate issue. (In that case, something is going wrong with the game_config lookup process most likely.) This only appears to fix the bug for normal saves, autosaves, and replay saves. --- src/dialogs.cpp | 10 ++++++++++ src/game_controller.cpp | 9 +++++++++ src/gamestatus.cpp | 12 ++++++++---- src/savegame.cpp | 2 +- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/dialogs.cpp b/src/dialogs.cpp index 279e03f357d8..d63df4e1b7a3 100644 --- a/src/dialogs.cpp +++ b/src/dialogs.cpp @@ -719,7 +719,15 @@ void save_preview_pane::draw_contents() std::string map_data = summary["map_data"]; if(map_data.empty()) { + LOG_DP << "When parsing save summary " << ((*info_)[index_]).name() << std::endl + << "Did not find a map_data field. Looking in game config for a child [" << summary["campaign_type"] << "] with id " << summary["scenario"] << std::endl; + assert(game_config_ && "ran into a null game config pointer inside a game preview pane"); const config &scenario = game_config_->find_child(summary["campaign_type"], "id", summary["scenario"]); + + if (!scenario) { + LOG_DP << "Did not find a matching scenario." << std::endl; + } + if (scenario && !scenario.find_child("side", "shroud", "yes")) { map_data = scenario["map_data"].str(); if (map_data.empty() && scenario.has_attribute("map")) { @@ -765,6 +773,8 @@ void save_preview_pane::draw_contents() ypos = std::max(ypos,map_rect.y + map_rect.h + save_preview_border); sdl_blit(map_surf,NULL,screen,&map_rect); + } else { + LOG_DP << "Never found a map for savefile " << (*info_)[index_].name() << std::endl; } char time_buf[256] = {0}; diff --git a/src/game_controller.cpp b/src/game_controller.cpp index 54f1c63f10a4..2efee951bb05 100644 --- a/src/game_controller.cpp +++ b/src/game_controller.cpp @@ -447,6 +447,15 @@ bool game_controller::is_loading() const bool game_controller::load_game() { + assert(resources::config_manager); + + if (state_.classification().campaign_type.size() == 0) { + state_ = game_state(); + state_.classification().campaign_type = "scenario"; + } + + DBG_GENERAL << "Current campaign type: " << state_.classification().campaign_type << std::endl; + savegame::loadgame load(disp(), resources::config_manager->game_config(), state_); diff --git a/src/gamestatus.cpp b/src/gamestatus.cpp index 1c81f32e8471..67122a0e7629 100644 --- a/src/gamestatus.cpp +++ b/src/gamestatus.cpp @@ -1167,12 +1167,16 @@ void extract_summary_from_config(config& cfg_save, config& cfg_summary) if(!shrouded) { if(has_snapshot) { - if (!cfg_snapshot.find_child("side", "shroud", "yes")) { - cfg_summary.add_child("map", cfg_snapshot.child_or_empty("map")); + if (!cfg_snapshot.find_child("side", "shroud", "yes") && cfg_snapshot.has_attribute("map_data")) { + cfg_summary["map_data"] = cfg_snapshot["map_data"].str(); + } else { + ERR_NG << "Not saving map because there is shroud" << std::endl; } } else if(has_replay) { - if (!cfg_replay_start.find_child("side","shroud","yes")) { - cfg_summary.add_child("map", cfg_replay_start.child_or_empty("map")); + if (!cfg_replay_start.find_child("side","shroud","yes") && cfg_replay_start.has_attribute("map_data")) { + cfg_summary["map_data"] = cfg_replay_start["map_data"]; + } else { + ERR_NG << "Not saving map because there is shroud" << std::endl; } } } diff --git a/src/savegame.cpp b/src/savegame.cpp index 8503d6dafcf5..acc825b24fd4 100644 --- a/src/savegame.cpp +++ b/src/savegame.cpp @@ -707,7 +707,7 @@ void loadgame::fill_mplevel_config(config& level){ // is empty the starting position contains the wanted info. const config& start_data = !gamestate_.snapshot.empty() ? gamestate_.snapshot : gamestate_.replay_start(); - level.add_child("map", start_data.child_or_empty("map")); + level["map_data"], start_data["map_data"]; level["id"] = start_data["id"]; level["name"] = start_data["name"]; level["completion"] = start_data["completion"];