Now have a working config manager that can exist in the world properly.

main
Zed A. Shaw 2 months ago
parent f6ddf4b03b
commit ddf1ba955c
  1. 18
      assets/config.json
  2. 3
      main.cpp
  3. 1
      meson.build
  4. 5
      tests/ansi_parser.cpp
  5. 23
      tests/config.cpp

@ -0,0 +1,18 @@
{
"map": {
"WALL_TILE": "█",
"FLOOR_TILE": "\u2849",
"PLAYER_TILE": "♣",
"ENEMY_TILE": "Ω",
"BG_TILE": "█"
},
"enemies": {
},
"player": {
},
"type": {
"TEST": 1234
}
}

@ -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("can get references of config", "[config]") {
Config config("./tests/config.json");
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");
test_func(config);
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…
Cancel
Save