-
Notifications
You must be signed in to change notification settings - Fork 2
/
ConfigLoader.cpp
97 lines (87 loc) · 2.8 KB
/
ConfigLoader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "ConfigLoader.h"
#include <iostream>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include "tools/SDLColorHelper.h"
void ConfigLoader::LoadConfig()
{
std::ifstream configFile( "config/Config.txt" );
std::string configLine;
while ( getline( configFile, configLine ) )
{
if ( configLine[0] == '#' || configLine.empty() )
continue;
std::stringstream ss(configLine);
std::string str;
ss >> str;
if ( configLine.find( "is_fast_mode" ) != std::string::npos )
{
std::string fastMode;
ss >> fastMode;
isFastMode = ( fastMode.find( "true" ) != std::string::npos );
}
else if ( configLine.find( "ball_speed_normal" ) != std::string::npos )
ss >> configValues[ ConfigValueType::BallSpeed ];
else if ( configLine.find( "ball_speed_fastmode" ) != std::string::npos )
ss >> configValues[ ConfigValueType::BallSpeed_FM ];
else if ( configLine.find( "bullet_speed" ) != std::string::npos )
ss >> configValues[ ConfigValueType::BulletSpeed ];
else if ( configLine.find( "bonus_box_speed" ) != std::string::npos )
ss >> configValues[ ConfigValueType::BonusBoxSpeed ];
else if ( configLine.find( "bonus_box_chance" ) != std::string::npos )
ss >> configValues[ ConfigValueType::BonusBoxChance ];
else if ( configLine.find( "points_regular" ) != std::string::npos )
ss >> points[TileType::Regular];
else if ( configLine.find( "points_hard" ) != std::string::npos )
ss >> points[TileType::Hard];
else if ( configLine.find( "points_explosive" ) != std::string::npos )
ss >> points[TileType::Explosive];
else if ( configLine.find( "points_unbreakable" ) != std::string::npos )
ss >> points[TileType::Unbreakable];
else if ( configLine.find( "points_hit" ) != std::string::npos )
ss >> configValues[ ConfigValueType::PointsHit ];
}
PrintConfig();
}
void ConfigLoader::PrintColor( const std::string &colorName, const SDL_Color &color )
{
PrintIndented( colorName );
std::cout << color;
}
void ConfigLoader::PrintIndented( const std::string &colorName )
{
std::cout << "\n\t" << std::setfill( '_' ) << std::setw( 23 ) << std::left << colorName;
}
void ConfigLoader::PrintConfig()
{
/*
for ( const auto &p : colorConfig )
{
if ( p.IsMultiColored() )
{
PrintIndented( p.GetTileTypeAsString() );
for ( int i = 0; i < 5; ++i )
{
std::stringstream ss;
ss << "\tColor[" << ( i + 1 ) << "]";
std::string str = "\t";
PrintColor( ss.str(), p.colors[i] );
}
}
else
{
PrintColor( p.GetTileTypeAsString(), p.colors[0] );
}
}
//std::cout << "\n\t" << p;
std::cout << std::endl;
*/
}
std::string ConfigLoader::RemoveCharacterFromString( std::string str, char ch )
{
auto newEnd = std::remove_if( str.begin(), str.end(), [&ch]( char c) { return c == ch; } );
str.erase( newEnd, str.end() );
return str;
}