This commit is contained in:
Thomas 2022-01-09 18:41:27 +01:00
parent a81ec496a6
commit 04a7a63a25
No known key found for this signature in database
GPG Key ID: E538821A6CDFDAD7
7 changed files with 31 additions and 14 deletions

View File

@ -4,7 +4,7 @@ general:
# Players config
players:
width: 100
width: 'aza'
startXPosition: 50
fireCooldown: 10
speed: 20

View File

@ -32,7 +32,7 @@ private:
char getChar(const configKey& key) const;
int getInt(const configKey& key) const;
int getInt(const configKey& key, int def) const;
void getColor(const configKey& key, nsGraphics::RGBAcolor& color, nsGraphics::RGBAcolor& def) const;
void getColor(const configKey& key, nsGraphics::RGBAcolor& color, const nsGraphics::RGBAcolor& def) const;
void getColor(const configKey& key, nsGraphics::RGBAcolor& color) const;
void getList(const configKey& key, vector<string>& vec) const;

View File

@ -26,12 +26,14 @@
// Syntax : DEBUG(cout << "hey" << endl)
// The debug flag defintion has been set here, but normally we would add it to the MakeFile
#define DEBUG_FLAG
//#define DEBUG_FLAG
#ifdef DEBUG_FLAG
#define DEBUG(X) X;
#define DEBUG_MSG(X) cerr << "DEBUG: " << X << endl;
#define DEBUG_INSTR(X) X;
#else
#define DEBUG(X)
#define DEBUG_MSG(X)
#define DEBUG_INSTR(X)
#endif

View File

@ -154,7 +154,7 @@ void ConfigBuilder::readConfig() {
readGrid("grid");
// players
collectedData.playersWidth = getInt("players.width");
collectedData.playersWidth = getInt("players.width", 5);
collectedData.startXPosition = getInt("players.startXPosition");
collectedData.playersSpeed = getInt("players.speed");
collectedData.playersFireCooldown = getInt("players.fireCooldown");
@ -192,13 +192,16 @@ const string& ConfigBuilder::getString(const configKey& key, const string& def)
try{
return getString(key);
}catch(config_error& e){
cerr << e.what() << endl;
cerr << e.what() << " . Using default value" << endl;
return def;
}
}
const string& ConfigBuilder::getString(const configKey& key) const {
DEBUG_MSG("Querying config key " << key)
if(internalValues.contains(key)){
// We don't really care about querying the key two time since we are... well, in debug mode
DEBUG_MSG("Got config value " << internalValues.at(key))
return internalValues.at(key);
}else{
throw config_error("Non-existent key requested : "+key);
@ -218,7 +221,7 @@ int ConfigBuilder::getInt(const configKey& key, int def) const {
try{
return getInt(key);
}catch(config_error& e){
cerr << e.what() << endl;
cerr << e.what() << " . Using default value" << endl;
return def;
}
}
@ -233,7 +236,7 @@ char ConfigBuilder::getChar(const configKey& key, char def) const {
try{
return getChar(key);
}catch(config_error& e){
cerr << e.what() << endl;
cerr << e.what() << " . Using default value" << endl;
return def;
}
}
@ -250,6 +253,15 @@ void ConfigBuilder::getList(const configKey& key, vector<string>& toPopulate) co
}while(internalValues.contains(key+"."+to_string(i)));
}
void ConfigBuilder::getColor(const configKey& key, nsGraphics::RGBAcolor& color, const nsGraphics::RGBAcolor& def) const {
try{
getColor(key, color);
}catch(config_error& e){
cerr << e.what() << " . Using default value" << endl;
color = def;
}
}
void ConfigBuilder::getColor(const configKey& key, nsGraphics::RGBAcolor& color) const {
// switch do not work with strings, and I don't want to implement a constexpr hash function
string colorStr = getString(key);

View File

@ -145,10 +145,13 @@ bool PixelManager::showDeathMenu() {
}// select option
else if (window.isPressed({13, false})){
switch(death.currentValue){
case 0:
case 0:{
return true;
case 1:
}
case 1:{
window.resetKey({13, false});
return false;
}
}
}
}

View File

@ -20,7 +20,7 @@ void Game::awakeGod() {
*/
/*
* This is a really long function, but I feel like it's still readable because of the switch, and..
* This is a really long function, but I feel like it's still readable because of the switch, and...
* Honestly I think splitting it into multiple small functions would be ugly
*/
bool Game::manageGod() {

View File

@ -18,12 +18,12 @@ using namespace std;
// TODO changer tout les unsigned par des size_t dans les boucles
int main(){
DEBUG(cout << "Starting program" << endl)
DEBUG_MSG("Starting program")
srand(time(NULL));
Game g;
g.managedGames();
DEBUG(cout << "Finished program. Goodbye !" << endl)
DEBUG_MSG("Finished program. Goodbye !")
return 0;
}