Now have a working config manager that can exist in the world properly.
This commit is contained in:
parent
f6ddf4b03b
commit
ddf1ba955c
5 changed files with 46 additions and 6 deletions
18
assets/config.json
Normal file
18
assets/config.json
Normal file
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"map": {
|
||||
"WALL_TILE": "█",
|
||||
"FLOOR_TILE": "\u2849",
|
||||
"PLAYER_TILE": "♣",
|
||||
"ENEMY_TILE": "Ω",
|
||||
"BG_TILE": "█"
|
||||
},
|
||||
"enemies": {
|
||||
|
||||
},
|
||||
"player": {
|
||||
|
||||
},
|
||||
"type": {
|
||||
"TEST": 1234
|
||||
}
|
||||
}
|
3
main.cpp
3
main.cpp
|
@ -54,6 +54,9 @@ void configure_world(DinkyECS::World &world, Map &game_map) {
|
|||
int main() {
|
||||
DinkyECS::World world;
|
||||
|
||||
Config config("./assets/config.json");
|
||||
world.set_the<Config>(config);
|
||||
|
||||
Map game_map(GAME_MAP_X, GAME_MAP_Y);
|
||||
game_map.generate();
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ roguish = executable('roguish', [
|
|||
'systems.cpp',
|
||||
'ansi_parser.cpp',
|
||||
'render.cpp',
|
||||
'config.cpp',
|
||||
],
|
||||
dependencies: dependencies)
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <ftxui/screen/terminal.hpp> // for ColorSupport, Color, Palette16, Palette256, TrueColor
|
||||
|
||||
|
||||
using namespace fmt;
|
||||
using namespace ftxui;
|
||||
|
||||
|
@ -56,12 +55,12 @@ TEST_CASE("test out ragel parser", "[gui]") {
|
|||
sf::Color default_bg(100,100,100);
|
||||
|
||||
// this sets the Truecolor so need to do it first
|
||||
ANSIParser parser(default_fg, default_bg);
|
||||
ANSIParser ansi(default_fg, default_bg);
|
||||
std::string colors = generate_colors();
|
||||
std::cout << colors;
|
||||
|
||||
|
||||
bool good = parser.parse(colors, [&](sf::Color bgcolor, sf::Color color, wchar_t ch) {
|
||||
bool good = ansi.parse(colors, [&](sf::Color bgcolor, sf::Color color, wchar_t ch) {
|
||||
bool correct_char = ch == '#' || ch == ' ' || ch == '\n' || ch == '\r';
|
||||
REQUIRE(correct_char);
|
||||
});
|
||||
|
|
|
@ -33,11 +33,30 @@ TEST_CASE("basic configuration system", "[config]") {
|
|||
REQUIRE(test_obj["name"] == "Zed");
|
||||
}
|
||||
|
||||
void test_func(Config &ref) {
|
||||
void test_can_ref(Config &ref) {
|
||||
REQUIRE(ref["types"]["OBJECT"]["name"] == "Zed");
|
||||
}
|
||||
|
||||
TEST_CASE("store config in any", "[config]") {
|
||||
TEST_CASE("can get references of config", "[config]") {
|
||||
Config config("./tests/config.json");
|
||||
test_func(config);
|
||||
test_can_ref(config);
|
||||
}
|
||||
|
||||
TEST_CASE("store config in any", "[config]") {
|
||||
auto as_any = std::make_any<Config>("./tests/config.json");
|
||||
|
||||
Config &cfg = std::any_cast<Config &>(as_any);
|
||||
REQUIRE(cfg["types"]["NUMBER"] == 1234);
|
||||
}
|
||||
|
||||
void test_will_live(DinkyECS::World &world) {
|
||||
Config config("./tests/config.json");
|
||||
world.set_the<Config>(config);
|
||||
}
|
||||
|
||||
TEST_CASE("can go into a world", "[config]") {
|
||||
DinkyECS::World world;
|
||||
test_will_live(world);
|
||||
Config &cfg = world.get_the<Config>();
|
||||
REQUIRE(cfg["types"]["NUMBER"] == 1234);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue