The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
game_config_manager.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2016 by Pauli Nieminen <[email protected]>
3  Part of thie Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #define GETTEXT_DOMAIN "wesnoth-test"
16 //#include <libintl.h>
17 
19 
20 #include "config.hpp"
21 #include "config_cache.hpp"
22 #include "filesystem.hpp"
23 #include "font.hpp"
24 #include "game_config.hpp"
25 #include "gettext.hpp"
28 #include "hotkey/hotkey_item.hpp"
29 #include "language.hpp"
30 #include "units/types.hpp"
31 
32 #include "gui/widgets/helper.hpp"
33 
34 #include <clocale>
35 
36 namespace test_utils {
37 
38  static bool match_english(const language_def& def)
39  {
40  return def.localename == "en_US";
41  }
42 
48 
50  static void check_manager()
51  {
52  if(manager)
53  return;
54  manager = new game_config_manager();
55  }
56  public:
58  : cfg_()
59  , paths_manager_()
60  , hotkey_manager_()
61  , font_manager_()
62  {
63 #ifdef _WIN32
64  setlocale(LC_ALL, "English");
65 #else
66  std::setlocale(LC_ALL, "C");
68 #endif
69  const std::string& intl_dir = filesystem::get_intl_dir();
70  translation::bind_textdomain("wesnoth", intl_dir.c_str(), "UTF-8");
71  translation::bind_textdomain("wesnoth-lib", intl_dir.c_str(), "UTF-8");
73 
74 
76  gui2::init();
80  ::init_textdomains(cfg_);
81  const std::vector<language_def>& languages = get_languages();
82  std::vector<language_def>::const_iterator English = std::find_if(languages.begin(),
83  languages.end(),
84  match_english); // Using German because the most active translation
85  ::set_language(*English);
86 
87  cfg_.merge_children("units");
88 
89  if (config &units = cfg_.child("units")) {
91  }
92 
93  game_config::load_config(cfg_.child("game_config"));
96 
98  paths_manager_.set_paths(cfg_);
100 
101  }
102 
104  {
105  check_manager();
106  return manager->get_config();
107  }
108 
110  {
111  return cfg_;
112  }
113  };
114 
115 
117 
119  {
121  }
122 
124  {
126  }
127 
128 }
void set_config(config &cfg)
Resets all data based on the provided config.
Definition: types.cpp:1005
static config_cache & instance()
Get reference to the singleton object.
void set_paths(const config &cfg)
this class is initialized once at game start put all initialization and wipe code in the methods here...
void merge_children(const std::string &key)
All children with the given key will be merged into the first element with that key.
Definition: config.cpp:574
void set_scope_active(scope s, bool set)
The paths manager is responsible for recording the various paths that binary files may be located at...
Definition: filesystem.hpp:210
unit_type_data unit_types
Definition: types.cpp:1314
void init()
Definition: gettext.cpp:189
Definitions for the interface to Wesnoth Markup Language (WML).
void set_language(const std::string &slocale, const std::vector< std::string > *alternates)
Definition: gettext.cpp:126
const config & get_test_config_ref()
void load_config(const config &v)
void bind_textdomain(const char *domain, const char *directory, const char *encoding)
Definition: gettext.cpp:105
std::string get_intl_dir()
std::string localename
Definition: language.hpp:46
void get_config(const std::string &path, config &cfg)
Gets a config object from given path.
static bool match_english(const language_def &def)
std::string path
void init_textdomains(const config &cfg)
Initializes the list of textdomains from a configuration object.
Definition: language.cpp:293
void set_default_textdomain(const char *domain)
Definition: gettext.cpp:121
bool init()
Initializes the gui subsystems.
Definition: helper.cpp:37
void deactivate_all_scopes()
bool load_font_config()
Definition: font.cpp:1048
config get_test_config()
bool load_language_list()
Definition: language.cpp:94
language_list get_languages()
Definition: language.cpp:118
Declarations for File-IO.
static game_config_manager * manager
void load_hotkeys(const config &cfg, bool set_as_default)
Iterates through all hotkeys present in the config struct and creates and adds them to the hotkey lis...
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
Definition: config.cpp:658
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
void add_define(const std::string &define)
Add a entry to preproc defines map.
GLsizei const GLcharARB ** string
Definition: glew.h:4503
unit_map * units
Definition: resources.cpp:35
filesystem::binary_paths_manager paths_manager_