From e0b655078786cb449d430008c81418a51e6dfced Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 19 Oct 2024 17:22:25 +0300 Subject: [PATCH] implemented toggle-debug command --- CMakeLists.txt | 2 +- console.cpp | 5 ++++- game.cpp | 24 +++++++++++++----------- game.h | 4 +++- toggleDebugCommand.cpp | 16 ++++++++++++++++ toggleDebugCommand.h | 16 ++++++++++++++++ 6 files changed, 53 insertions(+), 14 deletions(-) create mode 100644 toggleDebugCommand.cpp create mode 100644 toggleDebugCommand.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a7a592d..d9efa87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,7 @@ set(GUI tooltip.cpp concreteGuiManager.cpp ${BUTTONS} ${LISTBOXES}) set(STATES activeGameState.cpp inGameAppState.cpp guiAppState.cpp mapEditorAppState.cpp) set(UTIL util.cpp binds.h) set(CONTROLLERS gameObjectFrameController.cpp cameraController.cpp) -set(CONSOLE console.cpp abstractCommand.cpp addUnitCommand.cpp addResourceCommand.cpp addTechnologyCommand.cpp) +set(CONSOLE console.cpp abstractCommand.cpp addUnitCommand.cpp addResourceCommand.cpp addTechnologyCommand.cpp toggleDebugCommand.cpp) set(CORE gameManager.cpp game.cpp fxManager.cpp defConfigs.cpp ${CONSOLE} ${CONTROLLERS}) set(PROJECTILES projectile.cpp cruiseMissile.cpp) set(VEHICLES vehicle.cpp engineer.cpp resourceRover.cpp) diff --git a/console.cpp b/console.cpp index 58206f7..0b2c38c 100755 --- a/console.cpp +++ b/console.cpp @@ -2,13 +2,14 @@ #include "addUnitCommand.h" #include "addResourceCommand.h" #include "addTechnologyCommand.h" +#include "toggleDebugCommand.h" using namespace std; namespace battleship{ void Console::execute(string cmdStr) { int space = cmdStr.find(" "); - string cmdName, argsStr; + string cmdName = cmdStr, argsStr = ""; if(space != -1){ cmdName = cmdStr.substr(0, space); @@ -21,5 +22,7 @@ namespace battleship{ AddResourceCommand(argsStr).execute(); else if(cmdName == "add-technology") AddTechnologyCommand(argsStr).execute(); + else if(cmdName == "toggle-debug") + ToggleDebugCommand(argsStr).execute(); } } diff --git a/game.cpp b/game.cpp index 203c333..4e80bb4 100644 --- a/game.cpp +++ b/game.cpp @@ -118,22 +118,24 @@ namespace battleship{ AssetManager::getSingleton()->load(gm->getPath() + gop, true); AssetManager::getSingleton()->load(gm->getPath() + vfxp, true); - vector gameObjs; + if(debug){ + vector gameObjs; - for(Player *pl : Game::getSingleton()->getPlayers()){ - for(Unit *u : pl->getUnits()) - gameObjs.push_back((GameObject*)u); + for(Player *pl : Game::getSingleton()->getPlayers()){ + for(Unit *u : pl->getUnits()) + gameObjs.push_back((GameObject*)u); - for(Projectile *proj : pl->getProjectiles()) - gameObjs.push_back((GameObject*)proj); + for(Projectile *proj : pl->getProjectiles()) + gameObjs.push_back((GameObject*)proj); - for(ResourceDeposit *dep : pl->getResourceDeposits()) - gameObjs.push_back((GameObject*)dep); + for(ResourceDeposit *dep : pl->getResourceDeposits()) + gameObjs.push_back((GameObject*)dep); + } + + for(GameObject *obj : gameObjs) + obj->reinit(); } - for(GameObject *obj : gameObjs) - obj->reinit(); - gm->getStateManager()->attachAppState(activeState); } diff --git a/game.h b/game.h index 5899048..26aa1d5 100644 --- a/game.h +++ b/game.h @@ -28,8 +28,10 @@ namespace battleship{ float calcAbilFromTech(Ability::Type, std::vector, int, int); bool isUnitUnlocked(std::vector, int); std::vector findTradeOffers(Player*, Player*); + inline void setDebug(bool d){this->debug = d;} inline void addTradeOffer(TradeOffer *to){tradeOffers.push_back(to);} inline void addPlayer(Player *pl){players.push_back(pl);} + inline bool isDebug(){return debug;} inline std::vector& getPlayers(){return players;} inline Player* getPlayer(int id){return players[id];} inline int getNumPlayers(){return players.size();} @@ -41,7 +43,7 @@ namespace battleship{ void endGame(bool); std::vector parseTechTable(int, std::string, std::string, std::string); - bool paused = false, ended = false; + bool paused = false, ended = false, debug = false; std::vector technologies; std::vector abilities; std::vector players; diff --git a/toggleDebugCommand.cpp b/toggleDebugCommand.cpp new file mode 100644 index 0000000..02636fd --- /dev/null +++ b/toggleDebugCommand.cpp @@ -0,0 +1,16 @@ +#include "toggleDebugCommand.h" +#include "game.h" + +namespace battleship{ + void ToggleDebugCommand::validate(){ + if(!arguments.empty()) return; + } + + void ToggleDebugCommand::execute(){ + AbstractCommand::handle(); + validate(); + + Game *game = Game::getSingleton(); + game->setDebug(!game->isDebug()); + } +} diff --git a/toggleDebugCommand.h b/toggleDebugCommand.h new file mode 100644 index 0000000..794a795 --- /dev/null +++ b/toggleDebugCommand.h @@ -0,0 +1,16 @@ +#ifndef TOGGLE_DEBUG_COMMAND_H +#define TOGGLE_DEBUG_COMMAND_H + +#include "abstractCommand.h" + +namespace battleship{ + class ToggleDebugCommand : public AbstractCommand{ + public: + ToggleDebugCommand(std::string str) : AbstractCommand(str){} + void validate(); + void execute(); + private: + }; +} + +#endif