deploy new game_config_view object

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.
This commit is contained in:
gfgtdf 2020-06-22 21:54:57 +02:00
parent a34cb53c33
commit 93aa2ca409
82 changed files with 402 additions and 194 deletions

View file

@ -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

View file

@ -17,6 +17,7 @@
#include "config.hpp"
#include "gettext.hpp"
#include "serialization/string_utils.hpp"
#include "game_config_view.hpp"
#include <map>
@ -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();

View file

@ -20,6 +20,7 @@
#include <string>
class config;
class game_config_view;
namespace about
{
@ -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);
}

View file

@ -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>
@ -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();

View file

@ -21,6 +21,7 @@
#include "config.hpp"
#include "ai/game_info.hpp"
#include "game_config_view.hpp"
namespace ai {
@ -64,7 +65,7 @@ public:
* 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);

View file

@ -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();

View file

@ -41,6 +41,7 @@
#include "quit_confirmation.hpp"
#include "video.hpp"
class game_config_view;
class display;
class plugins_context;
@ -67,7 +68,7 @@ public:
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);
@ -180,7 +181,7 @@ protected:
void long_touch_callback(int x, int y);
const config& game_config_;
const game_config_view& game_config_;
CKey key_;

View file

@ -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"
@ -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")) {
@ -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")) {

View file

@ -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();

View file

