Skip to content

Commit

Permalink
SP: cleaned up code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Dec 18, 2020
1 parent b1983c2 commit 1ba2b7e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
31 changes: 14 additions & 17 deletions src/game_initialization/singleplayer.cpp
Expand Up @@ -14,6 +14,10 @@
#include "game_initialization/singleplayer.hpp"

#include "config.hpp"
#include "game_initialization/configure_engine.hpp"
#include "game_initialization/connect_engine.hpp"
#include "game_initialization/create_engine.hpp"
#include "game_launcher.hpp"
#include "gui/dialogs/campaign_selection.hpp"
#include "gui/dialogs/message.hpp"
#include "gui/dialogs/multiplayer/mp_staging.hpp"
Expand All @@ -26,13 +30,10 @@ static lg::log_domain log_engine("engine");

namespace sp
{
bool enter_create_mode(saved_game& state, jump_to_campaign_info jump_to_campaign)
bool select_campaign(saved_game& state, jump_to_campaign_info jump_to_campaign)
{
bool configure_canceled = false;

do {
while(true) {
ng::create_engine create_eng(state);

create_eng.set_current_level_type(ng::level::TYPE::SP_CAMPAIGN);

const std::vector<ng::create_engine::level_ptr> campaigns =
Expand Down Expand Up @@ -92,7 +93,7 @@ bool enter_create_mode(saved_game& state, jump_to_campaign_info jump_to_campaign
}

// Canceled difficulty dialog, relaunch the campaign selection dialog
return enter_create_mode(state, jump_to_campaign);
return select_campaign(state, jump_to_campaign);
}

create_eng.prepare_for_era_and_mods();
Expand All @@ -109,14 +110,15 @@ bool enter_create_mode(saved_game& state, jump_to_campaign_info jump_to_campaign
return false;
}

configure_canceled = !enter_configure_mode(state, create_eng);

} while (configure_canceled);
if(configure_campaign(state, create_eng)) {
break;
}
}

return true;
}

bool enter_configure_mode(saved_game& state, ng::create_engine& create_eng)
bool configure_campaign(saved_game& state, ng::create_engine& create_eng)
{
// We create the config engine here in order to ensure values like use_map_settings are set correctly
// TODO: should this be passed to this function instead of created here?
Expand All @@ -132,15 +134,10 @@ bool enter_configure_mode(saved_game& state, ng::create_engine& create_eng)
create_eng.get_parameters();
create_eng.prepare_for_new_level();

enter_connect_mode(state);

return true;
}

void enter_connect_mode(saved_game& state)
{
ng::connect_engine connect_eng(state, true, nullptr);
connect_eng.start_game();

return true;
}

} // end namespace sp
17 changes: 9 additions & 8 deletions src/game_initialization/singleplayer.hpp
Expand Up @@ -14,17 +14,18 @@

#pragma once

#include "configure_engine.hpp"
#include "connect_engine.hpp"
#include "create_engine.hpp"
#include "game_launcher.hpp"
struct jump_to_campaign_info;
class saved_game;

namespace sp
namespace ng
{
bool enter_create_mode(saved_game& state, jump_to_campaign_info jump_to);
class create_engine;
}

bool enter_configure_mode(saved_game& state, ng::create_engine& create_eng);
namespace sp
{
bool select_campaign(saved_game& state, jump_to_campaign_info jump_to);

void enter_connect_mode(saved_game& state);
bool configure_campaign(saved_game& state, ng::create_engine& create_eng);

} // end namespace sp
2 changes: 1 addition & 1 deletion src/game_launcher.cpp
Expand Up @@ -762,7 +762,7 @@ bool game_launcher::new_campaign()
state_.classification().campaign_type = game_classification::CAMPAIGN_TYPE::SCENARIO;
play_replay_ = false;

return sp::enter_create_mode(state_, jump_to_campaign_);
return sp::select_campaign(state_, jump_to_campaign_);
}

std::string game_launcher::jump_to_campaign_id() const
Expand Down

0 comments on commit 1ba2b7e

Please sign in to comment.