/
game_config_manager.cpp
129 lines (104 loc) · 3.16 KB
/
game_config_manager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
Copyright (C) 2008 - 2014 by Pauli Nieminen <paniemin@cc.hut.fi>
Part of thie Battle for Wesnoth Project http://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.
*/
#define GETTEXT_DOMAIN "wesnoth-test"
//#include <libintl.h>
#include "tests/utils/game_config_manager.hpp"
#include "config.hpp"
#include "config_cache.hpp"
#include "display.hpp"
#include "filesystem.hpp"
#include "font.hpp"
#include "game_config.hpp"
#include "gettext.hpp"
#include "hotkey/hotkey_manager.hpp"
#include "hotkey/hotkey_command.hpp"
#include "hotkey/hotkey_item.hpp"
#include "language.hpp"
#include "unit_types.hpp"
#include "gui/widgets/helper.hpp"
#include <clocale>
namespace test_utils {
static bool match_english(const language_def& def)
{
return def.localename == "en_US";
}
class game_config_manager {
config cfg_;
filesystem::binary_paths_manager paths_manager_;
const hotkey::manager hotkey_manager_;
font::manager font_manager_;
static game_config_manager* manager;
static void check_manager()
{
if(manager)
return;
manager = new game_config_manager();
}
public:
game_config_manager()
: cfg_()
, paths_manager_()
, hotkey_manager_()
, font_manager_()
{
#ifdef _WIN32
setlocale(LC_ALL, "English");
#else
std::setlocale(LC_ALL, "C");
translation::init();
#endif
const std::string& intl_dir = filesystem::get_intl_dir();
translation::bind_textdomain("wesnoth", intl_dir.c_str(), "UTF-8");
translation::bind_textdomain("wesnoth-lib", intl_dir.c_str(), "UTF-8");
translation::set_default_textdomain("wesnoth");
font::load_font_config();
gui2::init();
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_);
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);
}
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_);
font::load_font_config();
}
static config& get_config_static()
{
check_manager();
return manager->get_config();
}
config& get_config()
{
return cfg_;
}
};
game_config_manager* game_config_manager::manager;
const config& get_test_config_ref()
{
return game_config_manager::get_config_static();
}
config get_test_config()
{
return game_config_manager::get_config_static();
}
}