Shape added

This commit is contained in:
Savya Bikram Shah
2026-05-29 15:02:24 +05:45
parent 7a4bd29b57
commit b4d10f62cb
25 changed files with 1097 additions and 27 deletions

View File

@@ -13,5 +13,6 @@ public interface IColoringController
void PaintRegion(string regionId, Color color);
IReadOnlyDictionary<string, Color> GetCurrentColors();
UniTask PlayCompletionAnimationAsync(CancellationToken ct);
void Clear();
}

View File

@@ -84,6 +84,19 @@ public class ColoringController : IColoringController, IDisposable
return snapshot;
}
public async UniTask PlayCompletionAnimationAsync(CancellationToken ct)
{
if (_colorInstance == null) return;
var animator = _colorInstance.GetComponentInChildren<Animator>(includeInactive: true);
if (animator == null || animator.runtimeAnimatorController == null) return;
animator.Play(0, 0, 0f);
animator.Update(0f);
var length = animator.GetCurrentAnimatorStateInfo(0).length;
if (length <= 0f) return;
await UniTask.Delay(TimeSpan.FromSeconds(length), cancellationToken: ct);
}
public void Clear()
{
_history.Drop();

View File

@@ -1,6 +1,7 @@
using Darkmatter.Core.Contracts.Features.GameplayFlow;
using Darkmatter.Features.GameplayFlow.SceneRefs;
using Darkmatter.Features.GameplayFlow.Systems;
using Darkmatter.Features.GameplayFlow.UI;
using Darkmatter.Libs.Installers;
using UnityEngine;
using VContainer;
@@ -11,6 +12,8 @@ namespace Darkmatter.Features.GameplayFlow
public class GameplayFlowFeatureModule : MonoBehaviour, IModule
{
[SerializeField] private GameplaySceneRefs sceneRefs;
[SerializeField] private NextButtonView nextButtonView;
[SerializeField] private BackButtonView backButtonView;
public void Register(IContainerBuilder builder)
{
@@ -20,6 +23,12 @@ namespace Darkmatter.Features.GameplayFlow
builder.Register<GameplayFlowController>(Lifetime.Singleton)
.As<IGameplayFlowController>()
.As<IAsyncStartable>();
if (nextButtonView != null)
builder.RegisterEntryPoint<NextButtonPresenter>().WithParameter(nextButtonView);
if (backButtonView != null)
builder.RegisterEntryPoint<BackButtonPresenter>().WithParameter(backButtonView);
}
}
}

View File

@@ -106,9 +106,11 @@ namespace Darkmatter.Features.GameplayFlow.Systems
public async UniTask BackAsync(CancellationToken ct)
{
await SaveCurrentAsync(CancellationToken.None);
_loadingScreen.Show();
_shapeBuilder.Clear();
_coloring.Clear();
await _scenes.LoadSceneAsync(GameScene.Colorbook, progress: null, cancellationToken: ct);
await _scenes.UnloadSceneAsync(GameScene.Gameplay, progress: null, cancellationToken: ct);
}
public async UniTask SaveAsync(CancellationToken ct)
@@ -120,12 +122,17 @@ namespace Darkmatter.Features.GameplayFlow.Systems
public async UniTask NextAsync(CancellationToken ct)
{
await SaveCurrentAsync(ct);
await _coloring.PlayCompletionAnimationAsync(ct);
_progression.MarkCompleted(_templateId);
var nextId = _catalog.GetNextTemplate(_templateId);
if (string.IsNullOrEmpty(nextId))
{
_loadingScreen.Show();
_shapeBuilder.Clear();
_coloring.Clear();
await _scenes.LoadSceneAsync(GameScene.Colorbook, progress: null, cancellationToken: default);
await _scenes.UnloadSceneAsync(GameScene.Gameplay, progress: null, cancellationToken: default);
return;
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0d25e0f770e2843b1bfcfc70127113a5
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,44 @@
using System;
using Cysharp.Threading.Tasks;
using Darkmatter.Core.Contracts.Features.GameplayFlow;
using VContainer.Unity;
namespace Darkmatter.Features.GameplayFlow.UI
{
public class BackButtonPresenter : IStartable, IDisposable
{
private readonly BackButtonView _view;
private readonly IGameplayFlowController _flow;
public BackButtonPresenter(BackButtonView view, IGameplayFlowController flow)
{
_view = view;
_flow = flow;
}
public void Start()
{
_view.OnBackClicked += HandleBackClicked;
}
private void HandleBackClicked() => BackAsync().Forget();
private async UniTaskVoid BackAsync()
{
_view.SetInteractable(false);
try
{
await _flow.BackAsync(default);
}
finally
{
_view.SetInteractable(true);
}
}
public void Dispose()
{
_view.OnBackClicked -= HandleBackClicked;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: c389d35e3758a429abbf74013ad72c68

View File

@@ -0,0 +1,29 @@
using System;
using UnityEngine;
using UnityEngine.UI;
namespace Darkmatter.Features.GameplayFlow.UI
{
public class BackButtonView : MonoBehaviour
{
[SerializeField] private Button backButton;
public event Action OnBackClicked;
private void Awake()
{
if (backButton != null)
backButton.onClick.AddListener(() => OnBackClicked?.Invoke());
}
public void SetInteractable(bool value)
{
if (backButton != null) backButton.interactable = value;
}
private void OnDestroy()
{
if (backButton != null) backButton.onClick.RemoveAllListeners();
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b7254cdaad34b4d6fa607b0520ea5b4c

View File

@@ -0,0 +1,52 @@
using System;
using Cysharp.Threading.Tasks;
using Darkmatter.Core.Contracts.Features.GameplayFlow;
using Darkmatter.Core.Data.Signals.Features.Coloring;
using Darkmatter.Libs.Observer;
using VContainer.Unity;
namespace Darkmatter.Features.GameplayFlow.UI
{
public class NextButtonPresenter : IStartable, IDisposable
{
private readonly NextButtonView _view;
private readonly IGameplayFlowController _flow;
private readonly IEventBus _bus;
private IDisposable _colorSub;
public NextButtonPresenter(NextButtonView view, IGameplayFlowController flow, IEventBus bus)
{
_view = view;
_flow = flow;
_bus = bus;
}
public void Start()
{
_view.Hide();
_view.OnNextClicked += HandleNextClicked;
_colorSub = _bus.Subscribe<ColorAppliedSignal>(_ => _view.Show());
}
private void HandleNextClicked() => NextAsync().Forget();
private async UniTaskVoid NextAsync()
{
_view.SetInteractable(false);
try
{
await _flow.NextAsync(default);
}
finally
{
_view.SetInteractable(true);
}
}
public void Dispose()
{
_view.OnNextClicked -= HandleNextClicked;
_colorSub?.Dispose();
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 06e4d4a98bf0e45de98a7960005542a0

View File

@@ -0,0 +1,32 @@
using System;
using UnityEngine;
using UnityEngine.UI;
namespace Darkmatter.Features.GameplayFlow.UI
{
public class NextButtonView : MonoBehaviour
{
[SerializeField] private Button nextButton;
public event Action OnNextClicked;
private void Awake()
{
if (nextButton != null)
nextButton.onClick.AddListener(() => OnNextClicked?.Invoke());
}
public void Show() => gameObject.SetActive(true);
public void Hide() => gameObject.SetActive(false);
public void SetInteractable(bool value)
{
if (nextButton != null) nextButton.interactable = value;
}
private void OnDestroy()
{
if (nextButton != null) nextButton.onClick.RemoveAllListeners();
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e41584b03d9144e55b851c6db449aadb