diff --git a/Editor/src/Commands/Commands/Commands.cpp b/Editor/src/Commands/Commands/Commands.cpp index 90dcc97b..e94f69d2 100644 --- a/Editor/src/Commands/Commands/Commands.cpp +++ b/Editor/src/Commands/Commands/Commands.cpp @@ -16,4 +16,21 @@ namespace NuakeEditor return true; } + + bool SetGameState::Execute() + { + GameState gameState = Engine::GetGameState(); + if (gameState == GameState::Stopped && mGameState == GameState::Playing) + { + Engine::EnterPlayMode(); + } + else if (mGameState == GameState::Stopped) + { + Engine::ExitPlayMode(); + } + + Engine::SetGameState(mGameState); + + return true; + } } \ No newline at end of file diff --git a/Editor/src/Commands/Commands/Commands.h b/Editor/src/Commands/Commands/Commands.h index a1d8737a..d87b6717 100644 --- a/Editor/src/Commands/Commands/Commands.h +++ b/Editor/src/Commands/Commands/Commands.h @@ -5,7 +5,7 @@ #include #include #include - +#include namespace NuakeEditor { using namespace Nuake; @@ -32,4 +32,18 @@ namespace NuakeEditor { bool Execute() override; }; + // GameState + class SetGameState : public ICommand + { + private: + GameState mGameState; + + public: + SetGameState(GameState gameState) : + mGameState(gameState) + { + } + + bool Execute() override; + }; } \ No newline at end of file diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index b7a09b9e..e918d80b 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -344,7 +344,8 @@ namespace Nuake { { if (Engine::GetGameState() == GameState::Paused) { - Engine::SetGameState(GameState::Playing); + PushCommand(SetGameState(GameState::Playing)); + std::string statusMessage = ICON_FA_RUNNING + std::string(" Playing..."); SetStatusMessage(statusMessage.c_str(), { 97.0 / 255.0, 0, 1, 1 }); } @@ -363,7 +364,8 @@ namespace Nuake { JobSystem::Get().Dispatch(job, [this]() { SetStatusMessage("Entering play mode..."); - Engine::EnterPlayMode(); + + PushCommand(SetGameState(GameState::Playing)); std::string statusMessage = ICON_FA_RUNNING + std::string(" Playing..."); SetStatusMessage(statusMessage.c_str(), { 97.0 / 255.0, 0, 1, 1 }); diff --git a/Nuake/Engine.cpp b/Nuake/Engine.cpp index 900c1595..eb52e563 100644 --- a/Nuake/Engine.cpp +++ b/Nuake/Engine.cpp @@ -83,7 +83,7 @@ namespace Nuake s_LastFrameTime = (float)glfwGetTime();; // Reset timestep timer. // Dont trigger init if already in player mode. - if (s_GameState == GameState::Playing) + if (GetGameState() == GameState::Playing) { Logger::Log("Cannot enter play mode if is already in play mode.", "engine", WARNING); return; @@ -91,7 +91,7 @@ namespace Nuake if (GetCurrentScene()->OnInit()) { - s_GameState = GameState::Playing; + SetGameState(GameState::Playing); } else {