Skip to content

Commit 3037d75

Browse files
author
Thumperrr
committed
Modified GraphicsHandler and AppStateGame to use Configuration, instead of declaring hardcoded paths.
1 parent da0042a commit 3037d75

File tree

4 files changed

+11
-19
lines changed

4 files changed

+11
-19
lines changed

src/AppStateGame.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
#include "AppState.h"
22

3-
const std::string FILEPATH = "C:/Users/Steve/Documents/Visual Studio 2012/Projects/ChessPlusPlus/";
4-
53
namespace chesspp
64
{
75
AppStateGame::AppStateGame( Application* _app, sf::RenderWindow *_display ) : app(_app), AppState(_display), graphics(display)
86
{
9-
10-
std::string gamePath(FILEPATH + "res/games/new_game.txt");
117
board = new Board();
12-
board->newGame(gamePath);
8+
board->newGame(configuration::instance().getBoardInitialLayout());
139
}
1410

1511
int AppStateGame::id() { return 1; }

src/AppStateGame.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "SFML.hpp"
44
#include "TextureManager.h"
55
#include "Graphics.h"
6+
#include "Configuration.h"
67
#include "board/Board.h"
78

89
#ifdef _DEBUG

src/Graphics.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@ namespace chesspp
66
{
77

88

9-
GraphicsHandler::GraphicsHandler( sf::RenderWindow *_display ) : display(_display),
10-
backgroundPath(file_path + "res/img/chessboard_640x640.png"), // Hardcoded. Will change in the future.
11-
piecePath(file_path + "res/img/chess_pieces_80x80_each.png"), //
12-
validMovePath(file_path + "res/img/valid_move.png") //
9+
GraphicsHandler::GraphicsHandler( sf::RenderWindow *_display )
10+
: display(_display),
11+
cell_size(configuration::instance().getCellWidth())
1312
{
1413
try
1514
{
16-
board = sf::Sprite(TextureManager::getInstance().Load(backgroundPath));
17-
pieces = sf::Sprite(TextureManager::getInstance().Load(piecePath));
18-
validMove = sf::Sprite(TextureManager::getInstance().Load(validMovePath));
19-
}
15+
board = sf::Sprite(TextureManager::getInstance().Load(configuration::instance().getSpritePath_board()));
16+
pieces = sf::Sprite(TextureManager::getInstance().Load(configuration::instance().getSpritePath_pieces()));
17+
validMove = sf::Sprite(TextureManager::getInstance().Load(configuration::instance().getSpritePath_validMove()));
18+
}
2019
catch (chesspp::exception &e)
2120
{
2221
#ifdef _DEBUG

src/Graphics.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "SFML.hpp"
55
#include "TextureManager.h"
6+
#include "Configuration.h"
67
#include "board/Piece.h"
78
#include "board/logger.h"
89

@@ -15,11 +16,6 @@ namespace chesspp
1516
{
1617
namespace graphics
1718
{
18-
const std::string file_path = "C:/Users/Steve/Documents/Visual Studio 2012/Projects/ChessPlusPlus/";
19-
const int cell_size = 80;
20-
const int board_width = 8;
21-
const int board_height = 0; //Working on a game configuration interface so these don't have to be hard coded.
22-
2319
class GraphicsHandler
2420
{
2521

@@ -47,7 +43,7 @@ namespace chesspp
4743

4844
private:
4945
sf::Sprite board, pieces, validMove;
50-
std::string backgroundPath, piecePath, validMovePath;
46+
const int cell_size;
5147
sf::RenderWindow *display;
5248
};
5349
}

0 commit comments

Comments
 (0)