Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions config/board.json

This file was deleted.

46 changes: 46 additions & 0 deletions config/chesspp/board.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
35 changes: 35 additions & 0 deletions config/chesspp/resources.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
38 changes: 0 additions & 38 deletions config/graphics.json

This file was deleted.

4 changes: 2 additions & 2 deletions src/ChessPlusPlusState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<config::BoardConfig::Textures_t>
Expand Down
4 changes: 2 additions & 2 deletions src/ChessPlusPlusState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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;
Expand Down
24 changes: 12 additions & 12 deletions src/config/BoardConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define ChessPlusPlusBoardConfigurationManagerClass_HeaderPlusPlus

#include "Configuration.hpp"
#include "GraphicsConfig.hpp"
#include "ResourceConfig.hpp"
#include "util/Position.hpp"

#include <string>
Expand Down Expand Up @@ -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)
Expand All @@ -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));
}
}
}
Expand All @@ -74,7 +74,7 @@ namespace chesspp
template<typename... Args>
util::JsonReader::NestedValue metadata(Args const &... path) const
{
return reader.navigate("chesspp", "board", "metadata", path...);
return reader.navigate("board", "metadata", path...);
}
};
}
Expand Down
43 changes: 0 additions & 43 deletions src/config/GraphicsConfig.hpp

This file was deleted.

43 changes: 43 additions & 0 deletions src/config/ResourceConfig.hpp
Original file line number Diff line number Diff line change
@@ -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<typename... Args>
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<typename... Args>
auto filePaths(Args const &... path) const -> std::map<std::string, util::JsonReader::NestedValue>
{
return reader.navigate(path...).object();
}
};
}
}

#endif
14 changes: 7 additions & 7 deletions src/gfx/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
{
}

Expand Down
6 changes: 3 additions & 3 deletions src/gfx/Graphics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand All @@ -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();
Expand Down