mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-09 20:08:57 +03:00
Game state switching now uses commands
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <src/Core/Core.h>
|
||||
#include <src/Scene/Scene.h>
|
||||
#include <src/Resource/Project.h>
|
||||
|
||||
#include <Engine.h>
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
@@ -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 });
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user