diff --git a/config.yml b/config.yml index 40fc54b..2121ca1 100644 --- a/config.yml +++ b/config.yml @@ -4,7 +4,7 @@ general: # Players config players: - width: 100 + width: 'aza' startXPosition: 50 fireCooldown: 10 speed: 20 diff --git a/headers/configManagement.h b/headers/configManagement.h index 0b2b59e..626f10c 100644 --- a/headers/configManagement.h +++ b/headers/configManagement.h @@ -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& vec) const; diff --git a/headers/utils.h b/headers/utils.h index 8d50f19..ebd50ef 100644 --- a/headers/utils.h +++ b/headers/utils.h @@ -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 diff --git a/src/configManagement.cpp b/src/configManagement.cpp index 545d363..32318e4 100644 --- a/src/configManagement.cpp +++ b/src/configManagement.cpp @@ -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& 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); diff --git a/src/drawMenu.cpp b/src/drawMenu.cpp index 5cc7aea..1eaa665 100644 --- a/src/drawMenu.cpp +++ b/src/drawMenu.cpp @@ -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; + } } } } diff --git a/src/game/godManager.cpp b/src/game/godManager.cpp index b2d4644..f1cf045 100644 --- a/src/game/godManager.cpp +++ b/src/game/godManager.cpp @@ -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() { diff --git a/src/main.cpp b/src/main.cpp index 52e01c0..b9cea9e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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; } \ No newline at end of file