Skip to content

Commit

Permalink
deploy new game_config_view object
Browse files Browse the repository at this point in the history
the game_config_view object offers const
access to the game_config object, furthermore
it allows the game_config config object to be
replaced by a vector of config objects which
is what we will do later.
  • Loading branch information
gfgtdf committed Jun 29, 2020
1 parent a34cb53 commit 93aa2ca
Show file tree
Hide file tree
Showing 82 changed files with 402 additions and 194 deletions.
1 change: 1 addition & 0 deletions source_lists/libwesnoth_core
Expand Up @@ -7,6 +7,7 @@ filesystem.cpp
filesystem_common.cpp
font/constants.cpp
game_config.cpp
game_config_view.cpp
gettext.cpp
hash.cpp
log.cpp
Expand Down
3 changes: 2 additions & 1 deletion src/about.cpp
Expand Up @@ -17,6 +17,7 @@
#include "config.hpp"
#include "gettext.hpp"
#include "serialization/string_utils.hpp"
#include "game_config_view.hpp"

#include <map>

Expand Down Expand Up @@ -103,7 +104,7 @@ std::vector<std::string> get_background_images(const std::string& campaign)
return images_general;
}

void set_about(const config& cfg)
void set_about(const game_config_view& cfg)
{
parsed_credits_data.clear();

Expand Down
3 changes: 2 additions & 1 deletion src/about.hpp
Expand Up @@ -20,6 +20,7 @@
#include <string>

class config;
class game_config_view;

namespace about
{
Expand Down Expand Up @@ -62,6 +63,6 @@ std::vector<std::string> get_background_images(const std::string& campaign);
/**
* Regenerates the credits config
*/
void set_about(const config& cfg);
void set_about(const game_config_view& cfg);

}
4 changes: 2 additions & 2 deletions src/ai/configuration.cpp
Expand Up @@ -24,7 +24,7 @@
#include "log.hpp"
#include "serialization/parser.hpp"
#include "serialization/preprocessor.hpp"

#include "game_config_view.hpp"
#include <vector>
#include <deque>
#include <set>
Expand All @@ -37,7 +37,7 @@ static lg::log_domain log_ai_configuration("ai/config");
#define WRN_AI_CONFIGURATION LOG_STREAM(warn, log_ai_configuration)
#define ERR_AI_CONFIGURATION LOG_STREAM(err, log_ai_configuration)

void configuration::init(const config &game_config)
void configuration::init(const game_config_view &game_config)
{
ai_configurations_.clear();
era_ai_configurations_.clear();
Expand Down
3 changes: 2 additions & 1 deletion src/ai/configuration.hpp
Expand Up @@ -21,6 +21,7 @@

#include "config.hpp"
#include "ai/game_info.hpp"
#include "game_config_view.hpp"

namespace ai {

Expand Down Expand Up @@ -64,7 +65,7 @@ class configuration {
* Init the parameters of ai configuration parser
* @param game_config game config
*/
static void init(const config &game_config);
static void init(const game_config_view &game_config);
static void add_era_ai_from_config(const config &game_config);
static void add_mod_ai_from_config(config::const_child_itors configs);

Expand Down
2 changes: 1 addition & 1 deletion src/controller_base.cpp
Expand Up @@ -453,7 +453,7 @@ bool controller_base::in_context_menu(hotkey::HOTKEY_COMMAND /*command*/) const
return true;
}

const config& controller_base::get_theme(const config& game_config, std::string theme_name)
const config& controller_base::get_theme(const game_config_view& game_config, std::string theme_name)
{
if(theme_name.empty()) {
theme_name = preferences::theme();
Expand Down
5 changes: 3 additions & 2 deletions src/controller_base.hpp
Expand Up @@ -41,6 +41,7 @@
#include "quit_confirmation.hpp"
#include "video.hpp"

class game_config_view;
class display;
class plugins_context;

Expand All @@ -67,7 +68,7 @@ class controller_base : public video2::draw_layering, public events::pump_monito

virtual void play_slice(bool is_delay_enabled = true);

static const config& get_theme(const config& game_config, std::string theme_name);
static const config& get_theme(const game_config_view& game_config, std::string theme_name);

void apply_keyboard_scroll(int x, int y);

Expand Down Expand Up @@ -180,7 +181,7 @@ class controller_base : public video2::draw_layering, public events::pump_monito

void long_touch_callback(int x, int y);

const config& game_config_;
const game_config_view& game_config_;

CKey key_;

Expand Down
9 changes: 5 additions & 4 deletions src/editor/controller/editor_controller.cpp
Expand Up @@ -50,7 +50,7 @@
#include "sound.hpp"
#include "units/unit.hpp"
#include "units/animation_component.hpp"

#include "game_config_manager.hpp"
#include "quit_confirmation.hpp"

#include "utils/functional.hpp"
Expand Down Expand Up @@ -109,7 +109,7 @@ void editor_controller::init_gui()
// without deleting it.
}

void editor_controller::init_tods(const config& game_config)
void editor_controller::init_tods(const game_config_view& game_config)
{
for (const config &schedule : game_config.child_range("editor_times")) {

Expand Down Expand Up @@ -142,11 +142,12 @@ void editor_controller::init_tods(const config& game_config)
}
}

void editor_controller::init_music(const config& game_config)
void editor_controller::init_music(const game_config_view& game_config)
{
const std::string tag_name = "editor_music";
if (!game_config.has_child(tag_name))
if (game_config.child_range(tag_name).size() == 0) {
ERR_ED << "No editor music defined" << std::endl;
}
else {
for (const config& editor_music : game_config.child_range(tag_name)) {
for (const config& music : editor_music.child_range("music")) {
Expand Down
4 changes: 2 additions & 2 deletions src/editor/controller/editor_controller.hpp
Expand Up @@ -205,10 +205,10 @@ class editor_controller : public controller_base,
void init_gui();

/** init the available time-of-day settings */
void init_tods(const config& game_config);
void init_tods(const game_config_view& game_config);

/** init background music for the editor */
void init_music(const config& game_config);
void init_music(const game_config_view& game_config);

/** Load editor-specific tooltips */
void load_tooltips();
Expand Down
5 changes: 3 additions & 2 deletions src/editor/map/context_manager.cpp
Expand Up @@ -41,6 +41,7 @@

#include "gui/dialogs/editor/edit_scenario.hpp"
#include "gui/dialogs/editor/edit_side.hpp"
#include "game_config_view.hpp"

#include "terrain/translation.hpp"

Expand All @@ -63,7 +64,7 @@ static const std::string get_menu_marker(const bool changed)
return ss.str();
}

context_manager::context_manager(editor_display& gui, const config& game_config)
context_manager::context_manager(editor_display& gui, const game_config_view& game_config)
: locs_(nullptr)
, gui_(gui)
, game_config_(game_config)
Expand Down Expand Up @@ -672,7 +673,7 @@ void context_manager::save_scenario_as_dialog()
save_scenario_as(dlg.path());
}

void context_manager::init_map_generators(const config& game_config)
void context_manager::init_map_generators(const game_config_view& game_config)
{
for(const config& i : game_config.child_range("multiplayer")) {
if(i["map_generation"].empty() && i["scenario_generation"].empty()) {
Expand Down
7 changes: 4 additions & 3 deletions src/editor/map/context_manager.hpp
Expand Up @@ -20,6 +20,7 @@
#include "preferences/editor.hpp"

class map_generator;
class game_config_view;

namespace editor
{
Expand All @@ -29,7 +30,7 @@ class context_manager : public filter_context
public:
using context_ptr = std::unique_ptr<map_context>;

context_manager(editor_display& gui, const config& game_config);
context_manager(editor_display& gui, const game_config_view& game_config);
~context_manager();

bool is_active_transitions_hotkey(const std::string& item);
Expand Down Expand Up @@ -195,7 +196,7 @@ class context_manager : public filter_context
class location_palette* locs_;
private:
/** init available random map generators */
void init_map_generators(const config& game_config);
void init_map_generators(const game_config_view& game_config);

/**
* Shows an are-you-sure dialog if the map was modified.
Expand Down Expand Up @@ -312,7 +313,7 @@ class context_manager : public filter_context
private:
editor_display& gui_;

const config& game_config_;
const game_config_view& game_config_;

/** Default directory for map load/save as dialogs */
std::string default_dir_;
Expand Down
8 changes: 4 additions & 4 deletions src/editor/map/editor_map.cpp
Expand Up @@ -39,20 +39,20 @@ editor_map_load_exception wrap_exc(const char* type, const std::string& e_msg, c
return editor_map_load_exception(filename, msg);
}

editor_map::editor_map(const config& terrain_cfg)
editor_map::editor_map(const game_config_view& terrain_cfg)
: gamemap(std::make_shared<terrain_type_data>(terrain_cfg), "")
, selection_()
{
}

editor_map::editor_map(const config& terrain_cfg, const std::string& data)
editor_map::editor_map(const game_config_view& terrain_cfg, const std::string& data)
: gamemap(std::make_shared<terrain_type_data>(terrain_cfg), data)
, selection_()
{
sanity_check();
}

editor_map editor_map::from_string(const config& terrain_cfg, const std::string& data)
editor_map editor_map::from_string(const game_config_view& terrain_cfg, const std::string& data)
{
try {
return editor_map(terrain_cfg, data);
Expand All @@ -65,7 +65,7 @@ editor_map editor_map::from_string(const config& terrain_cfg, const std::string&
}
}

editor_map::editor_map(const config& terrain_cfg, std::size_t width, std::size_t height, const t_translation::terrain_code & filler)
editor_map::editor_map(const game_config_view& terrain_cfg, std::size_t width, std::size_t height, const t_translation::terrain_code & filler)
: gamemap(std::make_shared<terrain_type_data>(terrain_cfg), t_translation::write_game_map(t_translation::ter_map(width + 2, height + 2, filler)))
, selection_()
{
Expand Down
8 changes: 4 additions & 4 deletions src/editor/map/editor_map.hpp
Expand Up @@ -73,23 +73,23 @@ class editor_map : public gamemap
/**
* Empty map constructor
*/
explicit editor_map(const config& terrain_cfg);
explicit editor_map(const game_config_view& terrain_cfg);

/**
* Create an editor map from a map data string
*/
editor_map(const config& terrain_cfg, const std::string& data);
editor_map(const game_config_view& terrain_cfg, const std::string& data);

/**
* Wrapper around editor_map(cfg, data) that catches possible exceptions
* and wraps them in a editor_map_load_exception
*/
static editor_map from_string(const config& terrain_cfg, const std::string& data);
static editor_map from_string(const game_config_view& terrain_cfg, const std::string& data);

/**
* Create an editor map with the given dimensions and filler terrain
*/
editor_map(const config& terrain_cfg, std::size_t width, std::size_t height, const t_translation::terrain_code & filler);
editor_map(const game_config_view& terrain_cfg, std::size_t width, std::size_t height, const t_translation::terrain_code & filler);

/**
* Create an editor_map by upgrading an existing gamemap. The map data is
Expand Down
5 changes: 3 additions & 2 deletions src/editor/map/map_context.cpp
Expand Up @@ -29,6 +29,7 @@
#include "team.hpp"
#include "terrain/type_data.hpp"
#include "units/unit.hpp"
#include "game_config_view.hpp"

#include <boost/regex.hpp>

Expand Down Expand Up @@ -85,7 +86,7 @@ map_context::map_context(const editor_map& map, bool pure_map, const config& sch
{
}

map_context::map_context(const config& game_config, const std::string& filename)
map_context::map_context(const game_config_view& game_config, const std::string& filename)
: filename_(filename)
, map_data_key_()
, embedded_(false)
Expand Down Expand Up @@ -312,7 +313,7 @@ void map_context::replace_local_schedule(const std::vector<time_of_day>& schedul
}
}

void map_context::load_scenario(const config& game_config)
void map_context::load_scenario(const game_config_view& game_config)
{
config scenario;

Expand Down
5 changes: 3 additions & 2 deletions src/editor/map/map_context.hpp
Expand Up @@ -26,6 +26,7 @@
#include "display_context.hpp"

#include <vector>
class game_config_view;

namespace editor {

Expand Down Expand Up @@ -75,7 +76,7 @@ class map_context : public display_context
* inside scenarios do not change the filename, but set the "embedded" flag
* instead.
*/
map_context(const config& game_config, const std::string& filename);
map_context(const game_config_view& game_config, const std::string& filename);

/**
* Map context destructor
Expand Down Expand Up @@ -335,7 +336,7 @@ class map_context : public display_context
bool save_scenario();


void load_scenario(const config& game_config);
void load_scenario(const game_config_view& game_config);

config to_config();

Expand Down
4 changes: 2 additions & 2 deletions src/editor/palette/editor_palettes.hpp
Expand Up @@ -27,7 +27,7 @@ class editor_palette : public tristate_palette {

public:

editor_palette(editor_display &gui, const config& /*cfg*/
editor_palette(editor_display &gui, const game_config_view& /*cfg*/
, std::size_t item_size, std::size_t item_width, editor_toolkit &toolkit)
: tristate_palette(gui.video())
, groups_()
Expand Down Expand Up @@ -110,7 +110,7 @@ class editor_palette : public tristate_palette {
virtual const std::string& get_id(const Item& item) = 0;

/** Setup the internal data structure. */
virtual void setup(const config& cfg) = 0;
virtual void setup(const game_config_view& cfg) = 0;

virtual const std::string& active_group_id() {return active_group_;}

Expand Down
5 changes: 3 additions & 2 deletions src/editor/palette/item_palette.cpp
Expand Up @@ -20,6 +20,7 @@

#include "editor/palette/item_palette.hpp"
#include "gettext.hpp"
#include "game_config_view.hpp"

#include <string>

Expand All @@ -30,7 +31,7 @@ std::string item_palette::get_help_string()
return selected_fg_item().name;
}

void item_palette::setup(const config& cfg)
void item_palette::setup(const game_config_view& cfg)
{
for(const config& group : cfg.child_range("item_group")) {
groups_.emplace_back(group);
Expand Down Expand Up @@ -81,7 +82,7 @@ void item_palette::draw_item(const overlay& item, surface& image, std::stringstr
tooltip_text << item.name;
}

item_palette::item_palette(editor_display &gui, const config& cfg,
item_palette::item_palette(editor_display &gui, const game_config_view& cfg,
editor_toolkit &toolkit)
//TODO avoid magic numbers
: editor_palette<overlay>(gui, cfg, 36, 4, toolkit)
Expand Down
5 changes: 3 additions & 2 deletions src/editor/palette/item_palette.hpp
Expand Up @@ -20,6 +20,7 @@

#include "editor/palette/editor_palettes.hpp"
#include "overlay.hpp"
class game_config_view;

namespace editor {

Expand All @@ -32,10 +33,10 @@ class item_palette : public editor_palette<overlay> {
public:

item_palette(editor_display &gui,
const config& cfg,
const game_config_view& cfg,
editor_toolkit &toolkit);

virtual void setup(const config& cfg);
virtual void setup(const game_config_view& cfg);

virtual std::string get_help_string();

Expand Down

0 comments on commit 93aa2ca

Please sign in to comment.