Transposer/TransposerSceneManager.cs
namespace Sandbox.Transposer;
/// <summary>
/// Manages switching between the MainMenu and Game scenes.
/// Holds both scene instances and delegates update calls to the active one.
/// </summary>
public class TransposerSceneManager
{
private readonly Dictionary<SceneType, TransposerScene> _scenes = new();
private TransposerScene _currentScene;
private SceneType _currentSceneType;
public TransposerScene CurrentScene => _currentScene;
public SceneType CurrentSceneType => _currentSceneType;
public TransposerSceneManager()
{
GameScene gameScene = new();
gameScene.SceneManager = this;
_scenes[SceneType.Game] = gameScene;
MainMenuScene menuScene = new();
menuScene.SceneManager = this;
_scenes[SceneType.MainMenu] = menuScene;
}
/// <summary>
/// Start the game by activating the MainMenu scene.
/// </summary>
public void Begin()
{
SetScene( SceneType.MainMenu );
}
/// <summary>
/// Deactivate the current scene and activate the new one.
/// </summary>
public void SetScene( SceneType sceneType )
{
if ( !_scenes.TryGetValue( sceneType, out TransposerScene scene ) )
{
Log.Error( $"TransposerSceneManager: no scene of type {sceneType}" );
return;
}
_currentScene?.Deactivate();
_currentScene = scene;
_currentSceneType = sceneType;
_currentScene.Activate();
}
/// <summary>
/// Tick the active scene. Call once per frame after input polling.
/// </summary>
public void Update( float deltaTime )
{
_currentScene?.UpdateScene( deltaTime );
}
}