Skip to content

Commit

Permalink
improvements(config): remove useless game config
Browse files Browse the repository at this point in the history
  • Loading branch information
Milerius committed Oct 13, 2019
1 parent 513e314 commit 02c2477
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 137 deletions.
1 change: 0 additions & 1 deletion modules/config/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
## shared sources between the module and his unit tests
add_library(antara_config_shared_sources STATIC)
target_sources(antara_config_shared_sources PRIVATE
antara/gaming/config/config.game.cpp
antara/gaming/config/config.game.maker.cpp)
target_include_directories(antara_config_shared_sources PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(antara_config_shared_sources PUBLIC antara::default_settings antara::graphics nlohmann_json::nlohmann_json)
Expand Down
59 changes: 41 additions & 18 deletions modules/config/antara/gaming/config/antara.config.game.tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,47 @@

#include <doctest/doctest.h>
#include "antara/gaming/config/config.loading.hpp"
#include "antara/gaming/config/config.game.hpp"

struct my_awesome_cfg
{
int awesome_value{0};

bool operator==(const my_awesome_cfg &rhs) const
{
return awesome_value == rhs.awesome_value;
}

bool operator!=(const my_awesome_cfg &rhs) const
{
return !(rhs == *this);
}
};

void from_json(const nlohmann::json &j, my_awesome_cfg& cfg)
{
j.at("awesome_value").get_to(cfg.awesome_value);
}

void to_json(nlohmann::json &j, const my_awesome_cfg& cfg)
{
j["awesome_value"] = cfg.awesome_value;
}

namespace antara::gaming::config::tests
{
TEST_CASE ("game config from json")
{
auto json_game_cfg = R"({"window":{"size":{"height":1200,"width":800},"title":"my_game title", "fullscreen": false}})"_json;
game_cfg game_config{};
CHECK_NOTHROW(from_json(json_game_cfg, game_config));
CHECK_EQ(game_config, game_cfg{1200u, 800u, "my_game title", false});
CHECK_NE(game_config, game_cfg{1200u, 800u, "fake", false});
CHECK_NE(game_config.win_cfg, game_cfg{1200u, 800u, "fake", false}.win_cfg);
auto json_game_cfg = R"({"awesome_value": 42})"_json;
my_awesome_cfg game_config{};
CHECK_NOTHROW(from_json(json_game_cfg, game_config));
CHECK_EQ(game_config, my_awesome_cfg{42});
CHECK_NE(game_config, my_awesome_cfg{21});
}

TEST_CASE ("game config to json")
{
auto json_game_cfg = R"({"window":{"size":{"height":1200,"width":800},"title":"my_game title", "fullscreen": false}})"_json;
game_cfg game_config{1200u, 800u, "my_game title", false};
auto json_game_cfg = R"({"awesome_value": 42})"_json;
my_awesome_cfg game_config{42u};
nlohmann::json json_data;
CHECK_NOTHROW(to_json(json_data, game_config));
CHECK_EQ(json_game_cfg, json_data);
Expand All @@ -45,13 +68,13 @@ namespace antara::gaming::config::tests
AND_WHEN("we load the configuration from a root directory") {
THEN("we got a default configuration") {
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) || defined(EMSCRIPTEN) && !defined(EMSCRIPTEN_ONLY_WEB)
REQUIRE_EQ(load_configuration<config::game_cfg>("/toto", "my_game.config.json"),
game_cfg{});
REQUIRE_EQ(load_configuration<my_awesome_cfg>("/toto", "my_game.config.json"),
my_awesome_cfg{});
REQUIRE_FALSE(std::filesystem::exists("/toto"));

#else
auto res = load_configuration<config::game_cfg>(std::filesystem::path("G:\\toto"), "my_game.config.json");
REQUIRE_EQ(res, config::game_cfg{});
auto res = load_configuration<my_awesome_cfg>(std::filesystem::path("G:\\toto"), "my_game.config.json");
REQUIRE_EQ(res, my_awesome_cfg{});
auto path_exist = std::filesystem::exists("G:\\toto");
REQUIRE_FALSE(path_exist);
#endif
Expand All @@ -60,8 +83,8 @@ namespace antara::gaming::config::tests
AND_WHEN ("we load the configuration from a non root directory") {
THEN("we create a default configuration in the given path and we got a default configuration") {
REQUIRE_EQ(
load_configuration<game_cfg>(std::filesystem::current_path() / "my_assets/config",
"my_game.config.json"), game_cfg{}
load_configuration<my_awesome_cfg>(std::filesystem::current_path() / "my_assets/config",
"my_game.config.json"), my_awesome_cfg{}
);
REQUIRE(std::filesystem::exists(std::filesystem::current_path() / "my_assets/config/my_game.config.json"));
}
Expand All @@ -80,7 +103,7 @@ namespace antara::gaming::config::tests
GIVEN ("a configuration exist in the given path") {
auto path = std::filesystem::current_path() / "assets/config";
THEN("we create the configuration and the directories") {
auto json_game_cfg = R"({"window":{"size":{"height":1200,"width":800},"title":"my_game", "fullscreen": false}})"_json;
auto json_game_cfg = R"({"awesome_value": 42})"_json;
std::filesystem::create_directories(path);
REQUIRE(std::filesystem::exists(path)
);
Expand All @@ -92,8 +115,8 @@ namespace antara::gaming::config::tests
}
AND_WHEN("We load the configuration from this fresh directories") {
THEN("We got this config") {
game_cfg game_config{1200u, 800u, "my_game", false};
REQUIRE_EQ(load_configuration<game_cfg>(std::move(path), "my_game.config.json"),
my_awesome_cfg game_config{42};
REQUIRE_EQ(load_configuration<my_awesome_cfg>(std::move(path), "my_game.config.json"),
game_config);
}
AND_THEN("We clear the directory that we create for this test") {
Expand Down
38 changes: 0 additions & 38 deletions modules/config/antara/gaming/config/config.game.cpp

This file was deleted.

71 changes: 0 additions & 71 deletions modules/config/antara/gaming/config/config.game.hpp

This file was deleted.

1 change: 0 additions & 1 deletion modules/config/antara/gaming/config/config.game.maker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include <nlohmann/json.hpp>
#include "antara/gaming/graphics/component.canvas.hpp"
#include "config.game.hpp"

namespace antara::gaming::graphics
{
Expand Down
1 change: 0 additions & 1 deletion modules/sfml/antara/gaming/sfml/input.system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include <SFML/Window/Event.hpp>
#include <antara/gaming/graphics/component.canvas.hpp>
#include "antara/gaming/config/config.game.hpp"
#include "antara/gaming/event/quit.game.hpp"
#include "antara/gaming/event/mouse.button.pressed.hpp"
#include "antara/gaming/event/mouse.button.released.hpp"
Expand Down
1 change: 0 additions & 1 deletion modules/sfml/antara/gaming/sfml/komodo.intro.scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <entt/signal/dispatcher.hpp>
#include <entt/entity/helper.hpp>
#include <SFML/Graphics.hpp>
#include "antara/gaming/config/config.game.hpp"
#include "antara/gaming/scenes/base.scene.hpp"
#include "antara/gaming/graphics/component.layer.hpp"
#include "antara/gaming/transform/component.position.hpp"
Expand Down
6 changes: 1 addition & 5 deletions modules/world/antara/gaming/world/world.app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include "antara/gaming/core/real.path.hpp"
#include "antara/gaming/config/config.loading.hpp"
#include "antara/gaming/config/config.game.hpp"
#include "antara/gaming/config/config.game.maker.hpp"
#include "antara/gaming/event/start.game.hpp"
#include "antara/gaming/world/world.app.hpp"
Expand All @@ -34,13 +33,10 @@ void emscripten_antara_loop(void *world)
namespace antara::gaming::world
{
//! Constructor
app::app(std::string config_name, std::string config_maker_name) noexcept
app::app(std::string config_maker_name) noexcept
{
auto cfg = config::load_configuration<config::game_cfg>(core::assets_real_path() / "config",
std::move(config_name));
auto cfg_maker = config::load_configuration<graphics::canvas_2d>(core::assets_real_path() / "config",
std::move(config_maker_name));
this->entity_registry_.set<config::game_cfg>(cfg);
auto &canvas_2d_cmp = this->entity_registry_.set<graphics::canvas_2d>(cfg_maker);
canvas_2d_cmp.reset_canvas();
dispatcher_.sink<event::quit_game>().connect<&app::receive_quit_game>(*this);
Expand Down
2 changes: 1 addition & 1 deletion modules/world/antara/gaming/world/world.app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace antara::gaming::world
class app
{
public:
app(std::string config_name = "game.config.json", std::string config_maker_name = "game.config.maker.json") noexcept;
app(std::string config_maker_name = "game.config.maker.json") noexcept;

//! Public callbacks
void receive_quit_game(const event::quit_game &evt) noexcept;
Expand Down

0 comments on commit 02c2477

Please sign in to comment.