namespace Engine.Scene;

public class SceneManager : IUpdate, IRender
{
  public Scene? CurrentScene => _currentScene;

  private Scene? _currentScene;
  private Func<Scene>? _nextScene;

  public void TransitionTo(Func<Scene>? parScene)
  {
    _nextScene = parScene;
  }

  public void Update(double parDeltaTime)
  {
    if (_nextScene != null)
    {
      _currentScene?.Exit();
      _currentScene = _nextScene();
      _nextScene = null;
      _currentScene.Enter();
    }

    if (parDeltaTime != 0)
      _currentScene?.Update(parDeltaTime);
  }

  public void Render()
  {
    _currentScene?.Render();
  }
}