diff --git a/config/board.json b/config/board.json deleted file mode 100644 index 0aa8b3a..0000000 --- a/config/board.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - "chesspp": - { - "board": - { - "width": 8, - "height": 8, - "pieces": - [ - ["Rook", "Knight", "Bishop", "Queen", "King", "Bishop", "Knight", "Rook"], - ["Pawn", "Pawn" , "Pawn" , "Pawn" , "Pawn", "Pawn" , "Pawn" , "Pawn"], - [null , null , null , null , null , null , null , null ], - [null , null , null , null , null , null , null , null ], - [null , null , null , null , null , null , null , null ], - [null , null , null , null , null , null , null , null ], - ["Pawn", "Pawn" , "Pawn" , "Pawn" , "Pawn", "Pawn" , "Pawn" , "Pawn"], - ["Rook", "Knight", "Bishop", "Queen", "King", "Bishop", "Knight", "Rook"] - ], - "suits": - [ - ["Black", "Black", "Black", "Black", "Black", "Black", "Black", "Black"], - ["Black", "Black", "Black", "Black", "Black", "Black", "Black", "Black"], - [null , null , null , null , null , null , null , null ], - [null , null , null , null , null , null , null , null ], - [null , null , null , null , null , null , null , null ], - [null , null , null , null , null , null , null , null ], - ["White", "White", "White", "White", "White", "White", "White", "White"], - ["White", "White", "White", "White", "White", "White", "White", "White"] - ], - "cell width": 80, - "cell height": 80, - "metadata": - { - "pawn facing": - [ - [null , null , null , null , null , null , null , null ], - ["South", "South", "South", "South", "South", "South", "South", "South"], - [null , null , null , null , null , null , null , null ], - [null , null , null , null , null , null , null , null ], - [null , null , null , null , null , null , null , null ], - [null , null , null , null , null , null , null , null ], - ["North", "North", "North", "North", "North", "North", "North", "North"], - [null , null , null , null , null , null , null , null ] - ], - "first turn": "White" - } - } - } -} diff --git a/config/chesspp/board.json b/config/chesspp/board.json new file mode 100644 index 0000000..6be1074 --- /dev/null +++ b/config/chesspp/board.json @@ -0,0 +1,46 @@ +{ + "board": + { + "width": 8, + "height": 8, + "pieces": + [ + ["Rook", "Knight", "Bishop", "Queen", "King", "Bishop", "Knight", "Rook"], + ["Pawn", "Pawn" , "Pawn" , "Pawn" , "Pawn", "Pawn" , "Pawn" , "Pawn"], + [null , null , null , null , null , null , null , null ], + [null , null , null , null , null , null , null , null ], + [null , null , null , null , null , null , null , null ], + [null , null , null , null , null , null , null , null ], + ["Pawn", "Pawn" , "Pawn" , "Pawn" , "Pawn", "Pawn" , "Pawn" , "Pawn"], + ["Rook", "Knight", "Bishop", "Queen", "King", "Bishop", "Knight", "Rook"] + ], + "suits": + [ + ["Black", "Black", "Black", "Black", "Black", "Black", "Black", "Black"], + ["Black", "Black", "Black", "Black", "Black", "Black", "Black", "Black"], + [null , null , null , null , null , null , null , null ], + [null , null , null , null , null , null , null , null ], + [null , null , null , null , null , null , null , null ], + [null , null , null , null , null , null , null , null ], + ["White", "White", "White", "White", "White", "White", "White", "White"], + ["White", "White", "White", "White", "White", "White", "White", "White"] + ], + "cell width": 80, + "cell height": 80, + "metadata": + { + "pawn facing": + [ + [null , null , null , null , null , null , null , null ], + ["South", "South", "South", "South", "South", "South", "South", "South"], + [null , null , null , null , null , null , null , null ], + [null , null , null , null , null , null , null , null ], + [null , null , null , null , null , null , null , null ], + [null , null , null , null , null , null , null , null ], + ["North", "North", "North", "North", "North", "North", "North", "North"], + [null , null , null , null , null , null , null , null ] + ], + "first turn": "White" + } + } +} diff --git a/config/chesspp/resources.json b/config/chesspp/resources.json new file mode 100644 index 0000000..b60e12a --- /dev/null +++ b/config/chesspp/resources.json @@ -0,0 +1,35 @@ +{ + "missing": "res/img/missing.png", + "board": + { + "board": "res/img/chessboard_640x640.png", + "valid move": "res/img/valid_move.png", + "enemy move": "res/img/enemy_move.png", + "valid capture": "res/img/valid_capture.png", + "enemy capture": "res/img/enemy_capture.png", + "pieces": + { + "Black": + { + "Pawn": "res/img/pieces/black/pawn.png", + "Rook": "res/img/pieces/black/rook.png", + "Knight": "res/img/pieces/black/knight.png", + "Bishop": "res/img/pieces/black/bishop.png", + "Queen": "res/img/pieces/black/queen.png", + "King": "res/img/pieces/black/king.png", + "": "res/img/missing.png" + }, + "White": + { + "Pawn": "res/img/pieces/white/pawn.png", + "Rook": "res/img/pieces/white/rook.png", + "Knight": "res/img/pieces/white/knight.png", + "Bishop": "res/img/pieces/white/bishop.png", + "Queen": "res/img/pieces/white/queen.png", + "King": "res/img/pieces/white/king.png", + "": "res/img/missing.png" + }, + "": "res/img/missing.png" + } + } +} diff --git a/config/graphics.json b/config/graphics.json deleted file mode 100644 index b7a723d..0000000 --- a/config/graphics.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "chesspp": - { - "missing": "res/img/missing.png", - "board": - { - "board": "res/img/chessboard_640x640.png", - "valid move": "res/img/valid_move.png", - "enemy move": "res/img/enemy_move.png", - "valid capture": "res/img/valid_capture.png", - "enemy capture": "res/img/enemy_capture.png", - "pieces": - { - "Black": - { - "Pawn": "res/img/pieces/black/pawn.png", - "Rook": "res/img/pieces/black/rook.png", - "Knight": "res/img/pieces/black/knight.png", - "Bishop": "res/img/pieces/black/bishop.png", - "Queen": "res/img/pieces/black/queen.png", - "King": "res/img/pieces/black/king.png", - "": "res/img/missing.png" - }, - "White": - { - "Pawn": "res/img/pieces/white/pawn.png", - "Rook": "res/img/pieces/white/rook.png", - "Knight": "res/img/pieces/white/knight.png", - "Bishop": "res/img/pieces/white/bishop.png", - "Queen": "res/img/pieces/white/queen.png", - "King": "res/img/pieces/white/king.png", - "": "res/img/missing.png" - }, - "": "res/img/missing.png" - } - } - } -} diff --git a/src/ChessPlusPlusState.cpp b/src/ChessPlusPlusState.cpp index b678099..255cf60 100644 --- a/src/ChessPlusPlusState.cpp +++ b/src/ChessPlusPlusState.cpp @@ -10,9 +10,9 @@ namespace chesspp ChessPlusPlusState::ChessPlusPlusState(Application &_app, sf::RenderWindow &disp) : AppState(disp) , app(_app) - , board_config(gfx_config) + , board_config(rc_config) , classic_factory(board_config) - , graphics(display, gfx_config, board_config) + , graphics(display, rc_config, board_config) , board(board_config, classic_factory.factory()) , p(-1, -1) , players(util::KeyIter diff --git a/src/ChessPlusPlusState.hpp b/src/ChessPlusPlusState.hpp index 5431e30..a5ab6b7 100644 --- a/src/ChessPlusPlusState.hpp +++ b/src/ChessPlusPlusState.hpp @@ -5,7 +5,7 @@ #include "TextureManager.hpp" #include "gfx/Graphics.hpp" #include "config/Configuration.hpp" -#include "config/GraphicsConfig.hpp" +#include "config/ResourceConfig.hpp" #include "board/Board.hpp" #include "factory/ClassicFactory.hpp" @@ -19,7 +19,7 @@ namespace chesspp class ChessPlusPlusState : public AppState { Application &app; - config::GraphicsConfig gfx_config; + config::ResourceConfig rc_config; config::BoardConfig board_config; factory::ClassicFactory classic_factory; gfx::GraphicsHandler graphics; diff --git a/src/config/BoardConfig.hpp b/src/config/BoardConfig.hpp index 7169d64..7dccaae 100644 --- a/src/config/BoardConfig.hpp +++ b/src/config/BoardConfig.hpp @@ -2,7 +2,7 @@ #define ChessPlusPlusBoardConfigurationManagerClass_HeaderPlusPlus #include "Configuration.hpp" -#include "GraphicsConfig.hpp" +#include "ResourceConfig.hpp" #include "util/Position.hpp" #include @@ -31,15 +31,15 @@ namespace chesspp Textures_t textures; public: - BoardConfig(GraphicsConfig const &gfx) - : Configuration("config/board.json") - , board_width (reader()["chesspp"]["board"]["width"] ) - , board_height (reader()["chesspp"]["board"]["height"] ) - , cell_width (reader()["chesspp"]["board"]["cell width"] ) - , cell_height (reader()["chesspp"]["board"]["cell height"]) + BoardConfig(ResourceConfig const &rcc) + : Configuration("config/chesspp/board.json") + , board_width (reader()["board"]["width"] ) + , board_height (reader()["board"]["height"] ) + , cell_width (reader()["board"]["cell width"] ) + , cell_height (reader()["board"]["cell height"]) { - auto pieces = reader()["chesspp"]["board"]["pieces"]; - auto suits = reader()["chesspp"]["board"]["suits"]; + auto pieces = reader()["board"]["pieces"]; + auto suits = reader()["board"]["suits"]; for(BoardSize_t r = 0; r < board_height; ++r) { for(BoardSize_t c = 0; c < board_width; ++c) @@ -53,12 +53,12 @@ namespace chesspp } } - auto const &tex = gfx.spritePaths("board", "pieces"); + auto const &tex = rcc.filePaths("board", "pieces"); for(auto const &suit : tex) { for(auto const &piece : suit.second.object()) { - textures[suit.first][piece.first] = gfx.normalize(Textures_t::mapped_type::mapped_type(piece.second)); + textures[suit.first][piece.first] = rcc.normalize(Textures_t::mapped_type::mapped_type(piece.second)); } } } @@ -74,7 +74,7 @@ namespace chesspp template util::JsonReader::NestedValue metadata(Args const &... path) const { - return reader.navigate("chesspp", "board", "metadata", path...); + return reader.navigate("board", "metadata", path...); } }; } diff --git a/src/config/GraphicsConfig.hpp b/src/config/GraphicsConfig.hpp deleted file mode 100644 index e7ac4d4..0000000 --- a/src/config/GraphicsConfig.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef ChessPlusPlusGraphicsConfigurationManagerClass_HeaderPlusPlus -#define ChessPlusPlusGraphicsConfigurationManagerClass_HeaderPlusPlus - -#include "Configuration.hpp" - -namespace chesspp -{ - namespace config - { - class GraphicsConfig : public Configuration - { - public: - GraphicsConfig() - : Configuration("config/graphics.json") - { - } - virtual ~GraphicsConfig() = default; - - std::string normalize(std::string const &path) const - { - return res_path + path; - } - template - std::string spritePath(Args const &... path) const - { - auto val = reader.navigate("chesspp", path...); - if(val.type() != json_string) - { - return normalize(reader()["chesspp"]["missing"]); - } - return normalize(val); - } - //Must normalize return value - template - auto spritePaths(Args const &... path) const -> std::map - { - return reader.navigate("chesspp", path...).object(); - } - }; - } -} - -#endif diff --git a/src/config/ResourceConfig.hpp b/src/config/ResourceConfig.hpp new file mode 100644 index 0000000..af4c9e8 --- /dev/null +++ b/src/config/ResourceConfig.hpp @@ -0,0 +1,43 @@ +#ifndef ChessPlusPlusResourceConfigurationManagerClass_HeaderPlusPlus +#define ChessPlusPlusResourceConfigurationManagerClass_HeaderPlusPlus + +#include "Configuration.hpp" + +namespace chesspp +{ + namespace config + { + class ResourceConfig : public Configuration + { + public: + ResourceConfig() + : Configuration("config/chesspp/resources.json") + { + } + virtual ~ResourceConfig() = default; + + std::string normalize(std::string const &path) const + { + return res_path + path; + } + template + std::string filePath(Args const &... path) const + { + auto val = reader.navigate(path...); + if(val.type() != json_string) + { + return normalize(reader()["missing"]); + } + return normalize(val); + } + //Must normalize return value + template + auto filePaths(Args const &... path) const -> std::map + { + return reader.navigate(path...).object(); + } + }; + } +} + +#endif diff --git a/src/gfx/Graphics.cpp b/src/gfx/Graphics.cpp index c6039e7..f503e33 100644 --- a/src/gfx/Graphics.cpp +++ b/src/gfx/Graphics.cpp @@ -9,15 +9,15 @@ namespace chesspp { namespace gfx { - GraphicsHandler::GraphicsHandler(sf::RenderWindow &disp, config::GraphicsConfig &gfxc, config::BoardConfig &bc) + GraphicsHandler::GraphicsHandler(sf::RenderWindow &disp, config::ResourceConfig &rcc, config::BoardConfig &bc) : display(disp) - , gfx_config(gfxc) + , rc_config(rcc) , board_config(bc) - , board (TextureManager::instance().load(gfx_config.spritePath("board", "board" ))) - , valid_move (TextureManager::instance().load(gfx_config.spritePath("board", "valid move" ))) - , enemy_move (TextureManager::instance().load(gfx_config.spritePath("board", "enemy move" ))) - , valid_capture(TextureManager::instance().load(gfx_config.spritePath("board", "valid capture"))) - , enemy_capture(TextureManager::instance().load(gfx_config.spritePath("board", "enemy capture"))) + , board (TextureManager::instance().load(rc_config.filePath("board", "board" ))) + , valid_move (TextureManager::instance().load(rc_config.filePath("board", "valid move" ))) + , enemy_move (TextureManager::instance().load(rc_config.filePath("board", "enemy move" ))) + , valid_capture(TextureManager::instance().load(rc_config.filePath("board", "valid capture"))) + , enemy_capture(TextureManager::instance().load(rc_config.filePath("board", "enemy capture"))) { } diff --git a/src/gfx/Graphics.hpp b/src/gfx/Graphics.hpp index e039a8f..c68e1eb 100644 --- a/src/gfx/Graphics.hpp +++ b/src/gfx/Graphics.hpp @@ -2,7 +2,7 @@ #define GraphicsHandlerClass_HeaderPlusPlus #include "SFML.hpp" -#include "config/GraphicsConfig.hpp" +#include "config/ResourceConfig.hpp" #include "config/BoardConfig.hpp" #include "board/Board.hpp" @@ -15,7 +15,7 @@ namespace chesspp class GraphicsHandler { sf::RenderWindow &display; - config::GraphicsConfig &gfx_config; + config::ResourceConfig &rc_config; config::BoardConfig &board_config; sf::Sprite board @@ -25,7 +25,7 @@ namespace chesspp , enemy_capture; public: - GraphicsHandler(sf::RenderWindow &display, config::GraphicsConfig &gfxc, config::BoardConfig &bc); + GraphicsHandler(sf::RenderWindow &display, config::ResourceConfig &rcc, config::BoardConfig &bc); //Draws the board background. void drawBackground();