diff --git a/Agent/Task/TASK-0003.md b/Agent/Task/TASK-0003.md index bad01ff..95ce4a1 100644 --- a/Agent/Task/TASK-0003.md +++ b/Agent/Task/TASK-0003.md @@ -1,5 +1,9 @@ # TASK-0003: BootFlowService и запуск сценария +## Статус + +Ready + ## Цель Реализовать внешний flow coordinator, который запускает и управляет сценарием загрузки приложения. diff --git a/Assets/Scripts/Boot/Composition/GameLifetimeScope.cs b/Assets/Scripts/Boot/Composition/GameLifetimeScope.cs index d2ee5f6..937f3dd 100644 --- a/Assets/Scripts/Boot/Composition/GameLifetimeScope.cs +++ b/Assets/Scripts/Boot/Composition/GameLifetimeScope.cs @@ -29,6 +29,9 @@ namespace QuizPleaseTest.Boot.Composition .As() .As(); + builder.Register(Lifetime.Singleton) + .As(); + builder.Register(Lifetime.Singleton) .As>() .AsSelf(); diff --git a/Assets/Scripts/Boot/Flow/BootFlowService.cs b/Assets/Scripts/Boot/Flow/BootFlowService.cs index e3923d4..849550f 100644 --- a/Assets/Scripts/Boot/Flow/BootFlowService.cs +++ b/Assets/Scripts/Boot/Flow/BootFlowService.cs @@ -1,19 +1,42 @@ using System.Threading; using Cysharp.Threading.Tasks; +using QuizPleaseTest.Boot.States; using QuizPleaseTest.Common.Services; +using QuizPleaseTest.Common.StateMachine; namespace QuizPleaseTest.Boot.Flow { public class BootFlowService : Service, IBootFlowService { - public override UniTask InitializeAsync(CancellationToken ct) + private readonly IStatesController _statesController; + + public BootFlowService(IStatesController statesController) { - return UniTask.CompletedTask; + _statesController = statesController; + } + + public override async UniTask InitializeAsync(CancellationToken ct) + { + await RunFlowAsync(ct); } public override UniTask ReleaseAsync(CancellationToken ct) { return UniTask.CompletedTask; } + + private async UniTask RunFlowAsync(CancellationToken ct) + { + await _statesController.EnterStateAsync(BootStateCode.Splash, ct); + await _statesController.EnterStateAsync(BootStateCode.Load, ct); + + while (!ct.IsCancellationRequested) + { + await _statesController.EnterStateAsync(BootStateCode.Menu, ct); + await _statesController.EnterStateAsync(BootStateCode.Load, ct); + } + + ct.ThrowIfCancellationRequested(); + } } } diff --git a/Assets/Scripts/Boot/Flow/IMenuRestartSignal.cs b/Assets/Scripts/Boot/Flow/IMenuRestartSignal.cs new file mode 100644 index 0000000..bd49427 --- /dev/null +++ b/Assets/Scripts/Boot/Flow/IMenuRestartSignal.cs @@ -0,0 +1,11 @@ +using System.Threading; +using Cysharp.Threading.Tasks; + +namespace QuizPleaseTest.Boot.Flow +{ + public interface IMenuRestartSignal + { + UniTask WaitAsync(CancellationToken ct); + void RequestRestart(); + } +} diff --git a/Assets/Scripts/Boot/Flow/IMenuRestartSignal.cs.meta b/Assets/Scripts/Boot/Flow/IMenuRestartSignal.cs.meta new file mode 100644 index 0000000..5c45f2e --- /dev/null +++ b/Assets/Scripts/Boot/Flow/IMenuRestartSignal.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a2222222222222222222222222222222 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Boot/Flow/MenuRestartSignal.cs b/Assets/Scripts/Boot/Flow/MenuRestartSignal.cs new file mode 100644 index 0000000..f6194af --- /dev/null +++ b/Assets/Scripts/Boot/Flow/MenuRestartSignal.cs @@ -0,0 +1,23 @@ +using System.Threading; +using Cysharp.Threading.Tasks; + +namespace QuizPleaseTest.Boot.Flow +{ + public class MenuRestartSignal : IMenuRestartSignal + { + private UniTaskCompletionSource _restartCompletionSource; + + public UniTask WaitAsync(CancellationToken ct) + { + ct.ThrowIfCancellationRequested(); + + _restartCompletionSource = new UniTaskCompletionSource(); + return _restartCompletionSource.Task.AttachExternalCancellation(ct); + } + + public void RequestRestart() + { + _restartCompletionSource?.TrySetResult(); + } + } +} diff --git a/Assets/Scripts/Boot/Flow/MenuRestartSignal.cs.meta b/Assets/Scripts/Boot/Flow/MenuRestartSignal.cs.meta new file mode 100644 index 0000000..db12321 --- /dev/null +++ b/Assets/Scripts/Boot/Flow/MenuRestartSignal.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a3333333333333333333333333333333 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Boot/States/MenuState.cs b/Assets/Scripts/Boot/States/MenuState.cs index e058b15..18dae41 100644 --- a/Assets/Scripts/Boot/States/MenuState.cs +++ b/Assets/Scripts/Boot/States/MenuState.cs @@ -1,5 +1,6 @@ using System.Threading; using Cysharp.Threading.Tasks; +using QuizPleaseTest.Boot.Flow; using QuizPleaseTest.Boot.UI; using QuizPleaseTest.Common.StateMachine; @@ -8,16 +9,18 @@ namespace QuizPleaseTest.Boot.States public class MenuState : IState { private readonly MenuUIView _view; + private readonly IMenuRestartSignal _restartSignal; - public MenuState(MenuUIView view) + public MenuState(MenuUIView view, IMenuRestartSignal restartSignal) { _view = view; + _restartSignal = restartSignal; } - public UniTask EnterAsync(CancellationToken ct) + public async UniTask EnterAsync(CancellationToken ct) { _view.Initialize(); - return UniTask.CompletedTask; + await _restartSignal.WaitAsync(ct); } public UniTask ExitAsync(CancellationToken ct)