using System; using DevilLink2.Gameplay; using DevilLink2.Persistence; using DevilLink2.Presentation; namespace DevilLink2.UI { /// Navigation adapter; delegates all game creation and abandonment to the existing bootstrap/flow. public sealed class ModeSelectionController : IDisposable { private readonly BoardDemoBootstrap bootstrap; private readonly SavedPlayer player; private GameFlowController boundFlow; public event Action LobbyRequested; public ModeSelectionController(BoardDemoBootstrap bootstrap, SavedPlayer player) { this.bootstrap = bootstrap; this.player = player; } public GameFlowController StartMode(GameMode mode) { Detach(); bootstrap.InitializePersistent(mode, player); boundFlow = bootstrap.Flow; boundFlow.LobbyRequested += OnLobby; return boundFlow; } public void ReturnToLobby() { boundFlow?.ReturnToLobby(); } private void OnLobby() { LobbyRequested?.Invoke(); } private void Detach() { if (boundFlow != null) boundFlow.LobbyRequested -= OnLobby; boundFlow = null; } public void Dispose() { Detach(); } } }