ModeSelectionController.cs 1.2 KB

12345678910111213141516171819202122232425262728
  1. using System;
  2. using DevilLink2.Gameplay;
  3. using DevilLink2.Persistence;
  4. using DevilLink2.Presentation;
  5. namespace DevilLink2.UI
  6. {
  7. /// <summary>Navigation adapter; delegates all game creation and abandonment to the existing bootstrap/flow.</summary>
  8. public sealed class ModeSelectionController : IDisposable
  9. {
  10. private readonly BoardDemoBootstrap bootstrap;
  11. private readonly SavedPlayer player;
  12. private GameFlowController boundFlow;
  13. public event Action LobbyRequested;
  14. public ModeSelectionController(BoardDemoBootstrap bootstrap, SavedPlayer player)
  15. { this.bootstrap = bootstrap; this.player = player; }
  16. public GameFlowController StartMode(GameMode mode)
  17. {
  18. Detach(); bootstrap.InitializePersistent(mode, player); boundFlow = bootstrap.Flow;
  19. boundFlow.LobbyRequested += OnLobby;
  20. return boundFlow;
  21. }
  22. public void ReturnToLobby() { boundFlow?.ReturnToLobby(); }
  23. private void OnLobby() { LobbyRequested?.Invoke(); }
  24. private void Detach() { if (boundFlow != null) boundFlow.LobbyRequested -= OnLobby; boundFlow = null; }
  25. public void Dispose() { Detach(); }
  26. }
  27. }