Skip to content

Commit

Permalink
move extract_summary_from_config function
Browse files Browse the repository at this point in the history
  • Loading branch information
gfgtdf committed Jun 9, 2014
1 parent 1f00eb5 commit 6fc8c82
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 105 deletions.
103 changes: 0 additions & 103 deletions src/gamestatus.cpp
Expand Up @@ -763,109 +763,6 @@ void convert_old_saves(config& cfg){
LOG_RG<<"cfg after conversion "<<cfg<<"\n";
}

void extract_summary_from_config(config& cfg_save, config& cfg_summary)
{
const config &cfg_snapshot = cfg_save.child("snapshot");
const config &cfg_replay_start = cfg_save.child("replay_start");

const config &cfg_replay = cfg_save.child("replay");
const bool has_replay = cfg_replay && !cfg_replay.empty();
const bool has_snapshot = cfg_snapshot && cfg_snapshot.child("side");

cfg_summary["replay"] = has_replay;
cfg_summary["snapshot"] = has_snapshot;

cfg_summary["label"] = cfg_save["label"];
cfg_summary["campaign_type"] = cfg_save["campaign_type"];

if(cfg_save.has_child("carryover_sides_start")){
cfg_summary["scenario"] = cfg_save.child("carryover_sides_start")["next_scenario"];
} else {
cfg_summary["scenario"] = cfg_save["scenario"];
}

cfg_summary["difficulty"] = cfg_save["difficulty"];
cfg_summary["random_mode"] = cfg_save["random_mode"];


cfg_summary["campaign"] = cfg_save["campaign"];
cfg_summary["version"] = cfg_save["version"];
cfg_summary["corrupt"] = "";

if(has_snapshot) {
cfg_summary["turn"] = cfg_snapshot["turn_at"];
if (cfg_snapshot["turns"] != "-1") {
cfg_summary["turn"] = cfg_summary["turn"].str() + "/" + cfg_snapshot["turns"].str();
}
}

// Find the first human leader so we can display their icon in the load menu.

/** @todo Ideally we should grab all leaders if there's more than 1 human player? */
std::string leader;
std::string leader_image;

//BOOST_FOREACH(const config &p, cfg_save.child_range("player"))
//{
// if (p["canrecruit"].to_bool(false))) {
// leader = p["save_id"];
// }
//}

bool shrouded = false;

//if (!leader.empty())
//{
if (const config &snapshot = *(has_snapshot ? &cfg_snapshot : &cfg_replay_start))
{
BOOST_FOREACH(const config &side, snapshot.child_range("side"))
{
if (side["controller"] != team::CONTROLLER_to_string(team::HUMAN)) {
continue;
}

if (side["shroud"].to_bool()) {
shrouded = true;
}

if (side["canrecruit"].to_bool())
{
leader = side["id"].str();
leader_image = side["image"].str();
break;
}

BOOST_FOREACH(const config &u, side.child_range("unit"))
{
if (u["canrecruit"].to_bool()) {
leader = u["id"].str();
leader_image = u["image"].str();
break;
}
}
}
}
//}

cfg_summary["leader"] = leader;
// We need a binary path-independent path to the leader image here
// so it can be displayed for campaign-specific units in the dialog
// even when the campaign isn't loaded yet.
cfg_summary["leader_image"] = get_independent_image_path(leader_image);

if(!shrouded) {
if(has_snapshot) {
if (!cfg_snapshot.find_child("side", "shroud", "yes")) {
cfg_summary.add_child("map", cfg_snapshot.child_or_empty("map"));
}
} 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"));
}
}
}
}

game_state::game_state(const game_state& state) :
replay_data(state.replay_data),
snapshot(state.snapshot),
Expand Down
2 changes: 0 additions & 2 deletions src/gamestatus.hpp
Expand Up @@ -215,6 +215,4 @@ class game_state
mp_game_settings mp_settings_;
};

void extract_summary_from_config(config& cfg_save, config& cfg_summary);

#endif
102 changes: 102 additions & 0 deletions src/save_index.cpp
Expand Up @@ -394,3 +394,105 @@ save_info create_save_info::operator()(const std::string& filename) const

}

void extract_summary_from_config(config& cfg_save, config& cfg_summary)
{
const config &cfg_snapshot = cfg_save.child("snapshot");
const config &cfg_replay_start = cfg_save.child("replay_start");

const config &cfg_replay = cfg_save.child("replay");
const bool has_replay = cfg_replay && !cfg_replay.empty();
const bool has_snapshot = cfg_snapshot && cfg_snapshot.child("side");

cfg_summary["replay"] = has_replay;
cfg_summary["snapshot"] = has_snapshot;

cfg_summary["label"] = cfg_save["label"];
cfg_summary["campaign_type"] = cfg_save["campaign_type"];

if(cfg_save.has_child("carryover_sides_start")){
cfg_summary["scenario"] = cfg_save.child("carryover_sides_start")["next_scenario"];
} else {
cfg_summary["scenario"] = cfg_save["scenario"];
}

cfg_summary["difficulty"] = cfg_save["difficulty"];
cfg_summary["random_mode"] = cfg_save["random_mode"];


cfg_summary["campaign"] = cfg_save["campaign"];
cfg_summary["version"] = cfg_save["version"];
cfg_summary["corrupt"] = "";

if(has_snapshot) {
cfg_summary["turn"] = cfg_snapshot["turn_at"];
if (cfg_snapshot["turns"] != "-1") {
cfg_summary["turn"] = cfg_summary["turn"].str() + "/" + cfg_snapshot["turns"].str();
}
}

// Find the first human leader so we can display their icon in the load menu.

/** @todo Ideally we should grab all leaders if there's more than 1 human player? */
std::string leader;
std::string leader_image;

//BOOST_FOREACH(const config &p, cfg_save.child_range("player"))
//{
// if (p["canrecruit"].to_bool(false))) {
// leader = p["save_id"];
// }
//}

bool shrouded = false;

//if (!leader.empty())
//{
if (const config &snapshot = *(has_snapshot ? &cfg_snapshot : &cfg_replay_start))
{
BOOST_FOREACH(const config &side, snapshot.child_range("side"))
{
if (side["controller"] != team::CONTROLLER_to_string(team::HUMAN)) {
continue;
}

if (side["shroud"].to_bool()) {
shrouded = true;
}

if (side["canrecruit"].to_bool())
{
leader = side["id"].str();
leader_image = side["image"].str();
break;
}

BOOST_FOREACH(const config &u, side.child_range("unit"))
{
if (u["canrecruit"].to_bool()) {
leader = u["id"].str();
leader_image = u["image"].str();
break;
}
}
}
}
//}

cfg_summary["leader"] = leader;
// We need a binary path-independent path to the leader image here
// so it can be displayed for campaign-specific units in the dialog
// even when the campaign isn't loaded yet.
cfg_summary["leader_image"] = get_independent_image_path(leader_image);

if(!shrouded) {
if(has_snapshot) {
if (!cfg_snapshot.find_child("side", "shroud", "yes")) {
cfg_summary.add_child("map", cfg_snapshot.child_or_empty("map"));
}
} 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"));
}
}
}
}
2 changes: 2 additions & 0 deletions src/save_index.hpp
Expand Up @@ -102,6 +102,8 @@ class save_index_class
extern save_index_class save_index_manager;
} //end of namespace savegame


void extract_summary_from_config(config& cfg_save, config& cfg_summary);
void replace_underbar2space(std::string &name);
void replace_space2underbar(std::string &name);

Expand Down

0 comments on commit 6fc8c82

Please sign in to comment.