@ -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"
@ -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)
@ -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()) {

View file

@ -20,6 +20,7 @@
#include "preferences/editor.hpp"
class map_generator;
class game_config_view;
namespace editor
{
@ -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);
@ -195,7 +196,7 @@ public:
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.
@ -312,7 +313,7 @@ public:
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_;

View file

@ -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);
@ -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_()
{

View file

@ -73,23 +73,23 @@ public:
/**
* 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

View file

@ -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>
@ -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)
@ -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;

View file

@ -26,6 +26,7 @@
#include "display_context.hpp"
#include <vector>
class game_config_view;
namespace editor {
@ -75,7 +76,7 @@ public:
* 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
@ -335,7 +336,7 @@ public:
bool save_scenario();
void load_scenario(const config& game_config);
void load_scenario(const game_config_view& game_config);
config to_config();

View file

@ -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_()
@ -110,7 +110,7 @@ private:
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_;}

View file

@ -20,6 +20,7 @@
#include "editor/palette/item_palette.hpp"
#include "gettext.hpp"
#include "game_config_view.hpp"
#include <string>
@ -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);
@ -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)

View file

@ -20,6 +20,7 @@
#include "editor/palette/editor_palettes.hpp"
#include "overlay.hpp"
class game_config_view;
namespace editor {
@ -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();

View file

@ -158,7 +158,7 @@ protected:
};
namespace editor {
location_palette::location_palette(editor_display &gui, const config& /*cfg*/,
location_palette::location_palette(editor_display &gui, const game_config_view& /*cfg*/,
editor_toolkit &toolkit)
: common_palette(gui.video())
, item_size_(20)

View file

@ -22,7 +22,7 @@
class location_palette_item;
class location_palette_button;
class game_config_view;
namespace editor {
class editor_toolkit;
@ -31,7 +31,7 @@ class location_palette : public common_palette {
public:
location_palette(editor_display &gui, const config& /*cfg*/,
location_palette(editor_display &gui, const game_config_view& /*cfg*/,
editor_toolkit &toolkit);

View file

@ -22,7 +22,7 @@
namespace editor {
palette_manager::palette_manager(editor_display& gui, const config& cfg
palette_manager::palette_manager(editor_display& gui, const game_config_view& cfg
, editor_toolkit& toolkit)
: gui::widget(gui.video()),
gui_(gui),

View file

@ -35,7 +35,7 @@ class palette_manager : public gui::widget {
public:
palette_manager(editor_display &gui, const config& cfg
palette_manager(editor_display &gui, const game_config_view& cfg
, editor_toolkit &toolkit);
void set_group(std::size_t index);

View file

@ -22,6 +22,7 @@
#include "gettext.hpp"
#include "serialization/string_utils.hpp"
#include "game_config_view.hpp"
namespace {
static t_translation::terrain_code fg_terrain;
@ -67,7 +68,7 @@ void terrain_palette::select_fg_item(const t_translation::terrain_code& terrain)
}
void terrain_palette::setup(const config& cfg)
void terrain_palette::setup(const game_config_view& cfg)
{
// Get the available terrains temporary in items
t_translation::ter_list items = map().get_terrain_list();
@ -212,7 +213,7 @@ void terrain_palette::draw_item(const t_translation::terrain_code& terrain,
}
}
terrain_palette::terrain_palette(editor_display &gui, const config& cfg, editor_toolkit &toolkit)
terrain_palette::terrain_palette(editor_display &gui, const game_config_view& cfg, editor_toolkit &toolkit)
//TODO avoid magic numbers
: editor_palette<t_translation::terrain_code>(gui, cfg, 36, 4, toolkit)
{

View file

@ -33,12 +33,12 @@ class terrain_palette : public editor_palette<t_translation::terrain_code> {
public:
terrain_palette(editor_display &gui, const config& cfg,
terrain_palette(editor_display &gui, const game_config_view& cfg,
editor_toolkit &toolkit);
const gamemap& map() const { return gui_.get_map(); }
virtual void setup(const config& cfg);
virtual void setup(const game_config_view& cfg);
void select_bg_item(const t_translation::terrain_code& terrain);
void select_fg_item(const t_translation::terrain_code& terrain);

View file

@ -31,7 +31,7 @@ std::string unit_palette::get_help_string() {
return selected_fg_item().type_name();
}
void unit_palette::setup(const config& /*cfg*/)
void unit_palette::setup(const game_config_view& /*cfg*/)
{
for(const unit_type_data::unit_type_map::value_type &i : unit_types.types()) {
if(i.second.do_not_list())
@ -94,7 +94,7 @@ void unit_palette::draw_item(const unit_type& u, surface& image, std::stringstre
tooltip_text << u.type_name();
}
unit_palette::unit_palette(editor_display &gui, const config& cfg,
unit_palette::unit_palette(editor_display &gui, const game_config_view& cfg,
editor_toolkit &toolkit)
//TODO avoid magic numbers
: editor_palette<const unit_type&>(gui, cfg, 36, 4, toolkit)

View file

@ -33,10 +33,10 @@ class unit_palette : public editor_palette<const unit_type&> {
public:
unit_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();

View file

@ -22,10 +22,12 @@
#include "editor/action/mouse/mouse_action_item.hpp"
#include "editor/action/mouse/mouse_action_select.hpp"
#include "game_config_view.hpp"
namespace editor {
editor_toolkit::editor_toolkit(editor_display& gui, const CKey& key,
const config& game_config, context_manager& c_manager)
const game_config_view& game_config, context_manager& c_manager)
: gui_(gui)
, key_(key)
, palette_manager_()
@ -41,7 +43,7 @@ editor_toolkit::editor_toolkit(editor_display& gui, const CKey& key,
editor_toolkit::~editor_toolkit() = default;
void editor_toolkit::init_brushes(const config& game_config)
void editor_toolkit::init_brushes(const game_config_view& game_config)
{
for (const config &i : game_config.child_range("brush")) {
brushes_.emplace_back(i);
@ -54,7 +56,7 @@ void editor_toolkit::init_brushes(const config& game_config)
brush_ = &brushes_[0];
}
void editor_toolkit::init_sidebar(const config& game_config)
void editor_toolkit::init_sidebar(const game_config_view& game_config)
{
palette_manager_.reset(new palette_manager(gui_, game_config, *this));
}

View file

@ -20,7 +20,7 @@
#include "hotkey/hotkey_command.hpp"
class config;
class game_config_view;
namespace editor {
@ -28,7 +28,7 @@ class editor_toolkit {
public:
editor_toolkit(editor_display& gui, const CKey& key,
const config& game_config, context_manager& c_manager);
const game_config_view& game_config, context_manager& c_manager);
~editor_toolkit();
@ -38,10 +38,10 @@ public:
private:
/** init the sidebar objects */
void init_sidebar(const config& game_config);
void init_sidebar(const game_config_view& game_config);
/** init the brushes */
void init_brushes(const config& game_config);
void init_brushes(const game_config_view& game_config);
/** init the mouse actions (tools) */
void init_mouse_actions(context_manager& c_manager);

View file

@ -35,6 +35,7 @@
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/system/windows_error.hpp>
#include "game_config_view.hpp"
#ifdef _WIN32
#include "log_windows.hpp"
@ -1287,7 +1288,7 @@ binary_paths_manager::binary_paths_manager()
{
}
binary_paths_manager::binary_paths_manager(const config& cfg)
binary_paths_manager::binary_paths_manager(const game_config_view& cfg)
: paths_()
{
set_paths(cfg);
@ -1298,7 +1299,7 @@ binary_paths_manager::~binary_paths_manager()
cleanup();
}
void binary_paths_manager::set_paths(const config& cfg)
void binary_paths_manager::set_paths(const game_config_view& cfg)
{
cleanup();
init_binary_paths();

View file

@ -31,7 +31,7 @@
#include "serialization/string_utils.hpp"
class config;
class game_config_view;
struct SDL_RWops;
namespace filesystem {
@ -384,10 +384,10 @@ char path_separator();
struct binary_paths_manager
{
binary_paths_manager();
binary_paths_manager(const config& cfg);
binary_paths_manager(const game_config_view& cfg);
~binary_paths_manager();
void set_paths(const config& cfg);
void set_paths(const game_config_view& cfg);
private:
binary_paths_manager(const binary_paths_manager& o);

View file

@ -52,6 +52,7 @@ game_config_manager::game_config_manager(
cmdline_opts_(cmdline_opts),
jump_to_editor_(jump_to_editor),
game_config_(),
game_config_view_(),
old_defines_map_(),
paths_manager_(),
cache_(game_config::config_cache::instance())
@ -59,6 +60,7 @@ game_config_manager::game_config_manager(
assert(!singleton);
singleton = this;
game_config_view_.data().push_back(game_config_);
if(cmdline_opts_.nocache) {
cache_.set_use_cache(false);
}
@ -91,7 +93,7 @@ bool game_config_manager::init_game_config(FORCE_RELOAD_CONFIG force_reload)
game_config::reset_color_info();
load_game_config_with_loadscreen(force_reload);
game_config::load_config(game_config_.child("game_config"));
game_config::load_config(game_config().child("game_config"));
hotkey::deactivate_all_scopes();
hotkey::set_scope_active(hotkey::SCOPE_MAIN_MENU);
@ -295,7 +297,7 @@ void game_config_manager::load_game_config(FORCE_RELOAD_CONFIG force_reload,
}
// Extract the Lua scripts at toplevel.
game_lua_kernel::extract_preload_scripts(game_config_);
game_lua_kernel::extract_preload_scripts(game_config());
game_config_.clear_children("lua");
// Put the gfx rules back to game config.
@ -306,7 +308,7 @@ void game_config_manager::load_game_config(FORCE_RELOAD_CONFIG force_reload,
game_config::add_color_info(game_config_);
terrain_builder::set_terrain_rules_cfg(game_config());
tdata_ = std::make_shared<terrain_type_data>(game_config_);
tdata_ = std::make_shared<terrain_type_data>(game_config());
::init_strings(game_config());
theme::set_known_themes(&game_config());
} catch(const game::error& e) {
@ -553,18 +555,15 @@ void game_config_manager::load_addons_cfg()
void game_config_manager::set_multiplayer_hashes()
{
config& hashes = game_config_.add_child("multiplayer_hashes");
for (const config &ch : game_config_.child_range("multiplayer")) {
for (const config &ch : game_config().child_range("multiplayer")) {
hashes[ch["id"].str()] = ch.hash();
}
}
void game_config_manager::set_unit_data()
{
game_config_.merge_children("units");
gui2::dialogs::loading_screen::progress(loading_stage::load_unit_types);
if(config &units = game_config_.child("units")) {
unit_types.set_config(units);
}
unit_types.set_config(game_config().merged_children_view("units"));
}
void game_config_manager::reload_changed_game_config()

View file

@ -18,6 +18,7 @@
#include "config_cache.hpp"
#include "filesystem.hpp"
#include "terrain/type_data.hpp"
#include "game_config_view.hpp"
class config;
class game_classification;
@ -37,7 +38,7 @@ public:
NO_INCLUDE_RELOAD,
};
const config& game_config() const { return game_config_; }
const game_config_view& game_config() const { return game_config_view_; }
const preproc_map& old_defines_map() const { return old_defines_map_; }
const ter_data_cache & terrain_types() const { return tdata_; }
@ -69,6 +70,7 @@ private:
const bool jump_to_editor_;
config game_config_;
game_config_view game_config_view_;
preproc_map old_defines_map_;

80
src/game_config_view.cpp Normal file
View file

@ -0,0 +1,80 @@
/*
Copyright (C) 2013 - 2018 by Andrius Silinskas <silinskas.andrius@gmail.com>
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#include "game_config_view.hpp"
#include "config.hpp"
#include "log.hpp"
static lg::log_domain log_config("config");
#define ERR_CONFIG LOG_STREAM(err, log_config)
#define WRN_CONFIG LOG_STREAM(warn, log_config)
#define LOG_CONFIG LOG_STREAM(info, log_config)
config_array_view game_config_view::child_range(config_key_type key) const
{
config_array_view res;
for(const config& cfg : cfgs_) {
for (const config& child : cfg.child_range(key)) {
res.push_back(child);
}
}
return res;
}
const config& game_config_view::find_child(config_key_type key, const std::string &name, const std::string &value) const
{
for(const config& cfg : cfgs_) {
if(const config& res = cfg.find_child(key, name, value)) {
return res;
}
}
LOG_CONFIG << "gcv : cannot find [" << key << "] with " << name << "=" << value << ", count = " << cfgs_.size() <<"\n";
const config cfg;
return cfg.child("invalid");
}
const config& game_config_view::child(config_key_type key) const
{
for(const config& cfg : cfgs_) {
if(const config& res = cfg.child(key)) {
return res;
}
}
const config cfg;
return cfg.child("invalid");
}
const config& game_config_view::child_or_empty(config_key_type key) const
{
for(const config& cfg : cfgs_) {
if(const config& res = cfg.child(key)) {
return res;
}
}
static const config cfg;
return cfg;
}
game_config_view game_config_view::merged_children_view(config_key_type key) const
{
game_config_view res;
for(const config& cfg : cfgs_) {
for(const config& child : cfg.child_range(key)) {
res.cfgs_.push_back(child);
}
}
return res;
}

61
src/game_config_view.hpp Normal file
View file

@ -0,0 +1,61 @@
/*
Copyright (C) 2013 - 2018 by Andrius Silinskas <silinskas.andrius@gmail.com>
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#pragma once
#include "config.hpp"
#include <functional>
#include <vector>
using config_array_view = std::vector<std::reference_wrapper<const config>>;
class game_config_view
{
public:
game_config_view()
{
}
static game_config_view wrap(const config& cfg) {
return game_config_view(cfg);
}
config_array_view child_range(config_key_type key) const;
const config& find_child(config_key_type key, const std::string &name, const std::string &value) const;
const config& child(config_key_type key) const;
const config& child_or_empty(config_key_type key) const;
game_config_view merged_children_view(config_key_type key) const;
config_array_view& data()
{
return cfgs_;
}
private:
explicit game_config_view(const config& cfg)
: cfgs_()
{
cfgs_.push_back(cfg);
}
config_array_view cfgs_;
};

View file

@ -491,7 +491,7 @@ void connect_engine::start_game()
send_to_server(config("start_game"));
}
void connect_engine::start_game_commandline(const commandline_options& cmdline_opts, const config& game_config)
void connect_engine::start_game_commandline(const commandline_options& cmdline_opts, const game_config_view& game_config)
{
DBG_MP << "starting a new game in commandline mode" << std::endl;

View file

@ -22,6 +22,7 @@
namespace randomness { class mt_rng; }
struct mp_campaign_info;
class game_config_view;
namespace ng {
@ -63,7 +64,7 @@ public:
bool can_start_game() const;
void start_game();
void start_game_commandline(const commandline_options& cmdline_opts, const config& game_config);
void start_game_commandline(const commandline_options& cmdline_opts, const game_config_view& game_config);
void leave_game();

View file

@ -28,6 +28,7 @@
class saved_game;
class gamemap;
class game_config_view;
namespace ng {
@ -463,7 +464,7 @@ private:
std::string selected_campaign_difficulty_;
/** Reference to the main game config. */
const config& game_config_;
const game_config_view& game_config_;
};
} // end namespace ng

View file

@ -24,6 +24,7 @@
#include "gui/dialogs/depcheck_confirm_change.hpp"
#include "gui/dialogs/depcheck_select_new.hpp"
#include "gui/dialogs/message.hpp"
#include "game_config_view.hpp"
static lg::log_domain log_mp_create_depcheck("mp/create/depcheck");
#define DBG_MP LOG_STREAM(debug, log_mp_create_depcheck)
@ -55,7 +56,7 @@ namespace ng
{
namespace depcheck
{
manager::manager(const config& gamecfg, bool mp)
manager::manager(const game_config_view& gamecfg, bool mp)
: depinfo_()
, era_()
, scenario_()

View file

@ -20,6 +20,8 @@
#include "gettext.hpp"
#include "utils/make_enum.hpp"
class game_config_view;
namespace ng
{
@ -52,7 +54,7 @@ MAKE_ENUM(component_availability,
class manager
{
public:
manager(const config& gamecfg, bool mp);
manager(const game_config_view& gamecfg, bool mp);
/**
* Tries to set the selected era

View file

@ -32,6 +32,7 @@
#include "wml_exception.hpp"
#include "game_version.hpp"
#include "mp_game_settings.hpp"
#include "game_config_view.hpp"
#include <iterator>
@ -209,7 +210,7 @@ game_info::game_info(const config& game, const std::vector<std::string>& install
, required_addons()
, addons_outcome(SATISFIED)
{
const config& game_config = game_config_manager::get()->game_config();
const game_config_view& game_config = game_config_manager::get()->game_config();
// Parse the list of addons required to join this game.
for(const config& addon : game.child_range("addon")) {

View file

@ -98,7 +98,7 @@ config initial_level_config(saved_game& state)
* -- vultraz, 2017-11-24
*/
const config& game_config = game_config_manager::get()->game_config();
const game_config_view& game_config = game_config_manager::get()->game_config();
const config& era_cfg = game_config.find_child("era", "id", era);
if(!era_cfg) {

View file

@ -393,14 +393,14 @@ std::pair<wesnothd_connection_ptr, config> open_connection(std::string host)
/** Helper struct to manage the MP workflow arguments. */
struct mp_workflow_helper
{
mp_workflow_helper(const config& gc, saved_game& state, wesnothd_connection* connection, mp::lobby_info* li)
mp_workflow_helper(const game_config_view& gc, saved_game& state, wesnothd_connection* connection, mp::lobby_info* li)
: game_config(gc)
, state(state)
, connection(connection)
, lobby_info(li)
{}
const config& game_config;
const game_config_view& game_config;
saved_game& state;
@ -604,9 +604,9 @@ bool enter_lobby_mode(mp_workflow_helper_ptr helper, const std::vector<std::stri
/** Pubic entry points for the MP workflow */
namespace mp
{
void start_client(const config& game_config, saved_game& state, const std::string& host)
void start_client(const game_config_view& game_config, saved_game& state, const std::string& host)
{
const config* game_config_ptr = &game_config;
const game_config_view* game_config_ptr = &game_config;
// This function does not refer to an addon database, it calls filesystem functions.
// For the sanity of the mp lobby, this list should be fixed for the entire lobby session,
@ -676,7 +676,7 @@ bool goto_mp_wait(saved_game& state, wesnothd_connection* connection, bool obser
return dlg.show();
}
void start_local_game(const config& game_config, saved_game& state)
void start_local_game(const game_config_view& game_config, saved_game& state)
{
DBG_MP << "starting local game" << std::endl;
@ -689,7 +689,7 @@ void start_local_game(const config& game_config, saved_game& state)
enter_create_mode(workflow_helper);
}
void start_local_game_commandline(const config& game_config, saved_game& state, const commandline_options& cmdline_opts)
void start_local_game_commandline(const game_config_view& game_config, saved_game& state, const commandline_options& cmdline_opts)
{
DBG_MP << "starting local MP game from commandline" << std::endl;

View file

@ -21,6 +21,8 @@
class config;
class wesnothd_connection;
class game_config_view;
namespace mp {
// max. length of a player name
@ -34,7 +36,7 @@ const std::size_t max_login_size = 20;
*
* @param game_config The global, top-level WML configuration for the game
*/
void start_local_game(const config& game_config,
void start_local_game(const game_config_view& game_config,
saved_game& state);
/** Starts a multiplayer game in single-user mode.
@ -42,7 +44,7 @@ void start_local_game(const config& game_config,
* Same parameters as start_local_game plus:
* cmdline_opts The commandline options
*/
void start_local_game_commandline(const config& game_config,
void start_local_game_commandline(const game_config_view& game_config,
saved_game& state, const commandline_options& cmdline_opts);
/** Starts a multiplayer game in client mode.
@ -50,7 +52,7 @@ void start_local_game_commandline(const config& game_config,
* @param game_config The global, top-level WML configuration for the game
* @param host The host to connect to.
*/
void start_client(const config& game_config,
void start_client(const game_config_view& game_config,
saved_game& state, const std::string& host);
/**

View file

@ -17,6 +17,7 @@
#pragma once
class config;
class game_config_view;
#include "default_map_generator.hpp"
#include "map/location.hpp"
@ -62,6 +63,6 @@ private:
map_location random_point_at_side(std::size_t width, std::size_t height);
std::mt19937 rng_;
const config& game_config_;
const game_config_view& game_config_;
};

View file

@ -43,6 +43,7 @@
#include "serialization/string_utils.hpp"
#include "utils/general.hpp"
#include "utils/functional.hpp"
#include "game_config_view.hpp"
#include <cctype>
@ -102,7 +103,7 @@ namespace dialogs
REGISTER_DIALOG(game_load)
game_load::game_load(const config& cache_config, savegame::load_game_metadata& data)
game_load::game_load(const game_config_view& cache_config, savegame::load_game_metadata& data)
: filename_(data.filename)
, save_index_manager_(data.manager)
, change_difficulty_(register_bool("change_difficulty", true, data.select_difficulty))

View file

@ -32,9 +32,9 @@ namespace dialogs
class game_load : public modal_dialog
{
public:
game_load(const config& cache_config, savegame::load_game_metadata& data);
game_load(const game_config_view& cache_config, savegame::load_game_metadata& data);
static bool execute(const config& cache_config, savegame::load_game_metadata& data)
static bool execute(const game_config_view& cache_config, savegame::load_game_metadata& data)
{
return game_load(cache_config, data).show();
}
@ -72,7 +72,7 @@ private:
config& summary_;
std::vector<savegame::save_info> games_;
const config& cache_config_;
const game_config_view& cache_config_;
std::vector<std::string> last_words_;
};

View file

@ -15,6 +15,7 @@
#pragma once
#include "gui/dialogs/modal_dialog.hpp"
class game_config_view;
namespace gui2
{

View file

@ -115,7 +115,7 @@ bool mp_lobby::logout_prompt()
return show_prompt(_("Do you really want to log out?"));
}
mp_lobby::mp_lobby(const config& game_config, mp::lobby_info& info, wesnothd_connection &connection)
mp_lobby::mp_lobby(const game_config_view& game_config, mp::lobby_info& info, wesnothd_connection &connection)
: quit_confirmation(&mp_lobby::logout_prompt)
, game_config_(game_config)
, gamelistbox_(nullptr)
@ -832,7 +832,7 @@ void mp_lobby::pre_show(window& window)
}, true);
plugins_context_->set_accessor("game_list", [this](const config&) { return lobby_info_.gamelist(); });
plugins_context_->set_accessor("game_config", [this](const config&) { return game_config_; });
//plugins_context_->set_accessor("game_config", [this](const config&) { return game_config_; });
}
void mp_lobby::post_show(window& /*window*/)

View file

@ -23,6 +23,8 @@
#include "quit_confirmation.hpp"
class wesnothd_connection;
class game_config_view;
namespace gui2
{
@ -62,7 +64,7 @@ struct player_list
class mp_lobby : public modal_dialog, public quit_confirmation, private plugin_executor
{
public:
mp_lobby(const config& game_config, mp::lobby_info& info, wesnothd_connection &connection);
mp_lobby(const game_config_view& game_config, mp::lobby_info& info, wesnothd_connection &connection);
~mp_lobby();
@ -168,7 +170,7 @@ private:
/** Inherited from modal_dialog. */
virtual void post_show(window& window) override;
const config& game_config_;
const game_config_view& game_config_;
listbox* gamelistbox_;

View file

@ -45,6 +45,7 @@
#include "preferences/game.hpp"
#include "save_index.hpp"
#include "savegame.hpp"
#include "game_config_view.hpp"
#include <boost/algorithm/string.hpp>
@ -67,7 +68,7 @@ namespace prefs = preferences;
REGISTER_DIALOG(mp_create_game)
mp_create_game::mp_create_game(const config& cfg, saved_game& state, bool local_mode, mp::user_info* host_info)
mp_create_game::mp_create_game(const game_config_view& cfg, saved_game& state, bool local_mode, mp::user_info* host_info)
: cfg_(cfg)
, create_engine_(state)
, config_engine_()
@ -410,7 +411,7 @@ void mp_create_game::pre_show(window& win)
on_mod_toggle(win, cfg["index"].to_int(), nullptr);
}, true);
plugins_context_->set_accessor("game_config", [this](const config&) {return cfg_; });
//plugins_context_->set_accessor("game_config", [this](const config&) {return cfg_; });
plugins_context_->set_accessor("get_selected", [this](const config&) {
const ng::level& current_level = create_engine_.current_level();
return config {

View file

@ -24,6 +24,7 @@
#include "mp_game_settings.hpp"
class config;
class game_config_view;
namespace mp
{
@ -44,7 +45,7 @@ class mp_create_game : public modal_dialog, private plugin_executor
typedef std::pair<ng::level::TYPE, std::string> level_type_info;
public:
mp_create_game(const config& cfg, saved_game& state, bool local_mode, mp::user_info* host_info = nullptr);
mp_create_game(const game_config_view& cfg, saved_game& state, bool local_mode, mp::user_info* host_info = nullptr);
private:
/** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
@ -56,7 +57,7 @@ private:
/** Inherited from modal_dialog. */
virtual void post_show(window& window) override;
const config& cfg_;
const game_config_view& cfg_;
ng::create_engine create_engine_;
std::unique_ptr<ng::configure_engine> config_engine_;

View file

@ -58,6 +58,7 @@
#include "gui/widgets/toggle_button.hpp"
#include "gui/widgets/window.hpp"
#include "lexical_cast.hpp"
#include "game_config_view.hpp"
#if BOOST_VERSION >= 106700
#include <boost/integer/common_factor_rt.hpp>
@ -114,7 +115,7 @@ using namespace preferences;
REGISTER_DIALOG(preferences_dialog)
preferences_dialog::preferences_dialog(const config& game_cfg, const PREFERENCE_VIEW& initial_view)
preferences_dialog::preferences_dialog(const game_config_view& game_cfg, const PREFERENCE_VIEW& initial_view)
: resolutions_() // should be populated by set_resolution_list before use
, adv_preferences_cfg_()
, last_selected_item_(0)

View file

@ -25,6 +25,7 @@
#include <boost/dynamic_bitset.hpp>
class game_config_view;
// This file is not named preferences.hpp in order -I conflicts with
// src/preferences.hpp.
@ -71,10 +72,10 @@ namespace dialogs
class preferences_dialog : public modal_dialog
{
public:
preferences_dialog(const config& game_cfg, const preferences::PREFERENCE_VIEW& initial_view);
preferences_dialog(const game_config_view& game_cfg, const preferences::PREFERENCE_VIEW& initial_view);
/** The display function -- see @ref modal_dialog for more information. */
static void display(const config& game_cfg, const preferences::PREFERENCE_VIEW initial_view = preferences::VIEW_DEFAULT)
static void display(const game_config_view& game_cfg, const preferences::PREFERENCE_VIEW initial_view = preferences::VIEW_DEFAULT)
{
preferences_dialog(game_cfg, initial_view).show();
}

View file

@ -127,7 +127,7 @@ static const size_t cache_max_size = 100;
* normally doesn't happen a lot so the clearing of the cache is rather
* unusual.
*/
static const ::config* terrain = nullptr;
static const ::game_config_view* terrain = nullptr;
/** The cache. */
typedef std::map<key_type, value_type> tcache;

View file

@ -20,7 +20,7 @@
#include "gui/core/window_builder.hpp"
class config;
class game_config_view;
namespace gui2
{
namespace implementation
@ -75,7 +75,7 @@ public:
return map_data_;
}
void set_config(const ::config* terrain)
void set_config(const ::game_config_view* terrain)
{
terrain_ = terrain;
}
@ -89,7 +89,7 @@ private:
*
* This config must be set before the object can be drawn.
*/
const ::config* terrain_;
const ::game_config_view* terrain_;
/**
* Gets the image for the minimap.

View file

@ -87,11 +87,10 @@ void show_unit_description(const unit_type &t)
help::show_unit_help(t.id(), t.show_variations_in_help(), hide_help);
}
extern config dummy_cfg;
help_manager::help_manager(const config *cfg) //, gamemap *_map)
help_manager::help_manager(const game_config_view *cfg) //, gamemap *_map)
{
game_cfg = cfg == nullptr ? &dummy_cfg : cfg;
static game_config_view dummy_view;
game_cfg = cfg == nullptr ? &dummy_view : cfg;
// map = _map;
}

View file

@ -19,12 +19,14 @@ class terrain_type;
class unit;
class unit_type;
class CVideo;
class game_config_view;
#include <string>
namespace help {
struct help_manager {
help_manager(const config *game_config);
help_manager(const game_config_view *game_config);
~help_manager();
};

View file

@ -63,7 +63,7 @@ static lg::log_domain log_help("help");
namespace help {
const config *game_cfg = nullptr;
const game_config_view *game_cfg = nullptr;
// The default toplevel.
help::section default_toplevel;
// All sections and topics not referenced from the default toplevel.
@ -73,7 +73,6 @@ int last_num_encountered_units = -1;
int last_num_encountered_terrains = -1;
boost::tribool last_debug_state = boost::indeterminate;
config dummy_cfg;
std::vector<std::string> empty_string_vector;
const int max_section_level = 15;
const int title_size = font::SIZE_LARGE;
@ -293,7 +292,7 @@ void generate_sections(const config *help_cfg, const std::string &generator, sec
if (generator == "races") {
generate_races_sections(help_cfg, sec, level);
} else if (generator == "terrains") {
generate_terrain_sections(help_cfg, sec, level);
generate_terrain_sections(sec, level);
} else if (generator == "eras") {
DBG_HP << "Generating eras...\n";
generate_era_sections(help_cfg, sec, level);
@ -834,7 +833,7 @@ void generate_era_sections(const config* help_cfg, section & sec, int level)
}
}
void generate_terrain_sections(const config* /*help_cfg*/, section& sec, int /*level*/)
void generate_terrain_sections(section& sec, int /*level*/)
{
ter_data_cache tdata = load_terrain_types_data();
@ -1350,10 +1349,7 @@ void generate_contents()
default_toplevel.clear();
hidden_sections.clear();
if (game_cfg != nullptr) {
const config *help_config = &game_cfg->child("help");
if (!*help_config) {
help_config = &dummy_cfg;
}
const config *help_config = &game_cfg->child_or_empty("help");
try {
default_toplevel = parse_config(help_config);
// Create a config object that contains everything that is

View file

@ -45,6 +45,7 @@
#include <boost/logic/tribool.hpp>
#include <boost/optional.hpp>
class game_config_view;
class config;
class unit_type;
class terrain_type_data;
@ -216,7 +217,7 @@ void generate_sections(const config *help_cfg, const std::string &generator, sec
std::vector<topic> generate_topics(const bool sort_topics,const std::string &generator);
std::string generate_topic_text(const std::string &generator, const config *help_cfg,
const section &sec, const std::vector<topic>& generated_topics);
std::string generate_contents_links(const std::string& section_name, config const *help_cfg);
std::string generate_contents_links(const std::string& section_name, const config *help_cfg);
std::string generate_contents_links(const section &sec, const std::vector<topic>& topics);
/// return a hyperlink with the unit's name and pointing to the unit page
@ -227,7 +228,7 @@ std::vector<std::string> make_unit_links_list(
const std::vector<std::string>& type_id_list, bool ordered = false);
void generate_races_sections(const config *help_cfg, section &sec, int level);
void generate_terrain_sections(const config* help_cfg, section &sec, int level);
void generate_terrain_sections(section &sec, int level);
std::vector<topic> generate_unit_topics(const bool, const std::string& race);
void generate_unit_sections(const config *help_cfg, section &sec, int level, const bool, const std::string& race);
enum UNIT_DESCRIPTION_TYPE {FULL_DESCRIPTION, NO_DESCRIPTION, NON_REVEALING_DESCRIPTION};
@ -297,7 +298,7 @@ std::string get_first_word(const std::string &s);
/// Load the appropriate terrain types data to use
ter_data_cache load_terrain_types_data();
extern const config *game_cfg;
extern const game_config_view *game_cfg;
// The default toplevel.
extern help::section default_toplevel;
// All sections and topics not referenced from the default toplevel.

View file

@ -23,7 +23,7 @@
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string.hpp>
#include "utils/functional.hpp"
#include "game_config_view.hpp"
#include <SDL2/SDL.h>
#include <key.hpp>
#include <serialization/unicode.hpp>
@ -38,7 +38,7 @@ static lg::log_domain log_config("config");
namespace hotkey {
hotkey_list hotkeys_;
config default_hotkey_cfg_;
game_config_view default_hotkey_cfg_;
namespace {
const int TOUCH_MOUSE_INDEX = 255;
@ -401,7 +401,7 @@ const hotkey_ptr get_hotkey(const SDL_Event &event)
return hotkey_ptr(new hotkey_void());
}
void load_hotkeys(const config& cfg, bool set_as_default)
void load_hotkeys(const game_config_view& cfg, bool set_as_default)
{
for (const config &hk : cfg.child_range("hotkey")) {
@ -424,7 +424,7 @@ void reset_default_hotkeys()
{
hotkeys_.clear();
if (!default_hotkey_cfg_.empty()) {
if (!default_hotkey_cfg_.child_range("hotkey").empty()) {
load_hotkeys(default_hotkey_cfg_, true);
} else {
ERR_G<< "no default hotkeys set yet; all hotkeys are now unassigned!" << std::endl;

View file

@ -21,6 +21,7 @@
#include <string>
#include <boost/algorithm/string.hpp>
class game_config_view;
class config;
namespace hotkey {
@ -389,7 +390,7 @@ const hotkey_ptr get_hotkey(const SDL_Event &event);
* @param set_as_default Indicates whether the config struct should be treated as the
* default game settings.
*/
void load_hotkeys(const config& cfg, bool set_as_default = false);
void load_hotkeys(const game_config_view& cfg, bool set_as_default = false);
/**
* Reset all hotkeys to the defaults.

View file

@ -19,6 +19,7 @@
#include "preferences/general.hpp"
#include "serialization/parser.hpp"
#include "serialization/preprocessor.hpp"
#include "game_config_manager.hpp"
#include <stdexcept>
#include <clocale>
@ -352,7 +353,7 @@ const language_def& get_locale()
return known_languages[0];
}
void init_textdomains(const config& cfg)
void init_textdomains(const game_config_view& cfg)
{
for (const config &t : cfg.child_range("textdomain"))
{
@ -375,7 +376,7 @@ void init_textdomains(const config& cfg)
}
}
bool init_strings(const config& cfg)
bool init_strings(const game_config_view& cfg)
{
languages_.clear();
for (const config &l : cfg.child_range("language")) {

View file

@ -19,6 +19,8 @@
#include <iterator>
class game_config_view;
//this module controls internationalization.
class config;
@ -94,10 +96,10 @@ bool current_language_rtl();
const language_def& get_locale();
/** Initializes the list of textdomains from a configuration object */
void init_textdomains(const config& cfg);
void init_textdomains(const game_config_view& cfg);
/** Initializes certain English strings */
bool init_strings(const config& cfg);
bool init_strings(const game_config_view& cfg);
bool load_language_list();

View file

@ -26,6 +26,7 @@ class game_state;
class gamemap;
class game_data;
class game_board;
class game_config_view;
class play_controller;
class team;
class unit_map;
@ -146,7 +147,7 @@ private:
game_display* gui_;
play_controller& pc_;
const config& game_config_;
const game_config_view& game_config_;
gui::floating_textbox textbox_info_;
std::string last_search_;

View file

@ -33,6 +33,7 @@
#include "sound.hpp"
#include "utils/general.hpp"
#include "video.hpp" // non_interactive()
#include "game_config_view.hpp"
#include <sys/stat.h> // for setting the permissions of the preferences file
#ifndef _WIN32
@ -864,7 +865,7 @@ void _set_color_cursors(bool value)
void load_hotkeys()
{
hotkey::load_hotkeys(prefs, false);
hotkey::load_hotkeys(game_config_view::wrap(prefs), false);
}
void save_hotkeys()

View file

@ -264,7 +264,7 @@ void saved_game::expand_scenario()
if(this->starting_point_type_ == STARTING_POINT_NONE && !has_carryover_expanded_) {
game_config_manager::get()->load_game_config_for_game(this->classification());
const config& game_config = game_config_manager::get()->game_config();
const game_config_view& game_config = game_config_manager::get()->game_config();
const config& scenario =
game_config.find_child(classification().get_tagname(), "id", carryover_["next_scenario"]);

View file

@ -45,6 +45,7 @@
#include "statistics.hpp"
#include "game_version.hpp"
#include "video.hpp"
#include "game_config_view.hpp"
#include <algorithm>
#include <iomanip>
@ -80,7 +81,7 @@ void clean_saves(const std::string& label)
}
}
loadgame::loadgame(const std::shared_ptr<save_index_class>& index, const config& game_config, saved_game& gamestate)
loadgame::loadgame(const std::shared_ptr<save_index_class>& index, const game_config_view& game_config, saved_game& gamestate)
: game_config_(game_config)
, gamestate_(gamestate)
, load_data_(index)

View file

@ -25,6 +25,7 @@
#include <exception>
class config_writer;
class game_config_view;
class version_info;
namespace savegame
@ -108,7 +109,7 @@ private:
class loadgame
{
public:
loadgame(const std::shared_ptr<save_index_class>& index, const config& game_config, saved_game& gamestate);
loadgame(const std::shared_ptr<save_index_class>& index, const game_config_view& game_config, saved_game& gamestate);
virtual ~loadgame() {}
/* In any of the following three function, a bool value of false indicates
@ -145,7 +146,7 @@ private:
/** Copy era information into the snapshot. */
void copy_era(config& cfg);
const config& game_config_;
const game_config_view& game_config_;
saved_game& gamestate_; /** Primary output information. */

View file

@ -172,7 +172,7 @@ struct map_locker
};
void game_lua_kernel::extract_preload_scripts(const config& game_config)
void game_lua_kernel::extract_preload_scripts(const game_config_view& game_config)
{
game_lua_kernel::preload_scripts.clear();
for (const config& cfg : game_config.child_range("lua")) {
@ -1389,13 +1389,11 @@ int game_lua_kernel::impl_game_config_get(lua_State *L)
//^ finds the era with name matching mp_era, and creates a lua reference from the config of that era.
//This code for SigurdFD, not the cleanest implementation but seems to work just fine.
config::const_child_itors its = game_config_manager::get()->game_config().child_range("era");
std::string eras_list(its.front()["id"]);
its.pop_front();
for(const auto& cfg : its) {
eras_list = eras_list + "," + cfg["id"];
std::vector<std::string> eras_list;
for (const config& era : game_config_manager::get()->game_config().child_range("era") ) {
eras_list.push_back(era["id"].str());
}
return_string_attrib("eras", eras_list);
return_string_attrib("eras", utils::join(eras_list));
}
return lua_kernel_base::impl_game_config_get(L);
}
@ -1425,7 +1423,7 @@ int game_lua_kernel::impl_game_config_set(lua_State *L)
modify_string_attrib("next_scenario", gamedata().set_next_scenario(value));
modify_string_attrib("theme",
gamedata().set_theme(value);
const config& game_config = game_config_manager::get()->game_config();
const game_config_view& game_config = game_config_manager::get()->game_config();
game_display_->set_theme(play_controller_.get_theme(game_config, value));
);
modify_vector_string_attrib("defeat_music", gamedata().set_defeat_music(std::move(value)));

View file

@ -22,6 +22,7 @@
#include <string> // for string
class config;
class game_config_view;
class unit;
class vconfig;
namespace ai { class engine_lua; }
@ -61,7 +62,7 @@ class game_lua_kernel : public lua_kernel_base
const game_events::queued_event & get_event_info();
static void extract_preload_scripts(const config& game_config);
static void extract_preload_scripts(const game_config_view& game_config);
static std::vector<config> preload_scripts;
static config preload_config;

View file

@ -25,6 +25,7 @@
#include "map/map.hpp"
#include "preferences/game.hpp"
#include "serialization/string_utils.hpp"
#include "game_config_view.hpp"
static lg::log_domain log_engine("engine");
#define ERR_NG LOG_STREAM(err, log_engine)
@ -85,7 +86,7 @@ static map_location legacy_difference(const map_location& me, const map_location
*/
terrain_builder::building_ruleset terrain_builder::building_rules_;
const config* terrain_builder::rules_cfg_ = nullptr;
const game_config_view* terrain_builder::rules_cfg_ = nullptr;
terrain_builder::rule_image::rule_image(int layer, int x, int y, bool global_image, int cx, int cy, bool is_water)
: layer(layer)
@ -287,7 +288,7 @@ void terrain_builder::flush_local_rules()
}
}
void terrain_builder::set_terrain_rules_cfg(const config& cfg)
void terrain_builder::set_terrain_rules_cfg(const game_config_view& cfg)
{
rules_cfg_ = &cfg;
// use the swap trick to clear the rules cache and get a fresh one.
@ -881,6 +882,11 @@ void terrain_builder::add_rotated_rules(building_ruleset& rules, building_rule&
}
void terrain_builder::parse_config(const config& cfg, bool local)
{
return parse_config(game_config_view::wrap(cfg), local);
}
void terrain_builder::parse_config(const game_config_view& cfg, bool local)
{
log_scope("terrain_builder::parse_config");
int n = 0;
@ -1012,7 +1018,7 @@ void terrain_builder::add_off_map_rule(const std::string& image)
item["set_flag"] = "base";
// Parse the object
parse_global_config(cfg);
parse_global_config(game_config_view::wrap(cfg));
}
bool terrain_builder::rule_matches(const terrain_builder::building_rule& rule,

View file

@ -25,6 +25,8 @@
#include "terrain/translation.hpp"
class config;
class game_config_view;
class gamemap;
namespace image
{
@ -92,7 +94,7 @@ public:
* @param cfg The main game configuration object, where the
* [terrain_graphics] rule reside.
*/
static void set_terrain_rules_cfg(const config& cfg);
static void set_terrain_rules_cfg(const game_config_view& cfg);
const gamemap& map() const
{
@ -755,8 +757,9 @@ private:
* @param local Mark the rules as local only.
*/
void parse_config(const config& cfg, bool local = true);
void parse_config(const game_config_view& cfg, bool local = true);
void parse_global_config(const config& cfg)
void parse_global_config(const game_config_view& cfg)
{
parse_config(cfg, false);
}
@ -858,5 +861,5 @@ private:
static building_ruleset building_rules_;
/** Config used to parse global terrain rules */
static const config* rules_cfg_;
static const game_config_view* rules_cfg_;
};

View file

@ -15,6 +15,7 @@
#include "terrain/type_data.hpp"
#include "serialization/string_utils.hpp"
#include "game_config_view.hpp"
#include <map>
@ -23,7 +24,7 @@
#define LOG_G LOG_STREAM(info, lg::general())
#define DBG_G LOG_STREAM(debug, lg::general())
terrain_type_data::terrain_type_data(const config & game_config)
terrain_type_data::terrain_type_data(const game_config_view & game_config)
: terrainList_()
, tcodeToTerrain_()
, initialized_(false)

View file

@ -18,6 +18,8 @@
#include <map>
class game_config_view;
/**
* Contains the database of all known terrain types, both those defined
* explicitly by WML [terrain_type]s and those made by combining pairs of
@ -40,10 +42,10 @@ private:
using tcodeToTerrain_t = std::map<t_translation::terrain_code, terrain_type>;
mutable tcodeToTerrain_t tcodeToTerrain_;
mutable bool initialized_;
const config & game_config_;
const game_config_view & game_config_;
public:
terrain_type_data(const config & game_config);
terrain_type_data(const game_config_view & game_config);
/**
* On the first call to this function, parse all of the [terrain_type]s

View file

@ -22,6 +22,7 @@
#include "formula/debugger.hpp"
#include "game_classification.hpp"
#include "game_config.hpp"
#include "game_config_view.hpp"
#include "game_display.hpp"
#include "game_events/manager.hpp"
#include "game_initialization/create_engine.hpp"
@ -163,6 +164,7 @@ namespace {
/** The main config, which contains the entire WML tree. */
config main_config;
game_config_view game_config_view_ = game_config_view::wrap(main_config);
/**
* Helper class to generate a dialog.
@ -404,7 +406,7 @@ BOOST_AUTO_TEST_CASE(test_gui2)
cache.add_define("MULTIPLAYER");
cache.get_config(game_config::path +"/data", main_config);
const filesystem::binary_paths_manager bin_paths_manager(main_config);
const filesystem::binary_paths_manager bin_paths_manager(game_config_view_);
load_language_list();
game_config::load_config(main_config.child("game_config"));
@ -731,6 +733,7 @@ template<>
struct dialog_tester<game_load>
{
config cfg;
game_config_view view;
// It would be good to have a test directory instead of using the same directory as the player,
// however this code will support that - default_saves_dir() will respect --userdata-dir.
savegame::load_game_metadata data{savegame::save_index_class::default_saves_dir()};
@ -740,7 +743,8 @@ struct dialog_tester<game_load>
}
game_load* create()
{
return new game_load(cfg, data);
view = game_config_view::wrap(cfg);
return new game_load(view, data);
}
};
@ -823,15 +827,17 @@ template<>
struct dialog_tester<mp_lobby>
{
config game_config;
game_config_view gc_view;
wesnothd_connection connection;
std::vector<std::string> installed_addons;
mp::lobby_info li;
dialog_tester() : connection("", ""), li(installed_addons)
{
gc_view = game_config_view::wrap(game_config);
}
mp_lobby* create()
{
return new mp_lobby(game_config, li, connection);
return new mp_lobby(gc_view, li, connection);
}
};
@ -900,7 +906,7 @@ struct dialog_tester<mp_create_game>
}
mp_create_game* create()
{
return new mp_create_game(main_config, state, true, nullptr);
return new mp_create_game(game_config_view_, state, true, nullptr);
}
};

View file

@ -18,6 +18,7 @@
#include <sstream>
#include "game_config.hpp"
#include "game_config_view.hpp"
#include "config_cache.hpp"
#include "config.hpp"
#include "color_range.hpp"
@ -86,11 +87,12 @@ private:
void set_up_image_paths()
{
config cfg;
game_config_view v = game_config_view::wrap(cfg);
cfg.add_child("binary_path",
create_path_config("data/core"));
paths_manager_.set_paths(cfg);
paths_manager_.set_paths(v);
}
static config create_color_range(const std::string& id,

View file

@ -17,6 +17,7 @@
#include "tests/utils/fake_display.hpp"
#include "game_board.hpp"
#include "game_config_view.hpp"
#include "game_display.hpp"
#include "terrain/type_data.hpp"
#include "reports.hpp"
@ -32,6 +33,7 @@ namespace test_utils {
CVideo video_;
config dummy_cfg_;
game_config_view dummy_cfg_view_;
config dummy_cfg2_;
game_board dummy_board_;
reports dummy_reports;
@ -62,8 +64,9 @@ namespace test_utils {
fake_display_manager::fake_display_manager() :
video_(CVideo::FAKE_TEST),
dummy_cfg_(),
dummy_cfg_view_(game_config_view::wrap(dummy_cfg_)),
dummy_cfg2_(),
dummy_board_(std::make_shared<terrain_type_data>(dummy_cfg_), dummy_cfg2_),
dummy_board_(std::make_shared<terrain_type_data>(dummy_cfg_view_), dummy_cfg2_),
main_event_context_(),
disp_(dummy_board_, std::shared_ptr<wb::manager> (), dummy_reports, dummy_cfg_, dummy_cfg_)
{

View file

@ -17,6 +17,7 @@
#include "tests/utils/game_config_manager_tests.hpp"
#include "config.hpp"
#include "game_config_view.hpp"
#include "config_cache.hpp"
#include "filesystem.hpp"
#include "font/font_config.hpp"
@ -41,6 +42,7 @@ namespace test_utils {
class game_config_manager {
config cfg_;
game_config_view game_config_view_;
filesystem::binary_paths_manager paths_manager_;
const hotkey::manager hotkey_manager_;
font::manager font_manager_;
@ -55,6 +57,7 @@ namespace test_utils {
public:
game_config_manager()
: cfg_()
, game_config_view_(game_config_view::wrap(cfg_))
, paths_manager_()
, hotkey_manager_()
, font_manager_()
@ -75,25 +78,21 @@ namespace test_utils {
load_language_list();
game_config::config_cache::instance().add_define("TEST");
game_config::config_cache::instance().get_config(game_config::path + "/data/test/", cfg_);
::init_textdomains(cfg_);
::init_textdomains(game_config_view_);
const std::vector<language_def>& languages = get_languages();
std::vector<language_def>::const_iterator English = std::find_if(languages.begin(),
languages.end(),
match_english); // Using German because the most active translation
::set_language(*English);
cfg_.merge_children("units");
if (config &units = cfg_.child("units")) {
unit_types.set_config(units);
}
unit_types.set_config(game_config_view_.merged_children_view("units"));
game_config::load_config(cfg_.child("game_config"));
hotkey::deactivate_all_scopes();
hotkey::set_scope_active(hotkey::SCOPE_GAME);
hotkey::load_hotkeys(cfg_);
paths_manager_.set_paths(cfg_);
hotkey::load_hotkeys(game_config_view_);
paths_manager_.set_paths(game_config_view_);
font::load_font_config();
}

View file

@ -25,7 +25,7 @@
#include "sdl/rect.hpp"
#include "serialization/string_utils.hpp"
#include "wml_exception.hpp"
#include "game_config_view.hpp"
#include <sstream>
#include <utility>
@ -938,7 +938,7 @@ const theme::status_item* theme::get_status_item(const std::string& key) const
typedef std::map<std::string, config> known_themes_map;
known_themes_map theme::known_themes;
void theme::set_known_themes(const config* cfg)
void theme::set_known_themes(const game_config_view* cfg)
{
known_themes.clear();
if(!cfg)

View file

@ -26,6 +26,8 @@
#include <memory>
#include <SDL2/SDL_rect.h>
class game_config_view;
struct _rect { std::size_t x1,y1,x2,y2; };
struct theme_info
@ -275,7 +277,7 @@ public:
const SDL_Rect& palette_location(const SDL_Rect& screen) const
{ return palette_.location(screen); }
static void set_known_themes(const config* cfg);
static void set_known_themes(const game_config_view* cfg);
static std::vector<theme_info> get_known_themes();
const border_t& border() const { return border_; }

View file

@ -190,7 +190,7 @@ unit_type::ability_metadata::ability_metadata(const config& cfg)
* Load data into an empty unit_type (build to FULL).
*/
void unit_type::build_full(
const movement_type_map& mv_types, const race_map& races, const config::const_child_itors& traits)
const movement_type_map& mv_types, const race_map& races, const config_array_view& traits)
{
// Don't build twice.
if(FULL <= build_status_) {
@ -233,7 +233,7 @@ void unit_type::build_full(
* Partially load data into an empty unit_type (build to HELP_INDEXED).
*/
void unit_type::build_help_index(
const movement_type_map& mv_types, const race_map& races, const config::const_child_itors& traits)
const movement_type_map& mv_types, const race_map& races, const config_array_view& traits)
{
// Don't build twice.
if(HELP_INDEXED <= build_status_) {
@ -418,7 +418,7 @@ void unit_type::build_created()
void unit_type::build(BUILD_STATUS status,
const movement_type_map& movement_types,
const race_map& races,
const config::const_child_itors& traits)
const config_array_view& traits)
{
DBG_UT << "Building unit type " << log_id() << ", level " << status << '\n';
@ -839,7 +839,7 @@ unit_type_data::unit_type_data()
, hide_help_all_(false)
, hide_help_type_()
, hide_help_race_()
, unit_cfg_(nullptr)
, units_cfg_()
, build_status_(unit_type::NOT_BUILT)
{
}
@ -1013,12 +1013,12 @@ void unit_type::fill_variations_and_gender()
* This includes some processing of the config, such as expanding base units.
* A pointer to the config is stored, so the config must be persistent.
*/
void unit_type_data::set_config(const config& cfg)
void unit_type_data::set_config(const game_config_view& cfg)
{
DBG_UT << "unit_type_data::set_config, name: " << cfg["name"] << "\n";
LOG_UT << "unit_type_data::set_config, nunits: " << cfg.child_range("unit_type").size() << "\n";
clear();
unit_cfg_ = &cfg;
units_cfg_ = cfg;
for(const config& mt : cfg.child_range("movetype")) {
movement_types_.emplace(mt["name"].str(), movetype(mt));
@ -1143,6 +1143,12 @@ void unit_type_data::set_config(const config& cfg)
hide_help_all_ = hide_help["all"].to_bool();
read_hide_help(hide_help);
}
DBG_UT << "Finished creatign unti types\n";
}
void unit_type_data::build_unit_type(const unit_type & ut, unit_type::BUILD_STATUS status) const
{
ut.build(status, movement_types_, races_, units_cfg().child_range("trait"));
}
/**
@ -1197,8 +1203,6 @@ void unit_type_data::build_all(unit_type::BUILD_STATUS status)
return;
}
assert(unit_cfg_ != nullptr);
for(const auto& type : types_) {
build_unit_type(type.second, status);

View file

@ -22,7 +22,7 @@
#include "units/attack_type.hpp"
#include "units/alignment.hpp"
#include "units/type_error.hpp"
#include "game_config_view.hpp"
#include <memory>
#include <array>
#include <map>
@ -32,7 +32,7 @@
class unit_ability_list;
class unit_animation;
class game_config_view;
typedef std::map<std::string, movetype> movement_type_map;
@ -84,10 +84,10 @@ public:
private: // These will be called by build().
/// Load data into an empty unit_type (build to FULL).
void build_full(const movement_type_map &movement_types,
const race_map &races, const config::const_child_itors &traits);
const race_map &races, const config_array_view &traits);
/// Partially load data into an empty unit_type (build to HELP_INDEXED).
void build_help_index(const movement_type_map &movement_types,
const race_map &races, const config::const_child_itors &traits);
const race_map &races, const config_array_view &traits);
/// Load the most needed data into an empty unit_type (build to CREATE).
void build_created();
@ -95,11 +95,11 @@ private: // These will be called by build().
public:
/// Performs a build of this to the indicated stage.
void build(BUILD_STATUS status, const movement_type_map &movement_types,
const race_map &races, const config::const_child_itors &traits);
const race_map &races, const config_array_view &traits);
/// Performs a build of this to the indicated stage.
/// (This does not logically change the unit type, so allow const access.)
void build(BUILD_STATUS status, const movement_type_map &movement_types,
const race_map &races, const config::const_child_itors &traits) const
const race_map &races, const config_array_view &traits) const
{ const_cast<unit_type *>(this)->build(status, movement_types, races, traits); }
@ -375,8 +375,8 @@ public:
const unit_type_map &types() const { return types_; }
const race_map &races() const { return races_; }
const config::const_child_itors traits() const { return unit_cfg_->child_range("trait"); }
void set_config(const config &cfg);
config_array_view traits() const { return units_cfg().child_range("trait"); }
void set_config(const game_config_view &cfg);
/// Finds a unit_type by its id() and makes sure it is built to the specified level.
const unit_type *find(const std::string &key, unit_type::BUILD_STATUS status = unit_type::FULL) const;
@ -386,8 +386,7 @@ public:
/// Makes sure the all unit_types are built to the specified level.
void build_all(unit_type::BUILD_STATUS status);
/// Makes sure the provided unit_type is built to the specified level.
void build_unit_type(const unit_type & ut, unit_type::BUILD_STATUS status) const
{ ut.build(status, movement_types_, races_, unit_cfg_->child_range("trait")); }
void build_unit_type(const unit_type & ut, unit_type::BUILD_STATUS status) const;
/** Checks if the [hide_help] tag contains these IDs. */
bool hide_help(const std::string &type_id, const std::string &race_id) const;
@ -412,7 +411,8 @@ private:
std::vector< std::set<std::string>> hide_help_type_;
std::vector< std::set<std::string>> hide_help_race_;
const config *unit_cfg_;
const game_config_view& units_cfg() const { return units_cfg_; }
game_config_view units_cfg_;
unit_type::BUILD_STATUS build_status_;
};