From 02c2477586b04c187f630c6932a32e842cdea481 Mon Sep 17 00:00:00 2001 From: Roman Sztergbaum Date: Sun, 13 Oct 2019 03:36:16 +0200 Subject: [PATCH] improvements(config): remove useless game config --- modules/config/CMakeLists.txt | 1 - .../config/antara.config.game.tests.cpp | 59 ++++++++++----- .../antara/gaming/config/config.game.cpp | 38 ---------- .../antara/gaming/config/config.game.hpp | 71 ------------------- .../gaming/config/config.game.maker.hpp | 1 - .../sfml/antara/gaming/sfml/input.system.cpp | 1 - .../antara/gaming/sfml/komodo.intro.scene.hpp | 1 - .../world/antara/gaming/world/world.app.cpp | 6 +- .../world/antara/gaming/world/world.app.hpp | 2 +- 9 files changed, 43 insertions(+), 137 deletions(-) delete mode 100644 modules/config/antara/gaming/config/config.game.cpp delete mode 100644 modules/config/antara/gaming/config/config.game.hpp diff --git a/modules/config/CMakeLists.txt b/modules/config/CMakeLists.txt index dca1565c..ad787e0b 100644 --- a/modules/config/CMakeLists.txt +++ b/modules/config/CMakeLists.txt @@ -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) diff --git a/modules/config/antara/gaming/config/antara.config.game.tests.cpp b/modules/config/antara/gaming/config/antara.config.game.tests.cpp index a7c38399..5d35a3f0 100644 --- a/modules/config/antara/gaming/config/antara.config.game.tests.cpp +++ b/modules/config/antara/gaming/config/antara.config.game.tests.cpp @@ -16,24 +16,47 @@ #include #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); @@ -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("/toto", "my_game.config.json"), - game_cfg{}); + REQUIRE_EQ(load_configuration("/toto", "my_game.config.json"), + my_awesome_cfg{}); REQUIRE_FALSE(std::filesystem::exists("/toto")); #else - auto res = load_configuration(std::filesystem::path("G:\\toto"), "my_game.config.json"); - REQUIRE_EQ(res, config::game_cfg{}); + auto res = load_configuration(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 @@ -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(std::filesystem::current_path() / "my_assets/config", - "my_game.config.json"), game_cfg{} + load_configuration(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")); } @@ -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) ); @@ -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(std::move(path), "my_game.config.json"), + my_awesome_cfg game_config{42}; + REQUIRE_EQ(load_configuration(std::move(path), "my_game.config.json"), game_config); } AND_THEN("We clear the directory that we create for this test") { diff --git a/modules/config/antara/gaming/config/config.game.cpp b/modules/config/antara/gaming/config/config.game.cpp deleted file mode 100644 index d6147dbc..00000000 --- a/modules/config/antara/gaming/config/config.game.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/****************************************************************************** - * Copyright © 2013-2019 The Komodo Platform Developers. * - * * - * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * - * the top-level directory of this distribution for the individual copyright * - * holder information and the developer policies on copyright and licensing. * - * * - * Unless otherwise agreed in a custom licensing agreement, no part of the * - * Komodo Platform software, including this file may be copied, modified, * - * propagated or distributed except according to the terms contained in the * - * LICENSE file * - * * - * Removal or modification of this copyright notice is prohibited. * - * * - ******************************************************************************/ - -#include "antara/gaming/config/config.game.hpp" - -namespace antara::gaming::config -{ - void from_json(const nlohmann::json &json_data, antara::gaming::config::game_cfg &game_cfg) - { - game_cfg.win_cfg.title = json_data.at("window").at("title").get(); - game_cfg.win_cfg.height = json_data.at("window").at("size").at("height").get(); - game_cfg.win_cfg.width = json_data.at("window").at("size").at("width").get(); - game_cfg.win_cfg.is_fullscreen = json_data.at("window").at("fullscreen").get(); - } - - void to_json(nlohmann::json &json_data, const game_cfg &game_cfg) - { - json_data["window"] = nlohmann::json::object(); - json_data["window"]["size"] = nlohmann::json::object(); - json_data["window"]["size"]["height"] = game_cfg.win_cfg.height; - json_data["window"]["size"]["width"] = game_cfg.win_cfg.width; - json_data["window"]["title"] = game_cfg.win_cfg.title; - json_data["window"]["fullscreen"] = game_cfg.win_cfg.is_fullscreen; - } -} diff --git a/modules/config/antara/gaming/config/config.game.hpp b/modules/config/antara/gaming/config/config.game.hpp deleted file mode 100644 index 763ede71..00000000 --- a/modules/config/antara/gaming/config/config.game.hpp +++ /dev/null @@ -1,71 +0,0 @@ -/****************************************************************************** - * Copyright © 2013-2019 The Komodo Platform Developers. * - * * - * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * - * the top-level directory of this distribution for the individual copyright * - * holder information and the developer policies on copyright and licensing. * - * * - * Unless otherwise agreed in a custom licensing agreement, no part of the * - * Komodo Platform software, including this file may be copied, modified, * - * propagated or distributed except according to the terms contained in the * - * LICENSE file * - * * - * Removal or modification of this copyright notice is prohibited. * - * * - ******************************************************************************/ - -#pragma once - -#include -#include -#include -#include - -namespace antara::gaming::config -{ - struct window_cfg - { - bool operator==(const window_cfg &rhs_win) const noexcept - { - return height == rhs_win.height && - width == rhs_win.width && - title == rhs_win.title && - is_fullscreen == rhs_win.is_fullscreen; - } - - bool operator!=(const window_cfg &rhs_win) const noexcept - { - return !(rhs_win == *this); - } - - std::size_t height{1200}; //!< the height of the game window - std::size_t width{800}; //!< the width of the game window - std::string title{"my game window"}; //!< the title of the game window - bool is_fullscreen{false}; //!< is the window full screen? - }; - - struct game_cfg - { - bool operator==(const game_cfg &rhs_config) const noexcept - { - return win_cfg == rhs_config.win_cfg; - } - - bool operator!=(const game_cfg &rhs_config) const noexcept - { - return !(rhs_config == *this); - } - - game_cfg() = default; - - game_cfg(const game_cfg& other) = default; - - game_cfg& operator=(const game_cfg& other) = default; - - window_cfg win_cfg; - }; - - void from_json(const nlohmann::json &json_data, game_cfg &game_cfg); - - void to_json(nlohmann::json &json_data, const game_cfg &game_cfg); -} \ No newline at end of file diff --git a/modules/config/antara/gaming/config/config.game.maker.hpp b/modules/config/antara/gaming/config/config.game.maker.hpp index dc5707ba..edfb3261 100644 --- a/modules/config/antara/gaming/config/config.game.maker.hpp +++ b/modules/config/antara/gaming/config/config.game.maker.hpp @@ -18,7 +18,6 @@ #include #include "antara/gaming/graphics/component.canvas.hpp" -#include "config.game.hpp" namespace antara::gaming::graphics { diff --git a/modules/sfml/antara/gaming/sfml/input.system.cpp b/modules/sfml/antara/gaming/sfml/input.system.cpp index e377c2c8..d2628afc 100644 --- a/modules/sfml/antara/gaming/sfml/input.system.cpp +++ b/modules/sfml/antara/gaming/sfml/input.system.cpp @@ -16,7 +16,6 @@ #include #include -#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" diff --git a/modules/sfml/antara/gaming/sfml/komodo.intro.scene.hpp b/modules/sfml/antara/gaming/sfml/komodo.intro.scene.hpp index 3a567e44..fff8f9a2 100644 --- a/modules/sfml/antara/gaming/sfml/komodo.intro.scene.hpp +++ b/modules/sfml/antara/gaming/sfml/komodo.intro.scene.hpp @@ -21,7 +21,6 @@ #include #include #include -#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" diff --git a/modules/world/antara/gaming/world/world.app.cpp b/modules/world/antara/gaming/world/world.app.cpp index 3898126a..7339eb94 100644 --- a/modules/world/antara/gaming/world/world.app.cpp +++ b/modules/world/antara/gaming/world/world.app.cpp @@ -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" @@ -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(core::assets_real_path() / "config", - std::move(config_name)); auto cfg_maker = config::load_configuration(core::assets_real_path() / "config", std::move(config_maker_name)); - this->entity_registry_.set(cfg); auto &canvas_2d_cmp = this->entity_registry_.set(cfg_maker); canvas_2d_cmp.reset_canvas(); dispatcher_.sink().connect<&app::receive_quit_game>(*this); diff --git a/modules/world/antara/gaming/world/world.app.hpp b/modules/world/antara/gaming/world/world.app.hpp index a54639b4..15d18218 100644 --- a/modules/world/antara/gaming/world/world.app.hpp +++ b/modules/world/antara/gaming/world/world.app.hpp @@ -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;